@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,108 @@
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 { Icon } from "@iconify/react";
10
+ import LanguageMarkdownIcon from "@iconify/icons-mdi/language-markdown";
11
+ import Input from "./input.mjs";
12
+ export default function CommentInput({
13
+ disabledSend,
14
+ send,
15
+ onSuccess,
16
+ placeholder,
17
+ sendText,
18
+ sendIcon,
19
+ draftKey = "",
20
+ renderInnerFooter,
21
+ disableCmdEnter = false,
22
+ ...rest
23
+ }) {
24
+ const { t } = useContext(LocaleContext);
25
+ const renderFooter = ({ submit, content, loading, inSmallView }) => {
26
+ return /* @__PURE__ */ jsxs(
27
+ Box,
28
+ {
29
+ sx: {
30
+ p: 1,
31
+ display: "flex",
32
+ justifyContent: inSmallView ? "end" : "space-between",
33
+ alignItems: "end"
34
+ },
35
+ children: [
36
+ /* @__PURE__ */ jsx(
37
+ Box,
38
+ {
39
+ component: "a",
40
+ href: "https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax",
41
+ target: "_blank",
42
+ sx: {
43
+ display: inSmallView ? "none" : "flex",
44
+ alignItems: "center",
45
+ m: 0,
46
+ fontSize: 12,
47
+ color: "text.disabled",
48
+ textDecoration: "none",
49
+ "&:hover": { color: "text.secondary" }
50
+ },
51
+ children: /* @__PURE__ */ jsx(
52
+ Box,
53
+ {
54
+ component: "span",
55
+ sx: { display: "inline-flex", alignItems: "center", mr: 0.5, lineHeight: 1 },
56
+ title: "Styling with Markdown is supported",
57
+ children: /* @__PURE__ */ jsx(Icon, { icon: LanguageMarkdownIcon, style: { fontSize: 16 } })
58
+ }
59
+ )
60
+ }
61
+ ),
62
+ /* @__PURE__ */ jsx(
63
+ Box,
64
+ {
65
+ sx: {
66
+ display: "flex",
67
+ gap: 1,
68
+ alignItems: "center"
69
+ },
70
+ children: /* @__PURE__ */ jsx(
71
+ LoadingButton,
72
+ {
73
+ disabled: isBoolean(disabledSend) ? disabledSend : !content,
74
+ loading,
75
+ loadingPosition: "start",
76
+ startIcon: sendIcon || /* @__PURE__ */ jsx(SendIcon, { sx: { transform: "rotate(-45deg) translateX(3px)" } }),
77
+ variant: "contained",
78
+ color: "primary",
79
+ title: "\u2318 Enter",
80
+ onClick: submit,
81
+ className: "editor-submit-button",
82
+ children: /* @__PURE__ */ jsxs(Box, { component: "span", sx: { display: "inline-flex", gap: 0.5, fontSize: 12 }, children: [
83
+ /* @__PURE__ */ jsx("span", { children: sendText || t("sendComment") }),
84
+ /* @__PURE__ */ jsx(Box, { component: "span", sx: { display: inSmallView ? "none" : "inline" }, children: "(\u2318 Enter)" })
85
+ ] })
86
+ }
87
+ )
88
+ }
89
+ )
90
+ ]
91
+ }
92
+ );
93
+ };
94
+ return /* @__PURE__ */ jsx(
95
+ Input,
96
+ {
97
+ className: "editor-input-container",
98
+ placeholder: placeholder || t("commentInputPlaceholder"),
99
+ send,
100
+ onSuccess,
101
+ draftKey,
102
+ disableCmdEnter,
103
+ ...rest,
104
+ renderInnerFooter: renderInnerFooter ?? renderFooter,
105
+ renderEditorFooter: ({ error }) => error && /* @__PURE__ */ jsx(Alert, { severity: "error", children: error })
106
+ }
107
+ );
108
+ }
@@ -0,0 +1,4 @@
1
+ export { default as Input } from './input';
2
+ export { default as CommentInput } from './comment-input';
3
+ export { default as PostEdit } from './post-edit';
4
+ export { default as ScrollableEditorWrapper } from './scrollable-editor-wrapper';
@@ -0,0 +1,4 @@
1
+ export { default as Input } 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";
@@ -0,0 +1,29 @@
1
+ import { MutableRefObject } from 'react';
2
+ import { type BoxProps } from '@mui/material';
3
+ import type { EditorState, LexicalEditor } from 'lexical';
4
+ export type Send = (content: string) => Promise<any>;
5
+ export interface RenderProps {
6
+ content: EditorState | null;
7
+ submit: () => void;
8
+ loading: boolean;
9
+ error: any;
10
+ inSmallView: boolean;
11
+ }
12
+ export interface InputProps extends Omit<BoxProps, 'onChange'> {
13
+ initialContent?: string;
14
+ send?: Send;
15
+ placeholder?: string;
16
+ onSuccess?: (result: any) => void;
17
+ onChange?: (editorState: EditorState | null) => void;
18
+ autoFocus?: boolean;
19
+ draftKey?: string;
20
+ shortcut?: 'CMD_ENTER' | 'ENTER';
21
+ children?: React.ReactNode;
22
+ renderInnerFooter?: (args: RenderProps) => React.ReactElement<any>;
23
+ renderEditorFooter?: (args: RenderProps) => React.ReactElement<any>;
24
+ editorRef?: MutableRefObject<LexicalEditor | null>;
25
+ disableCmdEnter?: boolean;
26
+ }
27
+ export type Ref = HTMLDivElement;
28
+ declare const Input: ({ initialContent, send, placeholder, onSuccess, onChange, autoFocus, draftKey, shortcut, children, renderInnerFooter, renderEditorFooter, editorRef, disableCmdEnter, ...rest }: InputProps) => import("react").JSX.Element;
29
+ export default Input;
@@ -0,0 +1,149 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { createElement } from "react";
3
+ import { useState, useRef } from "react";
4
+ import { Box } from "@mui/material";
5
+ import isNil from "lodash/isNil";
6
+ import { EditorConfigProvider, useEditorConfig } from "@blocklet/editor/lib/config";
7
+ import { isEmptyContent } from "../lexical.mjs";
8
+ import ShortcutPlugin from "./shortcut-plugin.mjs";
9
+ import { AutoClearPlugin } from "./auto-clear-plugin.mjs";
10
+ import useMeasure from "../hooks/measure.mjs";
11
+ import { mergeSx } from "../utils.mjs";
12
+ import { MAX_COMMENT_LENGTH } from "../../constants.mjs";
13
+ import { BlockletEditor } from "../editor/blocklet-editor.mjs";
14
+ const Input = ({
15
+ initialContent = "",
16
+ send,
17
+ placeholder,
18
+ onSuccess,
19
+ onChange,
20
+ autoFocus,
21
+ draftKey = "",
22
+ shortcut,
23
+ children,
24
+ renderInnerFooter,
25
+ renderEditorFooter,
26
+ editorRef,
27
+ disableCmdEnter = false,
28
+ ...rest
29
+ }) => {
30
+ const sessionKey = draftKey || "";
31
+ const [content, setContent] = useState(null);
32
+ const [error, setError] = useState("");
33
+ const [loading, setLoading] = useState(false);
34
+ const [ref, { width }] = useMeasure();
35
+ const [clearKey, setClearKey] = useState(0);
36
+ const editorConfig = useEditorConfig();
37
+ const internalEditorRef = useRef(null);
38
+ const inSmallView = width < 700;
39
+ const draftContent = sessionStorage.getItem(sessionKey);
40
+ const setDraftContent = (data) => {
41
+ if (data) {
42
+ try {
43
+ sessionStorage.setItem(sessionKey, JSON.stringify(data));
44
+ } catch (err) {
45
+ console.log(err);
46
+ }
47
+ } else {
48
+ sessionStorage.removeItem(sessionKey);
49
+ sessionStorage.removeItem(`${sessionKey}:title`);
50
+ }
51
+ };
52
+ const handleChange = async (state) => {
53
+ const isEmpty = await isEmptyContent(state);
54
+ if (isEmpty) {
55
+ setContent(null);
56
+ onChange?.(null);
57
+ } else {
58
+ setContent(state);
59
+ onChange?.(state);
60
+ }
61
+ if (draftKey) {
62
+ setDraftContent(state);
63
+ }
64
+ setError("");
65
+ };
66
+ const submit = async () => {
67
+ if (!send) {
68
+ return;
69
+ }
70
+ setLoading(true);
71
+ setError("");
72
+ const originContent = content;
73
+ try {
74
+ const result = await send(isNil(content) ? "" : JSON.stringify(internalEditorRef?.current?.getEditorState()));
75
+ setContent(null);
76
+ if (draftKey) {
77
+ setDraftContent(null);
78
+ }
79
+ setClearKey(Date.now());
80
+ onSuccess?.(result);
81
+ } catch (e) {
82
+ setContent(originContent);
83
+ setError(e?.status === 429 ? e.response?.data || e.message : e.message);
84
+ console.error(e);
85
+ } finally {
86
+ setLoading(false);
87
+ }
88
+ };
89
+ const handleCmdEnterPressed = () => {
90
+ if (content && !loading) {
91
+ submit();
92
+ }
93
+ };
94
+ const mergedEditorConfig = {
95
+ ...editorConfig,
96
+ ...inSmallView && {
97
+ toolbar: {
98
+ items: ["component", "block", "italic", "bold", "underline", "media", ...editorConfig?.toolbar?.items || []]
99
+ }
100
+ },
101
+ characterLimitConfig: {
102
+ maxLength: MAX_COMMENT_LENGTH,
103
+ indicatorStyle: {
104
+ position: "absolute",
105
+ bottom: 6,
106
+ left: { xs: 12, md: 32 }
107
+ },
108
+ alignLeft: false
109
+ }
110
+ };
111
+ const editorState = draftKey && draftContent && !initialContent ? draftContent : initialContent;
112
+ const mergedSx = mergeSx(
113
+ {
114
+ position: "relative",
115
+ ".be-shell": {
116
+ border: 1,
117
+ borderColor: "divider",
118
+ borderRadius: 1,
119
+ overflow: "hidden"
120
+ },
121
+ ".be-editable, .be-content": {
122
+ minHeight: 150
123
+ }
124
+ },
125
+ rest.sx
126
+ );
127
+ return /* @__PURE__ */ createElement(Box, { ref, ...rest, key: draftKey, sx: mergedSx }, /* @__PURE__ */ jsx(EditorConfigProvider, { value: mergedEditorConfig, children: /* @__PURE__ */ jsxs(
128
+ BlockletEditor,
129
+ {
130
+ editorRef: (editor) => {
131
+ internalEditorRef.current = editor;
132
+ if (editorRef) {
133
+ editorRef.current = editor;
134
+ }
135
+ },
136
+ placeholder,
137
+ editorState,
138
+ onChange: handleChange,
139
+ autoFocus,
140
+ children: [
141
+ !disableCmdEnter && /* @__PURE__ */ jsx(ShortcutPlugin, { shortcut, callback: handleCmdEnterPressed }),
142
+ /* @__PURE__ */ jsx(AutoClearPlugin, { clearKey }),
143
+ children,
144
+ renderInnerFooter?.({ submit, content, loading, error, inSmallView })
145
+ ]
146
+ }
147
+ ) }), renderEditorFooter?.({ submit, content, loading, error, inSmallView }));
148
+ };
149
+ export default Input;
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { Send } from './input';
3
+ interface Props {
4
+ content: string;
5
+ send: Send;
6
+ onCancel?: () => void;
7
+ onSuccess?: () => void;
8
+ }
9
+ export default function PostEdit({ content, send, onCancel, onSuccess, ...rest }: Props): import("react").JSX.Element;
10
+ export {};
@@ -0,0 +1,49 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useContext } from "react";
3
+ import Box from "@mui/material/Box";
4
+ import Button from "@mui/material/Button";
5
+ import LoadingButton from "@mui/lab/LoadingButton";
6
+ import { Save as SaveIcon } from "@mui/icons-material";
7
+ import { LocaleContext } from "@arcblock/ux/lib/Locale/context";
8
+ import Input from "./input.mjs";
9
+ export default function PostEdit({ content, send, onCancel, onSuccess, ...rest }) {
10
+ const { t } = useContext(LocaleContext);
11
+ return /* @__PURE__ */ jsx(
12
+ Input,
13
+ {
14
+ initialContent: content,
15
+ send,
16
+ onSuccess,
17
+ ...rest,
18
+ renderEditorFooter: ({ submit, content: content2, loading }) => /* @__PURE__ */ jsxs(
19
+ Box,
20
+ {
21
+ sx: {
22
+ display: "flex",
23
+ justifyContent: "flex-end",
24
+ alignItems: "flex-end",
25
+ gap: 1,
26
+ mt: 1
27
+ },
28
+ children: [
29
+ /* @__PURE__ */ jsx(Button, { variant: "text", color: "primary", onClick: onCancel, children: t("cancel") }),
30
+ /* @__PURE__ */ jsx(
31
+ LoadingButton,
32
+ {
33
+ disabled: !content2,
34
+ loading,
35
+ loadingPosition: "start",
36
+ startIcon: /* @__PURE__ */ jsx(SaveIcon, {}),
37
+ variant: "contained",
38
+ color: "primary",
39
+ title: "\u2318 Enter",
40
+ onClick: submit,
41
+ children: t("saveChanges")
42
+ }
43
+ )
44
+ ]
45
+ }
46
+ )
47
+ }
48
+ );
49
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { SxProps } from '@mui/material';
3
+ interface Props {
4
+ safeDistance?: number;
5
+ sx?: SxProps;
6
+ children: React.ReactNode;
7
+ }
8
+ export default function ScrollableEditorWrapper({ safeDistance, sx, children, ...rest }: Props): import("react").JSX.Element;
9
+ export {};
@@ -0,0 +1,18 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { styled } from "@arcblock/ux/lib/Theme";
3
+ import Box from "@mui/material/Box";
4
+ import useMeasure from "../hooks/measure.mjs";
5
+ const Root = styled(Box)`
6
+ height: 100%;
7
+ .be-editable {
8
+ overflow-y: auto;
9
+ }
10
+ `;
11
+ export default function ScrollableEditorWrapper({ safeDistance = 0, sx, children, ...rest }) {
12
+ const [ref, { height }] = useMeasure();
13
+ const mergedSx = [...Array.isArray(sx) ? sx : [sx]];
14
+ if (height) {
15
+ mergedSx.push({ ".be-editable": { height: height - safeDistance } });
16
+ }
17
+ return /* @__PURE__ */ jsx(Root, { sx: mergedSx, ...rest, ref, children });
18
+ }
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ interface Props {
3
+ callback: () => void;
4
+ shortcut?: 'CMD_ENTER' | 'ENTER';
5
+ }
6
+ export default function CmdEnterShortcutPlugin({ callback, shortcut, }: Props): React.ReactElement<any> | null;
7
+ export {};
@@ -0,0 +1,28 @@
1
+ import { useEffect } from "react";
2
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
3
+ import { KEY_ENTER_COMMAND, COMMAND_PRIORITY_LOW } from "lexical";
4
+ export default function CmdEnterShortcutPlugin({
5
+ callback,
6
+ shortcut = "CMD_ENTER"
7
+ }) {
8
+ const [editor] = useLexicalComposerContext();
9
+ useEffect(() => {
10
+ return editor.registerCommand(
11
+ KEY_ENTER_COMMAND,
12
+ (e) => {
13
+ if (shortcut === "CMD_ENTER" && (e.metaKey || e.ctrlKey)) {
14
+ callback();
15
+ return true;
16
+ }
17
+ if (shortcut === "ENTER" && !e.shiftKey) {
18
+ e.preventDefault();
19
+ callback();
20
+ return true;
21
+ }
22
+ return false;
23
+ },
24
+ COMMAND_PRIORITY_LOW
25
+ );
26
+ }, [editor, callback]);
27
+ return null;
28
+ }
@@ -0,0 +1,10 @@
1
+ import type { EditorState } from 'lexical';
2
+ export declare const getExcerptFromLexicalContent: (content: any, size?: number) => string;
3
+ /**
4
+ * 检查 editor 内容是否为空
5
+ * - 从 editor state strcuture 判断是否为空
6
+ * - 检查是否只有 text node, 如果不是说明不为空 (仅输入一张图片的情况)
7
+ * - 检查 text content 空白/空行 的情况 (trim)
8
+ */
9
+ export declare const isEmptyContent: (editorState: EditorState) => boolean;
10
+ export declare const stringify: (editorState: EditorState | null | undefined) => string;
@@ -0,0 +1,56 @@
1
+ function lexicalRootToText(data) {
2
+ let parsedRoot = data;
3
+ if (typeof data === "string") {
4
+ try {
5
+ parsedRoot = JSON.parse(data).root;
6
+ if (typeof parsedRoot !== "object") {
7
+ return data;
8
+ }
9
+ } catch {
10
+ parsedRoot = {};
11
+ }
12
+ }
13
+ let text = "";
14
+ if (parsedRoot?.children) {
15
+ try {
16
+ parsedRoot.children.forEach((e) => {
17
+ if (e.text) {
18
+ text += e.text;
19
+ } else {
20
+ if (e.direction && text !== "") {
21
+ text += "\n";
22
+ }
23
+ text += lexicalRootToText(e);
24
+ }
25
+ });
26
+ } catch (err) {
27
+ console.error(`lexicalRootToText ${err?.toString()}`);
28
+ console.error(err);
29
+ }
30
+ }
31
+ return text;
32
+ }
33
+ export const getExcerptFromLexicalContent = (content, size = 150) => {
34
+ const textContent = (lexicalRootToText(content) || "").trim();
35
+ return textContent.length > size ? `${textContent.slice(0, size)}` : textContent;
36
+ };
37
+ export const isEmptyContent = (editorState) => {
38
+ const data = editorState.toJSON();
39
+ if (data.root.children?.length === 1 && !data.root.children[0].children?.length) {
40
+ return true;
41
+ }
42
+ const textOnly = !data.root.children.some((p) => {
43
+ if (p.type !== "paragraph") {
44
+ return true;
45
+ }
46
+ return p.children?.some((item) => item.type !== "text");
47
+ });
48
+ if (!textOnly) {
49
+ return false;
50
+ }
51
+ const text = lexicalRootToText(data.root);
52
+ return !text.trim();
53
+ };
54
+ export const stringify = (editorState) => {
55
+ return editorState ? JSON.stringify(editorState) : "";
56
+ };
@@ -0,0 +1,117 @@
1
+ declare const _default: {
2
+ cancel: string;
3
+ confirm: string;
4
+ commentInputPlaceholder: string;
5
+ copyLink: string;
6
+ delete: string;
7
+ deleted: string;
8
+ edit: string;
9
+ empty: string;
10
+ loadMore: string;
11
+ readMore: string;
12
+ saveChanges: string;
13
+ sendComment: string;
14
+ showMoreReplies: string;
15
+ all: string;
16
+ messages: string;
17
+ deleteMessage: {
18
+ title: string;
19
+ desc: string;
20
+ };
21
+ deleteComment: {
22
+ title: string;
23
+ desc: string;
24
+ };
25
+ profile: {
26
+ empty: string;
27
+ };
28
+ unsaved: {
29
+ title: string;
30
+ desc: string;
31
+ leave: string;
32
+ stay: string;
33
+ };
34
+ apiError: {
35
+ 400: string;
36
+ 401: string;
37
+ 403: string;
38
+ 409: string;
39
+ staleTip: string;
40
+ timeout: string;
41
+ error: string;
42
+ };
43
+ chat: {
44
+ notification: string;
45
+ reply: string;
46
+ unknown: string;
47
+ chats: string;
48
+ channel: string;
49
+ description: string;
50
+ newChannel: string;
51
+ updateChannel: string;
52
+ noChats: string;
53
+ unknownChannel: string;
54
+ channelDescription: string;
55
+ channelName: string;
56
+ deleteChannel: string;
57
+ commentedYourPost: string;
58
+ commentedPost: string;
59
+ newPost: string;
60
+ mentionInComment: string;
61
+ mentionInPost: string;
62
+ replyYourComment: string;
63
+ replyComment: string;
64
+ newMsg: string;
65
+ deleteChannelTitle: string;
66
+ deleteChannelDesc: string;
67
+ leaveChannel: string;
68
+ joinChannel: string;
69
+ openTask: string;
70
+ closeTask: string;
71
+ assignTask: string;
72
+ unassignTask: string;
73
+ points: string;
74
+ point: string;
75
+ pointUp: string;
76
+ loadMore: string;
77
+ notYetJoinedTheChannel: string;
78
+ typeSomething: string;
79
+ send: string;
80
+ selectBoardTip: string;
81
+ };
82
+ userActionLog: {
83
+ editedCapital: string;
84
+ times: string;
85
+ mostRecent: string;
86
+ and: string;
87
+ edited: string;
88
+ created: string;
89
+ added: string;
90
+ removed: string;
91
+ label: string;
92
+ labels: string;
93
+ assigned: string;
94
+ unassigned: string;
95
+ selfAssigned: string;
96
+ selfUnassigned: string;
97
+ published: string;
98
+ unpublished: string;
99
+ changeTitle: string;
100
+ changeBoard: string;
101
+ mention: string;
102
+ pin: string;
103
+ unpin: string;
104
+ markAsFeatured: string;
105
+ unmarkAsFeatured: string;
106
+ expand: string;
107
+ collapse: string;
108
+ expired: string;
109
+ expire: string;
110
+ passport: string;
111
+ passports: string;
112
+ };
113
+ pin: string;
114
+ unpin: string;
115
+ pinned: string;
116
+ };
117
+ export default _default;