@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,17 @@
1
+ /// <reference types="react" />
2
+ import type { BlockletEditorProps } from '@blocklet/editor';
3
+ import type { EditorState, LexicalEditor } from 'lexical';
4
+ export type OnChangeHandler = ({ content, editorState, editor, isEmpty, }: {
5
+ content: string;
6
+ editorState: EditorState;
7
+ editor: LexicalEditor;
8
+ isEmpty: boolean;
9
+ }) => void;
10
+ export interface EditorProps extends Omit<BlockletEditorProps, 'onChange' | 'ref'> {
11
+ initialContent?: string;
12
+ onChange?: OnChangeHandler;
13
+ children?: React.ReactNode;
14
+ onSave?: () => void;
15
+ ignoreInitialChange?: boolean;
16
+ }
17
+ export default function Editor({ initialContent, onChange, children, onSave, ignoreInitialChange, ...rest }: EditorProps): import("react").JSX.Element;
@@ -0,0 +1,35 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Box, styled } from "@mui/material";
3
+ import { OnContentChangePlugin } from "@blocklet/editor/lib/ext/OnContentChangePlugin";
4
+ import { CtrlsShortcutPlugin } from "@blocklet/editor/lib/ext/ShortcutPlugin";
5
+ import { isEmptyContent, stringify } from "../lexical.mjs";
6
+ import { BlockletEditor } from "./blocklet-editor.mjs";
7
+ const Root = styled(Box)`
8
+ .be-editable,
9
+ .be-content {
10
+ min-height: 150px;
11
+ }
12
+ `;
13
+ export default function Editor({
14
+ initialContent,
15
+ onChange,
16
+ children,
17
+ onSave,
18
+ ignoreInitialChange = true,
19
+ ...rest
20
+ }) {
21
+ const handleChange = async (editorState, editor) => {
22
+ const isEmpty = await isEmptyContent(editorState);
23
+ onChange?.({
24
+ content: isEmpty ? "" : stringify(editorState),
25
+ editorState,
26
+ editor,
27
+ isEmpty
28
+ });
29
+ };
30
+ return /* @__PURE__ */ jsx(Root, { children: /* @__PURE__ */ jsxs(BlockletEditor, { editorState: initialContent, ...rest, children: [
31
+ /* @__PURE__ */ jsx(OnContentChangePlugin, { onChange: handleChange, ignoreInitialChange }),
32
+ onSave && /* @__PURE__ */ jsx(CtrlsShortcutPlugin, { callback: onSave }),
33
+ children
34
+ ] }) });
35
+ }
@@ -0,0 +1,4 @@
1
+ export { LazyEditor } from './lazy-editor';
2
+ export type { OnChangeHandler, EditorProps } from './editor';
3
+ export { BlockletEditor, useBlockletEditorLoaded } from './blocklet-editor';
4
+ export { BlockletEditorViewer, useBlockletEditorViewerLoaded } from './viewer';
@@ -0,0 +1,3 @@
1
+ export { LazyEditor } from "./lazy-editor.mjs";
2
+ export { BlockletEditor, useBlockletEditorLoaded } from "./blocklet-editor.mjs";
3
+ export { BlockletEditorViewer, useBlockletEditorViewerLoaded } from "./viewer.mjs";
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { EditorProps } from './editor';
3
+ export declare function LazyEditor(props: EditorProps): import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Suspense } from "react";
3
+ import { lazyRetry as lazy } from "@arcblock/ux/lib/Util";
4
+ import { Box, Skeleton } from "@mui/material";
5
+ const Editor = lazy(() => import("./editor.mjs"));
6
+ export function LazyEditor(props) {
7
+ const fallback = /* @__PURE__ */ jsxs(Box, { sx: { px: 3 }, children: [
8
+ /* @__PURE__ */ jsx(Skeleton, {}),
9
+ /* @__PURE__ */ jsx(Skeleton, { width: "80%" }),
10
+ /* @__PURE__ */ jsx(Skeleton, { width: "60%" }),
11
+ /* @__PURE__ */ jsx(Skeleton, { width: "40%" })
12
+ ] });
13
+ return /* @__PURE__ */ jsx(Suspense, { fallback, children: /* @__PURE__ */ jsx(Editor, { ...props }) });
14
+ }
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { useBlockletEditorViewerLoaded, EditorViewerProps } from '@blocklet/editor/lib/blocklet-editor-viewer';
3
+ export interface EditorProps extends Omit<EditorViewerProps, 'editorState'> {
4
+ content: string;
5
+ }
6
+ export declare function BlockletEditorViewer({ content, prepend, ...rest }: EditorProps): import("react").JSX.Element;
7
+ export declare namespace BlockletEditorViewer {
8
+ var fallback: import("react").JSX.Element;
9
+ }
10
+ export { useBlockletEditorViewerLoaded };
@@ -0,0 +1,18 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { Suspense } from "react";
3
+ import { Skeleton } from "@mui/material";
4
+ import {
5
+ BlockletEditorViewer as InternalBlockletEditorViewer,
6
+ useBlockletEditorViewerLoaded
7
+ } from "@blocklet/editor/lib/blocklet-editor-viewer";
8
+ const fallback = /* @__PURE__ */ jsxs(Fragment, { children: [
9
+ /* @__PURE__ */ jsx(Skeleton, {}),
10
+ /* @__PURE__ */ jsx(Skeleton, { width: "80%" }),
11
+ /* @__PURE__ */ jsx(Skeleton, { width: "60%" }),
12
+ /* @__PURE__ */ jsx(Skeleton, { width: "40%" })
13
+ ] });
14
+ export function BlockletEditorViewer({ content, prepend, ...rest }) {
15
+ return /* @__PURE__ */ jsx(Suspense, { fallback, children: /* @__PURE__ */ jsx(InternalBlockletEditorViewer, { editorState: content, prepend, ...rest }) });
16
+ }
17
+ BlockletEditorViewer.fallback = fallback;
18
+ export { useBlockletEditorViewerLoaded };
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { BoxProps } from '@mui/material/Box';
3
+ interface InternalIconProps extends BoxProps {
4
+ title: string;
5
+ icon?: string;
6
+ }
7
+ interface IconProps extends InternalIconProps {
8
+ size?: 'small' | 'large';
9
+ }
10
+ declare function EmojiIcon({ title, icon, size, ...rest }: IconProps): import("react").JSX.Element;
11
+ export default EmojiIcon;
@@ -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;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { SxProps } from '@mui/material';
3
+ interface Props {
4
+ sx?: SxProps;
5
+ }
6
+ export default function EmptyStatus({ sx }: Props): import("react").JSX.Element;
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';
@@ -0,0 +1 @@
1
+ export { default as EmptyStatus } from "./empty-status.mjs";
@@ -0,0 +1,10 @@
1
+ interface Options {
2
+ tracking: (values: Record<string, any>) => boolean;
3
+ onChange?: () => void;
4
+ }
5
+ export declare const useChanged: (values: Record<string, any>, options: Options) => {
6
+ changed: boolean;
7
+ reset: (overrides?: Record<string, any>) => void;
8
+ initialValues: Record<string, any>;
9
+ };
10
+ export {};
@@ -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';
2
+ export { useChanged } from './changed';
3
+ export { useNow } from './now';
4
+ export { useInterval } from './interval';
5
+ export { useDownBreakpoint, useUpBreakpoint } from './responsive';
6
+ export { useEventCallback } from './use-event-callback';
@@ -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,6 @@
1
+ interface Options {
2
+ interval?: number;
3
+ paused?: boolean;
4
+ }
5
+ export declare const useInterval: (callback: () => void, options?: Options) => void;
6
+ export {};
@@ -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,10 @@
1
+ export interface Language {
2
+ name: string;
3
+ code: string;
4
+ }
5
+ export declare const useLocaleContext: () => {
6
+ locale: string;
7
+ t: (key: string, data: any) => string;
8
+ languages: Language[];
9
+ getLanguageName: (code: string) => string;
10
+ };
@@ -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,5 @@
1
+ declare const useMeasure: () => [any, {
2
+ width: number;
3
+ height: number;
4
+ }];
5
+ export default useMeasure;
@@ -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 @@
1
+ export declare const useNow: (interval?: number) => Date;
@@ -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
+ };
@@ -0,0 +1,17 @@
1
+ import { type Breakpoint } from '@mui/material';
2
+ export declare const useDownBreakpoint: (breakpoint: Breakpoint) => boolean;
3
+ export declare const useUpBreakpoint: (breakpoint: Breakpoint) => boolean;
4
+ export declare function useResponsive(): (responsiveValues: {
5
+ xs?: any;
6
+ sm?: any;
7
+ md?: any;
8
+ lg?: any;
9
+ xl?: any;
10
+ }) => any;
11
+ export declare const useResponsiveValue: (values: {
12
+ xs?: any;
13
+ sm?: any;
14
+ md?: any;
15
+ lg?: any;
16
+ xl?: any;
17
+ }) => any;
@@ -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
+ };
@@ -0,0 +1,12 @@
1
+ export declare const useSessionContext: () => {
2
+ isAuthenticated: boolean;
3
+ isAdmin: boolean;
4
+ isMember: boolean;
5
+ isBlogEditor: boolean;
6
+ hasAnyPassport: (passports: string | string[]) => boolean;
7
+ hasAnyPermission: (perms: string | string[]) => boolean;
8
+ canUpdatePost: () => boolean;
9
+ sessionReadyPromise: Promise<unknown>;
10
+ session: Session;
11
+ connectApi: any;
12
+ };
@@ -0,0 +1,48 @@
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 hasAnyPermission = (perms) => {
15
+ if (!perms || perms.length === 0) {
16
+ return true;
17
+ }
18
+ const permsArr = Array.isArray(perms) ? perms : [perms];
19
+ return permsArr.some((item) => permissionSet.has(item));
20
+ };
21
+ const isAdmin = hasAnyPassport(["admin", "owner"]);
22
+ const isBlogEditor = hasAnyPassport(["blogEditor"]);
23
+ const canUpdatePost = () => {
24
+ return isAdmin || isBlogEditor || hasAnyPermission(["update_post"]);
25
+ };
26
+ const resolver = useRef(void 0);
27
+ const sessionReadyPromise = useMemo(() => {
28
+ return new Promise((resolve) => {
29
+ resolver.current = resolve;
30
+ });
31
+ }, []);
32
+ useEffect(() => {
33
+ if (ctx.session.initialized) {
34
+ resolver.current?.();
35
+ }
36
+ }, [ctx.session?.initialized]);
37
+ return {
38
+ ...ctx,
39
+ isAuthenticated: !!ctx.session?.user,
40
+ isAdmin,
41
+ isMember: hasAnyPassport(["member"]),
42
+ isBlogEditor,
43
+ hasAnyPassport,
44
+ hasAnyPermission,
45
+ canUpdatePost,
46
+ sessionReadyPromise
47
+ };
48
+ };
@@ -0,0 +1 @@
1
+ export declare function useEventCallback<I extends unknown[], O>(fn: (...args: I) => O): (...args: I) => O;
@@ -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
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { BoxProps, type IconButtonProps } from '@mui/material';
3
+ export declare function IconButton<C extends React.ElementType>({ sx, ...rest }: IconButtonProps<C, {
4
+ component?: C;
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,3 @@
1
+ export declare function AutoClearPlugin({ clearKey }: {
2
+ clearKey: number;
3
+ }): null;
@@ -0,0 +1,20 @@
1
+ import { useEffect } from "react";
2
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
3
+ import { $createParagraphNode, $getRoot, $getSelection } from "lexical";
4
+ export function AutoClearPlugin({ clearKey }) {
5
+ const [editor] = useLexicalComposerContext();
6
+ useEffect(() => {
7
+ if (editor && clearKey) {
8
+ editor.update(() => {
9
+ const root = $getRoot();
10
+ const paragraph = $createParagraphNode();
11
+ root.clear();
12
+ root.append(paragraph);
13
+ if ($getSelection() !== null) {
14
+ paragraph.select();
15
+ }
16
+ });
17
+ }
18
+ }, [editor, clearKey]);
19
+ return null;
20
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { InputProps, RenderProps } from './input';
3
+ interface Props extends Omit<InputProps, 'render'> {
4
+ sendText?: string;
5
+ sendIcon?: React.ReactNode;
6
+ disabledSend?: boolean;
7
+ renderInnerFooter?: (args: RenderProps) => React.ReactElement<any>;
8
+ disableCmdEnter?: boolean;
9
+ }
10
+ export default function CommentInput({ disabledSend, send, onSuccess, placeholder, sendText, sendIcon, draftKey, renderInnerFooter, disableCmdEnter, ...rest }: Props): import("react").JSX.Element;
11
+ export {};