@lemon-fe/mini-app 0.1.103 → 1.0.0

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.
@@ -1,4 +1,4 @@
1
- import { CSSProperties, ReactElement } from 'react';
1
+ import { type CSSProperties, type ReactElement } from 'react';
2
2
  import type { NavigationStackScreen } from '../../typings';
3
3
  import './index.css';
4
4
  interface Props {
@@ -31,7 +31,6 @@ import { NavigationContext } from '../../context';
31
31
  import Screen from '../Screen';
32
32
  import { GO_BACK } from '../../constants';
33
33
  import { mini } from '../../global';
34
- import Capsule from '../Capsule';
35
34
  import './index.css';
36
35
 
37
36
  function App(props) {
@@ -134,7 +133,6 @@ function App(props) {
134
133
  };
135
134
  }
136
135
 
137
- console.log(routes.slice(0, -1).concat(newRoute));
138
136
  return {
139
137
  routes: routes.slice(0, -1).concat(newRoute)
140
138
  };
@@ -169,7 +167,18 @@ function App(props) {
169
167
  mini.setCapsule({
170
168
  visible: capsule
171
169
  });
172
- }, []);
170
+ }, [capsule]);
171
+ useEffect(function () {
172
+ mini.syncRoutes({
173
+ params: state.routes.map(function (item) {
174
+ var route = item.route;
175
+ return {
176
+ title: route.title,
177
+ path: route.path
178
+ };
179
+ })
180
+ });
181
+ }, [state.routes]);
173
182
  var ctx = useMemo(function () {
174
183
  return {
175
184
  navigation: {
@@ -192,7 +201,7 @@ function App(props) {
192
201
  }));
193
202
  return /*#__PURE__*/React.createElement(NavigationContext.Provider, {
194
203
  value: ctx
195
- }, children ? /*#__PURE__*/cloneElement(children, {}, screens) : screens, window.ReactNativeWebView === undefined && /*#__PURE__*/React.createElement(Capsule, null));
204
+ }, children ? /*#__PURE__*/cloneElement(children, {}, screens) : screens);
196
205
  }
197
206
 
198
207
  export default App;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { NavigationStackScreen } from '../../typings';
2
3
  import './index.css';
3
4
  interface Props {
@@ -11,3 +11,4 @@ export declare const GET_ACCESS_TOKEN = "GET_ACCESS_TOKEN";
11
11
  export declare const CHECK_ACCESS_TOKEN = "CHECK_ACCESS_TOKEN";
12
12
  export declare const SET_CAPSULE = "SET_CAPSULE";
13
13
  export declare const SET_EXTRA_PAYLOAD = "SET_EXTRA_PAYLOAD";
14
+ export declare const SYNC_ROUTES = "SYNC_ROUTES";
@@ -11,4 +11,5 @@ export var GET_USER_INFO = 'GET_USER_INFO';
11
11
  export var GET_ACCESS_TOKEN = 'GET_ACCESS_TOKEN';
12
12
  export var CHECK_ACCESS_TOKEN = 'CHECK_ACCESS_TOKEN';
13
13
  export var SET_CAPSULE = 'SET_CAPSULE';
14
- export var SET_EXTRA_PAYLOAD = 'SET_EXTRA_PAYLOAD';
14
+ export var SET_EXTRA_PAYLOAD = 'SET_EXTRA_PAYLOAD';
15
+ export var SYNC_ROUTES = 'SYNC_ROUTES';
@@ -1,9 +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> | undefined) => void;
4
+ navigate: (path: string, params?: Record<string, any>) => void;
5
5
  goBack: () => void;
6
- replace: (path: string, params?: Record<string, any> | undefined) => void;
6
+ replace: (path: string, params?: Record<string, any>) => void;
7
7
  };
8
8
  headerStyle?: CSSProperties | undefined;
9
9
  }>;
package/es/global.d.ts CHANGED
@@ -1,14 +1,13 @@
1
1
  import type { UserInfo } from './typings';
2
2
  declare global {
3
3
  interface Window {
4
- mini?: typeof mini;
4
+ mini?: Partial<typeof bridge>;
5
5
  ReactNativeWebView?: {
6
6
  postMessage: (e: string) => void;
7
7
  };
8
8
  }
9
9
  }
10
- export declare const mini: {
11
- loaded: boolean;
10
+ declare const bridge: {
12
11
  getSystemInfoSync(): {
13
12
  statusBarHeight: number;
14
13
  pixelRatio: number;
@@ -27,8 +26,8 @@ export declare const mini: {
27
26
  }): void;
28
27
  methodSuccess(id: number, value: unknown): void;
29
28
  methodFail(id: number, err: Error): void;
30
- addListener(cb: (e: string, value?: string | undefined) => void): () => void;
31
- postMessage(e: string, value?: string | undefined): void;
29
+ addListener(cb: (e: string, value?: string) => void): () => void;
30
+ postMessage(e: string, value?: string): void;
32
31
  scanCode(opts: {
33
32
  success: (value: string) => void;
34
33
  }): void;
@@ -51,12 +50,80 @@ export declare const mini: {
51
50
  visible: boolean;
52
51
  }): void;
53
52
  /**
54
- * 监听扫码事件,常用于effect中, 并且effec重新执行需要销毁上一次注册的监听器
53
+ * @description 监听扫码事件,常用于effect中, 并且effec重新执行需要销毁上一次注册的监听器
55
54
  * @param opts
56
55
  * @returns 监听器销毁函数
57
56
  */
58
57
  listenScanCode(opts: {
59
58
  success: (value: string) => void;
60
59
  }): () => void;
60
+ /**
61
+ * @decription 与APP同步路由,支持APP左滑回退
62
+ * @param opts
63
+ */
64
+ syncRoutes(opts: {
65
+ params: {
66
+ title: string;
67
+ path: string;
68
+ }[];
69
+ }): void;
70
+ };
71
+ export declare const mini: {
72
+ getSystemInfoSync: () => {
73
+ statusBarHeight: number;
74
+ pixelRatio: number;
75
+ safeArea: {
76
+ top: number;
77
+ right: number;
78
+ bottom: number;
79
+ left: number;
80
+ };
81
+ };
82
+ getExtraPayload: () => any;
83
+ methodRegister: (name: string, opts?: {
84
+ success?: ((value: any) => void) | undefined;
85
+ fail?: ((err: Error) => void) | undefined;
86
+ params?: any;
87
+ }) => void;
88
+ methodSuccess: (id: number, value: unknown) => void;
89
+ methodFail: (id: number, err: Error) => void;
90
+ addListener: (cb: (e: string, value?: string) => void) => () => void;
91
+ postMessage: (e: string, value?: string) => void;
92
+ scanCode: (opts: {
93
+ success: (value: string) => void;
94
+ }) => void;
95
+ exit: () => void;
96
+ setStatusBarStyle: (opts: {
97
+ success?: () => void;
98
+ params: 'default' | 'light-content' | 'dark-content';
99
+ }) => void;
100
+ getUserInfo: (opts: {
101
+ success?: ((user: UserInfo) => void) | undefined;
102
+ }) => void;
103
+ getAccessToken: (opts: {
104
+ success?: ((token: string | null) => void) | undefined;
105
+ }) => void;
106
+ checkAccessToken: (opts: {
107
+ success?: ((token: string | null) => void) | undefined;
108
+ fail?: ((err: Error) => void) | undefined;
109
+ }) => void;
110
+ setCapsule: (opts: {
111
+ visible: boolean;
112
+ }) => void;
113
+ listenScanCode: (opts: {
114
+ success: (value: string) => void;
115
+ }) => () => void;
116
+ syncRoutes: (opts: {
117
+ params: {
118
+ title: string;
119
+ path: string;
120
+ }[];
121
+ }) => void;
122
+ loaded: boolean;
61
123
  };
124
+ /**
125
+ * deprecated
126
+ * @param render () => void
127
+ */
62
128
  export declare function createApp(render: () => void): void;
129
+ export {};
package/es/global.js CHANGED
@@ -1,10 +1,15 @@
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';
1
+ 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; }
2
+
3
+ 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; }
4
+
5
+ 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; }
6
+
7
+ 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, SYNC_ROUTES } from './constants';
8
+ var whiteList = ['localhost', 'csp.nhsoft.cn', '127.0.0.1'];
2
9
  var methods = {};
3
10
  var listeners = [];
4
11
  var methodID = 0;
5
- var whiteList = ['localhost', 'csp.nhsoft.cn', '127.0.0.1'];
6
- export var mini = {
7
- loaded: false,
12
+ var bridge = {
8
13
  getSystemInfoSync: function getSystemInfoSync() {
9
14
  return {
10
15
  statusBarHeight: 0,
@@ -79,42 +84,60 @@ export var mini = {
79
84
  });
80
85
  },
81
86
  scanCode: function scanCode(opts) {
82
- mini.methodRegister(SCAN_CODE, opts);
87
+ bridge.methodRegister(SCAN_CODE, opts);
83
88
  },
84
89
  exit: function exit() {
85
- mini.methodRegister(EXIT);
90
+ bridge.methodRegister(EXIT);
86
91
  },
87
92
  setStatusBarStyle: function setStatusBarStyle(opts) {
88
- mini.methodRegister(SET_STATUS_BAR_STYLE, opts);
93
+ bridge.methodRegister(SET_STATUS_BAR_STYLE, opts);
89
94
  },
90
95
  getUserInfo: function getUserInfo(opts) {
91
- mini.methodRegister(GET_USER_INFO, opts);
96
+ bridge.methodRegister(GET_USER_INFO, opts);
92
97
  },
93
98
  getAccessToken: function getAccessToken(opts) {
94
- mini.methodRegister(GET_ACCESS_TOKEN, opts);
99
+ bridge.methodRegister(GET_ACCESS_TOKEN, opts);
95
100
  },
96
101
  checkAccessToken: function checkAccessToken(opts) {
97
- mini.methodRegister(CHECK_ACCESS_TOKEN, opts);
102
+ bridge.methodRegister(CHECK_ACCESS_TOKEN, opts);
98
103
  },
99
104
  setCapsule: function setCapsule(opts) {
100
- mini.methodRegister(SET_CAPSULE, {
105
+ bridge.methodRegister(SET_CAPSULE, {
101
106
  params: opts
102
107
  });
103
108
  },
104
109
 
105
110
  /**
106
- * 监听扫码事件,常用于effect中, 并且effec重新执行需要销毁上一次注册的监听器
111
+ * @description 监听扫码事件,常用于effect中, 并且effec重新执行需要销毁上一次注册的监听器
107
112
  * @param opts
108
113
  * @returns 监听器销毁函数
109
114
  */
110
115
  listenScanCode: function listenScanCode(opts) {
111
- return mini.addListener(function (e, value) {
116
+ return bridge.addListener(function (e, value) {
112
117
  if (e === SCAN_CODE && value) {
113
118
  opts.success(value);
114
119
  }
115
120
  });
121
+ },
122
+
123
+ /**
124
+ * @decription 与APP同步路由,支持APP左滑回退
125
+ * @param opts
126
+ */
127
+ syncRoutes: function syncRoutes(opts) {
128
+ bridge.methodRegister(SYNC_ROUTES, {
129
+ params: opts
130
+ });
116
131
  }
117
132
  };
133
+ export var mini = _objectSpread(_objectSpread({
134
+ loaded: false
135
+ }, bridge), window.mini);
136
+ /**
137
+ * deprecated
138
+ * 兼容代码, TODO: 移除
139
+ */
140
+
118
141
  window.mini = mini;
119
142
  window.addEventListener('message', function (evt) {
120
143
  var result = /^(([^:\/\s]+):\/?\/?([^\/\s@]*@)?([^\/@:]*)?:?(\d+)?)?(\/[^?]*)?(\?([^#]*))?(#[\s\S]*)?$/.exec(evt.origin);
@@ -166,6 +189,11 @@ window.addEventListener('message', function (evt) {
166
189
  }
167
190
  }
168
191
  }, false);
192
+ /**
193
+ * deprecated
194
+ * @param render () => void
195
+ */
196
+
169
197
  export function createApp(render) {
170
198
  var count = 0;
171
199
 
@@ -1,3 +1,3 @@
1
1
  import type { Path } from '../typings';
2
- export declare function createPath({ pathname, search, hash }: Partial<Path>): string;
3
- export declare function parsePath(path: string): Partial<Path>;
2
+ export declare function createPath({ pathname: mPathname, search, hash }: Partial<Path>): string;
3
+ export declare function parsePath(mPath: string): Partial<Path>;
package/es/utils/path.js CHANGED
@@ -1,15 +1,17 @@
1
1
  export function createPath(_ref) {
2
2
  var _ref$pathname = _ref.pathname,
3
- pathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
3
+ mPathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
4
4
  _ref$search = _ref.search,
5
5
  search = _ref$search === void 0 ? '' : _ref$search,
6
6
  _ref$hash = _ref.hash,
7
7
  hash = _ref$hash === void 0 ? '' : _ref$hash;
8
+ var pathname = mPathname;
8
9
  if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
9
10
  if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
10
11
  return pathname;
11
12
  }
12
- export function parsePath(path) {
13
+ export function parsePath(mPath) {
14
+ var path = mPath;
13
15
  var parsedPath = {};
14
16
 
15
17
  if (path) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/mini-app",
3
- "version": "0.1.103",
3
+ "version": "1.0.0",
4
4
  "description": "> TODO: description",
5
5
  "author": "鲁盛杰 <lusj@cnlemon.net>",
6
6
  "homepage": "",
@@ -15,13 +15,6 @@
15
15
  "publishConfig": {
16
16
  "registry": "https://registry.npmjs.org"
17
17
  },
18
- "repository": {
19
- "type": "git",
20
- "url": "git@gitlab.nhsoft.cn:lemon-fe/kits-next.git"
21
- },
22
- "scripts": {
23
- "test": "echo \"Error: run tests from root\" && exit 1"
24
- },
25
18
  "dependencies": {
26
19
  "color-string": "^1.9.0",
27
20
  "react-transition-group": "^4.4.5"
@@ -35,5 +28,7 @@
35
28
  "react": "^17.0.2",
36
29
  "react-dom": "17.0.2"
37
30
  },
38
- "gitHead": "b9730ec895f4fc20b1ff2ed94a4b974f2b62a49b"
39
- }
31
+ "scripts": {
32
+ "test": "echo \"Error: run tests from root\" && exit 1"
33
+ }
34
+ }
@@ -1,21 +0,0 @@
1
- .lemon-capsule {
2
- position: fixed;
3
- right: 15px;
4
- bottom: 15px;
5
- height: 30px;
6
- background-color: rgba(255, 255, 255, 0.6);
7
- border: 1px solid rgba(151, 151, 151, 0.2);
8
- border-radius: 15px;
9
- }
10
-
11
- .lemon-capsule-item {
12
- display: flex;
13
- align-items: center;
14
- justify-content: center;
15
- width: 44px;
16
- height: 100%;
17
- }
18
-
19
- .lemon-capsule-item:active {
20
- opacity: 0.5;
21
- }
@@ -1,2 +0,0 @@
1
- import './index.css';
2
- export default function Capsule(): JSX.Element;
@@ -1,51 +0,0 @@
1
- import React from 'react';
2
- import './index.css';
3
- export default function Capsule() {
4
- var generateCode = function generateCode() {
5
- var url = "nhsoft://external-apps?url=".concat(encodeURIComponent(window.location.href));
6
- window.alert("".concat(url, "\uFF0C\u8BF7\u590D\u5236\u5E76\u751F\u6210\u4E8C\u7EF4\u7801\u901A\u8FC7APP\u626B\u63CF"));
7
- };
8
-
9
- return /*#__PURE__*/React.createElement("div", {
10
- className: "lemon-capsule",
11
- onClick: generateCode
12
- }, /*#__PURE__*/React.createElement("div", {
13
- className: "lemon-capsule-item",
14
- tabIndex: 0
15
- }, /*#__PURE__*/React.createElement("svg", {
16
- viewBox: "0 0 1024 1024",
17
- version: "1.1",
18
- xmlns: "http://www.w3.org/2000/svg",
19
- "p-id": "4228",
20
- width: "24",
21
- height: "24",
22
- fill: "#333"
23
- }, /*#__PURE__*/React.createElement("path", {
24
- d: "M152.075264 123.511808c101.716992 0 203.435008 0 305.152 0 31.031296 3.073024 23.552 57.696256 23.552 93.184 0 63.742976 0 105.755648 0 168.96 0 36.721664 6.915072 81.729536-17.408 92.16-15.840256 6.793216-58.351616 2.048-78.848 2.048-56.271872 0-102.012928 0-161.792 0-37.400576 0-88.469504 8.927232-94.208-23.552 0-103.083008 0-206.164992 0-309.248C132.70528 135.544832 140.061696 127.200256 152.075264 123.511808zM194.059264 193.143808c0 73.387008 0 146.772992 0 220.16 73.387008 0 146.772992 0 220.16 0 0-74.411008 0-148.820992 0-223.232-73.044992 0-146.091008 0-219.136 0C193.890304 190.24384 193.9712 191.690752 194.059264 193.143808z",
25
- "p-id": "4229"
26
- }), /*#__PURE__*/React.createElement("path", {
27
- d: "M561.675264 123.511808c101.716992 0 203.435008 0 305.152 0 12.447744 4.61824 21.001216 13.1328 23.552 27.648 0 100.352 0 200.705024 0 301.056-2.792448 12.510208-9.324544 23.196672-21.504 26.624-19.904512 5.600256-52.977664 1.024-76.8 1.024-56.127488 0-102.14912 0-156.672 0-23.626752 0-58.642432 4.97664-77.824-1.024-27.077632-8.471552-19.456-61.329408-19.456-98.304 0-49.115136 0-106.445824 0-157.696C538.123264 180.148224 528.75264 129.476608 561.675264 123.511808zM603.659264 193.143808c0 73.387008 0 146.772992 0 220.16 73.387008 0 146.772992 0 220.16 0 0-74.411008 0-148.820992 0-223.232-73.044992 0-146.091008 0-219.136 0C603.490304 190.24384 603.5712 191.690752 603.659264 193.143808z",
28
- "p-id": "4230"
29
- }), /*#__PURE__*/React.createElement("path", {
30
- d: "M294.411264 257.655808c30.661632-5.786624 54.774784 14.930944 55.296 43.008 0.687104 37.025792-37.129216 57.365504-66.56 41.984C249.47712 325.050368 251.693056 265.71776 294.411264 257.655808z",
31
- "p-id": "4231"
32
- }), /*#__PURE__*/React.createElement("path", {
33
- d: "M704.011264 257.655808c72.223744-13.493248 70.839296 100.886528 0 89.088C658.929664 339.23584 657.47456 266.350592 704.011264 257.655808z",
34
- "p-id": "4232"
35
- }), /*#__PURE__*/React.createElement("path", {
36
- d: "M455.179264 895.607808c-100.692992 0-201.385984 0-302.08 0-12.540928-3.843072-21.01248-11.75552-24.576-24.576 0-102.740992 0-205.483008 0-308.224 2.982912-9.019392 9.868288-19.542016 20.48-22.528 20.0448-5.640192 52.7872-1.024 76.8-1.024 55.189504 0 105.184256 0 156.672 0 23.154688 0 56.85248-5.168128 77.824 1.024 28.371968 8.37632 20.48 60.376064 20.48 97.28 0 56.7296 0 105.121792 0 162.816C480.779264 840.206336 489.356288 892.051456 455.179264 895.607808zM194.059264 608.887808c0 73.388032 0 146.772992 0 220.16 73.387008 0 146.772992 0 220.16 0 0-74.411008 0-148.820992 0-223.232-73.044992 0-146.091008 0-219.136 0C193.890304 605.98784 193.9712 607.434752 194.059264 608.887808z",
37
- "p-id": "4233"
38
- }), /*#__PURE__*/React.createElement("path", {
39
- d: "M890.379264 566.903808c0 28.672 0 57.344 0 86.016-2.388992 29.014016-0.342016 62.462976-1.024 93.184-72.704 0-145.408 0-218.112 0 0-16.724992 0-33.451008 0-50.176-20.481024-2.387968-45.395968-0.342016-67.584-1.024-2.388992 64.854016-0.340992 134.142976-1.024 200.704-13.312 0-26.624 0-39.936 0-34.337792-6.882304-24.576-58.407936-24.576-99.328 0-57.078784 0-104.042496 0-158.72 0-23.865344-4.830208-59.64288 1.024-78.848 6.984704-22.913024 37.274624-19.456 67.584-19.456 51.24096 0 96.891904 0 148.48 0 0 45.396992 0 90.795008 0 136.192 22.868992 0 45.739008 0 68.608 0 0.681984-45.056-1.364992-92.841984 1.024-136.192C857.858048 537.302016 888.439808 537.783296 890.379264 566.903808z",
40
- "p-id": "4234"
41
- }), /*#__PURE__*/React.createElement("path", {
42
- d: "M299.531264 672.375808c32.740352-3.623936 59.804672 27.841536 47.104 62.464-17.604608 47.98976-101.778432 29.953024-86.016-30.72C264.976384 687.348736 277.561344 674.807808 299.531264 672.375808z",
43
- "p-id": "4235"
44
- }), /*#__PURE__*/React.createElement("path", {
45
- d: "M744.971264 895.607808c-24.576 0-49.152 0-73.728 0 0.681984-26.284032-1.363968-55.294976 1.024-79.872 24.235008 0 48.468992 0 72.704 0C744.971264 842.359808 744.971264 868.983808 744.971264 895.607808z",
46
- "p-id": "4236"
47
- }), /*#__PURE__*/React.createElement("path", {
48
- d: "M890.379264 815.735808c0 17.408 0 34.816 0 52.224-2.84672 14.56128-11.36128 23.45472-24.576 27.648-17.408 0-34.816 0-52.224 0 0.681984-26.284032-1.363968-55.294976 1.024-79.872C839.862272 815.735808 865.120256 815.735808 890.379264 815.735808z",
49
- "p-id": "4237"
50
- }))));
51
- }