@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.
Files changed (60) hide show
  1. package/README.md +6 -5
  2. package/changelog.md +19 -0
  3. package/dist/cjs/index.js +2 -2
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/types/client/WeavyClient.d.ts +1 -1
  6. package/dist/cjs/types/contexts/MessengerContext.d.ts +1 -2
  7. package/dist/cjs/types/hooks/useUser.d.ts +2 -1
  8. package/dist/cjs/types/types/Messenger.d.ts +0 -1
  9. package/dist/cjs/types/types/types.d.ts +10 -6
  10. package/dist/cjs/types/utils/styles.d.ts +2 -2
  11. package/dist/esm/index.js +2 -2
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/esm/types/client/WeavyClient.d.ts +1 -1
  14. package/dist/esm/types/contexts/MessengerContext.d.ts +1 -2
  15. package/dist/esm/types/hooks/useUser.d.ts +2 -1
  16. package/dist/esm/types/types/Messenger.d.ts +0 -1
  17. package/dist/esm/types/types/types.d.ts +10 -6
  18. package/dist/esm/types/utils/styles.d.ts +2 -2
  19. package/dist/index.d.ts +2 -3
  20. package/package.json +1 -1
  21. package/src/client/WeavyClient.ts +3 -3
  22. package/src/components/Chat.tsx +8 -11
  23. package/src/components/Conversation.tsx +2 -2
  24. package/src/components/ConversationListItem.tsx +2 -2
  25. package/src/components/FileBrowser.tsx +1 -1
  26. package/src/components/Messages.tsx +14 -13
  27. package/src/components/Messenger.tsx +4 -4
  28. package/src/components/Reactions.tsx +2 -1
  29. package/src/components/SearchUsers.tsx +2 -2
  30. package/src/components/Typing.tsx +4 -4
  31. package/src/contexts/MessengerContext.tsx +4 -12
  32. package/src/contexts/WeavyContext.tsx +8 -1
  33. package/src/hooks/useBadge.ts +1 -1
  34. package/src/hooks/useChat.ts +1 -1
  35. package/src/hooks/useConversation.ts +1 -1
  36. package/src/hooks/useConversations.ts +1 -1
  37. package/src/hooks/useFileUploader.ts +5 -1
  38. package/src/hooks/useMembers.ts +1 -1
  39. package/src/hooks/useMessages.ts +1 -1
  40. package/src/hooks/useMutateChat.ts +1 -1
  41. package/src/hooks/useMutateConversation.ts +1 -1
  42. package/src/hooks/useMutateConversationName.ts +1 -1
  43. package/src/hooks/useMutateDeleteReaction.ts +1 -1
  44. package/src/hooks/useMutateExternalBlobs.ts +1 -1
  45. package/src/hooks/useMutateMeeting.ts +1 -1
  46. package/src/hooks/useMutateMembers.ts +1 -1
  47. package/src/hooks/useMutateMessage.ts +2 -1
  48. package/src/hooks/useMutatePinned.ts +1 -1
  49. package/src/hooks/useMutateReaction.ts +1 -1
  50. package/src/hooks/useMutateRead.ts +1 -1
  51. package/src/hooks/useMutateRemoveMembers.ts +1 -1
  52. package/src/hooks/useMutateTyping.ts +1 -1
  53. package/src/hooks/usePresence.ts +4 -0
  54. package/src/hooks/useSearchUsers.ts +1 -1
  55. package/src/hooks/useUser.ts +4 -3
  56. package/src/index.ts +2 -2
  57. package/src/types/Messenger.ts +1 -1
  58. package/src/types/types.ts +12 -9
  59. package/src/utils/scrollbarDetection.js +50 -0
  60. 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.uri + "/api/conversations/" + id + "/typing", {
21
+ const response = await fetch(client.url + "/api/conversations/" + id + "/typing", {
22
22
  method: "PUT",
23
23
  body: JSON.stringify({}),
24
24
  headers: {
@@ -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.uri + "/api/users?q=" + text + "&skip=0&top=" + PAGE_SIZE, {
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()
@@ -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: any) {
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.uri + "/api/user", {
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.uri} is up and running!`)
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 { WeavyContext } from './contexts/WeavyContext';
3
+ import { WeavyContext } from './contexts/WeavyContext';
4
4
  import MessengerProvider from './contexts/MessengerContext';
5
- import { MessengerContext } from './contexts/MessengerContext';
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';
@@ -1,3 +1,3 @@
1
1
  export interface Messenger {
2
- options?: MessengerContextOptions
2
+
3
3
  }
@@ -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
- uri: string,
9
+ url: string,
3
10
  tokenFactory: (() => string | Promise<string>)
4
11
  }
5
12
 
6
13
  type WeavyContextProps = {
7
- client: any,
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
- filebrowserUrl?: string
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
+
@@ -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
- return `.${_prefix}-${str.substring(1)}`;
27
- } else {
28
- return `${_prefix}-${str}`;
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 one classname (with or without dot) using the themePrefix
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
  */