Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 修复无法使用 catch 事件和 dataset 的问题
Browse files Browse the repository at this point in the history
fix #219
resolve #231
  • Loading branch information
Darmody committed Sep 18, 2019
1 parent d02c1db commit 44485b4
Show file tree
Hide file tree
Showing 78 changed files with 113 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/remax-cli/src/build/adapters/alipay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const moduleFormat = 'esm';
const alias: any = {
className: 'class',
onClick: 'onTap',
catchClick: 'catchTap',
};

export function getNativePropName(prop: string) {
Expand Down
11 changes: 9 additions & 2 deletions packages/remax-cli/src/build/adapters/wechat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ export const moduleFormat = 'cjs';

// TODO: alias 方法在 remax 和 remax-cli 都重复定义了,想办法 DRY
const alias: { [prop: string]: string } = {
className: 'class',
activeColor: 'activeColor',
backgroundColor: 'backgroundColor',
onClick: 'bindtap',
catchClick: 'catchtap',
enable3D: 'enable-3D',
hTouchMove: 'htouchmove',
vTouchMove: 'vtouchmove',
};

export function getNativePropName(prop: string) {
Expand All @@ -38,7 +41,11 @@ export function getNativePropName(prop: string) {
return aliasProp;
}

if (prop.startsWith('on')) {
if (prop.endsWith('className')) {
return prop.replace('className', 'class');
}

if (prop.startsWith('on') || prop.startsWith('catch')) {
return prop.toLowerCase().replace('on', 'bind');
}

Expand Down
15 changes: 10 additions & 5 deletions packages/remax-cli/src/build/plugins/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ function addToComponentCollection(
}

function shouldRegisterAllProps(adapter: Adapter, node: t.JSXElement) {
if (adapter.name === 'alipay') {
return true;
}

if (
node.openingElement.attributes.find(a => a.type === 'JSXSpreadAttribute')
) {
Expand Down Expand Up @@ -77,7 +73,16 @@ function registerComponent(
}

let usedProps = adapter.hostComponents(componentName).props;
if (node && !shouldRegisterAllProps(adapter, node)) {
if (node && adapter.name === 'alipay') {
// 支付宝在使用全部props的基础上,还加入用户定义的prop,用于收集 dataset, catch 事件等props
node.openingElement.attributes.forEach(e => {
const propName = get(e, 'name.name') as string;

if (!usedProps.find(prop => prop === propName)) {
usedProps.push(propName);
}
});
} else if (node && !shouldRegisterAllProps(adapter, node)) {
usedProps = node.openingElement.attributes.map(e => {
const propName = get(e, 'name.name') as string;
return propName;
Expand Down
9 changes: 7 additions & 2 deletions packages/remax-cli/templates/alipay/component.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<% camelCased = function(str) { return str.replace(/-([a-z0-9])/g, function (g) { return g[1].toUpperCase(); })}%>
<% camelCased = function(str) {
if (str.indexOf('-') !== -1) {
return str;
}
return str.replace(/-([a-z0-9])/g, function (g) { return g[1].toUpperCase();
})}%>

<template name="REMAX_TPL_1_<%=id%>">
<<%=id%> <% for(let key of props) { %> <%=key%>="{{item.props.<%=camelCased(key)%>}}" <% } %>>
<<%=id%> <% for(let key of props) { %> <%=key%>="{{item.props['<%=camelCased(key)%>']}}" <% } %>>
<% if (id === 'swiper') { %>
<block a:for="{{item.children}}" a:key="{{item.id}}">
<swiper-item key="{{item.props.key}}">
Expand Down
2 changes: 1 addition & 1 deletion packages/remax-cli/templates/wechat/component.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% camelCased = function(str) { return str.replace(/-([a-z0-9])/g, function (g) { return g[1].toUpperCase(); })}%>

<template name="REMAX_TPL_<%=templateId%>_<%=id%>">
<<%=id%> <% for(let key of props) { %> <%=key%>="{{_h.v(i.props.<%=camelCased(key)%>)}}" <% } %>>
<<%=id%> <% for(let key of props) { %> <%=key%>="{{_h.v(i.props['<%=key%>'])}}" <% } %>>
<% if (id === 'swiper') { %>
<block wx:for="{{i.children}}" wx:key="{{id}}">
<swiper-item item-id="{{item.props.itemId}}" key="{{item.props.key}}">
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface ButtonProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
style?: React.CSSProperties;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface CanvasProps {
readonly dataset?: DOMStringMap;
id?: string;
style?: React.CSSProperties;
className?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Checkbox.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface CheckboxProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
value?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface CheckboxGroupProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
name?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface LifestyleProps {
readonly dataset?: DOMStringMap;
tntInstId: string;
scene: string;
size?: string | number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface CoverImageProps {
readonly dataset?: DOMStringMap;
className?: string;
style?: React.CSSProperties;
src?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/CoverView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface CoverViewProps {
readonly dataset?: DOMStringMap;
className?: string;
style?: React.CSSProperties;
onTap?: (e: any) => void;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface FormProps {
readonly dataset?: DOMStringMap;
className?: string;
style?: React.CSSProperties;
reportSubmit: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Icon.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import factory from './factory';
export interface IconProps {
readonly dataset?: DOMStringMap;
id?: string;
className: string;
type:
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface ImageProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
src?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface InputProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
value?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Label.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface LabelProps {
readonly dataset?: DOMStringMap;
id?: string;
for?: string;
}
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Lifestyle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface LifestyleProps {
readonly dataset?: DOMStringMap;
publicId: string;
onFollow?: (e: any) => void;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/remax/src/adapters/alipay/components/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface MapMarker {
readonly dataset?: DOMStringMap;
id?: number;
latitude: number;
longitude: number;
Expand All @@ -24,6 +25,7 @@ export interface MapMarker {
}

export interface MapPolyline {
readonly dataset?: DOMStringMap;
points: Array<{
latitude: number;
longitude: number;
Expand All @@ -38,6 +40,7 @@ export interface MapPolyline {
}

export interface MapCircle {
readonly dataset?: DOMStringMap;
latitude: number;
longitude: number;
color?: string;
Expand All @@ -47,20 +50,23 @@ export interface MapCircle {
}

export interface MapPosition {
readonly dataset?: DOMStringMap;
left?: number;
top?: number;
width?: number;
height?: number;
}

export interface MapControl {
readonly dataset?: DOMStringMap;
id?: number;
position: MapPosition;
iconPath: string;
clickable?: boolean;
}

export interface MapPolygon {
readonly dataset?: DOMStringMap;
points: Array<{
latitude: number;
longitude: number;
Expand All @@ -71,11 +77,13 @@ export interface MapPolygon {
}

export interface MapCoordinate {
readonly dataset?: DOMStringMap;
latitude?: number;
longitude?: number;
}

export interface MapSetting {
readonly dataset?: DOMStringMap;
// 手势
gestureEnable?: number;
// 比例尺
Expand All @@ -96,6 +104,7 @@ export interface MapSetting {
}

export interface Map extends MapCoordinate {
readonly dataset?: DOMStringMap;
style?: React.CSSProperties;
className?: string;
scale?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface MovableAreaProps {
readonly dataset?: DOMStringMap;
style?: React.CSSProperties;
width: number;
height: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface MovableViewProps {
readonly dataset?: DOMStringMap;
style?: React.CSSProperties;
width: number;
height: number;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Navigator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface NavigatorProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
openType?:
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Picker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface PickerProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
range?: string[] | any[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface PickerViewProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
value?: number[];
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Progress.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface ProgressProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
percent?: number;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Radio.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface RadioProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
value?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface RadioGroupProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
name?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/RichText.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface RichTextNode {
readonly dataset?: DOMStringMap;
type?: string;
name: string;
attrs?: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface ScrollViewProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
style?: React.CSSProperties;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Slider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface SliderProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
name?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Swiper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface SwiperProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
indicatorDots?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface SwiperItemProps {
readonly dataset?: DOMStringMap;
key: string;
}

Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Switch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory from './factory';

export interface SwitchProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
name?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface TextProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
style?: React.CSSProperties;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/TextArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import factory from './factory';
import * as React from 'react';

export interface TextareaProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
name?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/remax/src/adapters/alipay/components/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import factory from './factory';

export interface ViewProps {
readonly dataset?: DOMStringMap;
id?: string;
className?: string;
style?: React.CSSProperties;
Expand Down
Loading

0 comments on commit 44485b4

Please sign in to comment.