@blocklet/discuss-kit-ux-lite 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/LICENSE +13 -0
  2. package/dist/axios.d.ts +8 -0
  3. package/dist/blocklets.d.ts +13 -0
  4. package/dist/blocklets.mjs +17 -0
  5. package/dist/components/api-error-handler/api-error-handler.d.ts +13 -0
  6. package/dist/components/api-error-handler/api-error-handler.mjs +25 -0
  7. package/dist/components/api-error-handler/default-handler.d.ts +8 -0
  8. package/dist/components/api-error-handler/default-handler.mjs +69 -0
  9. package/dist/components/api-error-handler/index.d.ts +2 -0
  10. package/dist/components/api-error-handler/index.mjs +2 -0
  11. package/dist/components/api-error-handler/json-validation-interceptor.d.ts +2 -0
  12. package/dist/components/api-error-handler/json-validation-interceptor.mjs +9 -0
  13. package/dist/components/arcsphere/index.d.ts +16 -0
  14. package/dist/components/arcsphere/index.mjs +52 -0
  15. package/dist/components/authz/access-control.d.ts +24 -0
  16. package/dist/components/authz/access-control.mjs +15 -0
  17. package/dist/components/authz/context.d.ts +13 -0
  18. package/dist/components/authz/context.mjs +30 -0
  19. package/dist/components/authz/index.d.ts +2 -0
  20. package/dist/components/authz/index.mjs +2 -0
  21. package/dist/components/auto-translate/api.d.ts +14 -0
  22. package/dist/components/auto-translate/api.mjs +23 -0
  23. package/dist/components/auto-translate/auto-translate-button.d.ts +5 -0
  24. package/dist/components/auto-translate/auto-translate-button.mjs +48 -0
  25. package/dist/components/auto-translate/editor-store-adaptor.d.ts +1 -0
  26. package/dist/components/auto-translate/editor-store-adaptor.mjs +14 -0
  27. package/dist/components/auto-translate/index.d.ts +6 -0
  28. package/dist/components/auto-translate/index.mjs +6 -0
  29. package/dist/components/auto-translate/languages.d.ts +13 -0
  30. package/dist/components/auto-translate/languages.mjs +61 -0
  31. package/dist/components/auto-translate/post-auto-translate-plugin.d.ts +14 -0
  32. package/dist/components/auto-translate/post-auto-translate-plugin.mjs +32 -0
  33. package/dist/components/auto-translate/store.d.ts +21 -0
  34. package/dist/components/auto-translate/store.mjs +23 -0
  35. package/dist/components/auto-translate/translate.d.ts +17 -0
  36. package/dist/components/auto-translate/translate.mjs +103 -0
  37. package/dist/components/auto-translate/utils.d.ts +4 -0
  38. package/dist/components/auto-translate/utils.mjs +14 -0
  39. package/dist/components/auto-translate/with-availibility-check.d.ts +2 -0
  40. package/dist/components/auto-translate/with-availibility-check.mjs +10 -0
  41. package/dist/components/avatars/author-info.d.ts +23 -0
  42. package/dist/components/avatars/author-info.mjs +178 -0
  43. package/dist/components/avatars/avatar.d.ts +7 -0
  44. package/dist/components/avatars/avatar.mjs +9 -0
  45. package/dist/components/avatars/avatars.d.ts +10 -0
  46. package/dist/components/avatars/avatars.mjs +49 -0
  47. package/dist/components/avatars/badge.d.ts +14 -0
  48. package/dist/components/avatars/badge.mjs +178 -0
  49. package/dist/components/avatars/index.d.ts +5 -0
  50. package/dist/components/avatars/index.mjs +5 -0
  51. package/dist/components/avatars/system-user.d.ts +10 -0
  52. package/dist/components/avatars/system-user.mjs +58 -0
  53. package/dist/components/button-group/button-group.d.ts +18 -0
  54. package/dist/components/button-group/button-group.mjs +195 -0
  55. package/dist/components/button-group/index.d.ts +1 -0
  56. package/dist/components/button-group/index.mjs +1 -0
  57. package/dist/components/confirm.d.ts +29 -0
  58. package/dist/components/confirm.mjs +103 -0
  59. package/dist/components/dayjs.d.ts +3 -0
  60. package/dist/components/dayjs.mjs +5 -0
  61. package/dist/components/default-editor-config-provider.d.ts +8 -0
  62. package/dist/components/default-editor-config-provider.mjs +108 -0
  63. package/dist/components/dirty-prompt.d.ts +8 -0
  64. package/dist/components/dirty-prompt.mjs +117 -0
  65. package/dist/components/editor/blocklet-editor.d.ts +1 -0
  66. package/dist/components/editor/blocklet-editor.mjs +1 -0
  67. package/dist/components/editor/editor.d.ts +17 -0
  68. package/dist/components/editor/editor.mjs +35 -0
  69. package/dist/components/editor/index.d.ts +4 -0
  70. package/dist/components/editor/index.mjs +3 -0
  71. package/dist/components/editor/lazy-editor.d.ts +3 -0
  72. package/dist/components/editor/lazy-editor.mjs +14 -0
  73. package/dist/components/editor/viewer.d.ts +10 -0
  74. package/dist/components/editor/viewer.mjs +18 -0
  75. package/dist/components/emoji-icon.d.ts +11 -0
  76. package/dist/components/emoji-icon.mjs +62 -0
  77. package/dist/components/empty-status/empty-status.d.ts +7 -0
  78. package/dist/components/empty-status/empty-status.mjs +24 -0
  79. package/dist/components/empty-status/index.d.ts +1 -0
  80. package/dist/components/empty-status/index.mjs +1 -0
  81. package/dist/components/hooks/changed.d.ts +10 -0
  82. package/dist/components/hooks/changed.mjs +34 -0
  83. package/dist/components/hooks/index.d.ts +6 -0
  84. package/dist/components/hooks/index.mjs +6 -0
  85. package/dist/components/hooks/interval.d.ts +6 -0
  86. package/dist/components/hooks/interval.mjs +16 -0
  87. package/dist/components/hooks/locale-context.d.ts +10 -0
  88. package/dist/components/hooks/locale-context.mjs +12 -0
  89. package/dist/components/hooks/measure.d.ts +5 -0
  90. package/dist/components/hooks/measure.mjs +8 -0
  91. package/dist/components/hooks/now.d.ts +1 -0
  92. package/dist/components/hooks/now.mjs +10 -0
  93. package/dist/components/hooks/responsive.d.ts +17 -0
  94. package/dist/components/hooks/responsive.mjs +25 -0
  95. package/dist/components/hooks/session.d.ts +12 -0
  96. package/dist/components/hooks/session.mjs +48 -0
  97. package/dist/components/hooks/use-event-callback.d.ts +1 -0
  98. package/dist/components/hooks/use-event-callback.mjs +14 -0
  99. package/dist/components/icon-button.d.ts +6 -0
  100. package/dist/components/icon-button.mjs +37 -0
  101. package/dist/components/input/auto-clear-plugin.d.ts +3 -0
  102. package/dist/components/input/auto-clear-plugin.mjs +20 -0
  103. package/dist/components/input/comment-input.d.ts +11 -0
  104. package/dist/components/input/comment-input.mjs +108 -0
  105. package/dist/components/input/index.d.ts +4 -0
  106. package/dist/components/input/index.mjs +4 -0
  107. package/dist/components/input/input.d.ts +29 -0
  108. package/dist/components/input/input.mjs +149 -0
  109. package/dist/components/input/post-edit.d.ts +10 -0
  110. package/dist/components/input/post-edit.mjs +49 -0
  111. package/dist/components/input/scrollable-editor-wrapper.d.ts +9 -0
  112. package/dist/components/input/scrollable-editor-wrapper.mjs +18 -0
  113. package/dist/components/input/shortcut-plugin.d.ts +7 -0
  114. package/dist/components/input/shortcut-plugin.mjs +28 -0
  115. package/dist/components/lexical.d.ts +10 -0
  116. package/dist/components/lexical.mjs +56 -0
  117. package/dist/components/locale/en.d.ts +117 -0
  118. package/dist/components/locale/en.mjs +116 -0
  119. package/dist/components/locale/index.d.ts +236 -0
  120. package/dist/components/locale/index.mjs +3 -0
  121. package/dist/components/locale/zh.d.ts +119 -0
  122. package/dist/components/locale/zh.mjs +118 -0
  123. package/dist/components/pagination.d.ts +12 -0
  124. package/dist/components/pagination.mjs +44 -0
  125. package/dist/components/posts/comment-list/comment-list.d.ts +5 -0
  126. package/dist/components/posts/comment-list/comment-list.mjs +163 -0
  127. package/dist/components/posts/comment-list/context.d.ts +76 -0
  128. package/dist/components/posts/comment-list/context.mjs +318 -0
  129. package/dist/components/posts/comment.d.ts +16 -0
  130. package/dist/components/posts/comment.mjs +184 -0
  131. package/dist/components/posts/index.d.ts +6 -0
  132. package/dist/components/posts/index.mjs +6 -0
  133. package/dist/components/posts/menu.d.ts +14 -0
  134. package/dist/components/posts/menu.mjs +83 -0
  135. package/dist/components/posts/post-content.d.ts +16 -0
  136. package/dist/components/posts/post-content.mjs +63 -0
  137. package/dist/components/posts/post.d.ts +26 -0
  138. package/dist/components/posts/post.mjs +198 -0
  139. package/dist/components/profile-card/index.d.ts +1 -0
  140. package/dist/components/profile-card/index.mjs +1 -0
  141. package/dist/components/profile-card/profile-card.d.ts +15 -0
  142. package/dist/components/profile-card/profile-card.mjs +140 -0
  143. package/dist/components/rating/binary-thumb.d.ts +9 -0
  144. package/dist/components/rating/binary-thumb.mjs +162 -0
  145. package/dist/components/rating/github-reaction-container.d.ts +9 -0
  146. package/dist/components/rating/github-reaction-container.mjs +46 -0
  147. package/dist/components/rating/github-reaction.d.ts +18 -0
  148. package/dist/components/rating/github-reaction.mjs +174 -0
  149. package/dist/components/rating/index.d.ts +3 -0
  150. package/dist/components/rating/index.mjs +3 -0
  151. package/dist/components/rating/rater-list.d.ts +10 -0
  152. package/dist/components/rating/rater-list.mjs +33 -0
  153. package/dist/components/rating/rating.d.ts +27 -0
  154. package/dist/components/rating/rating.mjs +50 -0
  155. package/dist/components/segmented-control.d.ts +14 -0
  156. package/dist/components/segmented-control.mjs +55 -0
  157. package/dist/components/shared/relative-time.d.ts +8 -0
  158. package/dist/components/shared/relative-time.mjs +21 -0
  159. package/dist/components/toast.d.ts +8 -0
  160. package/dist/components/toast.mjs +44 -0
  161. package/dist/components/uploader/index.d.ts +13 -0
  162. package/dist/components/uploader/index.mjs +70 -0
  163. package/dist/components/uploader/utils.d.ts +1 -0
  164. package/dist/components/uploader/utils.mjs +16 -0
  165. package/dist/components/utils.d.ts +22 -0
  166. package/dist/components/utils.mjs +103 -0
  167. package/dist/components/view-more.d.ts +4 -0
  168. package/dist/components/view-more.mjs +50 -0
  169. package/dist/constants.d.ts +5 -0
  170. package/dist/constants.mjs +14 -0
  171. package/dist/global.d.ts +1 -0
  172. package/dist/index.d.ts +29 -0
  173. package/dist/index.mjs +29 -0
  174. package/dist/preferences.d.ts +2 -0
  175. package/dist/preferences.mjs +9 -0
  176. package/dist/theme/index.d.ts +8 -0
  177. package/dist/theme/index.mjs +96 -0
  178. package/dist/theme/typography.d.ts +2 -0
  179. package/dist/theme/typography.mjs +66 -0
  180. package/dist/type-override.d.ts +7 -0
  181. package/dist/types.d.ts +84 -0
  182. package/dist/types.mjs +0 -0
  183. package/dist/vite-env.d.ts +1 -0
  184. package/dist/ws.d.ts +3 -0
  185. package/dist/ws.mjs +39 -0
  186. package/package.json +81 -0
@@ -0,0 +1,50 @@
1
+ import { useEffect } from "react";
2
+ import { useSetState } from "ahooks";
3
+ function Rating({ ratingType, values, countPerValue, selectedValue, render, onRate, onUnrate }) {
4
+ const [state, setState] = useSetState({
5
+ selectedValue,
6
+ countPerValue: countPerValue || {}
7
+ });
8
+ const hasSelected = !!state.selectedValue;
9
+ const increaseCount = (value, inc) => {
10
+ setState((prevState) => ({
11
+ countPerValue: { ...prevState.countPerValue, [value]: (prevState.countPerValue[value] || 0) + inc }
12
+ }));
13
+ };
14
+ useEffect(() => {
15
+ setState({
16
+ countPerValue: countPerValue || {},
17
+ selectedValue
18
+ });
19
+ }, [countPerValue, selectedValue]);
20
+ if (!render) {
21
+ return null;
22
+ }
23
+ const options = values.map((value) => {
24
+ return {
25
+ value,
26
+ count: state.countPerValue?.[value] || 0,
27
+ selected: state.selectedValue === value
28
+ };
29
+ });
30
+ const toggleRate = async (value) => {
31
+ try {
32
+ if (state.selectedValue === value) {
33
+ await onUnrate();
34
+ increaseCount(value, -1);
35
+ setState({ selectedValue: void 0 });
36
+ } else {
37
+ await onRate({ ratingType, value });
38
+ if (hasSelected) {
39
+ increaseCount(state.selectedValue, -1);
40
+ }
41
+ increaseCount(value, 1);
42
+ setState({ selectedValue: value });
43
+ }
44
+ } catch (e) {
45
+ console.error("Failed to rate.", e);
46
+ }
47
+ };
48
+ return render({ options, toggleRate });
49
+ }
50
+ export default Rating;
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { type SxProps } from '@mui/material';
3
+ interface Option {
4
+ value: string;
5
+ label: React.ReactNode;
6
+ }
7
+ interface Props {
8
+ value: string;
9
+ options: Option[];
10
+ onChange?: (value: string) => void;
11
+ sx?: SxProps;
12
+ }
13
+ export declare function SegmentedControl({ value, options, onChange, sx, ...rest }: Props): import("react").JSX.Element;
14
+ export {};
@@ -0,0 +1,55 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Box, ToggleButton, ToggleButtonGroup } from "@mui/material";
3
+ import { mergeSx } from "./utils.mjs";
4
+ export function SegmentedControl({ value, options, onChange, sx, ...rest }) {
5
+ const mergedSx = mergeSx(
6
+ {
7
+ display: "inline-flex",
8
+ borderRadius: "100vh"
9
+ },
10
+ sx
11
+ );
12
+ return /* @__PURE__ */ jsx(Box, { sx: mergedSx, ...rest, children: /* @__PURE__ */ jsx(
13
+ ToggleButtonGroup,
14
+ {
15
+ size: "small",
16
+ value,
17
+ exclusive: true,
18
+ onChange: (_, v) => onChange?.(v),
19
+ sx: {
20
+ ".MuiToggleButtonGroup-grouped": {
21
+ m: 0.5,
22
+ px: 1.5,
23
+ border: 0,
24
+ borderRadius: "100vh",
25
+ lineHeight: 1.3,
26
+ textTransform: "none",
27
+ color: "text.primary"
28
+ },
29
+ ".MuiToggleButtonGroup-grouped.Mui-selected": {
30
+ border: 1,
31
+ borderColor: "divider"
32
+ },
33
+ ".MuiToggleButtonGroup-middleButton, .MuiToggleButtonGroup-lastButton": {
34
+ marginLeft: "-1px",
35
+ borderLeft: "1px solid transparent"
36
+ }
37
+ },
38
+ children: options.map((x) => {
39
+ return /* @__PURE__ */ jsx(
40
+ ToggleButton,
41
+ {
42
+ value: x.value,
43
+ sx: {
44
+ "&.Mui-selected": {
45
+ backgroundColor: "action.hover"
46
+ }
47
+ },
48
+ children: x.label
49
+ },
50
+ x.value
51
+ );
52
+ })
53
+ }
54
+ ) });
55
+ }
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ interface Props {
3
+ value: string | number | Date;
4
+ [key: string]: any;
5
+ autoUpdate?: boolean;
6
+ }
7
+ export default function RelativeTime({ value, autoUpdate, ...rest }: Props): import("react").JSX.Element;
8
+ export {};
@@ -0,0 +1,21 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import UxRelativeTime from "@arcblock/ux/lib/RelativeTime";
3
+ import { useUpdate } from "ahooks";
4
+ import { useEffect, useMemo } from "react";
5
+ export default function RelativeTime({ value, autoUpdate, ...rest }) {
6
+ const v = value instanceof Date ? value.getTime() : value;
7
+ const update = useUpdate();
8
+ const timestamp = useMemo(() => new Date(v).getTime(), [v]);
9
+ useEffect(() => {
10
+ if (autoUpdate) {
11
+ const diff = Math.abs(Date.now() - timestamp);
12
+ const isLessThan45Minutes = diff < 45 * 6e4;
13
+ if (isLessThan45Minutes) {
14
+ const timer = setInterval(update, 6e4);
15
+ return () => clearInterval(timer);
16
+ }
17
+ }
18
+ return void 0;
19
+ }, [autoUpdate, timestamp, update]);
20
+ return /* @__PURE__ */ jsx(UxRelativeTime, { value: v, ...rest });
21
+ }
@@ -0,0 +1,8 @@
1
+ import hotToast from 'react-hot-toast';
2
+ type Message = Parameters<typeof hotToast>[0];
3
+ export type ToastOptions = Parameters<typeof hotToast>[1];
4
+ type Toast = typeof hotToast & {
5
+ warning: (message: Message, options?: ToastOptions) => string;
6
+ };
7
+ declare let toast: Toast;
8
+ export { toast };
@@ -0,0 +1,44 @@
1
+ import hotToast from "react-hot-toast";
2
+ import bridge from "@arcblock/bridge";
3
+ let toast = Object.assign(hotToast, {
4
+ warning: (message, options) => {
5
+ return hotToast.error(message, { ...options, icon: "\u26A0\uFE0F" });
6
+ }
7
+ });
8
+ const isInArcSphere = window?.navigator?.userAgent.indexOf("ArcSphere") > -1;
9
+ if (isInArcSphere) {
10
+ toast = Object.assign(
11
+ (message) => {
12
+ try {
13
+ return bridge.call("arc__toast", { text: message });
14
+ } catch (e) {
15
+ return hotToast(message);
16
+ }
17
+ },
18
+ hotToast,
19
+ {
20
+ error: (message) => {
21
+ try {
22
+ return bridge.call("arc__toast", { text: message, level: "error" });
23
+ } catch (e) {
24
+ return hotToast.error(message);
25
+ }
26
+ },
27
+ success: (message) => {
28
+ try {
29
+ return bridge.call("arc__toast", { text: message, level: "success" });
30
+ } catch (e) {
31
+ return hotToast.success(message);
32
+ }
33
+ },
34
+ warning: (message, options) => {
35
+ try {
36
+ return bridge.call("arc__toast", { text: message, level: "warning" });
37
+ } catch (e) {
38
+ return hotToast.error(message, { ...options, icon: "\u26A0\uFE0F" });
39
+ }
40
+ }
41
+ }
42
+ );
43
+ }
44
+ export { toast };
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from 'react';
2
+ export * from './utils';
3
+ interface UploaderProviderProps {
4
+ children: ReactNode;
5
+ }
6
+ export declare const UploaderContext: import("react").Context<null>;
7
+ export declare function useUploader(): never;
8
+ export declare function UploaderTrigger({ onChange, children }: {
9
+ onChange?: Function;
10
+ children?: ReactNode;
11
+ }): import("react").JSX.Element;
12
+ export declare function UploaderProvider({ children }: UploaderProviderProps): import("react").JSX.Element;
13
+ export default UploaderProvider;
@@ -0,0 +1,70 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Box } from "@mui/material";
3
+ import { createContext, useContext, useRef, Suspense } from "react";
4
+ import { lazyRetry as lazy } from "@arcblock/ux/lib/Util";
5
+ import { createPortal } from "react-dom";
6
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
7
+ export * from "./utils.mjs";
8
+ const UploaderComponent = lazy(() => import("@blocklet/uploader").then((res) => ({ default: res.Uploader })));
9
+ export const UploaderContext = createContext(null);
10
+ export function useUploader() {
11
+ const uploaderRef = useContext(UploaderContext);
12
+ if (!uploaderRef) {
13
+ throw new Error("useUploader must be used within an UploaderProvider");
14
+ }
15
+ return uploaderRef;
16
+ }
17
+ export function UploaderTrigger({ onChange, children }) {
18
+ const uploaderRef = useUploader();
19
+ const handleOpen = () => {
20
+ const uploader = uploaderRef?.current?.getUploader();
21
+ const setMaxNumberOfFiles = (maxNumberOfFiles) => {
22
+ uploader?.setOptions({
23
+ // @ts-ignore
24
+ restrictions: {
25
+ maxNumberOfFiles
26
+ }
27
+ });
28
+ };
29
+ uploader?.open();
30
+ setMaxNumberOfFiles(1);
31
+ uploader?.onClose(() => {
32
+ setMaxNumberOfFiles(void 0);
33
+ });
34
+ if (onChange) {
35
+ uploader.onceUploadSuccess((...args) => {
36
+ onChange(...args);
37
+ });
38
+ }
39
+ };
40
+ return /* @__PURE__ */ jsx(Box, { onClick: handleOpen, children });
41
+ }
42
+ export function UploaderProvider({ children }) {
43
+ const uploaderRef = useRef(null);
44
+ const { locale } = useLocaleContext();
45
+ window.uploaderRef = uploaderRef;
46
+ return /* @__PURE__ */ jsxs(UploaderContext.Provider, { value: uploaderRef, children: [
47
+ children,
48
+ /* @__PURE__ */ jsx(Suspense, { children: createPortal(
49
+ /* @__PURE__ */ jsx(
50
+ UploaderComponent,
51
+ {
52
+ locale,
53
+ ref: uploaderRef,
54
+ popup: true,
55
+ coreProps: {
56
+ // 不做代码限制,默认使用 Media Kit 配置
57
+ // // 上传限制,参考 https://uppy.io/docs/uppy/#restrictions
58
+ // restrictions: {
59
+ // allowedFileExts: ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.mp4', '.webm', '.pdf'],
60
+ // maxNumberOfFiles: undefined, // default is unlimited
61
+ // },
62
+ }
63
+ },
64
+ "uploader"
65
+ ),
66
+ document.body
67
+ ) })
68
+ ] });
69
+ }
70
+ export default UploaderProvider;
@@ -0,0 +1 @@
1
+ export declare const getUploadedImageUrl: (imageUrl: string, width?: number) => string;
@@ -0,0 +1,16 @@
1
+ import { joinURL } from "ufo";
2
+ export const getUploadedImageUrl = (imageUrl, width = 320) => {
3
+ const prefix = joinURL(window.blocklet?.prefix || "/", "uploads");
4
+ let result = imageUrl;
5
+ if (imageUrl && imageUrl.startsWith("/") && !imageUrl.startsWith(prefix)) {
6
+ result = joinURL(prefix, imageUrl);
7
+ const tmp = new URL(result, window.location.origin);
8
+ if (!imageUrl.endsWith(".gif")) {
9
+ tmp.searchParams.set("imageFilter", "resize");
10
+ tmp.searchParams.set("w", width.toString());
11
+ tmp.searchParams.set("f", "webp");
12
+ }
13
+ return tmp.href;
14
+ }
15
+ return result;
16
+ };
@@ -0,0 +1,22 @@
1
+ import type { SxProps, Theme } from '@mui/material';
2
+ import type { SystemStyleObject } from '@mui/system';
3
+ export declare const repairBase64Avatar: (avatar?: string) => string | undefined;
4
+ export declare const getResizedAvatar: (avatar: string, size?: number) => string;
5
+ export declare const sleep: (ms: number) => Promise<unknown>;
6
+ export declare const minDelay: <T>(promise: Promise<T>, ms: number) => Promise<T>;
7
+ export declare const protectLogin: (session: any, action: () => Promise<any> | void) => void | Promise<unknown>;
8
+ export declare const copy: (text: string) => void;
9
+ export declare const getLastItem: <T>(arr: T[]) => T | null;
10
+ export declare function tryParseJSONObject(str: string): boolean;
11
+ export declare const getPreference: (key: string) => any;
12
+ export declare const getBlockletMountPointInfo: (name: string) => any;
13
+ export declare const blockletExists: (name: string) => boolean;
14
+ export declare const mergeSx: (initial: SystemStyleObject<Theme>, sx?: SxProps<Theme>) => any[];
15
+ export declare const discussKitMountPoint: string | undefined;
16
+ export declare const discussKitApiBaseUrl: string;
17
+ export declare const discussKitUploadsUrl: string;
18
+ export declare const isInDiscussKitApp: boolean | "" | undefined;
19
+ export declare const openProfile: (did: string, newTab?: boolean) => void;
20
+ export declare const randomId: () => string;
21
+ export declare const getDiscussKitClientId: () => any;
22
+ export declare const getPaymentKitMountPoint: () => string | undefined;
@@ -0,0 +1,103 @@
1
+ import { joinURL, withQuery, withTrailingSlash } from "ufo";
2
+ export const repairBase64Avatar = (avatar) => {
3
+ if (avatar && avatar.startsWith("data:")) {
4
+ return avatar.replace(/\s/g, encodeURIComponent(" "));
5
+ }
6
+ return avatar;
7
+ };
8
+ export const getResizedAvatar = (avatar, size = 72) => {
9
+ if (!avatar) {
10
+ return avatar;
11
+ }
12
+ if (avatar.indexOf("/.well-known/service") >= 0) {
13
+ const tmp = new URL(avatar, window.location.origin);
14
+ tmp.searchParams.set("imageFilter", "resize");
15
+ tmp.searchParams.set("w", size.toString());
16
+ tmp.searchParams.set("h", size.toString());
17
+ tmp.searchParams.set("f", "webp");
18
+ return tmp.href;
19
+ }
20
+ return avatar;
21
+ };
22
+ export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
23
+ export const minDelay = (promise, ms) => {
24
+ return Promise.all([promise, sleep(ms)]).then(([result]) => result);
25
+ };
26
+ export const protectLogin = (session, action) => {
27
+ if (session?.user) {
28
+ return action();
29
+ }
30
+ return new Promise((resolve) => {
31
+ session.login(() => resolve(action()));
32
+ });
33
+ };
34
+ const copyWithExecCommand = (text) => {
35
+ const tmp = document.createElement("TEXTAREA");
36
+ const active = document.activeElement;
37
+ tmp.style.position = "fixed";
38
+ tmp.style.opacity = "0";
39
+ tmp.style.left = "-9999px";
40
+ tmp.style.top = "0";
41
+ tmp.value = text;
42
+ document.body.appendChild(tmp);
43
+ tmp.select();
44
+ document.execCommand("copy");
45
+ document.body.removeChild(tmp);
46
+ active?.focus();
47
+ };
48
+ export const copy = (text) => {
49
+ if (navigator?.clipboard) {
50
+ try {
51
+ navigator.clipboard.writeText(text).catch(() => {
52
+ copyWithExecCommand(text);
53
+ });
54
+ return;
55
+ } catch (e) {
56
+ }
57
+ }
58
+ copyWithExecCommand(text);
59
+ };
60
+ export const getLastItem = (arr) => arr?.length ? arr[arr.length - 1] : null;
61
+ export function tryParseJSONObject(str) {
62
+ try {
63
+ const parsed = JSON.parse(str);
64
+ if (parsed && typeof parsed === "object") {
65
+ return true;
66
+ }
67
+ } catch (e) {
68
+ return false;
69
+ }
70
+ return false;
71
+ }
72
+ export const getPreference = (key) => window.blocklet?.preferences?.[key];
73
+ export const getBlockletMountPointInfo = (name) => {
74
+ return window.blocklet?.componentMountPoints?.find((x) => x.name === name);
75
+ };
76
+ export const blockletExists = (name) => {
77
+ const info = getBlockletMountPointInfo(name);
78
+ return info?.status === "running";
79
+ };
80
+ export const mergeSx = (initial, sx) => {
81
+ const mergedSx = [initial, ...Array.isArray(sx) ? sx : [sx]];
82
+ return mergedSx;
83
+ };
84
+ export const discussKitMountPoint = getBlockletMountPointInfo("did-comments")?.mountPoint;
85
+ export const discussKitApiBaseUrl = joinURL(window.location.origin, discussKitMountPoint || "", "api");
86
+ export const discussKitUploadsUrl = joinURL(discussKitMountPoint || "", "/uploads");
87
+ export const isInDiscussKitApp = discussKitMountPoint && withTrailingSlash(window.blocklet.prefix) === withTrailingSlash(discussKitMountPoint);
88
+ export const openProfile = (did, newTab) => {
89
+ if (did) {
90
+ window.open(withQuery(joinURL(discussKitMountPoint || "/", "profile"), { did }), newTab ? "_blank" : "_self");
91
+ }
92
+ };
93
+ export const randomId = () => crypto?.randomUUID?.() || Math.random().toString(36).substring(2);
94
+ export const getDiscussKitClientId = () => {
95
+ if (!window.__discuss_kit_client_id__) {
96
+ window.__discuss_kit_client_id__ = randomId();
97
+ }
98
+ return window.__discuss_kit_client_id__;
99
+ };
100
+ export const getPaymentKitMountPoint = () => {
101
+ const info = window.blocklet?.componentMountPoints?.find((x) => x.did === "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk");
102
+ return info?.mountPoint;
103
+ };
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare function ViewMore({ children, ...rest }: {
3
+ children: any;
4
+ } & React.HTMLAttributes<HTMLDivElement>): import("react").JSX.Element;
@@ -0,0 +1,50 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import Box from "@mui/material/Box";
4
+ import { styled } from "@arcblock/ux/lib/Theme";
5
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
6
+ import useMeasure from "./hooks/measure.mjs";
7
+ const MAX_HEIGHT = 200;
8
+ const Root = styled("div")`
9
+ &.markdown-viewer-collapsed .markdown-viewer-md-wrapper {
10
+ position: relative;
11
+ max-height: ${MAX_HEIGHT}px;
12
+ overflow: hidden;
13
+
14
+ .markdown-viewer-shadow {
15
+ position: absolute;
16
+ left: 0;
17
+ bottom: 0;
18
+ width: 100%;
19
+ height: 80px;
20
+ background-image: ${({ theme }) => `linear-gradient(to bottom, transparent, ${theme.palette.background.paper})`};
21
+ }
22
+ }
23
+ `;
24
+ export function ViewMore({ children, ...rest }) {
25
+ const { t } = useLocaleContext();
26
+ const [collapsed, setCollapsed] = useState(true);
27
+ const [ref, { height }] = useMeasure();
28
+ const _collapsed = collapsed && height > MAX_HEIGHT;
29
+ return /* @__PURE__ */ jsxs(Root, { ...rest, className: `${rest.className || ""} ${_collapsed ? "markdown-viewer-collapsed" : ""}`, children: [
30
+ /* @__PURE__ */ jsxs("div", { className: "markdown-viewer-md-wrapper", children: [
31
+ /* @__PURE__ */ jsx("div", { ref, "data-color-mode": "light", children }),
32
+ /* @__PURE__ */ jsx("div", { className: "markdown-viewer-shadow" })
33
+ ] }),
34
+ _collapsed && /* @__PURE__ */ jsx(
35
+ Box,
36
+ {
37
+ onClick: () => setCollapsed(false),
38
+ sx: {
39
+ display: "inline-block",
40
+ fontSize: 13,
41
+ fontWeight: "bold",
42
+ mt: 1,
43
+ color: "primary.light",
44
+ "&:hover": { color: "primary.dark", cursor: "pointer" }
45
+ },
46
+ children: t("readMore")
47
+ }
48
+ )
49
+ ] });
50
+ }
@@ -0,0 +1,5 @@
1
+ export declare const AIGNE_RUNTIME_DID = "z2qaBP9SahqU2L2YA3ip7NecwKACMByTFuiJ2";
2
+ export declare const AIGNE_STUDIO_DID = "z8iZpog7mcgcgBZzTiXJCWESvmnRrQmnd3XBB";
3
+ export declare const DISCUSS_KIT_DID = "z8ia1WEiBZ7hxURf6LwH21Wpg99vophFwSJdu";
4
+ export declare const MAX_DISCUSSION_LENGTH: number;
5
+ export declare const MAX_COMMENT_LENGTH: number;
@@ -0,0 +1,14 @@
1
+ export const AIGNE_RUNTIME_DID = "z2qaBP9SahqU2L2YA3ip7NecwKACMByTFuiJ2";
2
+ export const AIGNE_STUDIO_DID = "z8iZpog7mcgcgBZzTiXJCWESvmnRrQmnd3XBB";
3
+ export const DISCUSS_KIT_DID = "z8ia1WEiBZ7hxURf6LwH21Wpg99vophFwSJdu";
4
+ const DEFAULT_MAX_DISCUSSION_LENGTH = 25e3;
5
+ const DEFAULT_MAX_COMMENT_LENGTH = 1e4;
6
+ const MAX_POST_LENGTH = 5e4;
7
+ export const MAX_DISCUSSION_LENGTH = Math.min(
8
+ Number(window.blocklet.DISCUSS_KIT_MAX_DISCUSSION_LENGTH || DEFAULT_MAX_DISCUSSION_LENGTH),
9
+ MAX_POST_LENGTH
10
+ );
11
+ export const MAX_COMMENT_LENGTH = Math.min(
12
+ Number(window.blocklet.DISCUSS_KIT_MAX_COMMENT_LENGTH || DEFAULT_MAX_COMMENT_LENGTH),
13
+ MAX_POST_LENGTH
14
+ );
@@ -0,0 +1 @@
1
+ /// <reference path="../../../global.d.ts" />
@@ -0,0 +1,29 @@
1
+ export * from './theme';
2
+ export { Input, CommentInput, ScrollableEditorWrapper } from './components/input';
3
+ export * from './components/avatars';
4
+ export * from './components/posts';
5
+ export * from './components/rating';
6
+ export * from './components/empty-status';
7
+ export * from './components/authz';
8
+ export * from './components/confirm';
9
+ export * from './components/api-error-handler';
10
+ export { default as DefaultEditorConfigProvider } from './components/default-editor-config-provider';
11
+ export { default as Pagination } from './components/pagination';
12
+ export * from './components/editor';
13
+ export * as lexicalUtils from './components/lexical';
14
+ export * from './components/dirty-prompt';
15
+ export { translations } from './components/locale';
16
+ export { useNow, useChanged, useSessionContext, useEventCallback } from './components/hooks';
17
+ export * as utils from './components/utils';
18
+ export { default as preferences } from './preferences';
19
+ export * from './components/uploader';
20
+ export * from './components/button-group';
21
+ export * from './components/segmented-control';
22
+ export * from './ws';
23
+ export * from './components/toast';
24
+ export * from './components/arcsphere';
25
+ export { default as RelativeTime } from './components/shared/relative-time';
26
+ export * from './components/profile-card';
27
+ export * from './components/icon-button';
28
+ export * from './blocklets';
29
+ export * from './components/auto-translate';
package/dist/index.mjs ADDED
@@ -0,0 +1,29 @@
1
+ export * from "./theme/index.mjs";
2
+ export { Input, CommentInput, ScrollableEditorWrapper } from "./components/input/index.mjs";
3
+ export * from "./components/avatars/index.mjs";
4
+ export * from "./components/posts/index.mjs";
5
+ export * from "./components/rating/index.mjs";
6
+ export * from "./components/empty-status/index.mjs";
7
+ export * from "./components/authz/index.mjs";
8
+ export * from "./components/confirm.mjs";
9
+ export * from "./components/api-error-handler/index.mjs";
10
+ export { default as DefaultEditorConfigProvider } from "./components/default-editor-config-provider.mjs";
11
+ export { default as Pagination } from "./components/pagination.mjs";
12
+ export * from "./components/editor/index.mjs";
13
+ export * as lexicalUtils from "./components/lexical.mjs";
14
+ export * from "./components/dirty-prompt.mjs";
15
+ export { translations } from "./components/locale/index.mjs";
16
+ export { useNow, useChanged, useSessionContext, useEventCallback } from "./components/hooks/index.mjs";
17
+ export * as utils from "./components/utils.mjs";
18
+ export { default as preferences } from "./preferences.mjs";
19
+ export * from "./components/uploader/index.mjs";
20
+ export * from "./components/button-group/index.mjs";
21
+ export * from "./components/segmented-control.mjs";
22
+ export * from "./ws.mjs";
23
+ export * from "./components/toast.mjs";
24
+ export * from "./components/arcsphere/index.mjs";
25
+ export { default as RelativeTime } from "./components/shared/relative-time.mjs";
26
+ export * from "./components/profile-card/index.mjs";
27
+ export * from "./components/icon-button.mjs";
28
+ export * from "./blocklets.mjs";
29
+ export * from "./components/auto-translate/index.mjs";
@@ -0,0 +1,2 @@
1
+ declare const preferences: typeof window.blocklet.preferences;
2
+ export default preferences;
@@ -0,0 +1,9 @@
1
+ const prefs = window.blocklet.preferences;
2
+ const preferences = {
3
+ ...prefs,
4
+ // 对 preferences 做一些格式化处理
5
+ maxPinLimit: parseInt(`${prefs.maxPinLimit}`, 10),
6
+ maxFeaturedLimit: parseInt(`${prefs.maxFeaturedLimit}`, 10),
7
+ assignmentAuthorizedPassports: prefs.assignmentAuthorizedPassports?.split(",").map((x) => x.trim())
8
+ };
9
+ export default preferences;
@@ -0,0 +1,8 @@
1
+ import { type ThemeOptions } from '@mui/material/styles';
2
+ import React from 'react';
3
+ import { typography } from './typography';
4
+ export { typography };
5
+ export declare const themeOverrides: Partial<ThemeOptions>;
6
+ export declare function InternalThemeProvider({ children }: {
7
+ children: React.ReactNode;
8
+ }): JSX.Element;