Skip to content

Commit

Permalink
Merge branch 'NervJS:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
heweishui committed Jan 29, 2024
2 parents 9864c52 + 599390e commit 0a95b76
Show file tree
Hide file tree
Showing 27 changed files with 631 additions and 57 deletions.
6 changes: 5 additions & 1 deletion packages/taro-cli/src/__tests__/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('inspect', () => {
platform: undefined,
publicPath: undefined,
isWatch: false,
withoutBuild: false,
env: undefined,
blended: false,
assetsDest: undefined,
Expand Down Expand Up @@ -168,7 +169,9 @@ describe('inspect', () => {
name: 'convert',
opts: {
_: ['convert'],
options: {},
options: {
build: true,
},
isHelp: false
}
})
Expand All @@ -188,6 +191,7 @@ describe('inspect', () => {
opts: {
_,
options: {
build: true,
type
},
isHelp: true
Expand Down
11 changes: 8 additions & 3 deletions packages/taro-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export default class CLI {
assetsDest: ['assets-dest'], // specially for rn, Directory name where to store assets referenced in the bundle.
envPrefix: ['env-prefix'],
},
boolean: ['version', 'help', 'disable-global-config']
boolean: ['version', 'help', 'disable-global-config'],
default: {
build: true,
},
})
const _ = args._
const command = _[0]
Expand Down Expand Up @@ -166,10 +169,12 @@ export default class CLI {
platform,
plugin,
isWatch: Boolean(args.watch),
// 是否把 Taro 组件编译为原生自定义组件
// Note: 是否把 Taro 组件编译为原生自定义组件
isBuildNativeComp: _[1] === 'native-components',
// 新的混合编译模式,支持把组件单独编译为原生组件
// Note: 新的混合编译模式,支持把组件单独编译为原生组件
newBlended: Boolean(args['new-blended']),
// Note: 是否禁用编译
withoutBuild: !args.build,
port: args.port,
env: args.env,
deviceType: args.platform,
Expand Down
7 changes: 5 additions & 2 deletions packages/taro-cli/src/presets/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default (ctx: IPluginContext) => {
'--env [env]': 'Value for process.env.NODE_ENV',
'--mode [mode]': 'Value of dotenv extname',
'-p, --port [port]': 'Specified port',
'--no-build': 'Do not build project',
'--platform': '[rn] Specific React-Native build target: android / ios, android is default value',
'--reset-cache': '[rn] Clear transform cache',
'--public-path': '[rn] Assets public path',
Expand All @@ -35,15 +36,16 @@ export default (ctx: IPluginContext) => {
'taro build --type weapp --watch',
'taro build --type weapp --env production',
'taro build --type weapp --blended',
'taro build --type weapp --no-build',
'taro build native-components --type weapp',
'taro build --type weapp --new-blended',
'taro build --plugin weapp --watch',
'taro build --plugin weapp',
'taro build --type weapp --mode prepare --env-prefix TARO_APP_'
'taro build --type weapp --mode prepare --env-prefix TARO_APP_',
],
async fn (opts) {
const { options, config, _ } = opts
const { platform, isWatch, blended, newBlended } = options
const { platform, isWatch, blended, newBlended, withoutBuild } = options
const { fs, chalk, PROJECT_CONFIG } = ctx.helper
const { outputPath, configPath } = ctx.paths

Expand Down Expand Up @@ -110,6 +112,7 @@ export default (ctx: IPluginContext) => {
mode: isProduction ? 'production' : 'development',
blended,
isBuildNativeComp,
withoutBuild,
newBlended,
async modifyWebpackChain (chain, webpack, data) {
await ctx.applyPlugins({
Expand Down
31 changes: 31 additions & 0 deletions packages/taro-components-react/src/components/icon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import './style/index.scss'

import classNames from 'classnames'
import React from 'react'

import { omit } from '../../utils'


interface IProps {
type: string
color: string
size?: number | string
className?: string
}

const Icon = (props: IProps) => {
let { type, className = '', size = '23', color } = props
if (type) type = type.replace(/_/g, '-')
const cls = classNames(
{
[`weui-icon-${type}`]: true
},
className
)
const style = { 'font-size': size + 'px', color: color }

return (
<i {...omit(props, ['type', 'className'])} className={cls} style={style} />
)
}
export default Icon
304 changes: 304 additions & 0 deletions packages/taro-components-react/src/components/icon/style/index.scss

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/taro-components-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export { Editor } from '@tarojs/components/lib/react'
export { FollowSwan } from '@tarojs/components/lib/react'
export { Form } from '@tarojs/components/lib/react'
export { FunctionalPageNavigator } from '@tarojs/components/lib/react'
export { Icon } from '@tarojs/components/lib/react'
export { default as Icon } from './components/icon'
export { default as Image } from './components/image'
export { InlinePaymentPanel } from '@tarojs/components/lib/react'
export { Input } from '@tarojs/components/lib/react'
Expand Down
5 changes: 5 additions & 0 deletions packages/taro-components/types/Picker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { StyleProp, TextStyle, ViewStyle } from 'react-native'
import { StandardProps, CommonEventFunction, FormItemProps } from './common'
/** 选择器通用参数 */
interface PickerStandardProps extends StandardProps, FormItemProps {
/**
* 选择器的标题,微信小程序中仅安卓可用
* @supported weapp
*/
headerText?: string
/**
* 选择器类型,默认是普通选择器
* @default "selector"
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-h5/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const baseConfig: RollupOptions = {
}),
commonjs() as InputPluginOption,
postcss({
extract: true,
// extract: true, Note: 开启需要在 @tarojs/plugin-platform-h5 中的 API 引入样式
inject: { insertAt: 'top' },
minimize: true,
}) as InputPluginOption,
Expand Down
2 changes: 2 additions & 0 deletions packages/taro-mini-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export default async function build (appPath: string, config: IBuildConfig): Pro
const webpackConfig: webpack.Configuration = webpackChain.toConfig()

return new Promise<webpack.Stats>((resolve, reject) => {
if (config.withoutBuild) return

const compiler = webpack(webpackConfig)
const onBuildFinish = newConfig.onBuildFinish
let prerender: Prerender
Expand Down
1 change: 1 addition & 0 deletions packages/taro-mini-runner/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface IBuildConfig extends IProjectBaseConfig, IMiniAppConfig {
isBuildQuickapp: boolean
isSupportRecursive: boolean
isSupportXS: boolean
withoutBuild?: boolean
mode: 'production' | 'development'
modifyComponentConfig: Func
nodeModulesPath: string
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-platform-h5/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class H5 extends TaroPlatformWeb {
break
default:
if (this.useHtmlComponents) {
args[0].loaderMeta.extraImportForWeb += `import { PullDownRefresh } from '@tarojs/components'\n`
args[0].loaderMeta.extraImportForWeb += `import '@tarojs/components-react/dist/index.css'\nimport { PullDownRefresh } from '@tarojs/components'\n`
args[0].loaderMeta.execBeforeCreateWebApp += `config.PullDownRefresh = PullDownRefresh\n`
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@
* @canNotUse checkIsSupportSoterAuthentication
*/

/**
* 打开地图选择位置。
*
* @canUse chooseLocation
* @__object [mapOpts]
* @__success [address, latitude, longitude, name]
*/

/**
* 拍摄视频或从手机相册中选视频
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import Taro from '@tarojs/api'
import { stringify } from 'query-string'

import { MethodHandler } from '../utils/handler'

let container: HTMLDivElement | null = null
function createLocationChooser (handler, mapOpt: Taro.chooseLocation.Option['mapOpts'] = {}) {
// @ts-ignore
const systemBarHeight = window.systemBarHeight ? window.systemBarHeight : 0
const { key = LOCATION_APIKEY, referer = 'myapp', ...opts } = mapOpt
const query = {
key,
type: 1,
referer,
...opts,
}
if (!container) {
const css = `
.taro_choose_location {
display: flex;
position: fixed;
top: 100%;
z-index: 1;
flex-direction: column;
width: 100%;
height: 100%;
background-color: #fff;
transition: ease top 0.3s;
}
.taro_choose_location_bar {
display: flex;
flex: 0 60px;
height: 60px;
background-color: #ededed;
color: #090909;
align-items: center;
}
.taro_choose_location_back {
position: relative;
flex: 0 40px;
margin-left: 10px;
width: 25px;
height: 30px;
}
.taro_choose_location_back::before {
display: block;
position: absolute;
left: 0;
top: 0;
border: solid 15px;
border-color: transparent #090909 transparent transparent;
width: 0;
height: 0;
content: "";
}
.taro_choose_location_back::after {
display: block;
position: absolute;
left: 3px;
top: 0;
border: solid 15px;
border-color: transparent #ededed transparent transparent;
width: 0;
height: 0;
content: "";
}
.taro_choose_location_title {
flex: 1;
padding-left: 30px;
line-height: 60px;
}
.taro_choose_location_submit {
margin-right: 25px;
padding: 0;
border: none;
width: 75px;
height: 40px;
background-color: #08bf62;
line-height: 40px;
font-size: 20px;
color: #fff;
}
.taro_choose_location_frame {
flex: 1;
}
`
const style = document.createElement('style')
style.innerHTML = css
document.getElementsByTagName('head')[0].appendChild(style)

const html = `
<div class='taro_choose_location'>
<div style='height:${systemBarHeight}px; width:100%; background-color:transparent;'></div>
<div class='taro_choose_location_bar'>
<div class='taro_choose_location_back'></div>
<p class='taro_choose_location_title'>位置</p>
<button class='taro_choose_location_submit'>完成</button>
</div>
<iframe id='map-iframe' class='taro_choose_location_frame' frameborder='0' src="https://apis.map.qq.com/tools/locpicker?${stringify(query, { arrayFormat: 'comma', skipNull: true })}"/>
</div>
`
container = document.createElement('div')
container.innerHTML = html
}
const main: HTMLDivElement = container.querySelector('.taro_choose_location') as HTMLDivElement

function show () {
setTimeout(() => {
main.style.top = '0'
})
}

function hide () {
main.style.top = '100%'
}

function back () {
hide()
handler({ errMsg: 'cancel' })
}

function submit () {
hide()
handler()
}

function remove () {
container?.remove()
container = null
window.removeEventListener('popstate', back)
}

container.querySelector('.taro_choose_location_back')?.addEventListener('click', back)
container.querySelector('.taro_choose_location_submit')?.addEventListener('click', submit)

window.addEventListener('popstate', back)

return {
show,
remove,
container,
}
}

/**
* 打开地图选择位置。
*
* @canUse chooseLocation
* @__object [mapOpts]
* @__success [address, latitude, longitude, name]
*/
export const chooseLocation: typeof Taro.chooseLocation = ({ success, fail, complete, mapOpts } = {}) => {
const handle = new MethodHandler({ name: 'chooseLocation', success, fail, complete })
return new Promise((resolve, reject) => {
const chooseLocation: Partial<Taro.chooseLocation.SuccessCallbackResult> = {}
const onMessage = (event) => {
// 接收位置信息,用户选择确认位置点后选点组件会触发该事件,回传用户的位置信息
const loc = event.data

// 防止其他应用也会向该页面 post 信息,需判断 module 是否为'locationPicker'
if (!loc || loc.module !== 'locationPicker') return

chooseLocation.name = loc.poiname
chooseLocation.address = loc.poiaddress
chooseLocation.latitude = loc.latlng.lat
chooseLocation.longitude = loc.latlng.lng
}

const chooser = createLocationChooser((res) => {
window.removeEventListener('message', onMessage, false)
setTimeout(() => {
chooser.remove()
}, 300)
if (res) {
return handle.fail(res, { resolve, reject })
} else {
if (chooseLocation.latitude && chooseLocation.longitude) {
return handle.success(chooseLocation, { resolve, reject })
} else {
return handle.fail({}, { resolve, reject })
}
}
},
mapOpts
)

document.body.appendChild(chooser.container)

window.addEventListener('message', onMessage, false)
chooser.show()
})
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './chooseLocation'
export * from './getFuzzyLocation'
export * from './getLocation'
export * from './getLocation'
2 changes: 1 addition & 1 deletion packages/taro-platform-harmony-hybrid/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default class H5 extends TaroPlatformWeb {
break
default:
if (this.useHtmlComponents) {
args[0].loaderMeta.extraImportForWeb += `import { PullDownRefresh } from '@tarojs/components'\n`
args[0].loaderMeta.extraImportForWeb += `import '@tarojs/components-react/dist/index.css'\nimport { PullDownRefresh } from '@tarojs/components'\n`
args[0].loaderMeta.execBeforeCreateWebApp += `config.PullDownRefresh = PullDownRefresh\n`
}
}
Expand Down
Loading

0 comments on commit 0a95b76

Please sign in to comment.