wirejs-components 0.1.108 → 0.1.109
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.
|
@@ -4,9 +4,8 @@ export declare const AccountMenu: ({ api, initialState, topItems, bottomItems }:
|
|
|
4
4
|
initialState?: AuthenticationMachineState;
|
|
5
5
|
topItems?: (HTMLElement | ((state: AuthenticationState | undefined) => HTMLElement))[];
|
|
6
6
|
bottomItems?: (HTMLElement | ((state: AuthenticationState | undefined) => HTMLElement))[];
|
|
7
|
-
}) => HTMLElement & {
|
|
7
|
+
}) => Promise<HTMLElement & {
|
|
8
8
|
data: {
|
|
9
|
-
user: string;
|
|
10
9
|
menu: HTMLDivElement;
|
|
11
10
|
topSubmenu: HTMLElement[];
|
|
12
11
|
authenticator: HTMLElement & {
|
|
@@ -53,7 +52,6 @@ export declare const AccountMenu: ({ api, initialState, topItems, bottomItems }:
|
|
|
53
52
|
};
|
|
54
53
|
} & import("wirejs-dom/v2").DomEvents<HTMLElement & {
|
|
55
54
|
data: {
|
|
56
|
-
user: string;
|
|
57
55
|
menu: HTMLDivElement;
|
|
58
56
|
topSubmenu: HTMLElement[];
|
|
59
57
|
authenticator: HTMLElement & {
|
|
@@ -100,7 +98,6 @@ export declare const AccountMenu: ({ api, initialState, topItems, bottomItems }:
|
|
|
100
98
|
};
|
|
101
99
|
}> & import("wirejs-dom/v2").Extend<HTMLElement & {
|
|
102
100
|
data: {
|
|
103
|
-
user: string;
|
|
104
101
|
menu: HTMLDivElement;
|
|
105
102
|
topSubmenu: HTMLElement[];
|
|
106
103
|
authenticator: HTMLElement & {
|
|
@@ -145,4 +142,4 @@ export declare const AccountMenu: ({ api, initialState, topItems, bottomItems }:
|
|
|
145
142
|
}>;
|
|
146
143
|
bottomSubmenu: HTMLElement[];
|
|
147
144
|
};
|
|
148
|
-
}
|
|
145
|
+
}>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { html, node, id, list, css } from 'wirejs-dom/v2';
|
|
2
2
|
import { Authenticator } from './authenticator.js';
|
|
3
|
+
import { AuthenticatedContent } from './authenticated-content.js';
|
|
3
4
|
import { AuthMonitor } from '../utils/auth-monitor.js';
|
|
4
5
|
const style = css `
|
|
5
6
|
accountmenu {
|
|
@@ -15,7 +16,8 @@ const style = css `
|
|
|
15
16
|
border: 1px solid silver;
|
|
16
17
|
border-radius: 0.25rem;
|
|
17
18
|
cursor: pointer;
|
|
18
|
-
padding: 0 0.
|
|
19
|
+
padding: 0 0.25rem;
|
|
20
|
+
font-size: 1.5rem;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
.menu {
|
|
@@ -28,7 +30,7 @@ const style = css `
|
|
|
28
30
|
box-shadow: -0.125rem 0.125rem 0.25rem lightgray;
|
|
29
31
|
}
|
|
30
32
|
`;
|
|
31
|
-
export const AccountMenu = ({ api, initialState, topItems, bottomItems }) => {
|
|
33
|
+
export const AccountMenu = async ({ api, initialState, topItems, bottomItems }) => {
|
|
32
34
|
const uiState = {
|
|
33
35
|
expanded: false
|
|
34
36
|
};
|
|
@@ -60,7 +62,6 @@ export const AccountMenu = ({ api, initialState, topItems, bottomItems }) => {
|
|
|
60
62
|
const isSameState = lastKnownState && lastKnownState.state === state?.state;
|
|
61
63
|
const hasMessage = state?.message;
|
|
62
64
|
lastKnownState = state;
|
|
63
|
-
self.data.user = state?.user?.username || '';
|
|
64
65
|
if (!isSameState && !hasMessage)
|
|
65
66
|
close();
|
|
66
67
|
if (!isSameState) {
|
|
@@ -87,9 +88,19 @@ export const AccountMenu = ({ api, initialState, topItems, bottomItems }) => {
|
|
|
87
88
|
const getBottomMenu = () => (bottomItems || []).map(item => typeof item === 'function' ? item(lastKnownState) : item);
|
|
88
89
|
const self = html `<accountmenu>
|
|
89
90
|
${style}
|
|
90
|
-
<div class='
|
|
91
|
-
|
|
91
|
+
<div class='handle' onclick=${handleMenuClick}>${await AuthenticatedContent({
|
|
92
|
+
authenticated: (user) => html `<span>📋</span>`,
|
|
93
|
+
unauthenticated: () => html `<span>🫥</span>`,
|
|
94
|
+
loading: () => html `<span>⏳</span>`
|
|
95
|
+
})}</div>
|
|
92
96
|
<div class='menu' ${id('menu', HTMLDivElement)}>
|
|
97
|
+
${await AuthenticatedContent({
|
|
98
|
+
authenticated: (user) => html `<p>
|
|
99
|
+
Signed in as <b>${user.username}</b>.
|
|
100
|
+
</p>`,
|
|
101
|
+
unauthenticated: () => html `<p>Your are <i>Anonymous</i>.</p>`,
|
|
102
|
+
loading: () => html `<i>Loading ...</i>`
|
|
103
|
+
})}
|
|
93
104
|
${list('topSubmenu', getTopMenu())}
|
|
94
105
|
${node('authenticator', authenticator)}
|
|
95
106
|
${list('bottomSubmenu', getBottomMenu())}
|
|
@@ -98,7 +109,6 @@ export const AccountMenu = ({ api, initialState, topItems, bottomItems }) => {
|
|
|
98
109
|
if (!initialState) {
|
|
99
110
|
const state = await api.getState(null);
|
|
100
111
|
authenticator.data.setState(state);
|
|
101
|
-
self.data.user = state.user?.username || '';
|
|
102
112
|
}
|
|
103
113
|
});
|
|
104
114
|
return self;
|
|
@@ -2,17 +2,18 @@ import type { User } from "wirejs-resources";
|
|
|
2
2
|
export declare function AuthenticatedContent(options: {
|
|
3
3
|
authenticated: (user: User) => HTMLElement | Promise<HTMLElement>;
|
|
4
4
|
unauthenticated: () => HTMLElement | Promise<HTMLElement>;
|
|
5
|
+
loading?: () => HTMLElement | string;
|
|
5
6
|
containerElement?: string;
|
|
6
7
|
}): Promise<HTMLElement & {
|
|
7
8
|
data: {
|
|
8
|
-
content: HTMLElement;
|
|
9
|
+
content: string | HTMLElement;
|
|
9
10
|
};
|
|
10
11
|
} & import("wirejs-dom/v2").DomEvents<HTMLElement & {
|
|
11
12
|
data: {
|
|
12
|
-
content: HTMLElement;
|
|
13
|
+
content: string | HTMLElement;
|
|
13
14
|
};
|
|
14
15
|
}> & import("wirejs-dom/v2").Extend<HTMLElement & {
|
|
15
16
|
data: {
|
|
16
|
-
content: HTMLElement;
|
|
17
|
+
content: string | HTMLElement;
|
|
17
18
|
};
|
|
18
19
|
}>>;
|
|
@@ -6,9 +6,9 @@ export async function AuthenticatedContent(options) {
|
|
|
6
6
|
return state.state;
|
|
7
7
|
};
|
|
8
8
|
const getContent = async (state) => {
|
|
9
|
-
return state
|
|
9
|
+
return state ? (state.state === 'authenticated'
|
|
10
10
|
? await options.authenticated(state.user)
|
|
11
|
-
: await options.unauthenticated();
|
|
11
|
+
: await options.unauthenticated()) : (options.loading?.() ?? html `<span>⏳</span>`);
|
|
12
12
|
};
|
|
13
13
|
const initialContent = await getContent(AuthMonitor.lastKnownState);
|
|
14
14
|
const render = async (state) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wirejs-components",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.109",
|
|
4
4
|
"description": "Client-side components for wirejs apps, including basic UI and resource-aware components.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"homepage": "https://github.com/svidgen/create-wirejs-app#readme",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"wirejs-dom": "^1.0.44",
|
|
34
|
-
"wirejs-resources": "^0.1.
|
|
34
|
+
"wirejs-resources": "^0.1.166"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"typescript": "^5.7.3"
|