@authing/native-js-ui-components 3.0.0-rc.2 → 3.0.0-rc.4

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/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@authing/native-js-ui-components",
3
- "version": "3.0.0-rc.2",
4
- "framework": "Native",
3
+ "version": "3.0.0-rc.4",
5
4
  "private": false,
6
5
  "main": "lib/index.min.js",
7
6
  "typings": "lib/index.d.ts",
8
7
  "dependencies": {
9
- "@authing/react-ui-components": "3.0.0-rc.0",
8
+ "@authing/react-ui-components": "^3.0.0-rc.4",
10
9
  "react": "16.14.0",
11
10
  "react-dom": "16.14.0"
12
11
  },
@@ -167,5 +166,5 @@
167
166
  "webpack-manifest-plugin": "2.2.0",
168
167
  "workbox-webpack-plugin": "5.1.4"
169
168
  },
170
- "gitHead": "38168128397d6ea8bfa26f395532a493596a535d"
169
+ "gitHead": "6508c48dd4103ec5bd88aad52df3324cb4c93b66"
171
170
  }
package/src/App.tsx CHANGED
@@ -1,13 +1,18 @@
1
1
  import React, { useEffect } from "react";
2
2
  import "./App.css";
3
- import { Guard, GuardMode } from "./components";
3
+ import { AuthingGuard, GuardMode } from "./components";
4
4
 
5
5
  function App() {
6
6
  useEffect(() => {
7
- const guard = new Guard("6191cf610f772aa56dc70637", {
8
- target: ".App",
9
- mode: GuardMode.Modal,
10
- });
7
+ const guard = new AuthingGuard(
8
+ "6191cf610f772aa56dc70637",
9
+ {
10
+ target: ".App",
11
+ appHost: "https://core.dev2.authing-inc.co/",
12
+ mode: GuardMode.Modal,
13
+ },
14
+ "6194a41abf23c1d5268b362a"
15
+ );
11
16
 
12
17
  // @ts-ignore
13
18
  window.guard = guard;
@@ -40,18 +40,11 @@ export {
40
40
  };
41
41
 
42
42
  export type EventListeners = {
43
- [key in keyof GuardEventsHandlerKebab]: Exclude<
44
- Required<GuardEventsHandlerKebab>[key],
45
- undefined
46
- >[];
43
+ [key in keyof GuardEventsHandlerKebab]: Exclude<Required<GuardEventsHandlerKebab>[key], undefined>[];
47
44
  };
48
45
 
49
46
  export class AuthingGuard {
50
- constructor(
51
- private appId: string,
52
- private config?: UserConfig,
53
- private tenantId?: string
54
- ) {
47
+ constructor(private appId: string, private config?: UserConfig, private tenantId?: string) {
55
48
  this.render();
56
49
  }
57
50
 
@@ -78,19 +71,14 @@ export class AuthingGuard {
78
71
 
79
72
  private visible = this.config?.mode === GuardMode.Modal ? false : true;
80
73
 
81
- private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce(
82
- (acc, evtName) => {
83
- return Object.assign({}, acc, {
84
- [evtName]: [],
85
- });
86
- },
87
- {} as EventListeners
88
- );
74
+ private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce((acc, evtName) => {
75
+ return Object.assign({}, acc, {
76
+ [evtName]: [],
77
+ });
78
+ }, {} as EventListeners);
89
79
 
90
80
  private render(cb?: () => void) {
91
- const evts: GuardEventsHandler = Object.entries(
92
- GuardEventsCamelToKebabMap
93
- ).reduce((acc, [reactEvt, nativeEvt]) => {
81
+ const evts: GuardEventsHandler = Object.entries(GuardEventsCamelToKebabMap).reduce((acc, [reactEvt, nativeEvt]) => {
94
82
  return Object.assign({}, acc, {
95
83
  [reactEvt]: (...rest: any) => {
96
84
  if (nativeEvt === "close") {
@@ -123,10 +111,7 @@ export class AuthingGuard {
123
111
  );
124
112
  }
125
113
 
126
- on<T extends keyof GuardEventsHandlerKebab>(
127
- evt: T,
128
- handler: Exclude<GuardEventsHandlerKebab[T], undefined>
129
- ) {
114
+ on<T extends keyof GuardEventsHandlerKebab>(evt: T, handler: Exclude<GuardEventsHandlerKebab[T], undefined>) {
130
115
  this.eventListeners[evt]!.push(handler as any);
131
116
  }
132
117
 
@@ -1,8 +1 @@
1
- // export * from "./Guard";
2
- import { Guard } from "./Guard";
3
- import { GuardConfig, GuardLocalConfig } from "@authing/react-ui-components/components";
4
- export * from "./AuthingGuard";
5
-
6
- export { Guard };
7
- export type { GuardConfig, GuardLocalConfig };
8
-
1
+ export * from './AuthingGuard'
@@ -1,143 +0,0 @@
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 {
21
- GuardComponentConifg,
22
- GuardLocalConfig,
23
- } from "@authing/react-ui-components/components/Guard/config";
24
- import { GuardEvents } from "@authing/react-ui-components/components/Guard/event";
25
-
26
- export type {
27
- User,
28
- CommonMessage,
29
- GuardEventsHandler,
30
- AuthenticationClient,
31
- GuardEventsHandlerKebab,
32
- AuthenticationClientOptions,
33
- };
34
-
35
- export {
36
- GuardMode,
37
- GuardScenes,
38
- LoginMethods,
39
- getAuthClient,
40
- initAuthClient,
41
- RegisterMethods,
42
- GuardEventsCamelToKebabMap,
43
- };
44
-
45
- export type EventListeners = {
46
- [key in keyof GuardEventsHandlerKebab]: Exclude<
47
- Required<GuardEventsHandlerKebab>[key],
48
- undefined
49
- >[];
50
- };
51
-
52
- export class Guard {
53
- constructor(
54
- private appId: string,
55
- private config?: Partial<GuardLocalConfig>
56
- ) {
57
- this.render();
58
- }
59
-
60
- static getGuardContainer(selector?: string | HTMLElement) {
61
- const defaultId = "authing_guard_container";
62
-
63
- if (!selector) {
64
- let container = document.querySelector(`#${defaultId}`);
65
- if (!container) {
66
- container = document.createElement("div");
67
- container.id = defaultId;
68
- document.body.appendChild(container);
69
- }
70
-
71
- return container;
72
- }
73
-
74
- if (typeof selector === "string") {
75
- return document.querySelector(selector);
76
- }
77
-
78
- return selector;
79
- }
80
-
81
- private visible = this.config?.mode === GuardMode.Modal ? false : true;
82
-
83
- private eventListeners = Object.values(GuardEventsCamelToKebabMap).reduce(
84
- (acc, evtName) => {
85
- return Object.assign({}, acc, {
86
- [evtName]: [],
87
- });
88
- },
89
- {} as EventListeners
90
- );
91
-
92
- private render(cb?: () => void) {
93
- const evts: GuardEventsHandler = Object.entries(
94
- GuardEventsCamelToKebabMap
95
- ).reduce((acc, [reactEvt, nativeEvt]) => {
96
- return Object.assign({}, acc, {
97
- [reactEvt]: (...rest: any) => {
98
- if (nativeEvt === "close") {
99
- this.hide();
100
- }
101
-
102
- // TODO 返回最后一个执行函数的值,实际应该只让监听一次
103
- return (
104
- this.eventListeners[nativeEvt]
105
- // @ts-ignore
106
- .map((item: any) => {
107
- return item(...rest);
108
- })
109
- .slice(-1)[0] ?? true
110
- );
111
- },
112
- });
113
- }, {} as GuardEventsHandler);
114
-
115
- return ReactDOM.render(
116
- <ReactAuthingGuard
117
- {...(evts as GuardEvents)}
118
- appId={this.appId}
119
- config={this.config as GuardComponentConifg}
120
- visible={this.visible}
121
- />,
122
- Guard.getGuardContainer(this.config?.target),
123
- cb
124
- );
125
- }
126
-
127
- on<T extends keyof GuardEventsHandlerKebab>(
128
- evt: T,
129
- handler: Exclude<GuardEventsHandlerKebab[T], undefined>
130
- ) {
131
- this.eventListeners[evt]!.push(handler as any);
132
- }
133
-
134
- show() {
135
- this.visible = true;
136
- this.render();
137
- }
138
-
139
- hide() {
140
- this.visible = false;
141
- this.render();
142
- }
143
- }