@authing/native-js-ui-components 2.4.58 → 3.0.0-rc.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.
- package/lib/index.d.ts +26 -1
- package/lib/index.min.css +2 -1
- package/lib/index.min.js +2 -52806
- package/lib/index.min.js.LICENSE.txt +41 -0
- package/package.json +4 -3
- package/src/components/AuthingGuard/index.tsx +24 -9
- package/src/components/Guard/index.tsx +137 -0
- package/src/components/index.ts +5 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
object-assign
|
|
3
|
+
(c) Sindre Sorhus
|
|
4
|
+
@license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/*!
|
|
8
|
+
* The buffer module from node.js, for the browser.
|
|
9
|
+
*
|
|
10
|
+
* @author Feross Aboukhadijeh <http://feross.org>
|
|
11
|
+
* @license MIT
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
15
|
+
|
|
16
|
+
/** @license React v0.19.1
|
|
17
|
+
* scheduler.production.min.js
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
20
|
+
*
|
|
21
|
+
* This source code is licensed under the MIT license found in the
|
|
22
|
+
* LICENSE file in the root directory of this source tree.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** @license React v16.14.0
|
|
26
|
+
* react-dom.production.min.js
|
|
27
|
+
*
|
|
28
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
29
|
+
*
|
|
30
|
+
* This source code is licensed under the MIT license found in the
|
|
31
|
+
* LICENSE file in the root directory of this source tree.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/** @license React v16.14.0
|
|
35
|
+
* react.production.min.js
|
|
36
|
+
*
|
|
37
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
38
|
+
*
|
|
39
|
+
* This source code is licensed under the MIT license found in the
|
|
40
|
+
* LICENSE file in the root directory of this source tree.
|
|
41
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authing/native-js-ui-components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-rc.0",
|
|
4
|
+
"framework": "Native",
|
|
4
5
|
"private": false,
|
|
5
6
|
"main": "lib/index.min.js",
|
|
6
7
|
"typings": "lib/index.d.ts",
|
|
7
8
|
"dependencies": {
|
|
8
|
-
"@authing/react-ui-components": "^
|
|
9
|
+
"@authing/react-ui-components": "^3.0.0-rc.0",
|
|
9
10
|
"react": "16.14.0",
|
|
10
11
|
"react-dom": "16.14.0"
|
|
11
12
|
},
|
|
@@ -166,5 +167,5 @@
|
|
|
166
167
|
"webpack-manifest-plugin": "2.2.0",
|
|
167
168
|
"workbox-webpack-plugin": "5.1.4"
|
|
168
169
|
},
|
|
169
|
-
"gitHead": "
|
|
170
|
+
"gitHead": "e11810281e0d337f870d377e93bd369f92d42b6c"
|
|
170
171
|
}
|
|
@@ -40,11 +40,18 @@ export {
|
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export type EventListeners = {
|
|
43
|
-
[key in keyof GuardEventsHandlerKebab]: Exclude<
|
|
43
|
+
[key in keyof GuardEventsHandlerKebab]: Exclude<
|
|
44
|
+
Required<GuardEventsHandlerKebab>[key],
|
|
45
|
+
undefined
|
|
46
|
+
>[];
|
|
44
47
|
};
|
|
45
48
|
|
|
46
49
|
export class AuthingGuard {
|
|
47
|
-
constructor(
|
|
50
|
+
constructor(
|
|
51
|
+
private appId: string,
|
|
52
|
+
private config?: UserConfig,
|
|
53
|
+
private tenantId?: string
|
|
54
|
+
) {
|
|
48
55
|
this.render();
|
|
49
56
|
}
|
|
50
57
|
|
|
@@ -71,14 +78,19 @@ export class AuthingGuard {
|
|
|
71
78
|
|
|
72
79
|
private visible = this.config?.mode === GuardMode.Modal ? false : true;
|
|
73
80
|
|
|
74
|
-
private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce(
|
|
82
|
+
(acc, evtName) => {
|
|
83
|
+
return Object.assign({}, acc, {
|
|
84
|
+
[evtName]: [],
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
{} as EventListeners
|
|
88
|
+
);
|
|
79
89
|
|
|
80
90
|
private render(cb?: () => void) {
|
|
81
|
-
const evts: GuardEventsHandler = Object.entries(
|
|
91
|
+
const evts: GuardEventsHandler = Object.entries(
|
|
92
|
+
GuardEventsCamelToKebabMap
|
|
93
|
+
).reduce((acc, [reactEvt, nativeEvt]) => {
|
|
82
94
|
return Object.assign({}, acc, {
|
|
83
95
|
[reactEvt]: (...rest: any) => {
|
|
84
96
|
if (nativeEvt === "close") {
|
|
@@ -111,7 +123,10 @@ export class AuthingGuard {
|
|
|
111
123
|
);
|
|
112
124
|
}
|
|
113
125
|
|
|
114
|
-
on<T extends keyof GuardEventsHandlerKebab>(
|
|
126
|
+
on<T extends keyof GuardEventsHandlerKebab>(
|
|
127
|
+
evt: T,
|
|
128
|
+
handler: Exclude<GuardEventsHandlerKebab[T], undefined>
|
|
129
|
+
) {
|
|
115
130
|
this.eventListeners[evt]!.push(handler as any);
|
|
116
131
|
}
|
|
117
132
|
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import ReactDOM from "react-dom";
|
|
3
|
+
import { Guard as ReactAuthingGuard } from "@authing/react-ui-components";
|
|
4
|
+
import {
|
|
5
|
+
User,
|
|
6
|
+
GuardMode,
|
|
7
|
+
GuardScenes,
|
|
8
|
+
LoginMethods,
|
|
9
|
+
getAuthClient,
|
|
10
|
+
CommonMessage,
|
|
11
|
+
initAuthClient,
|
|
12
|
+
RegisterMethods,
|
|
13
|
+
GuardEventsHandler,
|
|
14
|
+
AuthenticationClient,
|
|
15
|
+
GuardEventsHandlerKebab,
|
|
16
|
+
GuardEventsCamelToKebabMap,
|
|
17
|
+
AuthenticationClientOptions,
|
|
18
|
+
} from "@authing/react-ui-components";
|
|
19
|
+
import "@authing/react-ui-components/lib/index.min.css";
|
|
20
|
+
import { GuardConfig } from "@authing/react-ui-components/components";
|
|
21
|
+
import { GuardComponentConifg } from "@authing/react-ui-components/components/Guard/config";
|
|
22
|
+
import { GuardEvents } from "@authing/react-ui-components/components/Guard/event";
|
|
23
|
+
|
|
24
|
+
export type {
|
|
25
|
+
User,
|
|
26
|
+
CommonMessage,
|
|
27
|
+
GuardEventsHandler,
|
|
28
|
+
AuthenticationClient,
|
|
29
|
+
GuardEventsHandlerKebab,
|
|
30
|
+
AuthenticationClientOptions,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
GuardMode,
|
|
35
|
+
GuardScenes,
|
|
36
|
+
LoginMethods,
|
|
37
|
+
getAuthClient,
|
|
38
|
+
initAuthClient,
|
|
39
|
+
RegisterMethods,
|
|
40
|
+
GuardEventsCamelToKebabMap,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type EventListeners = {
|
|
44
|
+
[key in keyof GuardEventsHandlerKebab]: Exclude<
|
|
45
|
+
Required<GuardEventsHandlerKebab>[key],
|
|
46
|
+
undefined
|
|
47
|
+
>[];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export class Guard {
|
|
51
|
+
constructor(private appId: string, private config?: GuardConfig) {
|
|
52
|
+
this.render();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static getGuardContainer(selector?: string | HTMLElement) {
|
|
56
|
+
const defaultId = "authing_guard_container";
|
|
57
|
+
|
|
58
|
+
if (!selector) {
|
|
59
|
+
let container = document.querySelector(`#${defaultId}`);
|
|
60
|
+
if (!container) {
|
|
61
|
+
container = document.createElement("div");
|
|
62
|
+
container.id = defaultId;
|
|
63
|
+
document.body.appendChild(container);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return container;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (typeof selector === "string") {
|
|
70
|
+
return document.querySelector(selector);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return selector;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private visible = this.config?.mode === GuardMode.Modal ? false : true;
|
|
77
|
+
|
|
78
|
+
private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce(
|
|
79
|
+
(acc, evtName) => {
|
|
80
|
+
return Object.assign({}, acc, {
|
|
81
|
+
[evtName]: [],
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
{} as EventListeners
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
private render(cb?: () => void) {
|
|
88
|
+
const evts: GuardEventsHandler = Object.entries(
|
|
89
|
+
GuardEventsCamelToKebabMap
|
|
90
|
+
).reduce((acc, [reactEvt, nativeEvt]) => {
|
|
91
|
+
return Object.assign({}, acc, {
|
|
92
|
+
[reactEvt]: (...rest: any) => {
|
|
93
|
+
if (nativeEvt === "close") {
|
|
94
|
+
this.hide();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// TODO 返回最后一个执行函数的值,实际应该只让监听一次
|
|
98
|
+
return (
|
|
99
|
+
this.eventListeners[nativeEvt]
|
|
100
|
+
// @ts-ignore
|
|
101
|
+
.map((item: any) => {
|
|
102
|
+
return item(...rest);
|
|
103
|
+
})
|
|
104
|
+
.slice(-1)[0] ?? true
|
|
105
|
+
);
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}, {} as GuardEventsHandler);
|
|
109
|
+
|
|
110
|
+
return ReactDOM.render(
|
|
111
|
+
<ReactAuthingGuard
|
|
112
|
+
{...(evts as GuardEvents)}
|
|
113
|
+
appId={this.appId}
|
|
114
|
+
config={this.config as GuardComponentConifg}
|
|
115
|
+
/>,
|
|
116
|
+
Guard.getGuardContainer(this.config?.target),
|
|
117
|
+
cb
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
on<T extends keyof GuardEventsHandlerKebab>(
|
|
122
|
+
evt: T,
|
|
123
|
+
handler: Exclude<GuardEventsHandlerKebab[T], undefined>
|
|
124
|
+
) {
|
|
125
|
+
this.eventListeners[evt]!.push(handler as any);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
show() {
|
|
129
|
+
this.visible = true;
|
|
130
|
+
this.render();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
hide() {
|
|
134
|
+
this.visible = false;
|
|
135
|
+
this.render();
|
|
136
|
+
}
|
|
137
|
+
}
|
package/src/components/index.ts
CHANGED