@blocklet/discuss-kit-ux 2.4.35 → 2.4.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/dist/axios.d.ts +8 -0
  2. package/dist/blocklets.d.ts +1 -1
  3. package/dist/blocklets.mjs +17 -0
  4. package/dist/components/api-error-handler/api-error-handler.d.ts +1 -1
  5. package/dist/components/api-error-handler/api-error-handler.mjs +25 -0
  6. package/dist/components/api-error-handler/default-handler.mjs +69 -0
  7. package/dist/components/api-error-handler/index.mjs +2 -0
  8. package/dist/components/api-error-handler/json-validation-interceptor.d.ts +1 -1
  9. package/dist/components/api-error-handler/json-validation-interceptor.mjs +9 -0
  10. package/dist/components/arcsphere/index.mjs +51 -0
  11. package/dist/components/authz/access-control.d.ts +15 -1
  12. package/dist/components/authz/access-control.mjs +15 -0
  13. package/dist/components/authz/context.d.ts +2 -1
  14. package/dist/components/authz/context.mjs +30 -0
  15. package/dist/components/authz/index.d.ts +1 -1
  16. package/dist/components/authz/index.mjs +2 -0
  17. package/dist/components/auto-translate/api.d.ts +1 -1
  18. package/dist/components/auto-translate/api.mjs +23 -0
  19. package/dist/components/auto-translate/auto-translate-button.d.ts +2 -1
  20. package/dist/components/auto-translate/auto-translate-button.mjs +47 -0
  21. package/dist/components/auto-translate/editor-store-adaptor.mjs +14 -0
  22. package/dist/components/auto-translate/index.mjs +6 -0
  23. package/dist/components/auto-translate/languages.mjs +61 -0
  24. package/dist/components/auto-translate/post-auto-translate-plugin.d.ts +4 -3
  25. package/dist/components/auto-translate/post-auto-translate-plugin.mjs +32 -0
  26. package/dist/components/auto-translate/store.d.ts +3 -3
  27. package/dist/components/auto-translate/store.mjs +23 -0
  28. package/dist/components/auto-translate/translate.d.ts +3 -2
  29. package/dist/components/auto-translate/translate.mjs +103 -0
  30. package/dist/components/auto-translate/utils.d.ts +1 -1
  31. package/dist/components/auto-translate/utils.mjs +14 -0
  32. package/dist/components/auto-translate/with-availibility-check.d.ts +1 -1
  33. package/dist/components/auto-translate/with-availibility-check.mjs +10 -0
  34. package/dist/components/avatars/author-info.d.ts +3 -2
  35. package/dist/components/avatars/author-info.mjs +184 -0
  36. package/dist/components/avatars/avatar.d.ts +2 -1
  37. package/dist/components/avatars/avatar.mjs +9 -0
  38. package/dist/components/avatars/avatars.d.ts +4 -3
  39. package/dist/components/avatars/avatars.mjs +49 -0
  40. package/dist/components/avatars/badge.d.ts +2 -1
  41. package/dist/components/avatars/badge.mjs +178 -0
  42. package/dist/components/avatars/index.mjs +5 -0
  43. package/dist/components/avatars/system-user.d.ts +1 -1
  44. package/dist/components/avatars/system-user.mjs +58 -0
  45. package/dist/components/back.d.ts +2 -1
  46. package/dist/components/back.mjs +28 -0
  47. package/dist/components/blog/blog-link.mjs +16 -0
  48. package/dist/components/blog/blog-list.d.ts +4 -3
  49. package/dist/components/blog/blog-list.mjs +441 -0
  50. package/dist/components/blog/cover-image.d.ts +4 -3
  51. package/dist/components/blog/cover-image.mjs +160 -0
  52. package/dist/components/blog/index.mjs +4 -0
  53. package/dist/components/blog/permalink.d.ts +3 -2
  54. package/dist/components/blog/permalink.mjs +78 -0
  55. package/dist/components/blog/types.d.ts +1 -1
  56. package/dist/components/blog/types.mjs +0 -0
  57. package/dist/components/button-group/button-group.d.ts +2 -1
  58. package/dist/components/button-group/button-group.mjs +195 -0
  59. package/dist/components/button-group/index.mjs +1 -0
  60. package/dist/components/chat/channel-group.d.ts +3 -2
  61. package/dist/components/chat/channel-group.mjs +41 -0
  62. package/dist/components/chat/chat-client.d.ts +2 -2
  63. package/dist/components/chat/chat-client.mjs +33 -0
  64. package/dist/components/chat/chat-header-addon.d.ts +2 -1
  65. package/dist/components/chat/chat-header-addon.mjs +26 -0
  66. package/dist/components/chat/chat-in-wallet.d.ts +2 -1
  67. package/dist/components/chat/chat-in-wallet.mjs +67 -0
  68. package/dist/components/chat/chat-input.d.ts +3 -2
  69. package/dist/components/chat/chat-input.mjs +295 -0
  70. package/dist/components/chat/chat-list-in-wallet.d.ts +2 -1
  71. package/dist/components/chat/chat-list-in-wallet.mjs +113 -0
  72. package/dist/components/chat/chat-list.d.ts +2 -1
  73. package/dist/components/chat/chat-list.mjs +109 -0
  74. package/dist/components/chat/chat-room.d.ts +3 -2
  75. package/dist/components/chat/chat-room.mjs +225 -0
  76. package/dist/components/chat/chat.d.ts +2 -1
  77. package/dist/components/chat/chat.mjs +163 -0
  78. package/dist/components/chat/context.d.ts +4 -3
  79. package/dist/components/chat/context.mjs +303 -0
  80. package/dist/components/chat/hooks.d.ts +1 -1
  81. package/dist/components/chat/hooks.mjs +59 -0
  82. package/dist/components/chat/index.mjs +7 -0
  83. package/dist/components/chat/message-list.d.ts +3 -2
  84. package/dist/components/chat/message-list.mjs +151 -0
  85. package/dist/components/chat/message.d.ts +4 -3
  86. package/dist/components/chat/message.mjs +312 -0
  87. package/dist/components/chat/participants.d.ts +3 -2
  88. package/dist/components/chat/participants.mjs +60 -0
  89. package/dist/components/chat/time.d.ts +1 -1
  90. package/dist/components/chat/time.mjs +16 -0
  91. package/dist/components/chat/types.d.ts +1 -1
  92. package/dist/components/chat/types.mjs +0 -0
  93. package/dist/components/chat/unread-notification.d.ts +2 -2
  94. package/dist/components/chat/unread-notification.mjs +43 -0
  95. package/dist/components/chat/user-search.d.ts +2 -1
  96. package/dist/components/chat/user-search.mjs +143 -0
  97. package/dist/components/check-mark.d.ts +2 -1
  98. package/dist/components/check-mark.mjs +98 -0
  99. package/dist/components/confirm.d.ts +4 -4
  100. package/dist/components/confirm.mjs +103 -0
  101. package/dist/components/dayjs.d.ts +1 -1
  102. package/dist/components/dayjs.mjs +4 -0
  103. package/dist/components/default-editor-config-provider.d.ts +3 -2
  104. package/dist/components/default-editor-config-provider.mjs +107 -0
  105. package/dist/components/dirty-prompt.d.ts +3 -2
  106. package/dist/components/dirty-prompt.mjs +117 -0
  107. package/dist/components/editor/editor.d.ts +4 -3
  108. package/dist/{editor-B3z0rXVh.mjs → components/editor/editor.mjs} +7 -8
  109. package/dist/components/editor/index.mjs +2 -0
  110. package/dist/components/editor/lazy-editor.d.ts +3 -2
  111. package/dist/components/editor/lazy-editor.mjs +14 -0
  112. package/dist/components/editor/plugins/video-path-fixer-plugin.mjs +29 -0
  113. package/dist/components/editor/preview.d.ts +4 -3
  114. package/dist/components/editor/preview.mjs +32 -0
  115. package/dist/components/emoji-icon.d.ts +2 -1
  116. package/dist/components/emoji-icon.mjs +62 -0
  117. package/dist/components/empty-status/empty-status.d.ts +2 -1
  118. package/dist/components/empty-status/empty-status.mjs +24 -0
  119. package/dist/components/empty-status/index.mjs +1 -0
  120. package/dist/components/hooks/changed.mjs +34 -0
  121. package/dist/components/hooks/index.mjs +6 -0
  122. package/dist/components/hooks/interval.mjs +16 -0
  123. package/dist/components/hooks/locale-context.mjs +12 -0
  124. package/dist/components/hooks/measure.mjs +8 -0
  125. package/dist/components/hooks/now.mjs +10 -0
  126. package/dist/components/hooks/responsive.d.ts +1 -1
  127. package/dist/components/hooks/responsive.mjs +25 -0
  128. package/dist/components/hooks/session.d.ts +1 -0
  129. package/dist/components/hooks/session.mjs +41 -0
  130. package/dist/components/hooks/use-event-callback.mjs +14 -0
  131. package/dist/components/icon-button.d.ts +4 -3
  132. package/dist/components/icon-button.mjs +37 -0
  133. package/dist/components/input/auto-clear-plugin.mjs +26 -0
  134. package/dist/components/input/comment-input.d.ts +2 -1
  135. package/dist/components/input/comment-input.mjs +107 -0
  136. package/dist/components/input/image-path-fixer-plugin.mjs +29 -0
  137. package/dist/components/input/index.mjs +4 -0
  138. package/dist/components/input/input.d.ts +4 -4
  139. package/dist/components/input/input.mjs +152 -0
  140. package/dist/components/input/post-edit.d.ts +2 -1
  141. package/dist/components/input/post-edit.mjs +49 -0
  142. package/dist/components/input/scrollable-editor-wrapper.d.ts +2 -1
  143. package/dist/components/input/scrollable-editor-wrapper.mjs +18 -0
  144. package/dist/components/input/shortcut-plugin.mjs +28 -0
  145. package/dist/components/label-picker.d.ts +2 -1
  146. package/dist/components/label-picker.mjs +41 -0
  147. package/dist/components/lexical.mjs +69 -0
  148. package/dist/components/locale/en.mjs +92 -0
  149. package/dist/components/locale/index.mjs +3 -0
  150. package/dist/components/locale/zh.mjs +94 -0
  151. package/dist/components/pagination.d.ts +3 -2
  152. package/dist/components/pagination.mjs +44 -0
  153. package/dist/components/paywall.d.ts +2 -2
  154. package/dist/components/paywall.mjs +110 -0
  155. package/dist/components/point-up/{box-animation.json.d.ts → box-animation.json} +1 -4
  156. package/dist/components/point-up/index.d.ts +3 -2
  157. package/dist/components/point-up/index.mjs +153 -0
  158. package/dist/components/point-up/lottie-component.d.ts +2 -1
  159. package/dist/components/point-up/lottie-component.mjs +7 -0
  160. package/dist/components/posts/comment-list/comment-list.d.ts +2 -1
  161. package/dist/components/posts/comment-list/comment-list.mjs +163 -0
  162. package/dist/components/posts/comment-list/context.d.ts +4 -4
  163. package/dist/components/posts/comment-list/context.mjs +318 -0
  164. package/dist/components/posts/comment.d.ts +3 -2
  165. package/dist/components/posts/comment.mjs +184 -0
  166. package/dist/components/posts/index.mjs +6 -0
  167. package/dist/components/posts/menu.d.ts +3 -2
  168. package/dist/components/posts/menu.mjs +83 -0
  169. package/dist/components/posts/post-content.d.ts +2 -1
  170. package/dist/components/posts/post-content.mjs +86 -0
  171. package/dist/components/posts/post.d.ts +4 -4
  172. package/dist/components/posts/post.mjs +198 -0
  173. package/dist/components/profile-card/index.mjs +1 -0
  174. package/dist/components/profile-card/profile-card.d.ts +4 -3
  175. package/dist/components/profile-card/profile-card.mjs +162 -0
  176. package/dist/components/rating/binary-thumb.d.ts +4 -3
  177. package/dist/components/rating/binary-thumb.mjs +157 -0
  178. package/dist/components/rating/github-reaction-container.d.ts +2 -1
  179. package/dist/components/rating/github-reaction-container.mjs +46 -0
  180. package/dist/components/rating/github-reaction.d.ts +3 -2
  181. package/dist/components/rating/github-reaction.mjs +173 -0
  182. package/dist/components/rating/index.mjs +3 -0
  183. package/dist/components/rating/rater-list.d.ts +3 -2
  184. package/dist/components/rating/rater-list.mjs +33 -0
  185. package/dist/components/rating/rating.d.ts +1 -1
  186. package/dist/components/rating/rating.mjs +50 -0
  187. package/dist/components/routes.d.ts +1 -1
  188. package/dist/components/routes.mjs +27 -0
  189. package/dist/components/segmented-control.d.ts +3 -2
  190. package/dist/components/segmented-control.mjs +55 -0
  191. package/dist/components/shared/relative-time.d.ts +2 -1
  192. package/dist/components/shared/relative-time.mjs +21 -0
  193. package/dist/components/toast.d.ts +1 -1
  194. package/dist/components/toast.mjs +44 -0
  195. package/dist/components/uploader/index.d.ts +3 -3
  196. package/dist/components/uploader/index.mjs +70 -0
  197. package/dist/components/uploader/utils.mjs +16 -0
  198. package/dist/components/utils.d.ts +4 -4
  199. package/dist/components/utils.mjs +139 -0
  200. package/dist/components/view-more.d.ts +1 -1
  201. package/dist/components/view-more.mjs +50 -0
  202. package/dist/constants.mjs +14 -0
  203. package/dist/global.d.ts +1 -0
  204. package/dist/index.mjs +37 -0
  205. package/dist/preferences.mjs +9 -0
  206. package/dist/theme/index.d.ts +3 -3
  207. package/dist/theme/index.mjs +96 -0
  208. package/dist/theme/typography.d.ts +1 -1
  209. package/dist/theme/typography.mjs +66 -0
  210. package/dist/type-override.d.ts +7 -0
  211. package/dist/types.mjs +0 -0
  212. package/dist/vite-env.d.ts +1 -0
  213. package/dist/ws.d.ts +2 -2
  214. package/dist/ws.mjs +39 -0
  215. package/package.json +18 -25
  216. package/dist/components/avatars/Avatars.stories.d.ts +0 -5
  217. package/dist/components/posts/Post.stories.d.ts +0 -7
  218. package/dist/index-BlqRGWgQ.mjs +0 -7631
  219. package/dist/index.es.js +0 -118
  220. package/dist/index.umd.js +0 -7589
  221. package/dist/test/fixtures/index.d.ts +0 -4
  222. package/dist/test/fixtures/mock-session.d.ts +0 -3
@@ -0,0 +1,62 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import Box from "@mui/material/Box";
3
+ const stringToColor = (str) => {
4
+ let hash = 0;
5
+ let i;
6
+ for (i = 0; i < str.length; i += 1) {
7
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
8
+ }
9
+ let color = "#";
10
+ for (i = 0; i < 3; i += 1) {
11
+ const value = hash >> i * 8 & 255;
12
+ color += `00${value.toString(16)}`.slice(-2);
13
+ }
14
+ return color;
15
+ };
16
+ function InternalIcon({ title, icon, ...rest }) {
17
+ const _icon = icon || Array.from(title)[0];
18
+ return /* @__PURE__ */ jsx(
19
+ Box,
20
+ {
21
+ component: "span",
22
+ sx: {
23
+ display: "flex",
24
+ justifyContent: "center",
25
+ alignItems: "center",
26
+ width: "1.2em",
27
+ height: "1.2em",
28
+ lineHeight: 1,
29
+ ...!icon && { bgcolor: stringToColor(title), color: "#fff" }
30
+ },
31
+ ...rest,
32
+ children: _icon
33
+ }
34
+ );
35
+ }
36
+ function EmojiIcon({ title, icon, size = "small", ...rest }) {
37
+ if (size === "large") {
38
+ const letterIconStyles = {
39
+ width: "100%",
40
+ height: "100%",
41
+ fontSize: "1.2em"
42
+ };
43
+ return /* @__PURE__ */ jsx(
44
+ Box,
45
+ {
46
+ sx: {
47
+ display: "flex",
48
+ justifyContent: "center",
49
+ alignItems: "center",
50
+ width: 40,
51
+ height: 40,
52
+ overflow: "hidden",
53
+ borderRadius: 1.5,
54
+ bgcolor: "grey.300"
55
+ },
56
+ children: /* @__PURE__ */ jsx(InternalIcon, { title, icon, ...rest, style: { ...!icon && letterIconStyles } })
57
+ }
58
+ );
59
+ }
60
+ return /* @__PURE__ */ jsx(InternalIcon, { title, icon, ...rest });
61
+ }
62
+ export default EmojiIcon;
@@ -1,6 +1,7 @@
1
+ /// <reference types="react" />
1
2
  import { SxProps } from '@mui/material';
2
3
  interface Props {
3
4
  sx?: SxProps;
4
5
  }
5
- export default function EmptyStatus({ sx }: Props): import("react/jsx-runtime").JSX.Element;
6
+ export default function EmptyStatus({ sx }: Props): import("react").JSX.Element;
6
7
  export {};
@@ -0,0 +1,24 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import Box from "@mui/material/Box";
3
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
4
+ import Empty from "@arcblock/ux/lib/Empty";
5
+ import { mergeSx } from "../utils.mjs";
6
+ export default function EmptyStatus({ sx }) {
7
+ const { t } = useLocaleContext();
8
+ return /* @__PURE__ */ jsx(
9
+ Box,
10
+ {
11
+ sx: [
12
+ {
13
+ display: "flex",
14
+ flexDirection: "column",
15
+ alignItems: "center",
16
+ justifyContent: "center"
17
+ },
18
+ // @ts-expect-error
19
+ mergeSx({ height: "50vh", width: "100%" }, sx)
20
+ ],
21
+ children: /* @__PURE__ */ jsx(Empty, { children: t("profile.empty") })
22
+ }
23
+ );
24
+ }
@@ -0,0 +1 @@
1
+ export { default as EmptyStatus } from "./empty-status.mjs";
@@ -0,0 +1,34 @@
1
+ import { useRef, useEffect, useState } from "react";
2
+ const isEqual = (a, b) => {
3
+ if (a === 0 && b === 0 || !a && !b) {
4
+ return true;
5
+ }
6
+ return a === b;
7
+ };
8
+ export const useChanged = (values, options) => {
9
+ const [trackingStarted, setTrackingStarted] = useState(false);
10
+ const [changed, setChanged] = useState(false);
11
+ const initialValues = useRef(values);
12
+ const detectChanges = () => {
13
+ const changesDetected = Object.keys(initialValues.current).some(
14
+ (key) => !isEqual(initialValues.current[key], values[key])
15
+ );
16
+ if (changesDetected) {
17
+ options.onChange?.();
18
+ }
19
+ setChanged(changesDetected);
20
+ };
21
+ const reset = (overrides) => {
22
+ initialValues.current = { ...values, ...overrides };
23
+ detectChanges();
24
+ };
25
+ useEffect(() => {
26
+ if (trackingStarted) {
27
+ detectChanges();
28
+ } else if (options.tracking(values) && !trackingStarted) {
29
+ initialValues.current = { ...values };
30
+ setTrackingStarted(true);
31
+ }
32
+ }, [values, trackingStarted]);
33
+ return { changed, reset, initialValues: initialValues.current };
34
+ };
@@ -0,0 +1,6 @@
1
+ export { useSessionContext } from "./session.mjs";
2
+ export { useChanged } from "./changed.mjs";
3
+ export { useNow } from "./now.mjs";
4
+ export { useInterval } from "./interval.mjs";
5
+ export { useDownBreakpoint, useUpBreakpoint } from "./responsive.mjs";
6
+ export { useEventCallback } from "./use-event-callback.mjs";
@@ -0,0 +1,16 @@
1
+ import { useEffect, useRef } from "react";
2
+ const DEFAULT_INTERVAL = 60 * 1e3;
3
+ export const useInterval = (callback, options = {}) => {
4
+ const { interval = DEFAULT_INTERVAL, paused = false } = options;
5
+ const callbackRef = useRef(void 0);
6
+ useEffect(() => {
7
+ callbackRef.current = callback;
8
+ }, [callback]);
9
+ useEffect(() => {
10
+ if (!paused) {
11
+ const timer = setInterval(() => callbackRef.current?.(), interval);
12
+ return () => clearInterval(timer);
13
+ }
14
+ return void 0;
15
+ }, [interval, paused]);
16
+ };
@@ -0,0 +1,12 @@
1
+ import { useLocaleContext as useLocaleContextUX } from "@arcblock/ux/lib/Locale/context";
2
+ export const useLocaleContext = () => {
3
+ const { languages, ...rest } = useLocaleContextUX();
4
+ function getLanguageName(code) {
5
+ return languages.find((x) => x.code === code)?.name || code;
6
+ }
7
+ return {
8
+ languages,
9
+ getLanguageName,
10
+ ...rest
11
+ };
12
+ };
@@ -0,0 +1,8 @@
1
+ import { useRef } from "react";
2
+ import { useSize } from "ahooks";
3
+ const useMeasure = () => {
4
+ const ref = useRef(null);
5
+ const size = useSize(ref);
6
+ return [ref, size || { width: 0, height: 0 }];
7
+ };
8
+ export default useMeasure;
@@ -0,0 +1,10 @@
1
+ import { useEffect, useState } from "react";
2
+ export const useNow = (interval = 1e3) => {
3
+ const [time, setTime] = useState(/* @__PURE__ */ new Date());
4
+ const updateTime = () => setTime(/* @__PURE__ */ new Date());
5
+ useEffect(() => {
6
+ const timer = setInterval(updateTime, interval);
7
+ return () => clearInterval(timer);
8
+ }, [interval]);
9
+ return time;
10
+ };
@@ -1,4 +1,4 @@
1
- import { Breakpoint } from '@mui/material';
1
+ import { type Breakpoint } from '@mui/material';
2
2
  export declare const useDownBreakpoint: (breakpoint: Breakpoint) => boolean;
3
3
  export declare const useUpBreakpoint: (breakpoint: Breakpoint) => boolean;
4
4
  export declare function useResponsive(): (responsiveValues: {
@@ -0,0 +1,25 @@
1
+ import { useTheme, useMediaQuery } from "@mui/material";
2
+ export const useDownBreakpoint = (breakpoint) => {
3
+ const theme = useTheme();
4
+ return useMediaQuery(theme.breakpoints.down(breakpoint));
5
+ };
6
+ export const useUpBreakpoint = (breakpoint) => {
7
+ const theme = useTheme();
8
+ return useMediaQuery(theme.breakpoints.up(breakpoint));
9
+ };
10
+ export function useResponsive() {
11
+ const theme = useTheme();
12
+ const matches = theme.breakpoints.keys.reduce(
13
+ // eslint-disable-next-line react-hooks/rules-of-hooks
14
+ (acc, cur) => ({ ...acc, [cur]: useMediaQuery(theme.breakpoints.up(cur)) }),
15
+ {}
16
+ );
17
+ return (responsiveValues) => {
18
+ const match = [...theme.breakpoints.keys].reverse().find((breakpoint) => matches[breakpoint] && breakpoint in responsiveValues);
19
+ return match && responsiveValues[match];
20
+ };
21
+ }
22
+ export const useResponsiveValue = (values) => {
23
+ const r = useResponsive();
24
+ return r(values);
25
+ };
@@ -5,6 +5,7 @@ export declare const useSessionContext: () => {
5
5
  isBlogEditor: boolean;
6
6
  hasAnyPassport: (passports: string | string[]) => boolean;
7
7
  hasAnyPermission: (perms: string | string[]) => boolean;
8
+ sessionReadyPromise: Promise<unknown>;
8
9
  session: Session;
9
10
  connectApi: any;
10
11
  };
@@ -0,0 +1,41 @@
1
+ import { useContext, useEffect, useMemo, useRef } from "react";
2
+ import { SessionContext } from "@arcblock/did-connect-react/lib/Session";
3
+ export const useSessionContext = () => {
4
+ const ctx = useContext(SessionContext) || {};
5
+ const roles = [...ctx?.session?.user?.passports?.map((p) => p.role) || [], "guest"];
6
+ const permissionSet = useMemo(() => new Set(ctx.session?.user?.permissions || []), [ctx.session?.user?.permissions]);
7
+ const hasAnyPassport = (passports) => {
8
+ if (!passports || passports.length === 0) {
9
+ return true;
10
+ }
11
+ const passportsArr = Array.isArray(passports) ? passports : [passports];
12
+ return roles.some((x) => passportsArr.includes(x));
13
+ };
14
+ const resolver = useRef(void 0);
15
+ const sessionReadyPromise = useMemo(() => {
16
+ return new Promise((resolve) => {
17
+ resolver.current = resolve;
18
+ });
19
+ }, []);
20
+ useEffect(() => {
21
+ if (ctx.session.initialized) {
22
+ resolver.current?.();
23
+ }
24
+ }, [ctx.session?.initialized]);
25
+ return {
26
+ ...ctx,
27
+ isAuthenticated: !!ctx.session?.user,
28
+ isAdmin: hasAnyPassport(["admin", "owner"]),
29
+ isMember: hasAnyPassport(["member"]),
30
+ isBlogEditor: hasAnyPassport(["blogEditor"]),
31
+ hasAnyPassport,
32
+ hasAnyPermission: (perms) => {
33
+ if (!perms || perms.length === 0) {
34
+ return true;
35
+ }
36
+ const permsArr = Array.isArray(perms) ? perms : [perms];
37
+ return permsArr.some((item) => permissionSet.has(item));
38
+ },
39
+ sessionReadyPromise
40
+ };
41
+ };
@@ -0,0 +1,14 @@
1
+ import { useCallback, useLayoutEffect, useRef } from "react";
2
+ export function useEventCallback(fn) {
3
+ const ref = useRef(void 0);
4
+ useLayoutEffect(() => {
5
+ ref.current = fn;
6
+ });
7
+ return useCallback((...args) => {
8
+ const { current } = ref;
9
+ if (current == null) {
10
+ throw new Error("callback created in useEventCallback can only be called from event handlers");
11
+ }
12
+ return current(...args);
13
+ }, []);
14
+ }
@@ -1,5 +1,6 @@
1
- import { BoxProps, IconButtonProps } from '@mui/material';
1
+ /// <reference types="react" />
2
+ import { BoxProps, type IconButtonProps } from '@mui/material';
2
3
  export declare function IconButton<C extends React.ElementType>({ sx, ...rest }: IconButtonProps<C, {
3
4
  component?: C;
4
- }>): import("react/jsx-runtime").JSX.Element;
5
- export declare function IconButtonGroup({ children, sx, ...rest }: BoxProps): import("react/jsx-runtime").JSX.Element;
5
+ }>): import("react").JSX.Element;
6
+ export declare function IconButtonGroup({ children, sx, ...rest }: BoxProps): import("react").JSX.Element;
@@ -0,0 +1,37 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Box, IconButton as MuiIconButton } from "@mui/material";
3
+ export function IconButton({ sx, ...rest }) {
4
+ const mergedSx = [
5
+ {
6
+ svg: {
7
+ width: "1em",
8
+ height: "1em",
9
+ fontSize: 20
10
+ },
11
+ color: "text.secondary",
12
+ "&:hover": {
13
+ color: "primary.main"
14
+ }
15
+ },
16
+ ...Array.isArray(sx) ? sx : [sx]
17
+ ];
18
+ return /* @__PURE__ */ jsx(MuiIconButton, { color: "primary", size: "small", sx: mergedSx, ...rest, disableFocusRipple: true });
19
+ }
20
+ export function IconButtonGroup({ children, sx, ...rest }) {
21
+ const mergedSx = [
22
+ {
23
+ display: "flex",
24
+ alignItems: "center",
25
+ gap: 2,
26
+ "& > .MuiIconButton-root:first-child": {
27
+ ml: "-5px"
28
+ },
29
+ // 避免局部 theme 覆盖问题 (如 comment donation 中的 IconButton 会以 donation 局部的 theme palette 为准)
30
+ ".MuiIconButton-root:hover": {
31
+ color: "primary.main"
32
+ }
33
+ },
34
+ ...Array.isArray(sx) ? sx : [sx]
35
+ ];
36
+ return /* @__PURE__ */ jsx(Box, { ...rest, sx: mergedSx, children });
37
+ }
@@ -0,0 +1,26 @@
1
+ import { useEffect } from "react";
2
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
3
+ import { $createParagraphNode, $getRoot, $getSelection } from "lexical";
4
+ export default function AutoClearPlugin({ value, isChanged }) {
5
+ const [editor] = useLexicalComposerContext();
6
+ useEffect(() => {
7
+ try {
8
+ if (!isChanged) return;
9
+ if (value) return;
10
+ if (!editor) return;
11
+ editor.update(() => {
12
+ const root = $getRoot();
13
+ const selection = $getSelection();
14
+ const paragraph = $createParagraphNode();
15
+ root.clear();
16
+ root.append(paragraph);
17
+ if (selection !== null) {
18
+ paragraph.select();
19
+ }
20
+ });
21
+ } catch (e) {
22
+ console.error(e);
23
+ }
24
+ }, [value, isChanged, editor]);
25
+ return null;
26
+ }
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { InputProps, RenderProps } from './input';
2
3
  interface Props extends Omit<InputProps, 'render'> {
3
4
  sendText?: string;
@@ -6,5 +7,5 @@ interface Props extends Omit<InputProps, 'render'> {
6
7
  renderInnerFooter?: (args: RenderProps) => React.ReactElement<any>;
7
8
  disableCmdEnter?: boolean;
8
9
  }
9
- export default function CommentInput({ disabledSend, send, onSuccess, placeholder, sendText, sendIcon, draftKey, renderInnerFooter, disableCmdEnter, ...rest }: Props): import("react/jsx-runtime").JSX.Element;
10
+ export default function CommentInput({ disabledSend, send, onSuccess, placeholder, sendText, sendIcon, draftKey, renderInnerFooter, disableCmdEnter, ...rest }: Props): import("react").JSX.Element;
10
11
  export {};
@@ -0,0 +1,107 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { LocaleContext } from "@arcblock/ux/lib/Locale/context";
3
+ import { Send as SendIcon } from "@mui/icons-material";
4
+ import LoadingButton from "@mui/lab/LoadingButton";
5
+ import Alert from "@mui/material/Alert";
6
+ import Box from "@mui/material/Box";
7
+ import isBoolean from "lodash/isBoolean";
8
+ import { useContext } from "react";
9
+ import LanguageMarkdownIcon from "virtual:icons/mdi/language-markdown";
10
+ import Input from "./input.mjs";
11
+ export default function CommentInput({
12
+ disabledSend,
13
+ send,
14
+ onSuccess,
15
+ placeholder,
16
+ sendText,
17
+ sendIcon,
18
+ draftKey = "",
19
+ renderInnerFooter,
20
+ disableCmdEnter = false,
21
+ ...rest
22
+ }) {
23
+ const { t } = useContext(LocaleContext);
24
+ const renderFooter = ({ submit, content, loading, inSmallView }) => {
25
+ return /* @__PURE__ */ jsxs(
26
+ Box,
27
+ {
28
+ sx: {
29
+ p: 1,
30
+ display: "flex",
31
+ justifyContent: inSmallView ? "end" : "space-between",
32
+ alignItems: "end"
33
+ },
34
+ children: [
35
+ /* @__PURE__ */ jsx(
36
+ Box,
37
+ {
38
+ component: "a",
39
+ href: "https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax",
40
+ target: "_blank",
41
+ sx: {
42
+ display: inSmallView ? "none" : "flex",
43
+ alignItems: "center",
44
+ m: 0,
45
+ fontSize: 12,
46
+ color: "text.disabled",
47
+ textDecoration: "none",
48
+ "&:hover": { color: "text.secondary" }
49
+ },
50
+ children: /* @__PURE__ */ jsx(
51
+ Box,
52
+ {
53
+ component: "span",
54
+ sx: { display: "inline-flex", alignItems: "center", mr: 0.5, lineHeight: 1 },
55
+ title: "Styling with Markdown is supported",
56
+ children: /* @__PURE__ */ jsx(LanguageMarkdownIcon, { style: { fontSize: 16 } })
57
+ }
58
+ )
59
+ }
60
+ ),
61
+ /* @__PURE__ */ jsx(
62
+ Box,
63
+ {
64
+ sx: {
65
+ display: "flex",
66
+ gap: 1,
67
+ alignItems: "center"
68
+ },
69
+ children: /* @__PURE__ */ jsx(
70
+ LoadingButton,
71
+ {
72
+ disabled: isBoolean(disabledSend) ? disabledSend : !content,
73
+ loading,
74
+ loadingPosition: "start",
75
+ startIcon: sendIcon || /* @__PURE__ */ jsx(SendIcon, { sx: { transform: "rotate(-45deg) translateX(3px)" } }),
76
+ variant: "contained",
77
+ color: "primary",
78
+ title: "\u2318 Enter",
79
+ onClick: submit,
80
+ className: "editor-submit-button",
81
+ children: /* @__PURE__ */ jsxs(Box, { component: "span", sx: { display: "inline-flex", gap: 0.5, fontSize: 12 }, children: [
82
+ /* @__PURE__ */ jsx("span", { children: sendText || t("sendComment") }),
83
+ /* @__PURE__ */ jsx(Box, { component: "span", sx: { display: inSmallView ? "none" : "inline" }, children: "(\u2318 Enter)" })
84
+ ] })
85
+ }
86
+ )
87
+ }
88
+ )
89
+ ]
90
+ }
91
+ );
92
+ };
93
+ return /* @__PURE__ */ jsx(
94
+ Input,
95
+ {
96
+ className: "editor-input-container",
97
+ placeholder: placeholder || t("commentInputPlaceholder"),
98
+ send,
99
+ onSuccess,
100
+ draftKey,
101
+ disableCmdEnter,
102
+ ...rest,
103
+ renderInnerFooter: renderInnerFooter ?? renderFooter,
104
+ renderEditorFooter: ({ error }) => error && /* @__PURE__ */ jsx(Alert, { severity: "error", children: error })
105
+ }
106
+ );
107
+ }
@@ -0,0 +1,29 @@
1
+ import { useLayoutEffect } from "react";
2
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
3
+ import { ImageNode } from "@blocklet/editor/lib/main/nodes/ImageNode";
4
+ import { joinURL } from "ufo";
5
+ import { discussKitUploadsUrl } from "../utils.mjs";
6
+ const originalExportJSON = ImageNode.prototype.exportJSON;
7
+ const ensureLeadingSlash = (str) => str.startsWith("/") ? str : `/${str}`;
8
+ ImageNode.prototype.exportJSON = function exportJSON() {
9
+ const json = originalExportJSON.call(this);
10
+ if (json.src && json.src.startsWith(discussKitUploadsUrl)) {
11
+ json.src = json.src.replace(discussKitUploadsUrl, "");
12
+ json.src = ensureLeadingSlash(json.src);
13
+ }
14
+ return json;
15
+ };
16
+ function imageNodeTransform(node) {
17
+ const targetNode = node;
18
+ const src = targetNode.getSrc();
19
+ if (src?.startsWith("/") && !src.startsWith(discussKitUploadsUrl)) {
20
+ targetNode.setSrc(joinURL(discussKitUploadsUrl, src));
21
+ }
22
+ }
23
+ export default function ImagePathFixerPlugin() {
24
+ const [editor] = useLexicalComposerContext();
25
+ useLayoutEffect(() => {
26
+ return editor.registerNodeTransform(ImageNode, imageNodeTransform);
27
+ }, [editor]);
28
+ return null;
29
+ }
@@ -0,0 +1,4 @@
1
+ export { default as Input, preloadInput } from "./input.mjs";
2
+ export { default as CommentInput } from "./comment-input.mjs";
3
+ export { default as PostEdit } from "./post-edit.mjs";
4
+ export { default as ScrollableEditorWrapper } from "./scrollable-editor-wrapper.mjs";
@@ -1,7 +1,7 @@
1
1
  import { MutableRefObject } from 'react';
2
- import { BoxProps } from '@mui/material';
3
- import { EditorState, LexicalEditor } from 'lexical';
4
- export declare const preloadInput: () => Promise<typeof import('@blocklet/editor').default>;
2
+ import { type BoxProps } from '@mui/material';
3
+ import type { EditorState, LexicalEditor } from 'lexical';
4
+ export declare const preloadInput: () => Promise<typeof import("@blocklet/editor").default>;
5
5
  export type Send = (content: string) => Promise<any>;
6
6
  export interface RenderProps {
7
7
  content: EditorState | null;
@@ -26,5 +26,5 @@ export interface InputProps extends Omit<BoxProps, 'onChange'> {
26
26
  disableCmdEnter?: boolean;
27
27
  }
28
28
  export type Ref = HTMLDivElement;
29
- declare const Input: ({ initialContent, send, placeholder, onSuccess, onChange, autoFocus, draftKey, shortcut, children, renderInnerFooter, renderEditorFooter, editorRef, disableCmdEnter, ...rest }: InputProps) => import("react/jsx-runtime").JSX.Element;
29
+ declare const Input: ({ initialContent, send, placeholder, onSuccess, onChange, autoFocus, draftKey, shortcut, children, renderInnerFooter, renderEditorFooter, editorRef, disableCmdEnter, ...rest }: InputProps) => import("react").JSX.Element;
30
30
  export default Input;