@lemon-fe/mini-app 0.1.102 → 0.1.122
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 +57 -42
- package/es/components/Capsule/index.js +0 -1
- package/es/components/Portal/index.js +13 -31
- package/es/components/Screen/index.js +5 -16
- package/es/constants/index.d.ts +12 -0
- package/es/constants/index.js +14 -1
- package/es/context/index.d.ts +2 -1
- package/es/context/index.js +2 -1
- package/es/global.d.ts +6 -6
- package/es/global.js +47 -35
- package/es/hooks/index.d.ts +1 -0
- package/es/utils/path.js +5 -11
- package/package.json +2 -2
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
-
|
|
3
2
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
|
|
5
3
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
-
|
|
7
4
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
-
|
|
9
5
|
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; }
|
|
10
|
-
|
|
11
6
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
-
|
|
13
7
|
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; }
|
|
14
|
-
|
|
15
8
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
|
-
|
|
17
9
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
-
|
|
19
10
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
20
|
-
|
|
21
11
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
22
|
-
|
|
23
12
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
24
|
-
|
|
25
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
26
|
-
|
|
27
14
|
import React, { cloneElement, useCallback, useEffect, useMemo, useState } from 'react';
|
|
28
15
|
import { TransitionGroup } from 'react-transition-group';
|
|
29
16
|
import { parsePath } from '../../utils/path';
|
|
@@ -33,37 +20,31 @@ import { GO_BACK } from '../../constants';
|
|
|
33
20
|
import { mini } from '../../global';
|
|
34
21
|
import Capsule from '../Capsule';
|
|
35
22
|
import './index.css';
|
|
36
|
-
|
|
37
23
|
function App(props) {
|
|
38
24
|
var pages = props.pages,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
25
|
+
children = props.children,
|
|
26
|
+
headerStyle = props.headerStyle,
|
|
27
|
+
_props$capsule = props.capsule,
|
|
28
|
+
capsule = _props$capsule === void 0 ? true : _props$capsule;
|
|
44
29
|
var _useState = useState({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
30
|
+
routes: [{
|
|
31
|
+
route: pages[0]
|
|
32
|
+
}]
|
|
33
|
+
}),
|
|
34
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
35
|
+
state = _useState2[0],
|
|
36
|
+
setState = _useState2[1];
|
|
53
37
|
var navigate = useCallback(function (path, otherParams) {
|
|
54
38
|
setState(function (prev) {
|
|
55
39
|
var routes = prev.routes;
|
|
56
|
-
|
|
57
40
|
var _parsePath = parsePath(path),
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
41
|
+
pathname = _parsePath.pathname,
|
|
42
|
+
search = _parsePath.search;
|
|
61
43
|
var params = search ? Object.fromEntries(Array.from(new URLSearchParams(search).entries())) : {};
|
|
62
44
|
Object.assign(params, otherParams);
|
|
63
45
|
var routeIndex = routes.findIndex(function (item) {
|
|
64
46
|
return item.route.path === pathname;
|
|
65
47
|
});
|
|
66
|
-
|
|
67
48
|
if (routeIndex >= 0) {
|
|
68
49
|
var nextRoutes = routes.slice(0, routeIndex + 1);
|
|
69
50
|
nextRoutes[routeIndex] = _objectSpread(_objectSpread({}, routes[routeIndex]), {}, {
|
|
@@ -73,38 +54,72 @@ function App(props) {
|
|
|
73
54
|
routes: nextRoutes
|
|
74
55
|
};
|
|
75
56
|
}
|
|
76
|
-
|
|
77
57
|
var page = pages.find(function (item) {
|
|
78
58
|
return item.path === pathname;
|
|
79
59
|
});
|
|
80
|
-
|
|
81
60
|
if (page !== undefined) {
|
|
82
61
|
var _nextRoutes = _toConsumableArray(routes);
|
|
83
|
-
|
|
84
62
|
_nextRoutes.push({
|
|
85
63
|
route: page,
|
|
86
64
|
params: params
|
|
87
65
|
});
|
|
88
|
-
|
|
89
66
|
return {
|
|
90
67
|
routes: _nextRoutes
|
|
91
68
|
};
|
|
92
69
|
}
|
|
93
|
-
|
|
70
|
+
return prev;
|
|
71
|
+
});
|
|
72
|
+
}, []);
|
|
73
|
+
var replace = useCallback(function (path, otherParams) {
|
|
74
|
+
setState(function (prev) {
|
|
75
|
+
var routes = prev.routes;
|
|
76
|
+
var _parsePath2 = parsePath(path),
|
|
77
|
+
pathname = _parsePath2.pathname,
|
|
78
|
+
search = _parsePath2.search;
|
|
79
|
+
var params = search ? Object.fromEntries(Array.from(new URLSearchParams(search).entries())) : {};
|
|
80
|
+
Object.assign(params, otherParams);
|
|
81
|
+
var routeIndex = routes.findIndex(function (item) {
|
|
82
|
+
return item.route.path === pathname;
|
|
83
|
+
});
|
|
84
|
+
if (routeIndex >= 0) {
|
|
85
|
+
var nextRoutes = routes.slice(0, routeIndex + 1);
|
|
86
|
+
nextRoutes[routeIndex] = _objectSpread(_objectSpread({}, routes[routeIndex]), {}, {
|
|
87
|
+
params: params
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
routes: nextRoutes
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
var page = pages.find(function (item) {
|
|
94
|
+
return item.path === pathname;
|
|
95
|
+
});
|
|
96
|
+
if (page !== undefined) {
|
|
97
|
+
var newRoute = {
|
|
98
|
+
route: page,
|
|
99
|
+
params: params
|
|
100
|
+
};
|
|
101
|
+
if (routes.length <= 0) {
|
|
102
|
+
return {
|
|
103
|
+
routes: [newRoute]
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
console.log(routes.slice(0, -1).concat(newRoute));
|
|
107
|
+
return {
|
|
108
|
+
routes: routes.slice(0, -1).concat(newRoute)
|
|
109
|
+
};
|
|
110
|
+
}
|
|
94
111
|
return prev;
|
|
95
112
|
});
|
|
96
113
|
}, []);
|
|
97
114
|
var goBack = useCallback(function () {
|
|
98
115
|
setState(function (prev) {
|
|
99
116
|
var nextRoutes = _toConsumableArray(prev.routes);
|
|
100
|
-
|
|
101
117
|
if (nextRoutes.length > 1) {
|
|
102
118
|
nextRoutes.pop();
|
|
103
119
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
104
120
|
routes: nextRoutes
|
|
105
121
|
});
|
|
106
122
|
}
|
|
107
|
-
|
|
108
123
|
mini.exit();
|
|
109
124
|
return prev;
|
|
110
125
|
});
|
|
@@ -125,11 +140,12 @@ function App(props) {
|
|
|
125
140
|
return {
|
|
126
141
|
navigation: {
|
|
127
142
|
navigate: navigate,
|
|
128
|
-
goBack: goBack
|
|
143
|
+
goBack: goBack,
|
|
144
|
+
replace: replace
|
|
129
145
|
},
|
|
130
146
|
headerStyle: headerStyle
|
|
131
147
|
};
|
|
132
|
-
}, [navigate, goBack, headerStyle]);
|
|
148
|
+
}, [navigate, goBack, replace, headerStyle]);
|
|
133
149
|
var screens = /*#__PURE__*/React.createElement(TransitionGroup, {
|
|
134
150
|
className: "lemon-routes"
|
|
135
151
|
}, state.routes.map(function (item, index) {
|
|
@@ -144,5 +160,4 @@ function App(props) {
|
|
|
144
160
|
value: ctx
|
|
145
161
|
}, children ? /*#__PURE__*/cloneElement(children, {}, screens) : screens, window.ReactNativeWebView === undefined && /*#__PURE__*/React.createElement(Capsule, null));
|
|
146
162
|
}
|
|
147
|
-
|
|
148
163
|
export default App;
|
|
@@ -5,7 +5,6 @@ export default function Capsule() {
|
|
|
5
5
|
var url = "nhsoft://external-apps?url=".concat(encodeURIComponent(window.location.href));
|
|
6
6
|
window.alert("".concat(url, "\uFF0C\u8BF7\u590D\u5236\u5E76\u751F\u6210\u4E8C\u7EF4\u7801\u901A\u8FC7APP\u626B\u63CF"));
|
|
7
7
|
};
|
|
8
|
-
|
|
9
8
|
return /*#__PURE__*/React.createElement("div", {
|
|
10
9
|
className: "lemon-capsule",
|
|
11
10
|
onClick: generateCode
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
2
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
|
|
5
3
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
-
|
|
7
4
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
-
|
|
9
5
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
-
|
|
11
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
|
|
13
7
|
import React, { createContext, memo, useContext, useEffect, useMemo, useState } from 'react';
|
|
14
8
|
var Slot = /*#__PURE__*/memo(function Content(props) {
|
|
15
9
|
return props.children;
|
|
@@ -28,7 +22,6 @@ var Context = /*#__PURE__*/createContext({
|
|
|
28
22
|
}
|
|
29
23
|
}
|
|
30
24
|
});
|
|
31
|
-
|
|
32
25
|
function Subject(initialData) {
|
|
33
26
|
var observers = [];
|
|
34
27
|
var data = initialData;
|
|
@@ -49,7 +42,6 @@ function Subject(initialData) {
|
|
|
49
42
|
var index = observers.findIndex(function (item) {
|
|
50
43
|
return item === observer;
|
|
51
44
|
});
|
|
52
|
-
|
|
53
45
|
if (index >= 0) {
|
|
54
46
|
observers.splice(index, 1);
|
|
55
47
|
}
|
|
@@ -58,15 +50,12 @@ function Subject(initialData) {
|
|
|
58
50
|
}
|
|
59
51
|
};
|
|
60
52
|
}
|
|
61
|
-
|
|
62
53
|
function PortalHost(props) {
|
|
63
54
|
var children = props.children;
|
|
64
|
-
|
|
65
55
|
var _useState = useState(new Map()),
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
57
|
+
nodes = _useState2[0],
|
|
58
|
+
setNodes = _useState2[1];
|
|
70
59
|
var observable = useMemo(function () {
|
|
71
60
|
return Subject(nodes);
|
|
72
61
|
}, []);
|
|
@@ -96,34 +85,28 @@ function PortalHost(props) {
|
|
|
96
85
|
value: portal
|
|
97
86
|
}, /*#__PURE__*/React.createElement(Slot, null, children));
|
|
98
87
|
}
|
|
99
|
-
|
|
100
88
|
function PortalSlot(props) {
|
|
101
89
|
var slot = props.slot;
|
|
102
|
-
|
|
103
90
|
var _useContext = useContext(Context),
|
|
104
|
-
|
|
105
|
-
|
|
91
|
+
observable = _useContext.observable;
|
|
106
92
|
var _useState3 = useState(observable.get().get(slot) || null),
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
93
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
94
|
+
node = _useState4[0],
|
|
95
|
+
setNode = _useState4[1];
|
|
111
96
|
useEffect(function () {
|
|
112
97
|
var _observable$subscribe = observable.subscribe({
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
98
|
+
next: function next(state) {
|
|
99
|
+
setNode(state.get(slot) || null);
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
unsubscribe = _observable$subscribe.unsubscribe;
|
|
119
103
|
return unsubscribe;
|
|
120
104
|
}, [slot]);
|
|
121
105
|
return node;
|
|
122
106
|
}
|
|
123
|
-
|
|
124
107
|
function Portal(props) {
|
|
125
108
|
var slot = props.slot,
|
|
126
|
-
|
|
109
|
+
children = props.children;
|
|
127
110
|
var portal = useContext(Context);
|
|
128
111
|
useEffect(function () {
|
|
129
112
|
return function () {
|
|
@@ -135,7 +118,6 @@ function Portal(props) {
|
|
|
135
118
|
}, [slot, children]);
|
|
136
119
|
return null;
|
|
137
120
|
}
|
|
138
|
-
|
|
139
121
|
Portal.Host = PortalHost;
|
|
140
122
|
Portal.Slot = PortalSlot;
|
|
141
123
|
export default Portal;
|
|
@@ -1,32 +1,23 @@
|
|
|
1
1
|
var _excluded = ["params", "route", "focused"];
|
|
2
|
-
|
|
3
2
|
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
3
|
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; }
|
|
6
|
-
|
|
7
4
|
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; }
|
|
8
|
-
|
|
9
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
-
|
|
11
6
|
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; }
|
|
12
|
-
|
|
13
7
|
import React, { createElement, forwardRef, memo, useContext, useMemo, useRef } from 'react';
|
|
14
8
|
import { CSSTransition } from 'react-transition-group';
|
|
15
9
|
import { NavigationContext, ScreenContext } from '../../context';
|
|
16
10
|
import { mini } from '../../global';
|
|
17
11
|
import './index.css';
|
|
18
12
|
import Portal from '../Portal';
|
|
19
|
-
|
|
20
13
|
function Content(props, ref) {
|
|
21
14
|
var route = props.route;
|
|
22
15
|
var statusBarHeight = useMemo(function () {
|
|
23
16
|
return mini.getSystemInfoSync().statusBarHeight;
|
|
24
17
|
}, []);
|
|
25
|
-
|
|
26
18
|
var _useContext = useContext(NavigationContext),
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
navigation = _useContext.navigation,
|
|
20
|
+
headerStyle = _useContext.headerStyle;
|
|
30
21
|
var node = useMemo(function () {
|
|
31
22
|
return /*#__PURE__*/createElement(route.screen);
|
|
32
23
|
}, [route.screen]);
|
|
@@ -64,14 +55,12 @@ function Content(props, ref) {
|
|
|
64
55
|
className: "lemon-route-body"
|
|
65
56
|
}, node)));
|
|
66
57
|
}
|
|
67
|
-
|
|
68
58
|
var MemoizedContent = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(Content));
|
|
69
59
|
export default function Screen(props) {
|
|
70
60
|
var params = props.params,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
61
|
+
route = props.route,
|
|
62
|
+
focused = props.focused,
|
|
63
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
75
64
|
var ref = useRef(null);
|
|
76
65
|
var ctx = useMemo(function () {
|
|
77
66
|
return {
|
package/es/constants/index.d.ts
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
1
|
export declare const GO_BACK = "GO_BACK";
|
|
2
|
+
export declare const METHOD = "METHOD";
|
|
3
|
+
export declare const METHOD_CALLBACK = "METHOD_CALLBACK";
|
|
4
|
+
export declare const INIT_IFRAME = "INIT_IFRAME";
|
|
5
|
+
export declare const LEMON_APP_EXTRA_PAYLOAD = "LEMON_APP_EXTRA_PAYLOAD";
|
|
6
|
+
export declare const SCAN_CODE = "SCAN_CODE";
|
|
7
|
+
export declare const EXIT = "EXIT";
|
|
8
|
+
export declare const SET_STATUS_BAR_STYLE = "SET_STATUS_BAR_STYLE";
|
|
9
|
+
export declare const GET_USER_INFO = "GET_USER_INFO";
|
|
10
|
+
export declare const GET_ACCESS_TOKEN = "GET_ACCESS_TOKEN";
|
|
11
|
+
export declare const CHECK_ACCESS_TOKEN = "CHECK_ACCESS_TOKEN";
|
|
12
|
+
export declare const SET_CAPSULE = "SET_CAPSULE";
|
|
13
|
+
export declare const SET_EXTRA_PAYLOAD = "SET_EXTRA_PAYLOAD";
|
package/es/constants/index.js
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
-
export var GO_BACK = 'GO_BACK';
|
|
1
|
+
export var GO_BACK = 'GO_BACK';
|
|
2
|
+
export var METHOD = 'METHOD';
|
|
3
|
+
export var METHOD_CALLBACK = 'METHOD_CALLBACK';
|
|
4
|
+
export var INIT_IFRAME = 'INIT_IFRAME';
|
|
5
|
+
export var LEMON_APP_EXTRA_PAYLOAD = 'LEMON_APP_EXTRA_PAYLOAD';
|
|
6
|
+
// methods
|
|
7
|
+
export var SCAN_CODE = 'SCAN_CODE';
|
|
8
|
+
export var EXIT = 'EXIT';
|
|
9
|
+
export var SET_STATUS_BAR_STYLE = 'SET_STATUS_BAR_STYLE';
|
|
10
|
+
export var GET_USER_INFO = 'GET_USER_INFO';
|
|
11
|
+
export var GET_ACCESS_TOKEN = 'GET_ACCESS_TOKEN';
|
|
12
|
+
export var CHECK_ACCESS_TOKEN = 'CHECK_ACCESS_TOKEN';
|
|
13
|
+
export var SET_CAPSULE = 'SET_CAPSULE';
|
|
14
|
+
export var SET_EXTRA_PAYLOAD = 'SET_EXTRA_PAYLOAD';
|
package/es/context/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { CSSProperties } from 'react';
|
|
2
2
|
export declare const NavigationContext: import("react").Context<{
|
|
3
3
|
navigation: {
|
|
4
|
-
navigate: (path: string, params?: Record<string, any>
|
|
4
|
+
navigate: (path: string, params?: Record<string, any>) => void;
|
|
5
5
|
goBack: () => void;
|
|
6
|
+
replace: (path: string, params?: Record<string, any>) => void;
|
|
6
7
|
};
|
|
7
8
|
headerStyle?: CSSProperties | undefined;
|
|
8
9
|
}>;
|
package/es/context/index.js
CHANGED
|
@@ -2,7 +2,8 @@ import { createContext } from 'react';
|
|
|
2
2
|
export var NavigationContext = /*#__PURE__*/createContext({
|
|
3
3
|
navigation: {
|
|
4
4
|
navigate: function navigate() {},
|
|
5
|
-
goBack: function goBack() {}
|
|
5
|
+
goBack: function goBack() {},
|
|
6
|
+
replace: function replace() {}
|
|
6
7
|
}
|
|
7
8
|
});
|
|
8
9
|
export var ScreenContext = /*#__PURE__*/createContext({
|
package/es/global.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { UserInfo } from './typings';
|
|
1
|
+
import type { UserInfo } from './typings';
|
|
2
2
|
declare global {
|
|
3
3
|
interface Window {
|
|
4
|
+
mini?: typeof mini;
|
|
4
5
|
ReactNativeWebView?: {
|
|
5
|
-
postMessage(e: string)
|
|
6
|
+
postMessage: (e: string) => void;
|
|
6
7
|
};
|
|
7
|
-
mini?: typeof mini;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export declare const mini: {
|
|
@@ -19,7 +19,7 @@ export declare const mini: {
|
|
|
19
19
|
left: number;
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
getExtraPayload():
|
|
22
|
+
getExtraPayload(): any;
|
|
23
23
|
methodRegister(name: string, opts?: {
|
|
24
24
|
success?: ((value: any) => void) | undefined;
|
|
25
25
|
fail?: ((err: Error) => void) | undefined;
|
|
@@ -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, value?: string
|
|
31
|
-
postMessage(e: string, value?: string
|
|
30
|
+
addListener(cb: (e: string, value?: string) => void): () => void;
|
|
31
|
+
postMessage(e: string, value?: string): void;
|
|
32
32
|
scanCode(opts: {
|
|
33
33
|
success: (value: string) => void;
|
|
34
34
|
}): void;
|
package/es/global.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { CHECK_ACCESS_TOKEN, EXIT, GET_ACCESS_TOKEN, GET_USER_INFO, INIT_IFRAME, LEMON_APP_EXTRA_PAYLOAD, METHOD, METHOD_CALLBACK, SCAN_CODE, SET_CAPSULE, SET_EXTRA_PAYLOAD, SET_STATUS_BAR_STYLE } from './constants';
|
|
2
2
|
var methods = {};
|
|
3
3
|
var listeners = [];
|
|
4
|
+
var methodID = 0;
|
|
5
|
+
var whiteList = ['localhost', 'csp.nhsoft.cn', '127.0.0.1'];
|
|
4
6
|
export var mini = {
|
|
5
7
|
loaded: false,
|
|
6
8
|
getSystemInfoSync: function getSystemInfoSync() {
|
|
@@ -16,26 +18,23 @@ export var mini = {
|
|
|
16
18
|
};
|
|
17
19
|
},
|
|
18
20
|
getExtraPayload: function getExtraPayload() {
|
|
19
|
-
return;
|
|
21
|
+
return JSON.parse(window.localStorage.getItem('LEMON_APP_EXTRA_PAYLOAD') || '{}');
|
|
20
22
|
},
|
|
21
23
|
methodRegister: function methodRegister(name) {
|
|
22
24
|
var _window$ReactNativeWe;
|
|
23
|
-
|
|
24
25
|
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
25
|
-
var mOpts = opts || {};
|
|
26
26
|
methods[methodID] = {
|
|
27
|
-
success:
|
|
28
|
-
fail:
|
|
27
|
+
success: opts.success,
|
|
28
|
+
fail: opts.fail
|
|
29
29
|
};
|
|
30
30
|
(_window$ReactNativeWe = window.ReactNativeWebView) === null || _window$ReactNativeWe === void 0 ? void 0 : _window$ReactNativeWe.postMessage(JSON.stringify({
|
|
31
|
-
type:
|
|
31
|
+
type: METHOD,
|
|
32
32
|
target: {
|
|
33
33
|
id: methodID,
|
|
34
34
|
name: name,
|
|
35
|
-
params:
|
|
35
|
+
params: opts.params
|
|
36
36
|
}
|
|
37
37
|
}));
|
|
38
|
-
|
|
39
38
|
if (methodID >= Number.MAX_SAFE_INTEGER) {
|
|
40
39
|
methodID = 0;
|
|
41
40
|
} else {
|
|
@@ -44,23 +43,19 @@ export var mini = {
|
|
|
44
43
|
},
|
|
45
44
|
methodSuccess: function methodSuccess(id, value) {
|
|
46
45
|
var method = methods[id];
|
|
47
|
-
|
|
48
46
|
if (method !== undefined) {
|
|
49
47
|
if (method.success !== undefined) {
|
|
50
48
|
method.success(value);
|
|
51
49
|
}
|
|
52
|
-
|
|
53
50
|
delete methods[id];
|
|
54
51
|
}
|
|
55
52
|
},
|
|
56
53
|
methodFail: function methodFail(id, err) {
|
|
57
54
|
var method = methods[id];
|
|
58
|
-
|
|
59
55
|
if (method !== undefined) {
|
|
60
56
|
if (method.fail !== undefined) {
|
|
61
57
|
method.fail(err);
|
|
62
58
|
}
|
|
63
|
-
|
|
64
59
|
delete methods[id];
|
|
65
60
|
}
|
|
66
61
|
},
|
|
@@ -78,37 +73,35 @@ export var mini = {
|
|
|
78
73
|
});
|
|
79
74
|
},
|
|
80
75
|
scanCode: function scanCode(opts) {
|
|
81
|
-
mini.methodRegister(
|
|
76
|
+
mini.methodRegister(SCAN_CODE, opts);
|
|
82
77
|
},
|
|
83
78
|
exit: function exit() {
|
|
84
|
-
mini.methodRegister(
|
|
79
|
+
mini.methodRegister(EXIT);
|
|
85
80
|
},
|
|
86
81
|
setStatusBarStyle: function setStatusBarStyle(opts) {
|
|
87
|
-
mini.methodRegister(
|
|
82
|
+
mini.methodRegister(SET_STATUS_BAR_STYLE, opts);
|
|
88
83
|
},
|
|
89
84
|
getUserInfo: function getUserInfo(opts) {
|
|
90
|
-
mini.methodRegister(
|
|
85
|
+
mini.methodRegister(GET_USER_INFO, opts);
|
|
91
86
|
},
|
|
92
87
|
getAccessToken: function getAccessToken(opts) {
|
|
93
|
-
mini.methodRegister(
|
|
88
|
+
mini.methodRegister(GET_ACCESS_TOKEN, opts);
|
|
94
89
|
},
|
|
95
90
|
checkAccessToken: function checkAccessToken(opts) {
|
|
96
|
-
mini.methodRegister(
|
|
91
|
+
mini.methodRegister(CHECK_ACCESS_TOKEN, opts);
|
|
97
92
|
},
|
|
98
93
|
setCapsule: function setCapsule(opts) {
|
|
99
|
-
mini.methodRegister(
|
|
94
|
+
mini.methodRegister(SET_CAPSULE, {
|
|
100
95
|
params: opts
|
|
101
96
|
});
|
|
102
97
|
},
|
|
103
|
-
|
|
104
98
|
/**
|
|
105
99
|
* 监听扫码事件,常用于effect中, 并且effec重新执行需要销毁上一次注册的监听器
|
|
106
100
|
* @param opts
|
|
107
101
|
* @returns 监听器销毁函数
|
|
108
|
-
*/
|
|
109
|
-
listenScanCode: function listenScanCode(opts) {
|
|
102
|
+
*/listenScanCode: function listenScanCode(opts) {
|
|
110
103
|
return mini.addListener(function (e, value) {
|
|
111
|
-
if (e ===
|
|
104
|
+
if (e === SCAN_CODE && value) {
|
|
112
105
|
opts.success(value);
|
|
113
106
|
}
|
|
114
107
|
});
|
|
@@ -117,29 +110,49 @@ export var mini = {
|
|
|
117
110
|
window.mini = mini;
|
|
118
111
|
window.addEventListener('message', function (evt) {
|
|
119
112
|
var result = /^(([^:\/\s]+):\/?\/?([^\/\s@]*@)?([^\/@:]*)?:?(\d+)?)?(\/[^?]*)?(\?([^#]*))?(#[\s\S]*)?$/.exec(evt.origin);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (evt.data === 'INIT_IFRAME') {
|
|
113
|
+
if (result !== null && whiteList.includes(result[4])) {
|
|
114
|
+
if (evt.data === INIT_IFRAME) {
|
|
123
115
|
window.ReactNativeWebView = {
|
|
124
116
|
postMessage: function postMessage(e) {
|
|
125
117
|
window.parent.postMessage(e, '*');
|
|
126
118
|
}
|
|
127
119
|
};
|
|
128
120
|
mini.loaded = true;
|
|
121
|
+
var nodeList = document.getElementsByTagName('link');
|
|
122
|
+
var favicon = undefined;
|
|
123
|
+
for (var i = 0; i < nodeList.length; i++) {
|
|
124
|
+
if (nodeList[i].getAttribute('rel') == 'icon' || nodeList[i].getAttribute('rel') == 'shortcut icon') {
|
|
125
|
+
favicon = nodeList[i].getAttribute('href');
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
window.parent.postMessage(JSON.stringify({
|
|
130
|
+
type: INIT_IFRAME,
|
|
131
|
+
target: {
|
|
132
|
+
title: document.title,
|
|
133
|
+
icon: favicon
|
|
134
|
+
}
|
|
135
|
+
}), '*');
|
|
129
136
|
} else {
|
|
130
|
-
var
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
137
|
+
var action = evt.data;
|
|
138
|
+
switch (action.type) {
|
|
139
|
+
case SET_EXTRA_PAYLOAD:
|
|
140
|
+
window.localStorage.setItem(LEMON_APP_EXTRA_PAYLOAD, JSON.stringify(action.payload));
|
|
141
|
+
break;
|
|
142
|
+
case METHOD_CALLBACK:
|
|
143
|
+
var msg = action.payload;
|
|
144
|
+
if (msg.type === 'success') {
|
|
145
|
+
mini.methodSuccess(msg.id, msg.data);
|
|
146
|
+
} else {
|
|
147
|
+
mini.methodFail(msg.id, new Error(msg.data));
|
|
148
|
+
}
|
|
149
|
+
default:
|
|
136
150
|
}
|
|
137
151
|
}
|
|
138
152
|
}
|
|
139
153
|
}, false);
|
|
140
154
|
export function createApp(render) {
|
|
141
155
|
var count = 0;
|
|
142
|
-
|
|
143
156
|
var check = function check() {
|
|
144
157
|
if (mini.loaded || count >= 10) {
|
|
145
158
|
render();
|
|
@@ -148,6 +161,5 @@ export function createApp(render) {
|
|
|
148
161
|
setTimeout(check, 100);
|
|
149
162
|
}
|
|
150
163
|
};
|
|
151
|
-
|
|
152
164
|
check();
|
|
153
165
|
}
|
package/es/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare function useNavigation(): {
|
|
2
2
|
navigate: (path: string, params?: Record<string, any> | undefined) => void;
|
|
3
3
|
goBack: () => void;
|
|
4
|
+
replace: (path: string, params?: Record<string, any> | undefined) => void;
|
|
4
5
|
};
|
|
5
6
|
export declare function useParams<T extends Record<string, any> | void = void>(): T;
|
|
6
7
|
export declare function useIsFocused(): boolean;
|
package/es/utils/path.js
CHANGED
|
@@ -1,36 +1,30 @@
|
|
|
1
1
|
export function createPath(_ref) {
|
|
2
2
|
var _ref$pathname = _ref.pathname,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
pathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
|
|
4
|
+
_ref$search = _ref.search,
|
|
5
|
+
search = _ref$search === void 0 ? '' : _ref$search,
|
|
6
|
+
_ref$hash = _ref.hash,
|
|
7
|
+
hash = _ref$hash === void 0 ? '' : _ref$hash;
|
|
8
8
|
if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
|
|
9
9
|
if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
|
|
10
10
|
return pathname;
|
|
11
11
|
}
|
|
12
12
|
export function parsePath(path) {
|
|
13
13
|
var parsedPath = {};
|
|
14
|
-
|
|
15
14
|
if (path) {
|
|
16
15
|
var hashIndex = path.indexOf('#');
|
|
17
|
-
|
|
18
16
|
if (hashIndex >= 0) {
|
|
19
17
|
parsedPath.hash = path.substr(hashIndex);
|
|
20
18
|
path = path.substr(0, hashIndex);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
var searchIndex = path.indexOf('?');
|
|
24
|
-
|
|
25
21
|
if (searchIndex >= 0) {
|
|
26
22
|
parsedPath.search = path.substr(searchIndex);
|
|
27
23
|
path = path.substr(0, searchIndex);
|
|
28
24
|
}
|
|
29
|
-
|
|
30
25
|
if (path) {
|
|
31
26
|
parsedPath.pathname = path;
|
|
32
27
|
}
|
|
33
28
|
}
|
|
34
|
-
|
|
35
29
|
return parsedPath;
|
|
36
30
|
}
|
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.122",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "鲁盛杰 <lusj@cnlemon.net>",
|
|
6
6
|
"homepage": "",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"react": "^17.0.2",
|
|
36
36
|
"react-dom": "17.0.2"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "c06d24110423eabd6a1c08e69b5bebcb339e709c"
|
|
39
39
|
}
|