@weavy/uikit-react 11.0.0 → 11.2.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/README.md +6 -5
- package/changelog.md +19 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/client/WeavyClient.d.ts +1 -1
- package/dist/cjs/types/contexts/MessengerContext.d.ts +1 -2
- package/dist/cjs/types/hooks/useUser.d.ts +2 -1
- package/dist/cjs/types/types/Messenger.d.ts +0 -1
- package/dist/cjs/types/types/types.d.ts +10 -6
- package/dist/cjs/types/utils/styles.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/client/WeavyClient.d.ts +1 -1
- package/dist/esm/types/contexts/MessengerContext.d.ts +1 -2
- package/dist/esm/types/hooks/useUser.d.ts +2 -1
- package/dist/esm/types/types/Messenger.d.ts +0 -1
- package/dist/esm/types/types/types.d.ts +10 -6
- package/dist/esm/types/utils/styles.d.ts +2 -2
- package/dist/index.d.ts +2 -3
- package/package.json +1 -1
- package/src/client/WeavyClient.ts +3 -3
- package/src/components/Chat.tsx +8 -11
- package/src/components/Conversation.tsx +2 -2
- package/src/components/ConversationListItem.tsx +2 -2
- package/src/components/FileBrowser.tsx +1 -1
- package/src/components/Messages.tsx +14 -13
- package/src/components/Messenger.tsx +4 -4
- package/src/components/Reactions.tsx +2 -1
- package/src/components/SearchUsers.tsx +2 -2
- package/src/components/Typing.tsx +4 -4
- package/src/contexts/MessengerContext.tsx +4 -12
- package/src/contexts/WeavyContext.tsx +8 -1
- package/src/hooks/useBadge.ts +1 -1
- package/src/hooks/useChat.ts +1 -1
- package/src/hooks/useConversation.ts +1 -1
- package/src/hooks/useConversations.ts +1 -1
- package/src/hooks/useFileUploader.ts +5 -1
- package/src/hooks/useMembers.ts +1 -1
- package/src/hooks/useMessages.ts +1 -1
- package/src/hooks/useMutateChat.ts +1 -1
- package/src/hooks/useMutateConversation.ts +1 -1
- package/src/hooks/useMutateConversationName.ts +1 -1
- package/src/hooks/useMutateDeleteReaction.ts +1 -1
- package/src/hooks/useMutateExternalBlobs.ts +1 -1
- package/src/hooks/useMutateMeeting.ts +1 -1
- package/src/hooks/useMutateMembers.ts +1 -1
- package/src/hooks/useMutateMessage.ts +2 -1
- package/src/hooks/useMutatePinned.ts +1 -1
- package/src/hooks/useMutateReaction.ts +1 -1
- package/src/hooks/useMutateRead.ts +1 -1
- package/src/hooks/useMutateRemoveMembers.ts +1 -1
- package/src/hooks/useMutateTyping.ts +1 -1
- package/src/hooks/usePresence.ts +4 -0
- package/src/hooks/useSearchUsers.ts +1 -1
- package/src/hooks/useUser.ts +4 -3
- package/src/index.ts +2 -2
- package/src/types/Messenger.ts +1 -1
- package/src/types/types.ts +12 -9
- package/src/utils/scrollbarDetection.js +50 -0
- package/src/utils/styles.ts +21 -6
|
@@ -18,7 +18,7 @@ export default function useMutateTyping() {
|
|
|
18
18
|
|
|
19
19
|
const mutateTyping = async ({ id }: MutateProps) => {
|
|
20
20
|
|
|
21
|
-
const response = await fetch(client.
|
|
21
|
+
const response = await fetch(client.url + "/api/conversations/" + id + "/typing", {
|
|
22
22
|
method: "PUT",
|
|
23
23
|
body: JSON.stringify({}),
|
|
24
24
|
headers: {
|
package/src/hooks/usePresence.ts
CHANGED
|
@@ -6,6 +6,10 @@ export default function usePresence() {
|
|
|
6
6
|
|
|
7
7
|
const {client} = useContext(WeavyContext);
|
|
8
8
|
|
|
9
|
+
if (!client) {
|
|
10
|
+
throw new Error('usePresence must be used within an WeavyProvider');
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
useEffect(() => {
|
|
10
14
|
client.subscribe("online", "online", handlePresenceChange)
|
|
11
15
|
}, []);
|
|
@@ -12,7 +12,7 @@ export default function useSearchUsers(text: string, options: any) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const getUsers = async () => {
|
|
15
|
-
const response = await fetch(client.
|
|
15
|
+
const response = await fetch(client.url + "/api/users?q=" + text + "&skip=0&top=" + PAGE_SIZE, {
|
|
16
16
|
headers: {
|
|
17
17
|
"content-type": "application/json",
|
|
18
18
|
"Authorization": "Bearer " + await client.tokenFactory()
|
package/src/hooks/useUser.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
//import { useContext } from "react";
|
|
2
2
|
import { useQuery } from "react-query";
|
|
3
|
+
import WeavyClient from "../client/WeavyClient";
|
|
3
4
|
//import { WeavyContext } from "../contexts/WeavyContext";
|
|
4
5
|
|
|
5
6
|
/// GET current user
|
|
6
|
-
export default function useUser(client:
|
|
7
|
+
export default function useUser(client: WeavyClient) {
|
|
7
8
|
//const { client } = useContext(WeavyContext);
|
|
8
9
|
|
|
9
10
|
if (!client) {
|
|
@@ -13,7 +14,7 @@ export default function useUser(client: any) {
|
|
|
13
14
|
const getUser = async () => {
|
|
14
15
|
|
|
15
16
|
try {
|
|
16
|
-
const response = await fetch(client.
|
|
17
|
+
const response = await fetch(client.url + "/api/user", {
|
|
17
18
|
headers: {
|
|
18
19
|
"content-type": "application/json",
|
|
19
20
|
"Authorization": "Bearer " + await client.tokenFactory()
|
|
@@ -27,7 +28,7 @@ export default function useUser(client: any) {
|
|
|
27
28
|
console.error("Could not load Weavy user data...")
|
|
28
29
|
return null;
|
|
29
30
|
} catch(err: any){
|
|
30
|
-
console.error(`Could not connect to the Weavy backend. Please make sure ${client.
|
|
31
|
+
console.error(`Could not connect to the Weavy backend. Please make sure ${client.url} is up and running!`)
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import WeavyClient from './client/WeavyClient';
|
|
2
2
|
import WeavyProvider from './contexts/WeavyContext';
|
|
3
|
-
import
|
|
3
|
+
import { WeavyContext } from './contexts/WeavyContext';
|
|
4
4
|
import MessengerProvider from './contexts/MessengerContext';
|
|
5
|
-
import
|
|
5
|
+
import { MessengerContext } from './contexts/MessengerContext';
|
|
6
6
|
import Messenger from './components/Messenger';
|
|
7
7
|
import ConversationBadge from './components/ConversationBadge';
|
|
8
8
|
import ConversationList from './components/ConversationList';
|
package/src/types/Messenger.ts
CHANGED
package/src/types/types.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
interface WeavyClient {
|
|
2
|
+
url: string,
|
|
3
|
+
tokenFactory: (() => string | Promise<string>),
|
|
4
|
+
subscribe: Function,
|
|
5
|
+
unsubscribe: Function,
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
type WeavyClientOptions = {
|
|
2
|
-
|
|
9
|
+
url: string,
|
|
3
10
|
tokenFactory: (() => string | Promise<string>)
|
|
4
11
|
}
|
|
5
12
|
|
|
6
13
|
type WeavyContextProps = {
|
|
7
|
-
client:
|
|
14
|
+
client: WeavyClient | null,
|
|
8
15
|
options?: WeavyContextOptions
|
|
9
16
|
};
|
|
10
17
|
|
|
@@ -12,11 +19,12 @@ type WeavyContextOptions = {
|
|
|
12
19
|
zoomAuthenticationUrl?: string,
|
|
13
20
|
teamsAuthenticationUrl?: string,
|
|
14
21
|
enableCloudFiles?: boolean,
|
|
15
|
-
|
|
22
|
+
enableScrollbarDetection?: boolean,
|
|
23
|
+
filebrowserUrl?: string,
|
|
24
|
+
reactions?: string[]
|
|
16
25
|
}
|
|
17
26
|
|
|
18
27
|
type MessengerContextProps = {
|
|
19
|
-
options?: MessengerContextOptions,
|
|
20
28
|
selectedConversationId: null | number,
|
|
21
29
|
setSelectedConversationId: Function
|
|
22
30
|
};
|
|
@@ -25,11 +33,6 @@ type UserContextProps = {
|
|
|
25
33
|
user: UserType
|
|
26
34
|
};
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
type MessengerContextOptions = {
|
|
30
|
-
reactions?: string[]
|
|
31
|
-
}
|
|
32
|
-
|
|
33
36
|
type PreviewContextProps = {
|
|
34
37
|
openPreview: Function,
|
|
35
38
|
closePreview: Function
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { prefix } from "./styles";
|
|
2
|
+
|
|
3
|
+
// SCROLLBAR DETECTION
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The target which the scrollbar classname will be applied to.
|
|
7
|
+
* @type Element
|
|
8
|
+
*/
|
|
9
|
+
export var scrollbarClassnameTarget = document.documentElement;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The callback function for the scrollbar observer.
|
|
13
|
+
* @param {ResizeObserverTarget[]} entries
|
|
14
|
+
*/
|
|
15
|
+
export function checkScrollbar(entries) {
|
|
16
|
+
var element, overflowWidth;
|
|
17
|
+
for (var entry in entries) {
|
|
18
|
+
element = entries[entry].target;
|
|
19
|
+
try {
|
|
20
|
+
overflowWidth = element === document.documentElement ? window.innerWidth : element.clientWidth;
|
|
21
|
+
if (overflowWidth !== element.offsetWidth) {
|
|
22
|
+
// we have visible scrollbars, add .scrollbar to html element
|
|
23
|
+
scrollbarClassnameTarget.classList.add(prefix("scrollbars"));
|
|
24
|
+
} else {
|
|
25
|
+
scrollbarClassnameTarget.classList.remove(prefix("scrollbars"));
|
|
26
|
+
}
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.warn("scrollbar detection failed", e);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Creates a scrollbar detection element and starts observing it.
|
|
35
|
+
*/
|
|
36
|
+
export default function observeScrollbars() {
|
|
37
|
+
// insert scrollbar detection element
|
|
38
|
+
var scrollCheck = document.getElementById(prefix("scrollbar-detection"));
|
|
39
|
+
|
|
40
|
+
if (!scrollCheck) {
|
|
41
|
+
scrollCheck = document.createElement("aside");
|
|
42
|
+
scrollCheck.id = prefix("scrollbar-detection");
|
|
43
|
+
scrollCheck.className = prefix("scrollbar-detection");
|
|
44
|
+
document.documentElement.insertBefore(scrollCheck, document.body);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var scrollObserver = new ResizeObserver(checkScrollbar);
|
|
48
|
+
scrollObserver.observe(scrollCheck);
|
|
49
|
+
}
|
|
50
|
+
|
package/src/utils/styles.ts
CHANGED
|
@@ -13,7 +13,7 @@ var themePrefix = "wy";
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Prefixes one or more classnames (with or without dot) using the themePrefix
|
|
16
|
+
* Prefixes one or more classnames (with or without dot or double dash) using the themePrefix
|
|
17
17
|
* @param {...string} strs
|
|
18
18
|
* @returns string[]
|
|
19
19
|
*/
|
|
@@ -22,18 +22,33 @@ var themePrefix = "wy";
|
|
|
22
22
|
if (_prefix) {
|
|
23
23
|
strs = strs.map((str) => {
|
|
24
24
|
str ??= '';
|
|
25
|
-
if (str[0] === '.') {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
if (str[0] === '.') { // .example-class
|
|
26
|
+
// Skip if already set
|
|
27
|
+
if (str.substring(1).indexOf(_prefix + "-") !== 0) {
|
|
28
|
+
return `.${_prefix}-${str.substring(1)}`;
|
|
29
|
+
}
|
|
30
|
+
} else if (str.indexOf("--") === 0) { // --example-var
|
|
31
|
+
// Skip if already set
|
|
32
|
+
if (str.substring(2).indexOf(_prefix + "-") !== 0) {
|
|
33
|
+
return `--${_prefix}-${str.substring(2)}`;
|
|
34
|
+
}
|
|
35
|
+
} else { // example-class
|
|
36
|
+
// Skip if already set
|
|
37
|
+
if (str.indexOf(_prefix + "-") !== 0) {
|
|
38
|
+
return `${_prefix}-${str}`;
|
|
39
|
+
}
|
|
29
40
|
}
|
|
41
|
+
|
|
42
|
+
// return untouched str
|
|
43
|
+
return str;
|
|
44
|
+
|
|
30
45
|
})
|
|
31
46
|
}
|
|
32
47
|
return strs;
|
|
33
48
|
}
|
|
34
49
|
|
|
35
50
|
/**
|
|
36
|
-
* Prefixes
|
|
51
|
+
* Prefixes a classname string (containing one or multiple space-separated classnames, with or without dot or double dash) using the themePrefix
|
|
37
52
|
* @param {string} str
|
|
38
53
|
* @returns string
|
|
39
54
|
*/
|