@blocklet/discuss-kit-ux 1.5.182 → 1.5.184

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,14 +1,17 @@
1
+ /// <reference types="react" />
1
2
  import type { BoxProps } from '@mui/material/Box';
2
3
  interface CoverImageUploadProps extends Omit<BoxProps, 'onChange'> {
3
4
  url?: string;
4
5
  onChange: (url: string | null) => void;
5
6
  }
6
- export declare function CoverImage({ url, aspectRatio, width, sx, fetchpriority, loading, }: {
7
+ export declare function CoverImage({ url, aspectRatio, width, sx, fetchpriority, loading, shadow, fallback, ...rest }: {
7
8
  url?: string;
8
9
  aspectRatio?: number;
9
10
  width?: number;
10
11
  loading?: 'lazy' | 'eager';
11
12
  fetchpriority?: 'auto' | 'low' | 'high';
13
+ shadow?: boolean;
14
+ fallback?: React.ReactNode;
12
15
  } & BoxProps): import("react/jsx-runtime").JSX.Element;
13
16
  export declare function CoverImageUpload({ url, onChange, ...rest }: CoverImageUploadProps): import("react/jsx-runtime").JSX.Element;
14
17
  export {};
@@ -1,2 +1,3 @@
1
1
  export { default as LazyEditor } from './lazy-editor';
2
2
  export type { OnChangeHandler } from './editor';
3
+ export { EditorPreview } from './preview';
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import type { BlockletEditorProps } from '@blocklet/editor';
3
+ export interface EditorProps extends Omit<BlockletEditorProps, 'onChange' | 'ref'> {
4
+ content: string;
5
+ children?: React.ReactNode;
6
+ }
7
+ export declare function EditorPreview({ content, children, ...rest }: EditorProps): import("react/jsx-runtime").JSX.Element;
@@ -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 { lazy } from "react";
7
- import { i as inferInitialEditorState, I as ImagePathFixerPlugin, a as isEmptyContent, s as stringify, g as getExcerptSync } from "./index-a2df4ae9.mjs";
7
+ import { i as inferInitialEditorState, I as ImagePathFixerPlugin, a as isEmptyContent, s as stringify, g as getExcerptSync } from "./index-c2d870f7.mjs";
8
8
  import "@blocklet/labels";
9
9
  import "@mui/material/styles";
10
10
  import "@mui/material/Box";
@@ -58,7 +58,8 @@ import "@arcblock/ux/lib/Toast";
58
58
  import "@mui/material/Pagination";
59
59
  import "unstated-next";
60
60
  import "react-dom";
61
- import "lottie-react";
61
+ import "js-cookie";
62
+ import "@arcblock/ws";
62
63
  const BlockletEditor = lazy(() => import("@blocklet/editor"));
63
64
  const Root = styled(Box)`
64
65
  .be-editable,
@@ -61,7 +61,8 @@ import Toast from "@arcblock/ux/lib/Toast";
61
61
  import MuiPagination from "@mui/material/Pagination";
62
62
  import { createContainer } from "unstated-next";
63
63
  import { createPortal } from "react-dom";
64
- import Lottie from "lottie-react";
64
+ import Cookie from "js-cookie";
65
+ import { WsClient } from "@arcblock/ws";
65
66
  const themeOverrides = {
66
67
  components: {
67
68
  MuiButton: {
@@ -361,7 +362,7 @@ const useMeasure = () => {
361
362
  const size = useSize(ref);
362
363
  return [ref, size || { width: 0, height: 0 }];
363
364
  };
364
- const BlockletEditor$1 = lazy(() => import("@blocklet/editor"));
365
+ const BlockletEditor$2 = lazy(() => import("@blocklet/editor"));
365
366
  const Root$5 = styled(Box)`
366
367
  position: relative;
367
368
  .be-shell {
@@ -461,7 +462,7 @@ const Input = ({
461
462
  };
462
463
  const editorState = draftKey && draftContent && !initialContent ? draftContent : inferInitialEditorState(initialContent);
463
464
  return /* @__PURE__ */ createElement(Root$5, { ref, ...rest, key: draftKey }, /* @__PURE__ */ jsx(EditorConfigProvider, { value: mergedEditorConfig, children: /* @__PURE__ */ jsxs(
464
- BlockletEditor$1,
465
+ BlockletEditor$2,
465
466
  {
466
467
  placeholder,
467
468
  editorState,
@@ -1035,8 +1036,8 @@ function ViewMore({ children, ...rest }) {
1035
1036
  )
1036
1037
  ] });
1037
1038
  }
1038
- const BlockletEditor = lazy(() => import("@blocklet/editor"));
1039
- const StyledBlockletEditor = styled$1(BlockletEditor)`
1039
+ const BlockletEditor$1 = lazy(() => import("@blocklet/editor"));
1040
+ const StyledBlockletEditor = styled$1(BlockletEditor$1)`
1040
1041
  .editor-scroller {
1041
1042
  min-height: initial;
1042
1043
  }
@@ -2352,7 +2353,10 @@ function CoverImage({
2352
2353
  width = 320,
2353
2354
  sx,
2354
2355
  fetchpriority = "auto",
2355
- loading = "eager"
2356
+ loading = "eager",
2357
+ shadow = true,
2358
+ fallback,
2359
+ ...rest
2356
2360
  }) {
2357
2361
  const [loaded, setLoaded] = useState(false);
2358
2362
  return /* @__PURE__ */ jsxs(
@@ -2365,12 +2369,13 @@ function CoverImage({
2365
2369
  overflow: "hidden",
2366
2370
  position: "relative",
2367
2371
  borderRadius: 2,
2368
- boxShadow: "rgb(0 0 0 / 12%) 0px 8px 30px",
2372
+ ...shadow && { boxShadow: "rgb(0 0 0 / 12%) 0px 8px 30px" },
2369
2373
  // https://stackoverflow.com/questions/49066011/overflow-hidden-with-border-radius-not-working-on-safari
2370
2374
  transform: "translateZ(0)"
2371
2375
  },
2372
2376
  ...Array.isArray(sx) ? sx : [sx]
2373
2377
  ],
2378
+ ...rest,
2374
2379
  children: [
2375
2380
  (!loaded || !url) && /* @__PURE__ */ jsx(
2376
2381
  Skeleton,
@@ -2386,7 +2391,7 @@ function CoverImage({
2386
2391
  }
2387
2392
  }
2388
2393
  ),
2389
- /* @__PURE__ */ jsx(
2394
+ !!url && /* @__PURE__ */ jsx(
2390
2395
  "img",
2391
2396
  {
2392
2397
  src: url ? composeImageUrl(url, width) : "",
@@ -2405,6 +2410,19 @@ function CoverImage({
2405
2410
  alt: "cover",
2406
2411
  onLoad: () => setLoaded(true)
2407
2412
  }
2413
+ ),
2414
+ !url && /* @__PURE__ */ jsx(
2415
+ Box$1,
2416
+ {
2417
+ sx: {
2418
+ position: "absolute",
2419
+ top: 0,
2420
+ left: 0,
2421
+ width: "100%",
2422
+ height: "100%"
2423
+ },
2424
+ children: fallback
2425
+ }
2408
2426
  )
2409
2427
  ]
2410
2428
  }
@@ -3113,7 +3131,7 @@ const uniqAndSort = (list, order = "asc") => {
3113
3131
  const sorted = orderBy(unique, ["createdAt", "id"], [order, order]);
3114
3132
  return sorted;
3115
3133
  };
3116
- function ChatProvider({ client, activeChatId, children }) {
3134
+ function ChatProvider({ client: client2, activeChatId, children }) {
3117
3135
  const [state, setState] = useSetState({
3118
3136
  initialized: false,
3119
3137
  chats: [],
@@ -3149,7 +3167,7 @@ function ChatProvider({ client, activeChatId, children }) {
3149
3167
  };
3150
3168
  const updateLastAckTime = async (chatId) => {
3151
3169
  updateChat(chatId, (chat) => ({ ...chat, lastAckTime: chat.lastMessageAt }));
3152
- await client.updateLastAckTime(chatId);
3170
+ await client2.updateLastAckTime(chatId);
3153
3171
  };
3154
3172
  const addMessage = (chatId, message) => {
3155
3173
  updateChat(chatId, (chat) => ({
@@ -3194,7 +3212,7 @@ function ChatProvider({ client, activeChatId, children }) {
3194
3212
  setActiveChat(null);
3195
3213
  };
3196
3214
  const loadMessages = async (chatId, cursor) => {
3197
- const { messages, nextCursor } = await client.fetchMessages(chatId, cursor);
3215
+ const { messages, nextCursor } = await client2.fetchMessages(chatId, cursor);
3198
3216
  updateChat(chatId, (chat) => ({
3199
3217
  ...chat,
3200
3218
  messages: uniqAndSort([...chat.messages || [], ...messages || []]),
@@ -3202,7 +3220,7 @@ function ChatProvider({ client, activeChatId, children }) {
3202
3220
  }));
3203
3221
  };
3204
3222
  const sendMessage = async (chatId, content) => {
3205
- const saved = await client.sendMessage(chatId, content);
3223
+ const saved = await client2.sendMessage(chatId, content);
3206
3224
  addMessage(chatId, saved);
3207
3225
  updateLastAckTime(chatId);
3208
3226
  };
@@ -3210,7 +3228,7 @@ function ChatProvider({ client, activeChatId, children }) {
3210
3228
  const {
3211
3229
  chat: { participants },
3212
3230
  messages: { messages, nextCursor }
3213
- } = await client.fetchChat(chatId);
3231
+ } = await client2.fetchChat(chatId);
3214
3232
  updateChat(chatId, (chat) => {
3215
3233
  const mapped = {
3216
3234
  ...chat,
@@ -3223,7 +3241,7 @@ function ChatProvider({ client, activeChatId, children }) {
3223
3241
  });
3224
3242
  };
3225
3243
  const joinChannel = async (chatId) => {
3226
- await client.joinChannel(chatId);
3244
+ await client2.joinChannel(chatId);
3227
3245
  updateChat(chatId, (chat) => ({
3228
3246
  ...chat,
3229
3247
  hasJoined: true
@@ -3231,17 +3249,17 @@ function ChatProvider({ client, activeChatId, children }) {
3231
3249
  updateLastAckTime(chatId);
3232
3250
  };
3233
3251
  const leaveChannel = async (chatId) => {
3234
- await client.leaveChannel(chatId);
3252
+ await client2.leaveChannel(chatId);
3235
3253
  updateChat(chatId, (chat) => ({
3236
3254
  ...chat,
3237
3255
  hasJoined: false
3238
3256
  }));
3239
3257
  };
3240
3258
  const deleteChannel = async (chatId) => {
3241
- await client.deleteChannel(chatId);
3259
+ await client2.deleteChannel(chatId);
3242
3260
  };
3243
3261
  const deleteMessage = async (chatId, messageId) => {
3244
- await client.deleteMessage(messageId);
3262
+ await client2.deleteMessage(messageId);
3245
3263
  updateChat(chatId, (chat) => {
3246
3264
  var _a2;
3247
3265
  return {
@@ -3252,7 +3270,7 @@ function ChatProvider({ client, activeChatId, children }) {
3252
3270
  };
3253
3271
  const init = async () => {
3254
3272
  try {
3255
- const { chats } = await client.init();
3273
+ const { chats } = await client2.init();
3256
3274
  setState({ initialized: true, chats });
3257
3275
  } catch (e) {
3258
3276
  console.error(e);
@@ -3260,7 +3278,7 @@ function ChatProvider({ client, activeChatId, children }) {
3260
3278
  }
3261
3279
  };
3262
3280
  const refresh = () => {
3263
- client.destroy();
3281
+ client2.destroy();
3264
3282
  return init();
3265
3283
  };
3266
3284
  useEffect(() => {
@@ -3274,7 +3292,7 @@ function ChatProvider({ client, activeChatId, children }) {
3274
3292
  error: void 0
3275
3293
  });
3276
3294
  }
3277
- return () => client.destroy();
3295
+ return () => client2.destroy();
3278
3296
  }, [currentUser == null ? void 0 : currentUser.did]);
3279
3297
  useEffect(() => {
3280
3298
  if (activeChatId) {
@@ -3290,16 +3308,16 @@ function ChatProvider({ client, activeChatId, children }) {
3290
3308
  }, [state, activeChatId]);
3291
3309
  useEffect(() => {
3292
3310
  const cancels = [
3293
- client.onMessage(({ chatId, message }) => {
3311
+ client2.onMessage(({ chatId, message }) => {
3294
3312
  addMessage(chatId, message);
3295
3313
  if (isActiveChat(chatId)) {
3296
3314
  updateLastAckTime(chatId);
3297
3315
  }
3298
3316
  }),
3299
- client.onCreateChat(({ chat }) => addChat(chat)),
3300
- client.onJoinChannel(({ chatId, participant }) => addParticipant(chatId, participant)),
3301
- client.onLeaveChannel(({ chatId, participant }) => removeParticipant(chatId, participant)),
3302
- client.onDeleteChannel(({ chatId }) => deleteChat(chatId))
3317
+ client2.onCreateChat(({ chat }) => addChat(chat)),
3318
+ client2.onJoinChannel(({ chatId, participant }) => addParticipant(chatId, participant)),
3319
+ client2.onLeaveChannel(({ chatId, participant }) => removeParticipant(chatId, participant)),
3320
+ client2.onDeleteChannel(({ chatId }) => deleteChat(chatId))
3303
3321
  ];
3304
3322
  return () => {
3305
3323
  cancels.forEach((cancel) => cancel == null ? void 0 : cancel());
@@ -3313,7 +3331,7 @@ function ChatProvider({ client, activeChatId, children }) {
3313
3331
  const value = useMemo(() => {
3314
3332
  return {
3315
3333
  ...state,
3316
- client,
3334
+ client: client2,
3317
3335
  setActiveChat,
3318
3336
  isActiveChat,
3319
3337
  getOppositeUser: (chat) => {
@@ -3333,7 +3351,7 @@ function ChatProvider({ client, activeChatId, children }) {
3333
3351
  hasUnreadMessages,
3334
3352
  refresh
3335
3353
  };
3336
- }, [state, client, currentUser == null ? void 0 : currentUser.did]);
3354
+ }, [state, client2, currentUser == null ? void 0 : currentUser.did]);
3337
3355
  return /* @__PURE__ */ jsx(ChatContext.Provider, { value, children });
3338
3356
  }
3339
3357
  function ChatList(props) {
@@ -3884,7 +3902,7 @@ function Empty({ sx }) {
3884
3902
  ] });
3885
3903
  }
3886
3904
  function Chat({ sx, ...rest }) {
3887
- const { client, initialized, chats, activeChatId, addChat, setActiveChat, refresh } = useChatContext();
3905
+ const { client: client2, initialized, chats, activeChatId, addChat, setActiveChat, refresh } = useChatContext();
3888
3906
  const [newChannelVisible, setNewChannelVisible] = useState(false);
3889
3907
  const downMd = useMediaQuery((theme) => theme.breakpoints.down("sm"));
3890
3908
  useEffect(() => {
@@ -3910,7 +3928,7 @@ function Chat({ sx, ...rest }) {
3910
3928
  ...Array.isArray(sx) ? sx : [sx]
3911
3929
  ];
3912
3930
  const handleNewChannel = async ({ name, description }) => {
3913
- const saved = await client.createChannel(name, description);
3931
+ const saved = await client2.createChannel(name, description);
3914
3932
  const newChannel = { ...saved, hasJoined: true };
3915
3933
  addChat(newChannel);
3916
3934
  setNewChannelVisible(false);
@@ -4255,7 +4273,7 @@ function Pagination({ page, size = 20, total, onChange, routerMode = true, ...re
4255
4273
  }
4256
4274
  );
4257
4275
  }
4258
- const Editor = lazy(() => import("./editor-7aa2a21c.mjs"));
4276
+ const Editor = lazy(() => import("./editor-d5392181.mjs"));
4259
4277
  function LazyEditor(props) {
4260
4278
  const fallback = /* @__PURE__ */ jsxs(Fragment, { children: [
4261
4279
  /* @__PURE__ */ jsx(Skeleton, {}),
@@ -4265,6 +4283,19 @@ function LazyEditor(props) {
4265
4283
  ] });
4266
4284
  return /* @__PURE__ */ jsx(Suspense, { fallback, children: /* @__PURE__ */ jsx(Editor, { ...props }) });
4267
4285
  }
4286
+ const BlockletEditor = lazy(() => import("@blocklet/editor"));
4287
+ function EditorPreview({ content, children, ...rest }) {
4288
+ const fallback = /* @__PURE__ */ jsxs(Fragment, { children: [
4289
+ /* @__PURE__ */ jsx(Skeleton, {}),
4290
+ /* @__PURE__ */ jsx(Skeleton, { width: "80%" }),
4291
+ /* @__PURE__ */ jsx(Skeleton, { width: "60%" }),
4292
+ /* @__PURE__ */ jsx(Skeleton, { width: "40%" })
4293
+ ] });
4294
+ return /* @__PURE__ */ jsx(Suspense, { fallback, children: /* @__PURE__ */ jsxs(BlockletEditor, { editorState: inferInitialEditorState(content), editable: false, ...rest, children: [
4295
+ /* @__PURE__ */ jsx(ImagePathFixerPlugin, {}),
4296
+ children
4297
+ ] }) });
4298
+ }
4268
4299
  const useBeforeUnloadPrompt = (dirty) => {
4269
4300
  useEffect(() => {
4270
4301
  const showPrompt = (e) => {
@@ -4349,8 +4380,8 @@ const en = {
4349
4380
  deleted: "This comment has been deleted",
4350
4381
  edit: "Edit",
4351
4382
  empty: "Be the first to leave a comment.",
4352
- loadMore: "Load more",
4353
- readMore: "Read more",
4383
+ loadMore: "Load More",
4384
+ readMore: "Read More",
4354
4385
  saveChanges: "Save Changes",
4355
4386
  sendComment: "Comment",
4356
4387
  showMoreReplies: "Show more replies",
@@ -4418,6 +4449,7 @@ const zh = {
4418
4449
  }
4419
4450
  };
4420
4451
  const translations = { zh, en };
4452
+ const Lottie = lazy(() => import("lottie-react"));
4421
4453
  function LottieComponent({ src, ...restProps }) {
4422
4454
  return /* @__PURE__ */ jsx(Lottie, { animationData: src, loop: true, ...restProps });
4423
4455
  }
@@ -9907,8 +9939,50 @@ const boxAnimation = {
9907
9939
  assets,
9908
9940
  layers
9909
9941
  };
9942
+ let client;
9943
+ function create(prefix2) {
9944
+ const pathPrefix = prefix2;
9945
+ const url = `//${window.location.host}${pathPrefix.replace(/\/$/, "")}`;
9946
+ return new WsClient(url, {
9947
+ heartbeatIntervalMs: 10 * 1e3,
9948
+ params: () => ({
9949
+ token: Cookie.get("login_token")
9950
+ }),
9951
+ reconnectAfterMs: (tries) => {
9952
+ if (Cookie.get("login_token")) {
9953
+ return Math.floor(Math.random() * 2 ** tries * 1e3);
9954
+ }
9955
+ return 2 ** tries * 1e3;
9956
+ }
9957
+ });
9958
+ }
9959
+ function getWsClient(prefix2 = ((_c) => (_c = window.blocklet) == null ? void 0 : _c.prefix)() || "/") {
9960
+ if (!client) {
9961
+ client = create(prefix2);
9962
+ }
9963
+ return client;
9964
+ }
9965
+ const useSubscription = (event, cb = () => {
9966
+ }, deps = [], prefix2 = ((_d) => (_d = window.blocklet) == null ? void 0 : _d.prefix)() || "/") => {
9967
+ useEffect(() => {
9968
+ if (event) {
9969
+ if (!client) {
9970
+ client = getWsClient(prefix2);
9971
+ }
9972
+ client.on(event, cb);
9973
+ return () => {
9974
+ client.off(event, cb);
9975
+ };
9976
+ }
9977
+ return () => {
9978
+ };
9979
+ }, [event, ...deps]);
9980
+ };
9910
9981
  const id = "point-up-component";
9911
9982
  const PointUpContext = createContext({});
9983
+ const WsEvents = Object.freeze({
9984
+ POINT_UP: "point.up"
9985
+ });
9912
9986
  const usePointUpContext = () => useContext(PointUpContext);
9913
9987
  function PointUp({ points }) {
9914
9988
  const { t } = useLocaleContext();
@@ -9956,16 +10030,34 @@ function PointUp({ points }) {
9956
10030
  );
9957
10031
  }
9958
10032
  function PointUpProvider({ children }) {
9959
- var _a2, _b2, _c;
10033
+ var _a2, _b2, _c, _d;
9960
10034
  const state = useReactive({
9961
10035
  pointsList: [],
9962
10036
  visible: false,
9963
10037
  currentPoints: 0
9964
10038
  });
9965
- const value = useMemo(() => {
9966
- const pointUp = ({ points }) => {
9967
- state.pointsList.push(points);
10039
+ const { session } = useSessionContext();
10040
+ const wsClient = getWsClient();
10041
+ const pointUp = useCallback(({ points }) => {
10042
+ state.pointsList.push(points);
10043
+ }, []);
10044
+ const pointUpComponent = (_c = (_b2 = (_a2 = window.blocklet) == null ? void 0 : _a2.componentMountPoints) == null ? void 0 : _b2.find) == null ? void 0 : _c.call(
10045
+ _b2,
10046
+ (item) => item.did === "z2qa2ZST7Frp8w1XGqyw9v85u12R3mBbB2oaA"
10047
+ );
10048
+ const handlers = {
10049
+ [WsEvents.POINT_UP]: (payload) => {
10050
+ pointUp(payload);
10051
+ }
10052
+ };
10053
+ useEffect(() => {
10054
+ wsClient.connect();
10055
+ return () => {
10056
+ if (wsClient.isConnected())
10057
+ ;
9968
10058
  };
10059
+ }, []);
10060
+ const value = useMemo(() => {
9969
10061
  return {
9970
10062
  pointUp
9971
10063
  };
@@ -9989,19 +10081,17 @@ function PointUpProvider({ children }) {
9989
10081
  state.visible = false;
9990
10082
  }
9991
10083
  }, [JSON.stringify(state.pointsList)]);
9992
- const pointUpComponent = (_c = (_b2 = (_a2 = window.blocklet) == null ? void 0 : _a2.componentMountPoints) == null ? void 0 : _b2.find) == null ? void 0 : _c.call(
9993
- _b2,
9994
- (item) => item.did === "z2qa2ZST7Frp8w1XGqyw9v85u12R3mBbB2oaA"
9995
- );
10084
+ useSubscription((_d = session == null ? void 0 : session.user) == null ? void 0 : _d.did, ({ event, data }) => {
10085
+ var _a3;
10086
+ return (_a3 = handlers[event]) == null ? void 0 : _a3.call(handlers, data);
10087
+ }, []);
9996
10088
  return /* @__PURE__ */ jsxs(PointUpContext.Provider, { value, children: [
9997
- state.currentPoints > 0 && createPortal(
10089
+ (pointUpComponent == null ? void 0 : pointUpComponent.mountPoint) && createPortal(
9998
10090
  /* @__PURE__ */ jsx(
9999
10091
  Box,
10000
10092
  {
10001
10093
  onClick: () => {
10002
- if (pointUpComponent == null ? void 0 : pointUpComponent.mountPoint) {
10003
- window.open(joinUrl(window.location.origin, pointUpComponent.mountPoint, "my"));
10004
- }
10094
+ window.open(joinUrl(window.location.origin, pointUpComponent.mountPoint, "my"));
10005
10095
  },
10006
10096
  id,
10007
10097
  sx: {
@@ -10027,7 +10117,7 @@ function PointUpProvider({ children }) {
10027
10117
  ] });
10028
10118
  }
10029
10119
  export {
10030
- ConfirmProvider as $,
10120
+ useConfirm as $,
10031
10121
  Avatar as A,
10032
10122
  BinaryThumb as B,
10033
10123
  CommentInput as C,
@@ -10045,32 +10135,37 @@ export {
10045
10135
  ChatClient as O,
10046
10136
  Pagination as P,
10047
10137
  Chat as Q,
10048
- ChatHeaderAddon as R,
10138
+ RelativeTime as R,
10049
10139
  ScrollableEditorWrapper as S,
10050
- useChatContext as T,
10051
- ChatProvider as U,
10052
- UnreadNotificationContext as V,
10053
- useUnreadNotification as W,
10054
- UnreadNotificationProvider as X,
10055
- Confirm as Y,
10056
- ConfirmContext as Z,
10057
- useConfirm as _,
10140
+ ChatHeaderAddon as T,
10141
+ useChatContext as U,
10142
+ ChatProvider as V,
10143
+ UnreadNotificationContext as W,
10144
+ useUnreadNotification as X,
10145
+ UnreadNotificationProvider as Y,
10146
+ Confirm as Z,
10147
+ ConfirmContext as _,
10058
10148
  isEmptyContent as a,
10059
- SecureLabelPicker as a0,
10060
- useApiErrorHandler as a1,
10061
- useDefaultApiErrorHandler as a2,
10062
- PreviousLocationRecorder as a3,
10063
- Back as a4,
10064
- LazyEditor as a5,
10065
- DirtyPromptContainer as a6,
10066
- ConfirmNavigation as a7,
10067
- UploaderContext as a8,
10068
- useUploader as a9,
10069
- UploaderTrigger as aa,
10070
- UploaderProvider as ab,
10071
- composeImageUrl as ac,
10072
- usePointUpContext as ad,
10073
- PointUpProvider as ae,
10149
+ ConfirmProvider as a0,
10150
+ SecureLabelPicker as a1,
10151
+ useApiErrorHandler as a2,
10152
+ useDefaultApiErrorHandler as a3,
10153
+ PreviousLocationRecorder as a4,
10154
+ Back as a5,
10155
+ LazyEditor as a6,
10156
+ EditorPreview as a7,
10157
+ DirtyPromptContainer as a8,
10158
+ ConfirmNavigation as a9,
10159
+ UploaderContext as aa,
10160
+ useUploader as ab,
10161
+ UploaderTrigger as ac,
10162
+ UploaderProvider as ad,
10163
+ composeImageUrl as ae,
10164
+ usePointUpContext as af,
10165
+ PointUpProvider as ag,
10166
+ create as ah,
10167
+ getWsClient as ai,
10168
+ useSubscription as aj,
10074
10169
  InternalThemeProvider as b,
10075
10170
  Input as c,
10076
10171
  translations as d,
package/dist/index.d.ts CHANGED
@@ -23,3 +23,5 @@ export * as routes from './components/routes';
23
23
  export { default as preferences } from './preferences';
24
24
  export * from './components/uploader';
25
25
  export * from './components/point-up';
26
+ export * from './ws';
27
+ export { default as RelativeTime } from './components/shared/relative-time';
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "@blocklet/labels";
2
- import { K, j, N, A, h, a4, B, z, y, E, Q, O, R, U, o, C, q, v, x, Y, Z, a7, $, H, J, D, a6, G, c, b, a5, M, P, ae, n, m, a3, S, a0, k, V, X, a8, ab, aa, ac, F, l, p, r, t, d, a1, L, e, T, w, _, a2, u, ad, W, a9, f } from "./index-a2df4ae9.mjs";
2
+ import { K, j, N, A, h, a5, B, z, y, E, Q, O, T, V, o, C, q, v, x, Z, _, a9, a0, H, J, D, a8, a7, G, c, b, a6, M, P, ag, n, m, a4, R, S, a1, k, W, Y, aa, ad, ac, ae, ah, F, ai, l, p, r, t, d, a2, L, e, U, w, $, a3, u, af, aj, X, ab, f } from "./index-c2d870f7.mjs";
3
3
  import "react/jsx-runtime";
4
4
  import "react";
5
5
  import "@mui/material/Box";
@@ -55,70 +55,76 @@ import "@arcblock/ux/lib/Toast";
55
55
  import "@mui/material/Pagination";
56
56
  import "unstated-next";
57
57
  import "react-dom";
58
- import "lottie-react";
58
+ import "js-cookie";
59
+ import "@arcblock/ws";
59
60
  export {
60
61
  K as AccessControl,
61
62
  j as AuthorInfo,
62
63
  N as AuthzProvider,
63
64
  A as Avatar,
64
65
  h as Avatars,
65
- a4 as Back,
66
+ a5 as Back,
66
67
  B as BinaryThumb,
67
68
  z as BlogCard,
68
69
  y as BlogList,
69
70
  E as BlogPermaLink,
70
71
  Q as Chat,
71
72
  O as ChatClient,
72
- R as ChatHeaderAddon,
73
- U as ChatProvider,
73
+ T as ChatHeaderAddon,
74
+ V as ChatProvider,
74
75
  o as Comment,
75
76
  C as CommentInput,
76
77
  q as CommentList,
77
78
  v as CommentsContext,
78
79
  x as CommentsProvider,
79
- Y as Confirm,
80
- Z as ConfirmContext,
81
- a7 as ConfirmNavigation,
82
- $ as ConfirmProvider,
80
+ Z as Confirm,
81
+ _ as ConfirmContext,
82
+ a9 as ConfirmNavigation,
83
+ a0 as ConfirmProvider,
83
84
  H as CoverImage,
84
85
  J as CoverImageUpload,
85
86
  D as DefaultEditorConfigProvider,
86
- a6 as DirtyPromptContainer,
87
+ a8 as DirtyPromptContainer,
88
+ a7 as EditorPreview,
87
89
  G as GithubReaction,
88
90
  c as Input,
89
91
  b as InternalThemeProvider,
90
- a5 as LazyEditor,
92
+ a6 as LazyEditor,
91
93
  M as Menu,
92
94
  P as Pagination,
93
- ae as PointUpProvider,
95
+ ag as PointUpProvider,
94
96
  n as Post,
95
97
  m as PostContent,
96
- a3 as PreviousLocationRecorder,
98
+ a4 as PreviousLocationRecorder,
99
+ R as RelativeTime,
97
100
  S as ScrollableEditorWrapper,
98
- a0 as SecureLabelPicker,
101
+ a1 as SecureLabelPicker,
99
102
  k as SystemUser,
100
- V as UnreadNotificationContext,
101
- X as UnreadNotificationProvider,
102
- a8 as UploaderContext,
103
- ab as UploaderProvider,
104
- aa as UploaderTrigger,
105
- ac as composeImageUrl,
103
+ W as UnreadNotificationContext,
104
+ Y as UnreadNotificationProvider,
105
+ aa as UploaderContext,
106
+ ad as UploaderProvider,
107
+ ac as UploaderTrigger,
108
+ ae as composeImageUrl,
109
+ ah as create,
106
110
  F as getBlogLink,
111
+ ai as getWsClient,
107
112
  l as lexicalUtils,
108
113
  p as preferences,
109
114
  r as routes,
110
115
  t as themeOverrides,
111
116
  d as translations,
112
- a1 as useApiErrorHandler,
117
+ a2 as useApiErrorHandler,
113
118
  L as useAuthzContext,
114
119
  e as useChanged,
115
- T as useChatContext,
120
+ U as useChatContext,
116
121
  w as useCommentsContext,
117
- _ as useConfirm,
118
- a2 as useDefaultApiErrorHandler,
122
+ $ as useConfirm,
123
+ a3 as useDefaultApiErrorHandler,
119
124
  u as useNow,
120
- ad as usePointUpContext,
121
- W as useUnreadNotification,
122
- a9 as useUploader,
125
+ af as usePointUpContext,
126
+ aj as useSubscription,
127
+ X as useUnreadNotification,
128
+ ab as useUploader,
123
129
  f as utils
124
130
  };
package/dist/index.umd.js CHANGED
@@ -5,8 +5,8 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  (function(global, factory) {
8
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@blocklet/labels"), require("react/jsx-runtime"), require("@mui/material/styles"), require("react"), require("@mui/material/Box"), require("@arcblock/ux/lib/Theme"), require("@blocklet/editor/lib/config"), require("@lexical/react/LexicalComposerContext"), require("lexical"), require("ahooks"), require("@mui/lab/LoadingButton"), require("@mui/icons-material"), require("@arcblock/ux/lib/Locale/context"), require("@mui/material/Alert"), require("@mui/material/Button"), require("@arcblock/did-connect/lib/Avatar"), require("@mui/material/useMediaQuery"), require("@arcblock/did-connect/lib/Address"), require("@mui/material/Tooltip"), require("@arcblock/ux/lib/RelativeTime"), require("@mui/material/Chip"), require("@mui/material/Stack"), require("lodash/groupBy"), require("lodash/flatMap"), require("lodash/uniqBy"), require("lodash/trim"), require("@mui/material/Avatar"), require("@iconify/react"), require("react-router-dom"), require("@mui/material/colors"), require("@arcblock/did-connect/lib/Session"), require("@mui/material"), require("@blocklet/editor/lib/ext/CheckboxPlugin"), require("@mui/material/MenuItem"), require("clsx"), require("@mui/material/IconButton"), require("@mui/material/Menu"), require("@arcblock/ux/lib/Dialog"), require("lodash/orderBy"), require("@mui/material/Typography"), require("@mui/material/Skeleton"), require("url-join"), require("dayjs"), require("dayjs/plugin/relativeTime"), require("mitt"), require("@mui/material/CircularProgress"), require("@mui/material/Fab"), require("lodash/debounce"), require("@mui/material/TextField"), require("axios"), require("@arcblock/ux/lib/Toast"), require("@mui/material/Pagination"), require("unstated-next"), require("react-dom"), require("lottie-react"), require("@blocklet/editor/lib/ext/OnContentChangePlugin"), require("@blocklet/editor/lib/ext/ShortcutPlugin"), require("@blocklet/editor/lib/ext/SafeAreaPlugin"), require("@lexical/text"), require("@blocklet/editor/lib/main/nodes/ImageNode")) : typeof define === "function" && define.amd ? define(["exports", "@blocklet/labels", "react/jsx-runtime", "@mui/material/styles", "react", "@mui/material/Box", "@arcblock/ux/lib/Theme", "@blocklet/editor/lib/config", "@lexical/react/LexicalComposerContext", "lexical", "ahooks", "@mui/lab/LoadingButton", "@mui/icons-material", "@arcblock/ux/lib/Locale/context", "@mui/material/Alert", "@mui/material/Button", "@arcblock/did-connect/lib/Avatar", "@mui/material/useMediaQuery", "@arcblock/did-connect/lib/Address", "@mui/material/Tooltip", "@arcblock/ux/lib/RelativeTime", "@mui/material/Chip", "@mui/material/Stack", "lodash/groupBy", "lodash/flatMap", "lodash/uniqBy", "lodash/trim", "@mui/material/Avatar", "@iconify/react", "react-router-dom", "@mui/material/colors", "@arcblock/did-connect/lib/Session", "@mui/material", "@blocklet/editor/lib/ext/CheckboxPlugin", "@mui/material/MenuItem", "clsx", "@mui/material/IconButton", "@mui/material/Menu", "@arcblock/ux/lib/Dialog", "lodash/orderBy", "@mui/material/Typography", "@mui/material/Skeleton", "url-join", "dayjs", "dayjs/plugin/relativeTime", "mitt", "@mui/material/CircularProgress", "@mui/material/Fab", "lodash/debounce", "@mui/material/TextField", "axios", "@arcblock/ux/lib/Toast", "@mui/material/Pagination", "unstated-next", "react-dom", "lottie-react", "@blocklet/editor/lib/ext/OnContentChangePlugin", "@blocklet/editor/lib/ext/ShortcutPlugin", "@blocklet/editor/lib/ext/SafeAreaPlugin", "@lexical/text", "@blocklet/editor/lib/main/nodes/ImageNode"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.DiscussKitComponents = {}, global.labels, global.jsxRuntime, global.styles, global.react, global.Box, global.Theme, global.config, global.LexicalComposerContext, global.lexical$1, global.ahooks, global.LoadingButton, global.iconsMaterial, global.context, global.Alert, global.Button, global.DidAvatar, global.useMediaQuery, global.DIDAddress, global.Tooltip, global.UxRelativeTime, global.Chip, global.Stack, global.groupBy, global.flatMap, global.uniqBy, global.trim, global.Avatar$1, global.react$1, global.reactRouterDom, global.colors, global.Session, global.material, global.CheckboxPlugin, global.MuiMenuItem, global.clsx, global.IconButton$1, global.MuiMenu, global.Dialog, global.orderBy, global.Typography, global.Skeleton, global.joinUrl, global.dayjs, global.relativeTime, global.mitt, global.CircularProgress, global.Fab, global.debounce, global.TextField, global.axios, global.Toast, global.MuiPagination, global.unstatedNext, global.reactDom, global.Lottie, global.OnContentChangePlugin, global.ShortcutPlugin, global.SafeAreaPlugin, global.text, global.ImageNode));
9
- })(this, function(exports2, labels, jsxRuntime, styles, react, Box, Theme, config, LexicalComposerContext, lexical$1, ahooks, LoadingButton, iconsMaterial, context, Alert, Button, DidAvatar, useMediaQuery, DIDAddress, Tooltip, UxRelativeTime, Chip, Stack, groupBy, flatMap, uniqBy, trim, Avatar$1, react$1, reactRouterDom, colors, Session, material, CheckboxPlugin, MuiMenuItem, clsx, IconButton$1, MuiMenu, Dialog, orderBy, Typography, Skeleton, joinUrl, dayjs, relativeTime, mitt, CircularProgress, Fab, debounce, TextField, axios, Toast, MuiPagination, unstatedNext, reactDom, Lottie, OnContentChangePlugin, ShortcutPlugin, SafeAreaPlugin, text, ImageNode) {
8
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@blocklet/labels"), require("react/jsx-runtime"), require("@mui/material/styles"), require("react"), require("@mui/material/Box"), require("@arcblock/ux/lib/Theme"), require("@blocklet/editor/lib/config"), require("@lexical/react/LexicalComposerContext"), require("lexical"), require("ahooks"), require("@mui/lab/LoadingButton"), require("@mui/icons-material"), require("@arcblock/ux/lib/Locale/context"), require("@mui/material/Alert"), require("@mui/material/Button"), require("@arcblock/did-connect/lib/Avatar"), require("@mui/material/useMediaQuery"), require("@arcblock/did-connect/lib/Address"), require("@mui/material/Tooltip"), require("@arcblock/ux/lib/RelativeTime"), require("@mui/material/Chip"), require("@mui/material/Stack"), require("lodash/groupBy"), require("lodash/flatMap"), require("lodash/uniqBy"), require("lodash/trim"), require("@mui/material/Avatar"), require("@iconify/react"), require("react-router-dom"), require("@mui/material/colors"), require("@arcblock/did-connect/lib/Session"), require("@mui/material"), require("@blocklet/editor/lib/ext/CheckboxPlugin"), require("@mui/material/MenuItem"), require("clsx"), require("@mui/material/IconButton"), require("@mui/material/Menu"), require("@arcblock/ux/lib/Dialog"), require("lodash/orderBy"), require("@mui/material/Typography"), require("@mui/material/Skeleton"), require("url-join"), require("dayjs"), require("dayjs/plugin/relativeTime"), require("mitt"), require("@mui/material/CircularProgress"), require("@mui/material/Fab"), require("lodash/debounce"), require("@mui/material/TextField"), require("axios"), require("@arcblock/ux/lib/Toast"), require("@mui/material/Pagination"), require("unstated-next"), require("react-dom"), require("js-cookie"), require("@arcblock/ws"), require("@blocklet/editor/lib/ext/OnContentChangePlugin"), require("@blocklet/editor/lib/ext/ShortcutPlugin"), require("@blocklet/editor/lib/ext/SafeAreaPlugin"), require("@lexical/text"), require("@blocklet/editor/lib/main/nodes/ImageNode")) : typeof define === "function" && define.amd ? define(["exports", "@blocklet/labels", "react/jsx-runtime", "@mui/material/styles", "react", "@mui/material/Box", "@arcblock/ux/lib/Theme", "@blocklet/editor/lib/config", "@lexical/react/LexicalComposerContext", "lexical", "ahooks", "@mui/lab/LoadingButton", "@mui/icons-material", "@arcblock/ux/lib/Locale/context", "@mui/material/Alert", "@mui/material/Button", "@arcblock/did-connect/lib/Avatar", "@mui/material/useMediaQuery", "@arcblock/did-connect/lib/Address", "@mui/material/Tooltip", "@arcblock/ux/lib/RelativeTime", "@mui/material/Chip", "@mui/material/Stack", "lodash/groupBy", "lodash/flatMap", "lodash/uniqBy", "lodash/trim", "@mui/material/Avatar", "@iconify/react", "react-router-dom", "@mui/material/colors", "@arcblock/did-connect/lib/Session", "@mui/material", "@blocklet/editor/lib/ext/CheckboxPlugin", "@mui/material/MenuItem", "clsx", "@mui/material/IconButton", "@mui/material/Menu", "@arcblock/ux/lib/Dialog", "lodash/orderBy", "@mui/material/Typography", "@mui/material/Skeleton", "url-join", "dayjs", "dayjs/plugin/relativeTime", "mitt", "@mui/material/CircularProgress", "@mui/material/Fab", "lodash/debounce", "@mui/material/TextField", "axios", "@arcblock/ux/lib/Toast", "@mui/material/Pagination", "unstated-next", "react-dom", "js-cookie", "@arcblock/ws", "@blocklet/editor/lib/ext/OnContentChangePlugin", "@blocklet/editor/lib/ext/ShortcutPlugin", "@blocklet/editor/lib/ext/SafeAreaPlugin", "@lexical/text", "@blocklet/editor/lib/main/nodes/ImageNode"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.DiscussKitComponents = {}, global.labels, global.jsxRuntime, global.styles, global.react, global.Box, global.Theme, global.config, global.LexicalComposerContext, global.lexical$1, global.ahooks, global.LoadingButton, global.iconsMaterial, global.context, global.Alert, global.Button, global.DidAvatar, global.useMediaQuery, global.DIDAddress, global.Tooltip, global.UxRelativeTime, global.Chip, global.Stack, global.groupBy, global.flatMap, global.uniqBy, global.trim, global.Avatar$1, global.react$1, global.reactRouterDom, global.colors, global.Session, global.material, global.CheckboxPlugin, global.MuiMenuItem, global.clsx, global.IconButton$1, global.MuiMenu, global.Dialog, global.orderBy, global.Typography, global.Skeleton, global.joinUrl, global.dayjs, global.relativeTime, global.mitt, global.CircularProgress, global.Fab, global.debounce, global.TextField, global.axios, global.Toast, global.MuiPagination, global.unstatedNext, global.reactDom, global.Cookie, global.ws, global.OnContentChangePlugin, global.ShortcutPlugin, global.SafeAreaPlugin, global.text, global.ImageNode));
9
+ })(this, function(exports2, labels, jsxRuntime, styles, react, Box, Theme, config, LexicalComposerContext, lexical$1, ahooks, LoadingButton, iconsMaterial, context, Alert, Button, DidAvatar, useMediaQuery, DIDAddress, Tooltip, UxRelativeTime, Chip, Stack, groupBy, flatMap, uniqBy, trim, Avatar$1, react$1, reactRouterDom, colors, Session, material, CheckboxPlugin, MuiMenuItem, clsx, IconButton$1, MuiMenu, Dialog, orderBy, Typography, Skeleton, joinUrl, dayjs, relativeTime, mitt, CircularProgress, Fab, debounce, TextField, axios, Toast, MuiPagination, unstatedNext, reactDom, Cookie, ws, OnContentChangePlugin, ShortcutPlugin, SafeAreaPlugin, text, ImageNode) {
10
10
  var _a, _b;
11
11
  "use strict";
12
12
  const themeOverrides = {
@@ -308,7 +308,7 @@ var __publicField = (obj, key, value) => {
308
308
  const size = ahooks.useSize(ref);
309
309
  return [ref, size || { width: 0, height: 0 }];
310
310
  };
311
- const BlockletEditor$2 = react.lazy(() => import("@blocklet/editor"));
311
+ const BlockletEditor$3 = react.lazy(() => import("@blocklet/editor"));
312
312
  const Root$6 = Theme.styled(Box)`
313
313
  position: relative;
314
314
  .be-shell {
@@ -408,7 +408,7 @@ var __publicField = (obj, key, value) => {
408
408
  };
409
409
  const editorState = draftKey && draftContent && !initialContent ? draftContent : inferInitialEditorState(initialContent);
410
410
  return /* @__PURE__ */ react.createElement(Root$6, { ref, ...rest, key: draftKey }, /* @__PURE__ */ jsxRuntime.jsx(config.EditorConfigProvider, { value: mergedEditorConfig, children: /* @__PURE__ */ jsxRuntime.jsxs(
411
- BlockletEditor$2,
411
+ BlockletEditor$3,
412
412
  {
413
413
  placeholder,
414
414
  editorState,
@@ -982,8 +982,8 @@ var __publicField = (obj, key, value) => {
982
982
  )
983
983
  ] });
984
984
  }
985
- const BlockletEditor$1 = react.lazy(() => import("@blocklet/editor"));
986
- const StyledBlockletEditor = styles.styled(BlockletEditor$1)`
985
+ const BlockletEditor$2 = react.lazy(() => import("@blocklet/editor"));
986
+ const StyledBlockletEditor = styles.styled(BlockletEditor$2)`
987
987
  .editor-scroller {
988
988
  min-height: initial;
989
989
  }
@@ -2299,7 +2299,10 @@ var __publicField = (obj, key, value) => {
2299
2299
  width = 320,
2300
2300
  sx,
2301
2301
  fetchpriority = "auto",
2302
- loading = "eager"
2302
+ loading = "eager",
2303
+ shadow = true,
2304
+ fallback,
2305
+ ...rest
2303
2306
  }) {
2304
2307
  const [loaded, setLoaded] = react.useState(false);
2305
2308
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -2312,12 +2315,13 @@ var __publicField = (obj, key, value) => {
2312
2315
  overflow: "hidden",
2313
2316
  position: "relative",
2314
2317
  borderRadius: 2,
2315
- boxShadow: "rgb(0 0 0 / 12%) 0px 8px 30px",
2318
+ ...shadow && { boxShadow: "rgb(0 0 0 / 12%) 0px 8px 30px" },
2316
2319
  // https://stackoverflow.com/questions/49066011/overflow-hidden-with-border-radius-not-working-on-safari
2317
2320
  transform: "translateZ(0)"
2318
2321
  },
2319
2322
  ...Array.isArray(sx) ? sx : [sx]
2320
2323
  ],
2324
+ ...rest,
2321
2325
  children: [
2322
2326
  (!loaded || !url) && /* @__PURE__ */ jsxRuntime.jsx(
2323
2327
  material.Skeleton,
@@ -2333,7 +2337,7 @@ var __publicField = (obj, key, value) => {
2333
2337
  }
2334
2338
  }
2335
2339
  ),
2336
- /* @__PURE__ */ jsxRuntime.jsx(
2340
+ !!url && /* @__PURE__ */ jsxRuntime.jsx(
2337
2341
  "img",
2338
2342
  {
2339
2343
  src: url ? composeImageUrl(url, width) : "",
@@ -2352,6 +2356,19 @@ var __publicField = (obj, key, value) => {
2352
2356
  alt: "cover",
2353
2357
  onLoad: () => setLoaded(true)
2354
2358
  }
2359
+ ),
2360
+ !url && /* @__PURE__ */ jsxRuntime.jsx(
2361
+ material.Box,
2362
+ {
2363
+ sx: {
2364
+ position: "absolute",
2365
+ top: 0,
2366
+ left: 0,
2367
+ width: "100%",
2368
+ height: "100%"
2369
+ },
2370
+ children: fallback
2371
+ }
2355
2372
  )
2356
2373
  ]
2357
2374
  }
@@ -3060,7 +3077,7 @@ var __publicField = (obj, key, value) => {
3060
3077
  const sorted = orderBy(unique, ["createdAt", "id"], [order, order]);
3061
3078
  return sorted;
3062
3079
  };
3063
- function ChatProvider({ client, activeChatId, children }) {
3080
+ function ChatProvider({ client: client2, activeChatId, children }) {
3064
3081
  const [state, setState] = ahooks.useSetState({
3065
3082
  initialized: false,
3066
3083
  chats: [],
@@ -3096,7 +3113,7 @@ var __publicField = (obj, key, value) => {
3096
3113
  };
3097
3114
  const updateLastAckTime = async (chatId) => {
3098
3115
  updateChat(chatId, (chat) => ({ ...chat, lastAckTime: chat.lastMessageAt }));
3099
- await client.updateLastAckTime(chatId);
3116
+ await client2.updateLastAckTime(chatId);
3100
3117
  };
3101
3118
  const addMessage = (chatId, message) => {
3102
3119
  updateChat(chatId, (chat) => ({
@@ -3141,7 +3158,7 @@ var __publicField = (obj, key, value) => {
3141
3158
  setActiveChat(null);
3142
3159
  };
3143
3160
  const loadMessages = async (chatId, cursor) => {
3144
- const { messages, nextCursor } = await client.fetchMessages(chatId, cursor);
3161
+ const { messages, nextCursor } = await client2.fetchMessages(chatId, cursor);
3145
3162
  updateChat(chatId, (chat) => ({
3146
3163
  ...chat,
3147
3164
  messages: uniqAndSort([...chat.messages || [], ...messages || []]),
@@ -3149,7 +3166,7 @@ var __publicField = (obj, key, value) => {
3149
3166
  }));
3150
3167
  };
3151
3168
  const sendMessage = async (chatId, content) => {
3152
- const saved = await client.sendMessage(chatId, content);
3169
+ const saved = await client2.sendMessage(chatId, content);
3153
3170
  addMessage(chatId, saved);
3154
3171
  updateLastAckTime(chatId);
3155
3172
  };
@@ -3157,7 +3174,7 @@ var __publicField = (obj, key, value) => {
3157
3174
  const {
3158
3175
  chat: { participants },
3159
3176
  messages: { messages, nextCursor }
3160
- } = await client.fetchChat(chatId);
3177
+ } = await client2.fetchChat(chatId);
3161
3178
  updateChat(chatId, (chat) => {
3162
3179
  const mapped = {
3163
3180
  ...chat,
@@ -3170,7 +3187,7 @@ var __publicField = (obj, key, value) => {
3170
3187
  });
3171
3188
  };
3172
3189
  const joinChannel = async (chatId) => {
3173
- await client.joinChannel(chatId);
3190
+ await client2.joinChannel(chatId);
3174
3191
  updateChat(chatId, (chat) => ({
3175
3192
  ...chat,
3176
3193
  hasJoined: true
@@ -3178,17 +3195,17 @@ var __publicField = (obj, key, value) => {
3178
3195
  updateLastAckTime(chatId);
3179
3196
  };
3180
3197
  const leaveChannel = async (chatId) => {
3181
- await client.leaveChannel(chatId);
3198
+ await client2.leaveChannel(chatId);
3182
3199
  updateChat(chatId, (chat) => ({
3183
3200
  ...chat,
3184
3201
  hasJoined: false
3185
3202
  }));
3186
3203
  };
3187
3204
  const deleteChannel = async (chatId) => {
3188
- await client.deleteChannel(chatId);
3205
+ await client2.deleteChannel(chatId);
3189
3206
  };
3190
3207
  const deleteMessage = async (chatId, messageId) => {
3191
- await client.deleteMessage(messageId);
3208
+ await client2.deleteMessage(messageId);
3192
3209
  updateChat(chatId, (chat) => {
3193
3210
  var _a2;
3194
3211
  return {
@@ -3199,7 +3216,7 @@ var __publicField = (obj, key, value) => {
3199
3216
  };
3200
3217
  const init = async () => {
3201
3218
  try {
3202
- const { chats } = await client.init();
3219
+ const { chats } = await client2.init();
3203
3220
  setState({ initialized: true, chats });
3204
3221
  } catch (e) {
3205
3222
  console.error(e);
@@ -3207,7 +3224,7 @@ var __publicField = (obj, key, value) => {
3207
3224
  }
3208
3225
  };
3209
3226
  const refresh = () => {
3210
- client.destroy();
3227
+ client2.destroy();
3211
3228
  return init();
3212
3229
  };
3213
3230
  react.useEffect(() => {
@@ -3221,7 +3238,7 @@ var __publicField = (obj, key, value) => {
3221
3238
  error: void 0
3222
3239
  });
3223
3240
  }
3224
- return () => client.destroy();
3241
+ return () => client2.destroy();
3225
3242
  }, [currentUser == null ? void 0 : currentUser.did]);
3226
3243
  react.useEffect(() => {
3227
3244
  if (activeChatId) {
@@ -3237,16 +3254,16 @@ var __publicField = (obj, key, value) => {
3237
3254
  }, [state, activeChatId]);
3238
3255
  react.useEffect(() => {
3239
3256
  const cancels = [
3240
- client.onMessage(({ chatId, message }) => {
3257
+ client2.onMessage(({ chatId, message }) => {
3241
3258
  addMessage(chatId, message);
3242
3259
  if (isActiveChat(chatId)) {
3243
3260
  updateLastAckTime(chatId);
3244
3261
  }
3245
3262
  }),
3246
- client.onCreateChat(({ chat }) => addChat(chat)),
3247
- client.onJoinChannel(({ chatId, participant }) => addParticipant(chatId, participant)),
3248
- client.onLeaveChannel(({ chatId, participant }) => removeParticipant(chatId, participant)),
3249
- client.onDeleteChannel(({ chatId }) => deleteChat(chatId))
3263
+ client2.onCreateChat(({ chat }) => addChat(chat)),
3264
+ client2.onJoinChannel(({ chatId, participant }) => addParticipant(chatId, participant)),
3265
+ client2.onLeaveChannel(({ chatId, participant }) => removeParticipant(chatId, participant)),
3266
+ client2.onDeleteChannel(({ chatId }) => deleteChat(chatId))
3250
3267
  ];
3251
3268
  return () => {
3252
3269
  cancels.forEach((cancel) => cancel == null ? void 0 : cancel());
@@ -3260,7 +3277,7 @@ var __publicField = (obj, key, value) => {
3260
3277
  const value = react.useMemo(() => {
3261
3278
  return {
3262
3279
  ...state,
3263
- client,
3280
+ client: client2,
3264
3281
  setActiveChat,
3265
3282
  isActiveChat,
3266
3283
  getOppositeUser: (chat) => {
@@ -3280,7 +3297,7 @@ var __publicField = (obj, key, value) => {
3280
3297
  hasUnreadMessages,
3281
3298
  refresh
3282
3299
  };
3283
- }, [state, client, currentUser == null ? void 0 : currentUser.did]);
3300
+ }, [state, client2, currentUser == null ? void 0 : currentUser.did]);
3284
3301
  return /* @__PURE__ */ jsxRuntime.jsx(ChatContext.Provider, { value, children });
3285
3302
  }
3286
3303
  function ChatList(props) {
@@ -3831,7 +3848,7 @@ var __publicField = (obj, key, value) => {
3831
3848
  ] });
3832
3849
  }
3833
3850
  function Chat({ sx, ...rest }) {
3834
- const { client, initialized, chats, activeChatId, addChat, setActiveChat, refresh } = useChatContext();
3851
+ const { client: client2, initialized, chats, activeChatId, addChat, setActiveChat, refresh } = useChatContext();
3835
3852
  const [newChannelVisible, setNewChannelVisible] = react.useState(false);
3836
3853
  const downMd = material.useMediaQuery((theme) => theme.breakpoints.down("sm"));
3837
3854
  react.useEffect(() => {
@@ -3857,7 +3874,7 @@ var __publicField = (obj, key, value) => {
3857
3874
  ...Array.isArray(sx) ? sx : [sx]
3858
3875
  ];
3859
3876
  const handleNewChannel = async ({ name, description }) => {
3860
- const saved = await client.createChannel(name, description);
3877
+ const saved = await client2.createChannel(name, description);
3861
3878
  const newChannel = { ...saved, hasJoined: true };
3862
3879
  addChat(newChannel);
3863
3880
  setNewChannelVisible(false);
@@ -4212,6 +4229,19 @@ var __publicField = (obj, key, value) => {
4212
4229
  ] });
4213
4230
  return /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback, children: /* @__PURE__ */ jsxRuntime.jsx(Editor$1, { ...props }) });
4214
4231
  }
4232
+ const BlockletEditor$1 = react.lazy(() => import("@blocklet/editor"));
4233
+ function EditorPreview({ content, children, ...rest }) {
4234
+ const fallback = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4235
+ /* @__PURE__ */ jsxRuntime.jsx(material.Skeleton, {}),
4236
+ /* @__PURE__ */ jsxRuntime.jsx(material.Skeleton, { width: "80%" }),
4237
+ /* @__PURE__ */ jsxRuntime.jsx(material.Skeleton, { width: "60%" }),
4238
+ /* @__PURE__ */ jsxRuntime.jsx(material.Skeleton, { width: "40%" })
4239
+ ] });
4240
+ return /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback, children: /* @__PURE__ */ jsxRuntime.jsxs(BlockletEditor$1, { editorState: inferInitialEditorState(content), editable: false, ...rest, children: [
4241
+ /* @__PURE__ */ jsxRuntime.jsx(ImagePathFixerPlugin, {}),
4242
+ children
4243
+ ] }) });
4244
+ }
4215
4245
  const useBeforeUnloadPrompt = (dirty) => {
4216
4246
  react.useEffect(() => {
4217
4247
  const showPrompt = (e) => {
@@ -4296,8 +4326,8 @@ var __publicField = (obj, key, value) => {
4296
4326
  deleted: "This comment has been deleted",
4297
4327
  edit: "Edit",
4298
4328
  empty: "Be the first to leave a comment.",
4299
- loadMore: "Load more",
4300
- readMore: "Read more",
4329
+ loadMore: "Load More",
4330
+ readMore: "Read More",
4301
4331
  saveChanges: "Save Changes",
4302
4332
  sendComment: "Comment",
4303
4333
  showMoreReplies: "Show more replies",
@@ -4365,6 +4395,7 @@ var __publicField = (obj, key, value) => {
4365
4395
  }
4366
4396
  };
4367
4397
  const translations = { zh, en };
4398
+ const Lottie = react.lazy(() => import("lottie-react"));
4368
4399
  function LottieComponent({ src, ...restProps }) {
4369
4400
  return /* @__PURE__ */ jsxRuntime.jsx(Lottie, { animationData: src, loop: true, ...restProps });
4370
4401
  }
@@ -9854,8 +9885,50 @@ var __publicField = (obj, key, value) => {
9854
9885
  assets,
9855
9886
  layers
9856
9887
  };
9888
+ let client;
9889
+ function create(prefix2) {
9890
+ const pathPrefix = prefix2;
9891
+ const url = `//${window.location.host}${pathPrefix.replace(/\/$/, "")}`;
9892
+ return new ws.WsClient(url, {
9893
+ heartbeatIntervalMs: 10 * 1e3,
9894
+ params: () => ({
9895
+ token: Cookie.get("login_token")
9896
+ }),
9897
+ reconnectAfterMs: (tries) => {
9898
+ if (Cookie.get("login_token")) {
9899
+ return Math.floor(Math.random() * 2 ** tries * 1e3);
9900
+ }
9901
+ return 2 ** tries * 1e3;
9902
+ }
9903
+ });
9904
+ }
9905
+ function getWsClient(prefix2 = ((_c) => (_c = window.blocklet) == null ? void 0 : _c.prefix)() || "/") {
9906
+ if (!client) {
9907
+ client = create(prefix2);
9908
+ }
9909
+ return client;
9910
+ }
9911
+ const useSubscription = (event, cb = () => {
9912
+ }, deps = [], prefix2 = ((_d) => (_d = window.blocklet) == null ? void 0 : _d.prefix)() || "/") => {
9913
+ react.useEffect(() => {
9914
+ if (event) {
9915
+ if (!client) {
9916
+ client = getWsClient(prefix2);
9917
+ }
9918
+ client.on(event, cb);
9919
+ return () => {
9920
+ client.off(event, cb);
9921
+ };
9922
+ }
9923
+ return () => {
9924
+ };
9925
+ }, [event, ...deps]);
9926
+ };
9857
9927
  const id = "point-up-component";
9858
9928
  const PointUpContext = react.createContext({});
9929
+ const WsEvents = Object.freeze({
9930
+ POINT_UP: "point.up"
9931
+ });
9859
9932
  const usePointUpContext = () => react.useContext(PointUpContext);
9860
9933
  function PointUp({ points }) {
9861
9934
  const { t } = context.useLocaleContext();
@@ -9903,16 +9976,34 @@ var __publicField = (obj, key, value) => {
9903
9976
  );
9904
9977
  }
9905
9978
  function PointUpProvider({ children }) {
9906
- var _a2, _b2, _c;
9979
+ var _a2, _b2, _c, _d;
9907
9980
  const state = ahooks.useReactive({
9908
9981
  pointsList: [],
9909
9982
  visible: false,
9910
9983
  currentPoints: 0
9911
9984
  });
9912
- const value = react.useMemo(() => {
9913
- const pointUp = ({ points }) => {
9914
- state.pointsList.push(points);
9985
+ const { session } = useSessionContext();
9986
+ const wsClient = getWsClient();
9987
+ const pointUp = react.useCallback(({ points }) => {
9988
+ state.pointsList.push(points);
9989
+ }, []);
9990
+ const pointUpComponent = (_c = (_b2 = (_a2 = window.blocklet) == null ? void 0 : _a2.componentMountPoints) == null ? void 0 : _b2.find) == null ? void 0 : _c.call(
9991
+ _b2,
9992
+ (item) => item.did === "z2qa2ZST7Frp8w1XGqyw9v85u12R3mBbB2oaA"
9993
+ );
9994
+ const handlers = {
9995
+ [WsEvents.POINT_UP]: (payload) => {
9996
+ pointUp(payload);
9997
+ }
9998
+ };
9999
+ react.useEffect(() => {
10000
+ wsClient.connect();
10001
+ return () => {
10002
+ if (wsClient.isConnected())
10003
+ ;
9915
10004
  };
10005
+ }, []);
10006
+ const value = react.useMemo(() => {
9916
10007
  return {
9917
10008
  pointUp
9918
10009
  };
@@ -9936,19 +10027,17 @@ var __publicField = (obj, key, value) => {
9936
10027
  state.visible = false;
9937
10028
  }
9938
10029
  }, [JSON.stringify(state.pointsList)]);
9939
- const pointUpComponent = (_c = (_b2 = (_a2 = window.blocklet) == null ? void 0 : _a2.componentMountPoints) == null ? void 0 : _b2.find) == null ? void 0 : _c.call(
9940
- _b2,
9941
- (item) => item.did === "z2qa2ZST7Frp8w1XGqyw9v85u12R3mBbB2oaA"
9942
- );
10030
+ useSubscription((_d = session == null ? void 0 : session.user) == null ? void 0 : _d.did, ({ event, data }) => {
10031
+ var _a3;
10032
+ return (_a3 = handlers[event]) == null ? void 0 : _a3.call(handlers, data);
10033
+ }, []);
9943
10034
  return /* @__PURE__ */ jsxRuntime.jsxs(PointUpContext.Provider, { value, children: [
9944
- state.currentPoints > 0 && reactDom.createPortal(
10035
+ (pointUpComponent == null ? void 0 : pointUpComponent.mountPoint) && reactDom.createPortal(
9945
10036
  /* @__PURE__ */ jsxRuntime.jsx(
9946
10037
  Box,
9947
10038
  {
9948
10039
  onClick: () => {
9949
- if (pointUpComponent == null ? void 0 : pointUpComponent.mountPoint) {
9950
- window.open(joinUrl(window.location.origin, pointUpComponent.mountPoint, "my"));
9951
- }
10040
+ window.open(joinUrl(window.location.origin, pointUpComponent.mountPoint, "my"));
9952
10041
  },
9953
10042
  id,
9954
10043
  sx: {
@@ -10030,6 +10119,7 @@ var __publicField = (obj, key, value) => {
10030
10119
  exports2.CoverImageUpload = CoverImageUpload;
10031
10120
  exports2.DefaultEditorConfigProvider = DefaultEditorConfigProvider;
10032
10121
  exports2.DirtyPromptContainer = DirtyPromptContainer;
10122
+ exports2.EditorPreview = EditorPreview;
10033
10123
  exports2.GithubReaction = GithubReaction;
10034
10124
  exports2.Input = Input;
10035
10125
  exports2.InternalThemeProvider = InternalThemeProvider;
@@ -10040,6 +10130,7 @@ var __publicField = (obj, key, value) => {
10040
10130
  exports2.Post = PostComponent;
10041
10131
  exports2.PostContent = PostContent;
10042
10132
  exports2.PreviousLocationRecorder = PreviousLocationRecorder;
10133
+ exports2.RelativeTime = RelativeTime;
10043
10134
  exports2.ScrollableEditorWrapper = ScrollableEditorWrapper;
10044
10135
  exports2.SecureLabelPicker = SecureLabelPicker;
10045
10136
  exports2.SystemUser = SystemUser;
@@ -10049,7 +10140,9 @@ var __publicField = (obj, key, value) => {
10049
10140
  exports2.UploaderProvider = UploaderProvider;
10050
10141
  exports2.UploaderTrigger = UploaderTrigger;
10051
10142
  exports2.composeImageUrl = composeImageUrl;
10143
+ exports2.create = create;
10052
10144
  exports2.getBlogLink = getBlogLink;
10145
+ exports2.getWsClient = getWsClient;
10053
10146
  exports2.lexicalUtils = lexical;
10054
10147
  exports2.preferences = preferences;
10055
10148
  exports2.routes = routes;
@@ -10064,6 +10157,7 @@ var __publicField = (obj, key, value) => {
10064
10157
  exports2.useDefaultApiErrorHandler = useDefaultApiErrorHandler;
10065
10158
  exports2.useNow = useNow;
10066
10159
  exports2.usePointUpContext = usePointUpContext;
10160
+ exports2.useSubscription = useSubscription;
10067
10161
  exports2.useUnreadNotification = useUnreadNotification;
10068
10162
  exports2.useUploader = useUploader;
10069
10163
  exports2.utils = utils;
@@ -29,5 +29,9 @@ declare const preferences: {
29
29
  socialShareButtonsDiscussion: boolean;
30
30
  socialShareButtonsBlog: boolean;
31
31
  socialShareButtonsDoc: boolean;
32
+ blogListTemplate: "standard" | "corp";
33
+ blogTemplate: "standard" | "corp";
34
+ blogListTemplatePrimaryColor: string;
35
+ blogListTemplateAccentColor: string;
32
36
  };
33
37
  export default preferences;
package/dist/ws.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare function create(prefix: string): any;
2
+ export declare function getWsClient(prefix?: string): any;
3
+ export declare const useSubscription: (event: string, cb?: () => void, deps?: never[], prefix?: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/discuss-kit-ux",
3
- "version": "1.5.182",
3
+ "version": "1.5.184",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -28,8 +28,9 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@blocklet/editor": "1.5.182",
32
- "@blocklet/labels": "1.5.182",
31
+ "@arcblock/ws": "^1.18.95",
32
+ "@blocklet/editor": "1.5.184",
33
+ "@blocklet/labels": "1.5.184",
33
34
  "@blocklet/uploader": "^0.0.42",
34
35
  "@emotion/css": "^11.10.5",
35
36
  "@emotion/react": "^11.10.5",
@@ -40,6 +41,7 @@
40
41
  "ahooks": "^3.7.8",
41
42
  "axios": "^0.27.2",
42
43
  "dayjs": "^1.11.7",
44
+ "js-cookie": "^3.0.5",
43
45
  "lexical": "^0.12.0",
44
46
  "lottie-react": "^2.4.0",
45
47
  "mitt": "^3.0.0",
@@ -91,5 +93,5 @@
91
93
  "resolutions": {
92
94
  "react": "^18.2.0"
93
95
  },
94
- "gitHead": "a23964ec273fe5a9c15733b31bfdbf7b0df72fe5"
96
+ "gitHead": "498f8ec6f32d91ad8a0cf12c7bf863066dc4ec63"
95
97
  }