@blocklet/discuss-kit-ux 2.1.90 → 2.1.92

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.
@@ -1,11 +1,13 @@
1
1
  import { User } from '../../types';
2
2
  import { default as ChatClient } from './chat-client';
3
- import { Chat as ChatType, ChannelUpdatePayload } from './types';
3
+ import { Message, Chat as ChatType, ChannelUpdatePayload } from './types';
4
4
  export interface ChatProviderProps {
5
5
  children: React.ReactNode;
6
6
  client: ChatClient;
7
7
  activeChatId?: string | null;
8
8
  isInWallet: boolean;
9
+ renderMessage?: (message: Message) => React.ReactNode;
10
+ chatRoomHeaderAddons?: (chat: ChatType) => React.ReactNode;
9
11
  }
10
12
  type EditingChannel = ChannelUpdatePayload | null;
11
13
  interface ChatState {
@@ -36,7 +38,9 @@ interface ChatContextValue extends ChatState {
36
38
  getLastMessageText: (chat: ChatType) => string;
37
39
  isInWallet: boolean;
38
40
  setEditingChannel: (channel: EditingChannel) => void;
41
+ renderMessage?: (message: Message) => React.ReactNode;
42
+ chatRoomHeaderAddons?: (chat: ChatType) => React.ReactNode;
39
43
  }
40
44
  export declare const useChatContext: () => ChatContextValue;
41
- export declare function ChatProvider({ client, activeChatId, children, isInWallet }: ChatProviderProps): import("react/jsx-runtime").JSX.Element;
45
+ export declare function ChatProvider({ client, activeChatId, children, isInWallet, renderMessage, chatRoomHeaderAddons, }: ChatProviderProps): import("react/jsx-runtime").JSX.Element;
42
46
  export {};
@@ -4,7 +4,7 @@ import { OnContentChangePlugin } from "@blocklet/editor/lib/ext/OnContentChangeP
4
4
  import { CtrlsShortcutPlugin } from "@blocklet/editor/lib/ext/ShortcutPlugin";
5
5
  import { SafeAreaPlugin } from "@blocklet/editor/lib/ext/SafeAreaPlugin";
6
6
  import { lazyRetry } from "@arcblock/ux/lib/Util";
7
- import { i as inferInitialEditorState, I as ImagePathFixerPlugin, V as VideoPathFixerPlugin, a as isEmptyContent, s as stringify, g as getExcerptSync } from "./index-D5Gxtfb_.mjs";
7
+ import { i as inferInitialEditorState, I as ImagePathFixerPlugin, V as VideoPathFixerPlugin, a as isEmptyContent, s as stringify, g as getExcerptSync } from "./index-DXCcMmcr.mjs";
8
8
  const BlockletEditor = lazyRetry(() => import("@blocklet/editor"));
9
9
  const Root = styled(Box)`
10
10
  .be-editable,
@@ -7,7 +7,7 @@ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
7
7
  import { useTheme, ThemeProvider, styled as styled$1 } from "@mui/material/styles";
8
8
  import { create as create$1, styled } from "@arcblock/ux/lib/Theme";
9
9
  import { useEffect, useRef, useState, createElement, useContext, useMemo, useCallback, isValidElement, Suspense, createContext, Fragment as Fragment$1, forwardRef, useImperativeHandle } from "react";
10
- import { Box, useTheme as useTheme$1, useMediaQuery, styled as styled$2, Tooltip as Tooltip$1, Chip as Chip$1, alpha, ClickAwayListener, Dialog as Dialog$1, DialogTitle, DialogContent, DialogActions, DialogContentText, Button as Button$1, Divider, Skeleton, IconButton as IconButton$2, InputBase, tooltipClasses as tooltipClasses$1, CircularProgress, Backdrop, Autocomplete, Typography as Typography$1, TextField, InputAdornment, SwipeableDrawer, Badge as Badge$1, Paper, ToggleButtonGroup, ToggleButton } from "@mui/material";
10
+ import { Box, useTheme as useTheme$1, useMediaQuery, styled as styled$2, Tooltip as Tooltip$1, Chip as Chip$1, alpha, ClickAwayListener, Dialog as Dialog$1, DialogTitle, DialogContent, DialogActions, DialogContentText, Button as Button$1, Divider, Skeleton, IconButton as IconButton$2, InputBase, tooltipClasses as tooltipClasses$1, CircularProgress, Backdrop, Stack as Stack$1, Autocomplete, Typography as Typography$1, TextField, InputAdornment, SwipeableDrawer, Badge as Badge$1, Paper, ToggleButtonGroup, ToggleButton } from "@mui/material";
11
11
  import isNil from "lodash/isNil";
12
12
  import { useEditorConfig, EditorConfigProvider } from "@blocklet/editor/lib/config";
13
13
  import { lazyWithPreload } from "react-lazy-with-preload";
@@ -1628,7 +1628,7 @@ function Menu({ items = [], ...rest }) {
1628
1628
  size: "medium",
1629
1629
  className: "menu-icon",
1630
1630
  onClick: handleClick,
1631
- sx: { p: 1, borderRadius: 1, border: 1, borderColor: "grey.200", height: 32, width: 32 },
1631
+ sx: { p: 1, borderRadius: 1, border: 1, borderColor: "divider", height: 32, width: 32 },
1632
1632
  children: /* @__PURE__ */ jsx(MoreVert, { sx: { fontSize: 18 } })
1633
1633
  }
1634
1634
  ),
@@ -3776,7 +3776,14 @@ const uniqAndSort = (list, order = "asc") => {
3776
3776
  const sorted = orderBy(unique, ["createdAt", "id"], [order, order]);
3777
3777
  return sorted;
3778
3778
  };
3779
- function ChatProvider({ client: client2, activeChatId, children, isInWallet }) {
3779
+ function ChatProvider({
3780
+ client: client2,
3781
+ activeChatId,
3782
+ children,
3783
+ isInWallet,
3784
+ renderMessage,
3785
+ chatRoomHeaderAddons
3786
+ }) {
3780
3787
  const [state, setState] = useSetState({
3781
3788
  initialized: false,
3782
3789
  chats: [],
@@ -4046,7 +4053,9 @@ function ChatProvider({ client: client2, activeChatId, children, isInWallet }) {
4046
4053
  getLastMessageText,
4047
4054
  isInWallet,
4048
4055
  createDM,
4049
- setEditingChannel: (payload) => setState((prev) => ({ ...prev, editingChannel: payload }))
4056
+ setEditingChannel: (payload) => setState((prev) => ({ ...prev, editingChannel: payload })),
4057
+ renderMessage,
4058
+ chatRoomHeaderAddons
4050
4059
  };
4051
4060
  }, [state, client2, currentUser == null ? void 0 : currentUser.did]);
4052
4061
  return /* @__PURE__ */ jsx(ChatContext.Provider, { value, children });
@@ -4201,7 +4210,7 @@ function Message({ message, prevMessage, showTime = true, ...rest }) {
4201
4210
  const { t } = useLocaleContext();
4202
4211
  const { session, isAdmin } = useSessionContext();
4203
4212
  const { confirm } = useConfirm();
4204
- const { activeChatId, deleteMessage, isInWallet } = useChatContext();
4213
+ const { activeChatId, deleteMessage, isInWallet, renderMessage } = useChatContext();
4205
4214
  const handleDeleteMessage = async () => {
4206
4215
  var _a3;
4207
4216
  if (activeChatId) {
@@ -4217,7 +4226,7 @@ function Message({ message, prevMessage, showTime = true, ...rest }) {
4217
4226
  }
4218
4227
  };
4219
4228
  const renderPostContent = () => {
4220
- return /* @__PURE__ */ jsx(Box$1, { className: "author-chat-item", children: /* @__PURE__ */ jsx(PostContent, { content: message.content }) });
4229
+ return /* @__PURE__ */ jsx(Box$1, { className: "author-chat-item", children: renderMessage ? renderMessage(message) : /* @__PURE__ */ jsx(PostContent, { content: message.content }) });
4221
4230
  };
4222
4231
  const menuItems = [];
4223
4232
  const isSender = message.sender.did === ((_a2 = session == null ? void 0 : session.user) == null ? void 0 : _a2.did);
@@ -4715,7 +4724,7 @@ function Back({ url, fallbackUrl, iconOnly, sx, ...rest }) {
4715
4724
  }
4716
4725
  const tablerSend = (props) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", "data-iconify": "tabler", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsx("path", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M10 14L21 3m0 0l-6.5 18a.55.55 0 0 1-1 0L10 14l-7-3.5a.55.55 0 0 1 0-1z" }) });
4717
4726
  const tablerLetterCase = (props) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", "data-iconify": "tabler", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsx("path", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M14 15.5a3.5 3.5 0 1 0 7 0a3.5 3.5 0 1 0-7 0M3 19V8.5a3.5 3.5 0 0 1 7 0V19m-7-6h7m11-1v7" }) });
4718
- const Editor = lazyRetry(() => import("./editor-BkVOFZrE.mjs"));
4727
+ const Editor = lazyRetry(() => import("./editor-DdY8k2T0.mjs"));
4719
4728
  function LazyEditor(props) {
4720
4729
  const fallback2 = /* @__PURE__ */ jsxs(Box, { sx: { px: 3 }, children: [
4721
4730
  /* @__PURE__ */ jsx(Skeleton, {}),
@@ -5044,7 +5053,8 @@ function ChatRoom({ chat, inWallet, ...rest }) {
5044
5053
  joinChannel,
5045
5054
  leaveChannel,
5046
5055
  deleteChannel,
5047
- setEditingChannel
5056
+ setEditingChannel,
5057
+ chatRoomHeaderAddons
5048
5058
  } = useChatContext();
5049
5059
  const { confirm } = useConfirm();
5050
5060
  const isActive = isActiveChat(chat.id);
@@ -5077,9 +5087,12 @@ function ChatRoom({ chat, inWallet, ...rest }) {
5077
5087
  }
5078
5088
  if (chat.type === "dm") {
5079
5089
  const oppositeUser = getOppositeUser(chat);
5080
- return /* @__PURE__ */ jsxs(Box$1, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
5081
- /* @__PURE__ */ jsx(Avatar, { did: oppositeUser == null ? void 0 : oppositeUser.did, src: oppositeUser == null ? void 0 : oppositeUser.avatar, size: 24, shape: "circle", variant: "rounded" }),
5082
- /* @__PURE__ */ jsx(RoomTitle, { title: oppositeUser.fullName })
5090
+ return /* @__PURE__ */ jsxs(Stack$1, { direction: "row", alignItems: "center", justifyContent: "space-between", width: 1, children: [
5091
+ /* @__PURE__ */ jsxs(Box$1, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
5092
+ /* @__PURE__ */ jsx(Avatar, { did: oppositeUser == null ? void 0 : oppositeUser.did, src: oppositeUser == null ? void 0 : oppositeUser.avatar, size: 24, shape: "circle", variant: "rounded" }),
5093
+ /* @__PURE__ */ jsx(RoomTitle, { title: oppositeUser.fullName })
5094
+ ] }),
5095
+ chatRoomHeaderAddons && chatRoomHeaderAddons(chat)
5083
5096
  ] });
5084
5097
  }
5085
5098
  if (chat.type === "channel") {
@@ -5090,8 +5103,10 @@ function ChatRoom({ chat, inWallet, ...rest }) {
5090
5103
  );
5091
5104
  }
5092
5105
  if (isAdmin || isCreator) {
5106
+ menuItems.unshift(
5107
+ /* @__PURE__ */ jsx(Menu.Item, { onClick: () => setEditingChannel(chat), children: /* @__PURE__ */ jsx(Box$1, { component: "span", children: "Edit" }) }, "edit")
5108
+ );
5093
5109
  menuItems.push(
5094
- /* @__PURE__ */ jsx(Menu.Item, { onClick: () => setEditingChannel(chat), children: /* @__PURE__ */ jsx(Box$1, { component: "span", children: "Edit" }) }, "edit"),
5095
5110
  /* @__PURE__ */ jsx(Menu.Item, { onClick: handleDeleteChannel, children: /* @__PURE__ */ jsx(Box$1, { component: "span", sx: { color: "error.main" }, children: t("chat.deleteChannel") }) }, "delete")
5096
5111
  );
5097
5112
  }
@@ -5112,6 +5127,7 @@ function ChatRoom({ chat, inWallet, ...rest }) {
5112
5127
  }
5113
5128
  ),
5114
5129
  chat.hasJoined && /* @__PURE__ */ jsx(Box$1, { children: /* @__PURE__ */ jsx(Participants, { users: chat.participants, sx: { border: "none" } }) }),
5130
+ chatRoomHeaderAddons && chatRoomHeaderAddons(chat),
5115
5131
  /* @__PURE__ */ jsx(Menu, { items: menuItems })
5116
5132
  ] })
5117
5133
  ] });
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "@blocklet/labels";
2
- import { T, n, W, A, m, ad, B, F, K, J, L, ap, Y, X, $, Z, _, a1, w, C, x, y, E, a5, a6, ah, a8, O, Q, ac, D, ag, af, H, G, b, k, ae, M, P, ao, v, q, R, S, a9, aq, o, a2, a4, ai, al, ak, ar, N, am, as, l, f, p, r, j, t, h, aa, U, c, a0, z, a7, ab, u, an, d, at, a3, aj, e } from "./index-D5Gxtfb_.mjs";
2
+ import { T, n, W, A, m, ad, B, F, K, J, L, ap, Y, X, $, Z, _, a1, w, C, x, y, E, a5, a6, ah, a8, O, Q, ac, D, ag, af, H, G, b, k, ae, M, P, ao, v, q, R, S, a9, aq, o, a2, a4, ai, al, ak, ar, N, am, as, l, f, p, r, j, t, h, aa, U, c, a0, z, a7, ab, u, an, d, at, a3, aj, e } from "./index-DXCcMmcr.mjs";
3
3
  import "react/jsx-runtime";
4
4
  import "react";
5
5
  import "@mui/material/Box";
package/dist/index.umd.js CHANGED
@@ -1552,7 +1552,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1552
1552
  size: "medium",
1553
1553
  className: "menu-icon",
1554
1554
  onClick: handleClick,
1555
- sx: { p: 1, borderRadius: 1, border: 1, borderColor: "grey.200", height: 32, width: 32 },
1555
+ sx: { p: 1, borderRadius: 1, border: 1, borderColor: "divider", height: 32, width: 32 },
1556
1556
  children: /* @__PURE__ */ jsxRuntime.jsx(iconsMaterial.MoreVert, { sx: { fontSize: 18 } })
1557
1557
  }
1558
1558
  ),
@@ -3700,7 +3700,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3700
3700
  const sorted = orderBy(unique, ["createdAt", "id"], [order, order]);
3701
3701
  return sorted;
3702
3702
  };
3703
- function ChatProvider({ client: client2, activeChatId, children, isInWallet }) {
3703
+ function ChatProvider({
3704
+ client: client2,
3705
+ activeChatId,
3706
+ children,
3707
+ isInWallet,
3708
+ renderMessage,
3709
+ chatRoomHeaderAddons
3710
+ }) {
3704
3711
  const [state, setState] = ahooks.useSetState({
3705
3712
  initialized: false,
3706
3713
  chats: [],
@@ -3970,7 +3977,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3970
3977
  getLastMessageText,
3971
3978
  isInWallet,
3972
3979
  createDM,
3973
- setEditingChannel: (payload) => setState((prev) => ({ ...prev, editingChannel: payload }))
3980
+ setEditingChannel: (payload) => setState((prev) => ({ ...prev, editingChannel: payload })),
3981
+ renderMessage,
3982
+ chatRoomHeaderAddons
3974
3983
  };
3975
3984
  }, [state, client2, currentUser == null ? void 0 : currentUser.did]);
3976
3985
  return /* @__PURE__ */ jsxRuntime.jsx(ChatContext.Provider, { value, children });
@@ -4125,7 +4134,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4125
4134
  const { t } = context.useLocaleContext();
4126
4135
  const { session, isAdmin } = useSessionContext();
4127
4136
  const { confirm } = useConfirm();
4128
- const { activeChatId, deleteMessage, isInWallet } = useChatContext();
4137
+ const { activeChatId, deleteMessage, isInWallet, renderMessage } = useChatContext();
4129
4138
  const handleDeleteMessage = async () => {
4130
4139
  var _a3;
4131
4140
  if (activeChatId) {
@@ -4141,7 +4150,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4141
4150
  }
4142
4151
  };
4143
4152
  const renderPostContent = () => {
4144
- return /* @__PURE__ */ jsxRuntime.jsx(Box, { className: "author-chat-item", children: /* @__PURE__ */ jsxRuntime.jsx(PostContent, { content: message.content }) });
4153
+ return /* @__PURE__ */ jsxRuntime.jsx(Box, { className: "author-chat-item", children: renderMessage ? renderMessage(message) : /* @__PURE__ */ jsxRuntime.jsx(PostContent, { content: message.content }) });
4145
4154
  };
4146
4155
  const menuItems = [];
4147
4156
  const isSender = message.sender.did === ((_a2 = session == null ? void 0 : session.user) == null ? void 0 : _a2.did);
@@ -4968,7 +4977,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4968
4977
  joinChannel,
4969
4978
  leaveChannel,
4970
4979
  deleteChannel,
4971
- setEditingChannel
4980
+ setEditingChannel,
4981
+ chatRoomHeaderAddons
4972
4982
  } = useChatContext();
4973
4983
  const { confirm } = useConfirm();
4974
4984
  const isActive = isActiveChat(chat.id);
@@ -5001,9 +5011,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5001
5011
  }
5002
5012
  if (chat.type === "dm") {
5003
5013
  const oppositeUser = getOppositeUser(chat);
5004
- return /* @__PURE__ */ jsxRuntime.jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
5005
- /* @__PURE__ */ jsxRuntime.jsx(Avatar, { did: oppositeUser == null ? void 0 : oppositeUser.did, src: oppositeUser == null ? void 0 : oppositeUser.avatar, size: 24, shape: "circle", variant: "rounded" }),
5006
- /* @__PURE__ */ jsxRuntime.jsx(RoomTitle, { title: oppositeUser.fullName })
5014
+ return /* @__PURE__ */ jsxRuntime.jsxs(material.Stack, { direction: "row", alignItems: "center", justifyContent: "space-between", width: 1, children: [
5015
+ /* @__PURE__ */ jsxRuntime.jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
5016
+ /* @__PURE__ */ jsxRuntime.jsx(Avatar, { did: oppositeUser == null ? void 0 : oppositeUser.did, src: oppositeUser == null ? void 0 : oppositeUser.avatar, size: 24, shape: "circle", variant: "rounded" }),
5017
+ /* @__PURE__ */ jsxRuntime.jsx(RoomTitle, { title: oppositeUser.fullName })
5018
+ ] }),
5019
+ chatRoomHeaderAddons && chatRoomHeaderAddons(chat)
5007
5020
  ] });
5008
5021
  }
5009
5022
  if (chat.type === "channel") {
@@ -5014,8 +5027,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5014
5027
  );
5015
5028
  }
5016
5029
  if (isAdmin || isCreator) {
5030
+ menuItems.unshift(
5031
+ /* @__PURE__ */ jsxRuntime.jsx(Menu.Item, { onClick: () => setEditingChannel(chat), children: /* @__PURE__ */ jsxRuntime.jsx(Box, { component: "span", children: "Edit" }) }, "edit")
5032
+ );
5017
5033
  menuItems.push(
5018
- /* @__PURE__ */ jsxRuntime.jsx(Menu.Item, { onClick: () => setEditingChannel(chat), children: /* @__PURE__ */ jsxRuntime.jsx(Box, { component: "span", children: "Edit" }) }, "edit"),
5019
5034
  /* @__PURE__ */ jsxRuntime.jsx(Menu.Item, { onClick: handleDeleteChannel, children: /* @__PURE__ */ jsxRuntime.jsx(Box, { component: "span", sx: { color: "error.main" }, children: t("chat.deleteChannel") }) }, "delete")
5020
5035
  );
5021
5036
  }
@@ -5036,6 +5051,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5036
5051
  }
5037
5052
  ),
5038
5053
  chat.hasJoined && /* @__PURE__ */ jsxRuntime.jsx(Box, { children: /* @__PURE__ */ jsxRuntime.jsx(Participants, { users: chat.participants, sx: { border: "none" } }) }),
5054
+ chatRoomHeaderAddons && chatRoomHeaderAddons(chat),
5039
5055
  /* @__PURE__ */ jsxRuntime.jsx(Menu, { items: menuItems })
5040
5056
  ] })
5041
5057
  ] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/discuss-kit-ux",
3
- "version": "2.1.90",
3
+ "version": "2.1.92",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -44,8 +44,8 @@
44
44
  "ufo": "^1.5.4",
45
45
  "unstated-next": "^1.1.0",
46
46
  "url-join": "^4.0.1",
47
- "@blocklet/editor": "^2.1.90",
48
- "@blocklet/labels": "^2.1.90"
47
+ "@blocklet/editor": "^2.1.92",
48
+ "@blocklet/labels": "^2.1.92"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@arcblock/did-connect": "^2.10.36",