@blocklet/discuss-kit-ux 2.0.98 → 2.0.100

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.
@@ -14,8 +14,10 @@ interface Session {
14
14
  initialized: boolean;
15
15
  user: SessionContextUser;
16
16
  login: (...args: any[]) => void;
17
+ switchPassport: (...args: any[]) => void;
17
18
  }
18
19
  export declare const useSessionContext: () => {
20
+ isAuthenticated: boolean;
19
21
  isAdmin: boolean;
20
22
  isMember: boolean;
21
23
  isBlogEditor: boolean;
@@ -19,3 +19,5 @@ export declare const mergeSx: (initial: SystemStyleObject<Theme>, sx?: SxProps<T
19
19
  export declare const discussKitMountPoint: string | undefined;
20
20
  export declare const isInDiscussKitApp: boolean | "" | undefined;
21
21
  export declare const openProfile: (did: string, newTab?: boolean) => void;
22
+ export declare const randomId: () => string;
23
+ export declare const getDiscussKitClientId: () => string;
@@ -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, V as VideoPathFixerPlugin, a as isEmptyContent, s as stringify, g as getExcerptSync } from "./index-8LMyNkyB.mjs";
7
+ import { i as inferInitialEditorState, I as ImagePathFixerPlugin, V as VideoPathFixerPlugin, a as isEmptyContent, s as stringify, g as getExcerptSync } from "./index-BQ_vgrJf.mjs";
8
8
  const BlockletEditor = lazy(() => import("@blocklet/editor"));
9
9
  const Root = styled(Box)`
10
10
  .be-editable,
@@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
- var _a, _b, _c;
7
+ var _a, _b, _c, _d;
8
8
  import { Labels2, LabelPicker } from "@blocklet/labels";
9
9
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
10
10
  import { useTheme, ThemeProvider, styled } from "@mui/material/styles";
@@ -349,12 +349,23 @@ const openProfile = (did, newTab) => {
349
349
  window.open(withQuery(joinURL(discussKitMountPoint || "/", "profile"), { did }), newTab ? "_blank" : "_self");
350
350
  }
351
351
  };
352
+ const randomId = () => {
353
+ var _a2;
354
+ return ((_a2 = crypto == null ? void 0 : crypto.randomUUID) == null ? void 0 : _a2.call(crypto)) || Math.random().toString(36).substring(2);
355
+ };
356
+ const getDiscussKitClientId = () => {
357
+ if (!window.__discuss_kit_client_id__) {
358
+ window.__discuss_kit_client_id__ = randomId();
359
+ }
360
+ return window.__discuss_kit_client_id__;
361
+ };
352
362
  const utils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
353
363
  __proto__: null,
354
364
  blockletExists,
355
365
  copy,
356
366
  discussKitMountPoint,
357
367
  getBlockletMountPointInfo,
368
+ getDiscussKitClientId,
358
369
  getDraftSessionKeyPrefix,
359
370
  getExcerptFromLexicalContent,
360
371
  getLastItem,
@@ -366,6 +377,7 @@ const utils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
366
377
  minDelay,
367
378
  openProfile,
368
379
  protectLogin,
380
+ randomId,
369
381
  repairBase64Avatar,
370
382
  sleep,
371
383
  tryParseJSONObject
@@ -1041,15 +1053,16 @@ function Badge({
1041
1053
  ] }) : null;
1042
1054
  }
1043
1055
  const useSessionContext = () => {
1044
- var _a2, _b2, _c2, _d;
1056
+ var _a2, _b2, _c2, _d2, _e;
1045
1057
  const ctx = useContext(SessionContext) || {};
1046
1058
  const loginRole = (_b2 = (_a2 = ctx == null ? void 0 : ctx.session) == null ? void 0 : _a2.user) == null ? void 0 : _b2.role;
1047
1059
  const permissionSet = useMemo(() => {
1048
1060
  var _a3, _b3;
1049
1061
  return new Set(((_b3 = (_a3 = ctx.session) == null ? void 0 : _a3.user) == null ? void 0 : _b3.permissions) || []);
1050
- }, [(_d = (_c2 = ctx.session) == null ? void 0 : _c2.user) == null ? void 0 : _d.permissions]);
1062
+ }, [(_d2 = (_c2 = ctx.session) == null ? void 0 : _c2.user) == null ? void 0 : _d2.permissions]);
1051
1063
  return {
1052
1064
  ...ctx,
1065
+ isAuthenticated: !!((_e = ctx.session) == null ? void 0 : _e.user),
1053
1066
  isAdmin: ["admin", "owner"].includes(loginRole),
1054
1067
  isMember: ["member"].includes(loginRole),
1055
1068
  isBlogEditor: ["blogEditor"].includes(loginRole),
@@ -2223,7 +2236,7 @@ const preferences = {
2223
2236
  maxDiscussionLength: parseInt(`${prefs.maxDiscussionLength}`, 10),
2224
2237
  maxPinLimit: parseInt(`${prefs.maxPinLimit}`, 10),
2225
2238
  maxFeaturedLimit: parseInt(`${prefs.maxFeaturedLimit}`, 10),
2226
- assignmentAuthorizedPassports: prefs.assignmentAuthorizedPassports.split(",").map((x) => x.trim())
2239
+ assignmentAuthorizedPassports: (_d = prefs.assignmentAuthorizedPassports) == null ? void 0 : _d.split(",").map((x) => x.trim())
2227
2240
  };
2228
2241
  function Confirm({
2229
2242
  open,
@@ -4296,7 +4309,7 @@ function NotificationMessage({ chat, message, prevMessage }) {
4296
4309
  return null;
4297
4310
  };
4298
4311
  const render = () => {
4299
- var _a2, _b2, _c2, _d;
4312
+ var _a2, _b2, _c2, _d2;
4300
4313
  const baseCardSx = {
4301
4314
  py: 1.5,
4302
4315
  px: 2,
@@ -4439,7 +4452,7 @@ function NotificationMessage({ chat, message, prevMessage }) {
4439
4452
  ]
4440
4453
  }
4441
4454
  ),
4442
- /* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { fontSize: 16 }, children: (_d = (_b2 = message == null ? void 0 : message.comment) == null ? void 0 : _b2.excerpt) == null ? void 0 : _d.replace((_c2 = session == null ? void 0 : session.user) == null ? void 0 : _c2.fullName, "") }),
4455
+ /* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { fontSize: 16 }, children: (_d2 = (_b2 = message == null ? void 0 : message.comment) == null ? void 0 : _b2.excerpt) == null ? void 0 : _d2.replace((_c2 = session == null ? void 0 : session.user) == null ? void 0 : _c2.fullName, "") }),
4443
4456
  renderQuote(message.post)
4444
4457
  ]
4445
4458
  }
@@ -4762,7 +4775,7 @@ function Back({ url, fallbackUrl, iconOnly, sx, ...rest }) {
4762
4775
  }
4763
4776
  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" }) });
4764
4777
  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" }) });
4765
- const Editor = lazy(() => import("./editor-DYjHI-qS.mjs"));
4778
+ const Editor = lazy(() => import("./editor-DI-qfaZA.mjs"));
4766
4779
  function LazyEditor(props) {
4767
4780
  const fallback2 = /* @__PURE__ */ jsxs(Box, { sx: { px: 3 }, children: [
4768
4781
  /* @__PURE__ */ jsx(Skeleton, {}),
@@ -5656,7 +5669,7 @@ function Empty({ sx }) {
5656
5669
  ] });
5657
5670
  }
5658
5671
  function ChatListInWallet({ sx, ...rest }) {
5659
- var _a2, _b2, _c2, _d;
5672
+ var _a2, _b2, _c2, _d2;
5660
5673
  const { session } = useSessionContext();
5661
5674
  const { initialized, chats, activeChatId } = useChatContext();
5662
5675
  const { unread } = useUnreadNotification();
@@ -5757,7 +5770,7 @@ function ChatListInWallet({ sx, ...rest }) {
5757
5770
  sx: {
5758
5771
  width: 1,
5759
5772
  height: 1,
5760
- ...((_d = window.chatInWallet) == null ? void 0 : _d.safeAreaInsetTop) && {
5773
+ ...((_d2 = window.chatInWallet) == null ? void 0 : _d2.safeAreaInsetTop) && {
5761
5774
  pt: `${window.chatInWallet.safeAreaInsetTop}px`
5762
5775
  }
5763
5776
  },
@@ -11868,14 +11881,14 @@ function create(prefix2) {
11868
11881
  }
11869
11882
  });
11870
11883
  }
11871
- function getWsClient(prefix2 = ((_d) => (_d = window.blocklet) == null ? void 0 : _d.prefix)() || "/") {
11884
+ function getWsClient(prefix2 = ((_e) => (_e = window.blocklet) == null ? void 0 : _e.prefix)() || "/") {
11872
11885
  if (!client) {
11873
11886
  client = create(prefix2);
11874
11887
  }
11875
11888
  return client;
11876
11889
  }
11877
11890
  const useSubscription = (event, cb = () => {
11878
- }, deps = [], prefix2 = ((_e) => (_e = window.blocklet) == null ? void 0 : _e.prefix)() || "/") => {
11891
+ }, deps = [], prefix2 = ((_f) => (_f = window.blocklet) == null ? void 0 : _f.prefix)() || "/") => {
11879
11892
  useEffect(() => {
11880
11893
  if (event) {
11881
11894
  if (!client) {
@@ -11942,7 +11955,7 @@ function PointUp({ points }) {
11942
11955
  );
11943
11956
  }
11944
11957
  function PointUpProvider({ children }) {
11945
- var _a2, _b2, _c2, _d;
11958
+ var _a2, _b2, _c2, _d2;
11946
11959
  const state = useReactive({
11947
11960
  pointsList: [],
11948
11961
  visible: false,
@@ -11993,10 +12006,16 @@ function PointUpProvider({ children }) {
11993
12006
  state.visible = false;
11994
12007
  }
11995
12008
  }, [JSON.stringify(state.pointsList)]);
11996
- useSubscription((_d = session == null ? void 0 : session.user) == null ? void 0 : _d.did, ({ event, data }) => {
11997
- var _a3;
11998
- return (_a3 = handlers[event]) == null ? void 0 : _a3.call(handlers, data);
11999
- }, []);
12009
+ useSubscription(
12010
+ (_d2 = session == null ? void 0 : session.user) == null ? void 0 : _d2.did,
12011
+ ({ event, clientId, data }) => {
12012
+ var _a3;
12013
+ if (clientId === getDiscussKitClientId()) {
12014
+ (_a3 = handlers[event]) == null ? void 0 : _a3.call(handlers, data);
12015
+ }
12016
+ },
12017
+ []
12018
+ );
12000
12019
  return /* @__PURE__ */ jsxs(PointUpContext.Provider, { value, children: [
12001
12020
  (pointUpComponent == null ? void 0 : pointUpComponent.mountPoint) && createPortal(
12002
12021
  /* @__PURE__ */ jsx(
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, am, ar, N, as, l, f, p, r, j, t, h, aa, U, c, a0, z, a7, ab, u, an, d, at, a3, aj, e } from "./index-8LMyNkyB.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, am, ar, N, as, l, f, p, r, j, t, h, aa, U, c, a0, z, a7, ab, u, an, d, at, a3, aj, e } from "./index-BQ_vgrJf.mjs";
3
3
  import "react/jsx-runtime";
4
4
  import "react";
5
5
  import "@mui/material/Box";
package/dist/index.umd.js CHANGED
@@ -8,7 +8,7 @@ var __publicField = (obj, key, value) => {
8
8
  return value;
9
9
  };
10
10
 
11
- var _a, _b, _c;
11
+ var _a, _b, _c, _d;
12
12
  const typography = {
13
13
  h1: {
14
14
  fontSize: "1.875rem",
@@ -275,12 +275,23 @@ var __publicField = (obj, key, value) => {
275
275
  window.open(ufo.withQuery(ufo.joinURL(discussKitMountPoint || "/", "profile"), { did }), newTab ? "_blank" : "_self");
276
276
  }
277
277
  };
278
+ const randomId = () => {
279
+ var _a2;
280
+ return ((_a2 = crypto == null ? void 0 : crypto.randomUUID) == null ? void 0 : _a2.call(crypto)) || Math.random().toString(36).substring(2);
281
+ };
282
+ const getDiscussKitClientId = () => {
283
+ if (!window.__discuss_kit_client_id__) {
284
+ window.__discuss_kit_client_id__ = randomId();
285
+ }
286
+ return window.__discuss_kit_client_id__;
287
+ };
278
288
  const utils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
279
289
  __proto__: null,
280
290
  blockletExists,
281
291
  copy,
282
292
  discussKitMountPoint,
283
293
  getBlockletMountPointInfo,
294
+ getDiscussKitClientId,
284
295
  getDraftSessionKeyPrefix,
285
296
  getExcerptFromLexicalContent,
286
297
  getLastItem,
@@ -292,6 +303,7 @@ var __publicField = (obj, key, value) => {
292
303
  minDelay,
293
304
  openProfile,
294
305
  protectLogin,
306
+ randomId,
295
307
  repairBase64Avatar,
296
308
  sleep,
297
309
  tryParseJSONObject
@@ -967,15 +979,16 @@ var __publicField = (obj, key, value) => {
967
979
  ] }) : null;
968
980
  }
969
981
  const useSessionContext = () => {
970
- var _a2, _b2, _c2, _d;
982
+ var _a2, _b2, _c2, _d2, _e;
971
983
  const ctx = react.useContext(Session.SessionContext) || {};
972
984
  const loginRole = (_b2 = (_a2 = ctx == null ? void 0 : ctx.session) == null ? void 0 : _a2.user) == null ? void 0 : _b2.role;
973
985
  const permissionSet = react.useMemo(() => {
974
986
  var _a3, _b3;
975
987
  return new Set(((_b3 = (_a3 = ctx.session) == null ? void 0 : _a3.user) == null ? void 0 : _b3.permissions) || []);
976
- }, [(_d = (_c2 = ctx.session) == null ? void 0 : _c2.user) == null ? void 0 : _d.permissions]);
988
+ }, [(_d2 = (_c2 = ctx.session) == null ? void 0 : _c2.user) == null ? void 0 : _d2.permissions]);
977
989
  return {
978
990
  ...ctx,
991
+ isAuthenticated: !!((_e = ctx.session) == null ? void 0 : _e.user),
979
992
  isAdmin: ["admin", "owner"].includes(loginRole),
980
993
  isMember: ["member"].includes(loginRole),
981
994
  isBlogEditor: ["blogEditor"].includes(loginRole),
@@ -2149,7 +2162,7 @@ var __publicField = (obj, key, value) => {
2149
2162
  maxDiscussionLength: parseInt(`${prefs.maxDiscussionLength}`, 10),
2150
2163
  maxPinLimit: parseInt(`${prefs.maxPinLimit}`, 10),
2151
2164
  maxFeaturedLimit: parseInt(`${prefs.maxFeaturedLimit}`, 10),
2152
- assignmentAuthorizedPassports: prefs.assignmentAuthorizedPassports.split(",").map((x) => x.trim())
2165
+ assignmentAuthorizedPassports: (_d = prefs.assignmentAuthorizedPassports) == null ? void 0 : _d.split(",").map((x) => x.trim())
2153
2166
  };
2154
2167
  function Confirm({
2155
2168
  open,
@@ -4222,7 +4235,7 @@ var __publicField = (obj, key, value) => {
4222
4235
  return null;
4223
4236
  };
4224
4237
  const render = () => {
4225
- var _a2, _b2, _c2, _d;
4238
+ var _a2, _b2, _c2, _d2;
4226
4239
  const baseCardSx = {
4227
4240
  py: 1.5,
4228
4241
  px: 2,
@@ -4365,7 +4378,7 @@ var __publicField = (obj, key, value) => {
4365
4378
  ]
4366
4379
  }
4367
4380
  ),
4368
- /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "body1", sx: { fontSize: 16 }, children: (_d = (_b2 = message == null ? void 0 : message.comment) == null ? void 0 : _b2.excerpt) == null ? void 0 : _d.replace((_c2 = session == null ? void 0 : session.user) == null ? void 0 : _c2.fullName, "") }),
4381
+ /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "body1", sx: { fontSize: 16 }, children: (_d2 = (_b2 = message == null ? void 0 : message.comment) == null ? void 0 : _b2.excerpt) == null ? void 0 : _d2.replace((_c2 = session == null ? void 0 : session.user) == null ? void 0 : _c2.fullName, "") }),
4369
4382
  renderQuote(message.post)
4370
4383
  ]
4371
4384
  }
@@ -5582,7 +5595,7 @@ var __publicField = (obj, key, value) => {
5582
5595
  ] });
5583
5596
  }
5584
5597
  function ChatListInWallet({ sx, ...rest }) {
5585
- var _a2, _b2, _c2, _d;
5598
+ var _a2, _b2, _c2, _d2;
5586
5599
  const { session } = useSessionContext();
5587
5600
  const { initialized, chats, activeChatId } = useChatContext();
5588
5601
  const { unread } = useUnreadNotification();
@@ -5683,7 +5696,7 @@ var __publicField = (obj, key, value) => {
5683
5696
  sx: {
5684
5697
  width: 1,
5685
5698
  height: 1,
5686
- ...((_d = window.chatInWallet) == null ? void 0 : _d.safeAreaInsetTop) && {
5699
+ ...((_d2 = window.chatInWallet) == null ? void 0 : _d2.safeAreaInsetTop) && {
5687
5700
  pt: `${window.chatInWallet.safeAreaInsetTop}px`
5688
5701
  }
5689
5702
  },
@@ -11794,14 +11807,14 @@ var __publicField = (obj, key, value) => {
11794
11807
  }
11795
11808
  });
11796
11809
  }
11797
- function getWsClient(prefix2 = ((_d) => (_d = window.blocklet) == null ? void 0 : _d.prefix)() || "/") {
11810
+ function getWsClient(prefix2 = ((_e) => (_e = window.blocklet) == null ? void 0 : _e.prefix)() || "/") {
11798
11811
  if (!client) {
11799
11812
  client = create(prefix2);
11800
11813
  }
11801
11814
  return client;
11802
11815
  }
11803
11816
  const useSubscription = (event, cb = () => {
11804
- }, deps = [], prefix2 = ((_e) => (_e = window.blocklet) == null ? void 0 : _e.prefix)() || "/") => {
11817
+ }, deps = [], prefix2 = ((_f) => (_f = window.blocklet) == null ? void 0 : _f.prefix)() || "/") => {
11805
11818
  react.useEffect(() => {
11806
11819
  if (event) {
11807
11820
  if (!client) {
@@ -11868,7 +11881,7 @@ var __publicField = (obj, key, value) => {
11868
11881
  );
11869
11882
  }
11870
11883
  function PointUpProvider({ children }) {
11871
- var _a2, _b2, _c2, _d;
11884
+ var _a2, _b2, _c2, _d2;
11872
11885
  const state = ahooks.useReactive({
11873
11886
  pointsList: [],
11874
11887
  visible: false,
@@ -11919,10 +11932,16 @@ var __publicField = (obj, key, value) => {
11919
11932
  state.visible = false;
11920
11933
  }
11921
11934
  }, [JSON.stringify(state.pointsList)]);
11922
- useSubscription((_d = session == null ? void 0 : session.user) == null ? void 0 : _d.did, ({ event, data }) => {
11923
- var _a3;
11924
- return (_a3 = handlers[event]) == null ? void 0 : _a3.call(handlers, data);
11925
- }, []);
11935
+ useSubscription(
11936
+ (_d2 = session == null ? void 0 : session.user) == null ? void 0 : _d2.did,
11937
+ ({ event, clientId, data }) => {
11938
+ var _a3;
11939
+ if (clientId === getDiscussKitClientId()) {
11940
+ (_a3 = handlers[event]) == null ? void 0 : _a3.call(handlers, data);
11941
+ }
11942
+ },
11943
+ []
11944
+ );
11926
11945
  return /* @__PURE__ */ jsxRuntime.jsxs(PointUpContext.Provider, { value, children: [
11927
11946
  (pointUpComponent == null ? void 0 : pointUpComponent.mountPoint) && ReactDOM.createPortal(
11928
11947
  /* @__PURE__ */ jsxRuntime.jsx(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/discuss-kit-ux",
3
- "version": "2.0.98",
3
+ "version": "2.0.100",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -31,8 +31,8 @@
31
31
  "@arcblock/bridge": "^2.10.12",
32
32
  "@arcblock/react-hooks": "^2.10.12",
33
33
  "@arcblock/ws": "^1.18.128",
34
- "@blocklet/editor": "2.0.98",
35
- "@blocklet/labels": "2.0.98",
34
+ "@blocklet/editor": "2.0.100",
35
+ "@blocklet/labels": "2.0.100",
36
36
  "@blocklet/uploader": "^0.1.20",
37
37
  "@emotion/css": "^11.10.5",
38
38
  "@emotion/react": "^11.10.5",
@@ -100,5 +100,5 @@
100
100
  "resolutions": {
101
101
  "react": "^18.2.0"
102
102
  },
103
- "gitHead": "48f5be0c9040037f11ba939b63b4d78dab0ea220"
103
+ "gitHead": "843130ec0c98f4dc0cc08ac7b92fe24d148b884a"
104
104
  }