react-base-client 1.0.151 → 1.1.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.
Files changed (33) hide show
  1. package/package.json +2 -3
  2. package/src/.umi/core/EmptyRoute.tsx +9 -0
  3. package/src/.umi/core/defineApp.ts +18 -0
  4. package/src/.umi/core/history.ts +64 -0
  5. package/src/.umi/core/plugin.ts +52 -0
  6. package/src/.umi/core/pluginConfig.d.ts +327 -0
  7. package/src/.umi/core/polyfill.ts +163 -0
  8. package/src/.umi/core/route.tsx +13 -0
  9. package/src/.umi/core/terminal.ts +38 -0
  10. package/src/.umi/exports.ts +19 -0
  11. package/src/.umi/plugin-access/context.ts +5 -0
  12. package/src/.umi/plugin-access/index.tsx +87 -0
  13. package/src/.umi/plugin-access/runtime.tsx +23 -0
  14. package/src/.umi/plugin-initialState/@@initialState.ts +50 -0
  15. package/src/.umi/plugin-initialState/Provider.tsx +19 -0
  16. package/src/.umi/plugin-initialState/runtime.tsx +8 -0
  17. package/src/.umi/plugin-initialState/runtimeConfig.d.ts +5 -0
  18. package/src/.umi/plugin-model/index.tsx +181 -0
  19. package/src/.umi/plugin-model/model.ts +8 -0
  20. package/src/.umi/plugin-model/runtime.tsx +20 -0
  21. package/src/.umi/plugin-request/index.ts +9 -0
  22. package/src/.umi/plugin-request/request.ts +265 -0
  23. package/src/.umi/plugin-request/runtimeConfig.d.ts +6 -0
  24. package/src/.umi/plugin-request/types.d.ts +10 -0
  25. package/src/.umi/testBrowser.tsx +88 -0
  26. package/src/.umi/tsconfig.json +35 -0
  27. package/src/.umi/typings.d.ts +136 -0
  28. package/src/.umi/umi.ts +74 -0
  29. package/src/components/AMap/index.tsx +90 -32
  30. package/src/components/AMap/typing.d.ts +41 -36
  31. package/src/components/SubmitForm/index.tsx +138 -133
  32. package/src/components/XAMap/index.tsx +167 -0
  33. package/tsconfig.json +0 -29
@@ -0,0 +1,38 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ const console = globalThis.console;
5
+ let count = 0;
6
+ let groupLevel = 0;
7
+ function send(type: string, message?: string) {
8
+ if(process.env.NODE_ENV==='production'){
9
+ return;
10
+ }else{
11
+ const encodedMessage = message ? `&m=${encodeURI(message)}` : '';
12
+ fetch(`/__umi/api/terminal?type=${type}&t=${Date.now()}&c=${count++}&g=${groupLevel}${encodedMessage}`, { mode: 'no-cors' })
13
+ }
14
+ }
15
+ function prettyPrint(obj: any) {
16
+ return JSON.stringify(obj, null, 2);
17
+ }
18
+ function stringifyObjs(objs: any[]) {
19
+ const obj = objs.length > 1 ? objs.map(stringify).join(' ') : objs[0];
20
+ return typeof obj === 'object' ? `${prettyPrint(obj)}` : obj.toString();
21
+ }
22
+ function stringify(obj: any) {
23
+ return typeof obj === 'object' ? `${JSON.stringify(obj)}` : obj.toString();
24
+ }
25
+ const terminal = {
26
+ log(...objs: any[]) { send('log', stringifyObjs(objs)) },
27
+ info(...objs: any[]) { send('info', stringifyObjs(objs)) },
28
+ warn(...objs: any[]) { send('warn', stringifyObjs(objs)) },
29
+ error(...objs: any[]) { send('error', stringifyObjs(objs)) },
30
+ group() { groupLevel++ },
31
+ groupCollapsed() { groupLevel++ },
32
+ groupEnd() { groupLevel && --groupLevel },
33
+ clear() { send('clear') },
34
+ trace(...args: any[]) { console.trace(...args) },
35
+ profile(...args: any[]) { console.profile(...args) },
36
+ profileEnd(...args: any[]) { console.profileEnd(...args) },
37
+ };
38
+ export { terminal };
@@ -0,0 +1,19 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ // @umijs/renderer-*
5
+ export { createBrowserHistory, createHashHistory, createMemoryHistory, createSearchParams, generatePath, matchPath, matchRoutes, Navigate, NavLink, Outlet, resolvePath, useLocation, useMatch, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useSearchParams, Helmet, useAppData, useSelectedRoutes, useClientLoaderData, useServerLoaderData, renderClient, __getRoot, Link, useRouteData, __useFetcher, withRouter } from 'H:/af_code/af-react-mobile-base-client/node_modules/@umijs/renderer-react';
6
+ export type { History } from 'H:/af_code/af-react-mobile-base-client/node_modules/@umijs/renderer-react'
7
+ // umi/client/client/plugin
8
+ export { ApplyPluginsType, PluginManager } from 'H:/af_code/af-react-mobile-base-client/node_modules/umi/client/client/plugin.js';
9
+ export { history, createHistory } from './core/history';
10
+ export { terminal } from './core/terminal';
11
+ export { TestBrowser } from './testBrowser';
12
+ // plugins
13
+ export { Access, useAccess, useAccessMarkedRoutes } from 'H:/af_code/af-react-mobile-base-client/src/.umi/plugin-access';
14
+ export { Provider, useModel } from 'H:/af_code/af-react-mobile-base-client/src/.umi/plugin-model';
15
+ export { useRequest, UseRequestProvider, request, getRequestInstance } from 'H:/af_code/af-react-mobile-base-client/src/.umi/plugin-request';
16
+ // plugins types.d.ts
17
+ export * from 'H:/af_code/af-react-mobile-base-client/src/.umi/plugin-request/types.d';
18
+ export { defineApp } from './core/defineApp'
19
+ export type { RuntimeConfig } from './core/defineApp'
@@ -0,0 +1,5 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import React from 'react';
5
+ export const AccessContext = React.createContext<any>(null);
@@ -0,0 +1,87 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import React, { PropsWithChildren } from 'react';
5
+ import { AccessContext } from './context';
6
+ import type { IRoute } from 'umi';
7
+
8
+ export const useAccess = () => {
9
+ return React.useContext(AccessContext);
10
+ };
11
+
12
+ export interface AccessProps {
13
+ accessible: boolean;
14
+ fallback?: React.ReactNode;
15
+ }
16
+ export const Access: React.FC<PropsWithChildren<AccessProps>> = (props) => {
17
+ if (process.env.NODE_ENV === 'development' && typeof props.accessible !== 'boolean') {
18
+ throw new Error('[access] the `accessible` property on <Access /> should be a boolean');
19
+ }
20
+
21
+ return <>{ props.accessible ? props.children : props.fallback }</>;
22
+ };
23
+
24
+ export const useAccessMarkedRoutes = (routes: IRoute[]) => {
25
+ const access = useAccess();
26
+ const markdedRoutes: IRoute[] = React.useMemo(() => {
27
+ const process = (route, parentAccessCode, parentRoute) => {
28
+ let accessCode = route.access;
29
+ // 用父级的路由检测父级的 accessCode
30
+ let detectorRoute = route;
31
+ if (!accessCode && parentAccessCode) {
32
+ accessCode = parentAccessCode;
33
+ detectorRoute = parentRoute;
34
+ }
35
+
36
+ // set default status
37
+ route.unaccessible = false;
38
+
39
+ // check access code
40
+ if (typeof accessCode === 'string') {
41
+ const detector = access[accessCode];
42
+
43
+ if (typeof detector === 'function') {
44
+ route.unaccessible = !detector(detectorRoute);
45
+ } else if (typeof detector === 'boolean') {
46
+ route.unaccessible = !detector;
47
+ } else if (typeof detector === 'undefined') {
48
+ route.unaccessible = true;
49
+ }
50
+ }
51
+
52
+ // check children access code
53
+ if (route.children?.length) {
54
+ const isNoAccessibleChild = !route.children.reduce((hasAccessibleChild, child) => {
55
+ process(child, accessCode, route);
56
+
57
+ return hasAccessibleChild || !child.unaccessible;
58
+ }, false);
59
+
60
+ // make sure parent route is unaccessible if all children are unaccessible
61
+ if (isNoAccessibleChild) {
62
+ route.unaccessible = true;
63
+ }
64
+ }
65
+
66
+ // check children access code
67
+ if (route.routes?.length) {
68
+ const isNoAccessibleChild = !route.routes.reduce((hasAccessibleChild, child) => {
69
+ process(child, accessCode, route);
70
+
71
+ return hasAccessibleChild || !child.unaccessible;
72
+ }, false);
73
+
74
+ // make sure parent route is unaccessible if all children are unaccessible
75
+ if (isNoAccessibleChild) {
76
+ route.unaccessible = true;
77
+ }
78
+ }
79
+
80
+ return route;
81
+ }
82
+
83
+ return routes.map(route => process(route));
84
+ }, [routes.length, access]);
85
+
86
+ return markdedRoutes;
87
+ }
@@ -0,0 +1,23 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import React from 'react';
5
+ import accessFactory from '@/access'
6
+ import { useModel } from '@@/plugin-model';
7
+
8
+ import { AccessContext } from './context';
9
+
10
+ function Provider(props) {
11
+ const { initialState } = useModel('@@initialState');
12
+ const access = React.useMemo(() => accessFactory(initialState), [initialState]);
13
+
14
+ return (
15
+ <AccessContext.Provider value={access}>
16
+ { props.children }
17
+ </AccessContext.Provider>
18
+ );
19
+ }
20
+
21
+ export function accessProvider(container) {
22
+ return <Provider>{ container }</Provider>;
23
+ }
@@ -0,0 +1,50 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import { useState, useEffect, useCallback } from 'react';
5
+ import { getInitialState } from '@/app';
6
+
7
+ export type InitialStateType = Awaited<ReturnType<typeof getInitialState>> | undefined;
8
+
9
+ const initState = {
10
+ initialState: undefined as InitialStateType,
11
+ loading: true,
12
+ error: undefined,
13
+ };
14
+
15
+ export default () => {
16
+ const [state, setState] = useState(initState);
17
+ const refresh = useCallback(async () => {
18
+ setState((s) => ({ ...s, loading: true, error: undefined }));
19
+ try {
20
+ const ret = await getInitialState();
21
+ setState((s) => ({ ...s, initialState: ret, loading: false }));
22
+ } catch (e) {
23
+ setState((s) => ({ ...s, error: e, loading: false }));
24
+ }
25
+ }, []);
26
+
27
+ const setInitialState = useCallback(
28
+ async (
29
+ initialState: InitialStateType | ((initialState: InitialStateType) => InitialStateType),
30
+ ) => {
31
+ setState((s) => {
32
+ if (typeof initialState === 'function') {
33
+ return { ...s, initialState: initialState(s.initialState), loading: false };
34
+ }
35
+ return { ...s, initialState, loading: false };
36
+ });
37
+ },
38
+ [],
39
+ );
40
+
41
+ useEffect(() => {
42
+ refresh();
43
+ }, []);
44
+
45
+ return {
46
+ ...state,
47
+ refresh,
48
+ setInitialState,
49
+ };
50
+ }
@@ -0,0 +1,19 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import React from 'react';
5
+ import { useModel } from '@@/plugin-model';
6
+ function Loading() { return <div />; }
7
+ export default function InitialStateProvider(props: any) {
8
+ const appLoaded = React.useRef(false);
9
+ const { loading = false } = useModel("@@initialState") || {};
10
+ React.useEffect(() => {
11
+ if (!loading) {
12
+ appLoaded.current = true;
13
+ }
14
+ }, [loading]);
15
+ if (loading && !appLoaded.current) {
16
+ return <Loading />;
17
+ }
18
+ return props.children;
19
+ }
@@ -0,0 +1,8 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import React from 'react';
5
+ import Provider from './Provider';
6
+ export function dataflowProvider(container) {
7
+ return <Provider>{ container }</Provider>;
8
+ }
@@ -0,0 +1,5 @@
1
+ // This file is generated by Umi automatically
2
+ // DO NOT CHANGE IT MANUALLY!
3
+ export interface IRuntimeConfig {
4
+ getInitialState?: () => Promise<Record<string, any>>
5
+ }
@@ -0,0 +1,181 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ // @ts-ignore
5
+ import type { models as rawModels } from '@@/plugin-model/model';
6
+ import isEqual from 'H:/af_code/af-react-mobile-base-client/node_modules/fast-deep-equal/index.js';
7
+ import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
8
+
9
+ type Models = typeof rawModels;
10
+
11
+ type GetNamespaces<M> = {
12
+ [K in keyof M]: M[K] extends { namespace: string }
13
+ ? M[K]['namespace']
14
+ : never;
15
+ }[keyof M];
16
+
17
+ type Namespaces = GetNamespaces<Models>;
18
+
19
+ // @ts-ignore
20
+ const Context = React.createContext<{ dispatcher: Dispatcher }>(null);
21
+
22
+ class Dispatcher {
23
+ callbacks: Record<Namespaces, Set<Function>> = {};
24
+ data: Record<Namespaces, unknown> = {};
25
+ update = (namespace: Namespaces) => {
26
+ if (this.callbacks[namespace]) {
27
+ this.callbacks[namespace].forEach((cb) => {
28
+ try {
29
+ const data = this.data[namespace];
30
+ cb(data);
31
+ } catch (e) {
32
+ cb(undefined);
33
+ }
34
+ });
35
+ }
36
+ };
37
+ }
38
+
39
+ interface ExecutorProps {
40
+ hook: () => any;
41
+ onUpdate: (val: any) => void;
42
+ namespace: string;
43
+ }
44
+
45
+ function Executor(props: ExecutorProps) {
46
+ const { hook, onUpdate, namespace } = props;
47
+
48
+ const updateRef = useRef(onUpdate);
49
+ const initialLoad = useRef(false);
50
+
51
+ let data: any;
52
+ try {
53
+ data = hook();
54
+ } catch (e) {
55
+ console.error(
56
+ `plugin-model: Invoking '${namespace || 'unknown'}' model failed:`,
57
+ e,
58
+ );
59
+ }
60
+
61
+ // 首次执行时立刻返回初始值
62
+ useMemo(() => {
63
+ updateRef.current(data);
64
+ }, []);
65
+
66
+ // React 16.13 后 update 函数用 useEffect 包裹
67
+ useEffect(() => {
68
+ if (initialLoad.current) {
69
+ updateRef.current(data);
70
+ } else {
71
+ initialLoad.current = true;
72
+ }
73
+ });
74
+
75
+ return null;
76
+ }
77
+
78
+ const dispatcher = new Dispatcher();
79
+
80
+ export function Provider(props: {
81
+ models: Record<string, any>;
82
+ children: React.ReactNode;
83
+ }) {
84
+ return (
85
+ <Context.Provider value={{ dispatcher }}>
86
+ {Object.keys(props.models).map((namespace) => {
87
+ return (
88
+ <Executor
89
+ key={namespace}
90
+ hook={props.models[namespace]}
91
+ namespace={namespace}
92
+ onUpdate={(val) => {
93
+ dispatcher.data[namespace] = val;
94
+ dispatcher.update(namespace);
95
+ }}
96
+ />
97
+ );
98
+ })}
99
+ {props.children}
100
+ </Context.Provider>
101
+ );
102
+ }
103
+
104
+ type GetModelByNamespace<M, N> = {
105
+ [K in keyof M]: M[K] extends { namespace: string; model: unknown }
106
+ ? M[K]['namespace'] extends N
107
+ ? M[K]['model'] extends (...args: any) => any
108
+ ? ReturnType<M[K]['model']>
109
+ : never
110
+ : never
111
+ : never;
112
+ }[keyof M];
113
+
114
+ type Model<N> = GetModelByNamespace<Models, N>;
115
+ type Selector<N, S> = (model: Model<N>) => S;
116
+
117
+ type SelectedModel<N, T> = T extends (...args: any) => any
118
+ ? ReturnType<NonNullable<T>>
119
+ : Model<N>;
120
+
121
+ export function useModel<N extends Namespaces>(namespace: N): Model<N>;
122
+
123
+ export function useModel<N extends Namespaces, S>(
124
+ namespace: N,
125
+ selector: Selector<N, S>,
126
+ ): SelectedModel<N, typeof selector>;
127
+
128
+ export function useModel<N extends Namespaces, S>(
129
+ namespace: N,
130
+ selector?: Selector<N, S>,
131
+ ): SelectedModel<N, typeof selector> {
132
+ const { dispatcher } = useContext<{ dispatcher: Dispatcher }>(Context);
133
+ const selectorRef = useRef(selector);
134
+ selectorRef.current = selector;
135
+ const [state, setState] = useState(() =>
136
+ selectorRef.current
137
+ ? selectorRef.current(dispatcher.data[namespace])
138
+ : dispatcher.data[namespace],
139
+ );
140
+ const stateRef = useRef<any>(state);
141
+ stateRef.current = state;
142
+
143
+ const isMount = useRef(false);
144
+ useEffect(() => {
145
+ isMount.current = true;
146
+ return () => {
147
+ isMount.current = false;
148
+ };
149
+ }, []);
150
+
151
+ useEffect(() => {
152
+ const handler = (data: any) => {
153
+ if (!isMount.current) {
154
+ // 如果 handler 执行过程中,组件被卸载了,则强制更新全局 data
155
+ // TODO: 需要加个 example 测试
156
+ setTimeout(() => {
157
+ dispatcher.data[namespace] = data;
158
+ dispatcher.update(namespace);
159
+ });
160
+ } else {
161
+ const currentState = selectorRef.current
162
+ ? selectorRef.current(data)
163
+ : data;
164
+ const previousState = stateRef.current;
165
+ if (!isEqual(currentState, previousState)) {
166
+ setState(currentState);
167
+ }
168
+ }
169
+ };
170
+
171
+ dispatcher.callbacks[namespace] ||= new Set() as any; // rawModels 是 umi 动态生成的文件,导致前面 callback[namespace] 的类型无法推导出来,所以用 as any 来忽略掉
172
+ dispatcher.callbacks[namespace].add(handler);
173
+ dispatcher.update(namespace);
174
+
175
+ return () => {
176
+ dispatcher.callbacks[namespace].delete(handler);
177
+ };
178
+ }, [namespace]);
179
+
180
+ return state;
181
+ }
@@ -0,0 +1,8 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import model_1 from 'H:/af_code/af-react-mobile-base-client/src/.umi/plugin-initialState/@@initialState';
5
+
6
+ export const models = {
7
+ model_1: { namespace: '@@initialState', model: model_1 },
8
+ } as const
@@ -0,0 +1,20 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import React from 'react';
5
+ import { Provider } from './';
6
+ import { models as rawModels } from './model';
7
+
8
+ function ProviderWrapper(props: any) {
9
+ const models = React.useMemo(() => {
10
+ return Object.keys(rawModels).reduce((memo, key) => {
11
+ memo[rawModels[key].namespace] = rawModels[key].model;
12
+ return memo;
13
+ }, {});
14
+ }, []);
15
+ return <Provider models={models} {...props}>{ props.children }</Provider>
16
+ }
17
+
18
+ export function dataflowProvider(container, opts) {
19
+ return <ProviderWrapper {...opts}>{ container }</ProviderWrapper>;
20
+ }
@@ -0,0 +1,9 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ export {
5
+ useRequest,
6
+ UseRequestProvider,
7
+ request,
8
+ getRequestInstance,
9
+ } from './request';