@lemon-fe/mini-app 0.1.63 → 0.1.97
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/es/components/AppContainer/index.js +1 -1
- package/es/components/Screen/index.d.ts +4 -6
- package/es/components/Screen/index.js +35 -27
- package/es/context/index.d.ts +1 -0
- package/es/context/index.js +3 -1
- package/es/global.d.ts +14 -2
- package/es/global.js +20 -5
- package/es/hooks/index.d.ts +1 -0
- package/es/hooks/index.js +4 -0
- package/package.json +5 -6
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import type { NavigationStackScreen } from '../../typings';
|
|
3
2
|
import './index.css';
|
|
4
3
|
interface Props {
|
|
5
|
-
route: NavigationStackScreen;
|
|
6
4
|
params?: Record<string, any>;
|
|
7
|
-
|
|
5
|
+
focused: boolean;
|
|
6
|
+
route: NavigationStackScreen;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export default _default;
|
|
8
|
+
export default function Screen(props: Props): JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
var _excluded = ["
|
|
1
|
+
var _excluded = ["params", "route", "focused"];
|
|
2
|
+
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
|
|
5
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
2
6
|
|
|
3
7
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
8
|
|
|
@@ -6,28 +10,15 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
6
10
|
|
|
7
11
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
12
|
-
|
|
13
|
-
import React, { createElement, memo, useContext, useMemo, useRef } from 'react';
|
|
13
|
+
import React, { createElement, forwardRef, memo, useContext, useMemo, useRef } from 'react';
|
|
14
14
|
import { CSSTransition } from 'react-transition-group';
|
|
15
15
|
import { NavigationContext, ScreenContext } from '../../context';
|
|
16
16
|
import { mini } from '../../global';
|
|
17
17
|
import './index.css';
|
|
18
18
|
import Portal from '../Portal';
|
|
19
19
|
|
|
20
|
-
function
|
|
21
|
-
var route = props.route
|
|
22
|
-
params = props.params,
|
|
23
|
-
index = props.index,
|
|
24
|
-
restProps = _objectWithoutProperties(props, _excluded);
|
|
25
|
-
|
|
26
|
-
var ctx = useMemo(function () {
|
|
27
|
-
return {
|
|
28
|
-
params: params
|
|
29
|
-
};
|
|
30
|
-
}, [params]);
|
|
20
|
+
function Content(props, ref) {
|
|
21
|
+
var route = props.route;
|
|
31
22
|
var statusBarHeight = useMemo(function () {
|
|
32
23
|
return mini.getSystemInfoSync().statusBarHeight;
|
|
33
24
|
}, []);
|
|
@@ -36,17 +27,10 @@ function Screen(props) {
|
|
|
36
27
|
navigation = _useContext.navigation,
|
|
37
28
|
headerStyle = _useContext.headerStyle;
|
|
38
29
|
|
|
39
|
-
var ref = useRef(null);
|
|
40
30
|
var node = useMemo(function () {
|
|
41
31
|
return /*#__PURE__*/createElement(route.screen);
|
|
42
32
|
}, [route.screen]);
|
|
43
|
-
return /*#__PURE__*/React.createElement(
|
|
44
|
-
timeout: 300,
|
|
45
|
-
classNames: "lemon-transition",
|
|
46
|
-
nodeRef: ref
|
|
47
|
-
}, restProps), /*#__PURE__*/React.createElement(ScreenContext.Provider, {
|
|
48
|
-
value: ctx
|
|
49
|
-
}, /*#__PURE__*/React.createElement(Portal.Host, null, /*#__PURE__*/React.createElement("div", {
|
|
33
|
+
return /*#__PURE__*/React.createElement(Portal.Host, null, /*#__PURE__*/React.createElement("div", {
|
|
50
34
|
className: "lemon-route",
|
|
51
35
|
ref: ref
|
|
52
36
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -78,7 +62,31 @@ function Screen(props) {
|
|
|
78
62
|
slot: "header-right"
|
|
79
63
|
})))), /*#__PURE__*/React.createElement("div", {
|
|
80
64
|
className: "lemon-route-body"
|
|
81
|
-
}, node)))
|
|
65
|
+
}, node)));
|
|
82
66
|
}
|
|
83
67
|
|
|
84
|
-
|
|
68
|
+
var MemoizedContent = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(Content));
|
|
69
|
+
export default function Screen(props) {
|
|
70
|
+
var params = props.params,
|
|
71
|
+
route = props.route,
|
|
72
|
+
focused = props.focused,
|
|
73
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
74
|
+
|
|
75
|
+
var ref = useRef(null);
|
|
76
|
+
var ctx = useMemo(function () {
|
|
77
|
+
return {
|
|
78
|
+
params: params,
|
|
79
|
+
focused: focused
|
|
80
|
+
};
|
|
81
|
+
}, [params, focused]);
|
|
82
|
+
return /*#__PURE__*/React.createElement(CSSTransition, _objectSpread({
|
|
83
|
+
timeout: 300,
|
|
84
|
+
classNames: "lemon-transition",
|
|
85
|
+
nodeRef: ref
|
|
86
|
+
}, restProps), /*#__PURE__*/React.createElement(ScreenContext.Provider, {
|
|
87
|
+
value: ctx
|
|
88
|
+
}, /*#__PURE__*/React.createElement(MemoizedContent, {
|
|
89
|
+
route: route,
|
|
90
|
+
ref: ref
|
|
91
|
+
})));
|
|
92
|
+
}
|
package/es/context/index.d.ts
CHANGED
package/es/context/index.js
CHANGED
package/es/global.d.ts
CHANGED
|
@@ -27,8 +27,8 @@ export declare const mini: {
|
|
|
27
27
|
}): void;
|
|
28
28
|
methodSuccess(id: number, value: unknown): void;
|
|
29
29
|
methodFail(id: number, err: Error): void;
|
|
30
|
-
addListener(cb: (e: string) => void): () => void;
|
|
31
|
-
postMessage(e: string): void;
|
|
30
|
+
addListener(cb: (e: string, value?: string | undefined) => void): () => void;
|
|
31
|
+
postMessage(e: string, value?: string | undefined): void;
|
|
32
32
|
scanCode(opts: {
|
|
33
33
|
success: (value: string) => void;
|
|
34
34
|
}): void;
|
|
@@ -43,8 +43,20 @@ export declare const mini: {
|
|
|
43
43
|
getAccessToken(opts: {
|
|
44
44
|
success?: ((token: string | null) => void) | undefined;
|
|
45
45
|
}): void;
|
|
46
|
+
checkAccessToken(opts: {
|
|
47
|
+
success?: ((token: string | null) => void) | undefined;
|
|
48
|
+
fail?: ((err: Error) => void) | undefined;
|
|
49
|
+
}): void;
|
|
46
50
|
setCapsule(opts: {
|
|
47
51
|
visible: boolean;
|
|
48
52
|
}): void;
|
|
53
|
+
/**
|
|
54
|
+
* 监听扫码事件,常用于effect中, 并且effec重新执行需要销毁上一次注册的监听器
|
|
55
|
+
* @param opts
|
|
56
|
+
* @returns 监听器销毁函数
|
|
57
|
+
*/
|
|
58
|
+
listenScanCode(opts: {
|
|
59
|
+
success: (value: string) => void;
|
|
60
|
+
}): () => void;
|
|
49
61
|
};
|
|
50
62
|
export declare function createApp(render: () => void): void;
|
package/es/global.js
CHANGED
|
@@ -67,15 +67,14 @@ export var mini = {
|
|
|
67
67
|
addListener: function addListener(cb) {
|
|
68
68
|
listeners.push(cb);
|
|
69
69
|
return function () {
|
|
70
|
-
|
|
70
|
+
listeners.splice(listeners.findIndex(function (item) {
|
|
71
71
|
return item === cb;
|
|
72
|
-
});
|
|
73
|
-
listeners.splice(index, 1);
|
|
72
|
+
}), 1);
|
|
74
73
|
};
|
|
75
74
|
},
|
|
76
|
-
postMessage: function postMessage(e) {
|
|
75
|
+
postMessage: function postMessage(e, value) {
|
|
77
76
|
listeners.forEach(function (item) {
|
|
78
|
-
item(e);
|
|
77
|
+
item(e, value);
|
|
79
78
|
});
|
|
80
79
|
},
|
|
81
80
|
scanCode: function scanCode(opts) {
|
|
@@ -93,10 +92,26 @@ export var mini = {
|
|
|
93
92
|
getAccessToken: function getAccessToken(opts) {
|
|
94
93
|
mini.methodRegister('GET_ACCESS_TOKEN', opts);
|
|
95
94
|
},
|
|
95
|
+
checkAccessToken: function checkAccessToken(opts) {
|
|
96
|
+
mini.methodRegister('CHECK_ACCESS_TOKEN', opts);
|
|
97
|
+
},
|
|
96
98
|
setCapsule: function setCapsule(opts) {
|
|
97
99
|
mini.methodRegister('SET_CAPSULE', {
|
|
98
100
|
params: opts
|
|
99
101
|
});
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 监听扫码事件,常用于effect中, 并且effec重新执行需要销毁上一次注册的监听器
|
|
106
|
+
* @param opts
|
|
107
|
+
* @returns 监听器销毁函数
|
|
108
|
+
*/
|
|
109
|
+
listenScanCode: function listenScanCode(opts) {
|
|
110
|
+
return mini.addListener(function (e, value) {
|
|
111
|
+
if (e === 'SCAN_CODE' && value) {
|
|
112
|
+
opts.success(value);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
100
115
|
}
|
|
101
116
|
};
|
|
102
117
|
window.mini = mini;
|
package/es/hooks/index.d.ts
CHANGED
package/es/hooks/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemon-fe/mini-app",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.97",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "鲁盛杰 <lusj@cnlemon.net>",
|
|
6
6
|
"homepage": "",
|
|
@@ -23,18 +23,17 @@
|
|
|
23
23
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"color-string": "^1.9.0",
|
|
26
27
|
"react-transition-group": "^4.4.2"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {
|
|
29
|
-
"
|
|
30
|
-
"react": ">=
|
|
31
|
-
"react-dom": ">=17.0.2"
|
|
30
|
+
"react": ">=16.8",
|
|
31
|
+
"react-dom": ">=16.8"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/react-transition-group": "^4.4.4",
|
|
35
|
-
"color-string": "^1.9.0",
|
|
36
35
|
"react": "^17.0.2",
|
|
37
36
|
"react-dom": "17.0.2"
|
|
38
37
|
},
|
|
39
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "7823b5e252d052d697f8f4c584d39ee3c2014d92"
|
|
40
39
|
}
|