@blocklet/pages-kit 0.4.115 → 0.4.117

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.
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.default = () => Promise.resolve().then(() => __importStar(require('rehype-mermaid')));
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = ActionButton;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = require("@iconify/react");
9
+ const material_1 = require("@mui/material");
10
+ const react_2 = require("react");
11
+ const loading_button_1 = __importDefault(require("./loading-button"));
12
+ function ActionButton({ tip, tipSucceed, title, titleSucceed, icon, iconSucceed, autoReset, placement = 'top', ...props }) {
13
+ const [active, setActive] = (0, react_2.useState)(false);
14
+ const [error, setError] = (0, react_2.useState)();
15
+ const timer = (0, react_2.useRef)();
16
+ const onClose = () => {
17
+ setError(undefined);
18
+ if (autoReset) {
19
+ timer.current = window.setTimeout(() => {
20
+ setActive(false);
21
+ }, 3000);
22
+ }
23
+ };
24
+ const onOpen = () => {
25
+ clearTimeout(timer.current);
26
+ };
27
+ const realIcon = active ? iconSucceed : icon;
28
+ const toolTipTitleText = error ? (0, jsx_runtime_1.jsx)(material_1.Box, { color: "error", children: error.message }) : (active && tipSucceed) || tip;
29
+ const buttonText = active ? titleSucceed : title;
30
+ return ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: toolTipTitleText, disableInteractive: true, placement: placement, onClose: onClose, onOpen: onOpen, children: (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(loading_button_1.default, { startIcon: realIcon && (typeof realIcon === 'string' ? (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: realIcon }) : realIcon), loadingPosition: realIcon ? 'start' : undefined, ...props, onClick: async (e) => {
31
+ if (!props.onClick)
32
+ return;
33
+ try {
34
+ await props.onClick(e);
35
+ setActive(true);
36
+ }
37
+ catch (error) {
38
+ setError(error);
39
+ }
40
+ }, children: buttonText }) }) }));
41
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useMarkdownOptions = exports.MarkdownContext = exports.MarkdownProvider = exports.MarkdownRenderer = void 0;
7
+ const markdown_context_1 = require("./markdown-context");
8
+ Object.defineProperty(exports, "MarkdownContext", { enumerable: true, get: function () { return markdown_context_1.MarkdownContext; } });
9
+ Object.defineProperty(exports, "MarkdownProvider", { enumerable: true, get: function () { return markdown_context_1.MarkdownProvider; } });
10
+ Object.defineProperty(exports, "useMarkdownOptions", { enumerable: true, get: function () { return markdown_context_1.useMarkdownOptions; } });
11
+ const markdown_renderer_1 = __importDefault(require("./markdown-renderer"));
12
+ exports.MarkdownRenderer = markdown_renderer_1.default;
13
+ exports.default = markdown_renderer_1.default;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
+ const lab_1 = require("@mui/lab");
5
+ const react_1 = require("react");
6
+ const LoadingButton = (0, react_1.forwardRef)(({ onClick, ...props }, ref) => {
7
+ const [loading, setLoading] = (0, react_1.useState)(false);
8
+ const handleClick = (0, react_1.useCallback)(async (e) => {
9
+ try {
10
+ setLoading(true);
11
+ await onClick?.(e);
12
+ }
13
+ finally {
14
+ setLoading(false);
15
+ }
16
+ }, [onClick]);
17
+ return (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, { ref: ref, ...props, loading: props.loading || loading, onClick: handleClick });
18
+ });
19
+ exports.default = LoadingButton;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMarkdownOptions = exports.MarkdownContext = void 0;
4
+ exports.MarkdownProvider = MarkdownProvider;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = require("react");
7
+ const defaultOptions = {
8
+ codeOptions: {
9
+ showActionButton: true,
10
+ },
11
+ };
12
+ exports.MarkdownContext = (0, react_1.createContext)(defaultOptions);
13
+ const useMarkdownOptions = () => (0, react_1.useContext)(exports.MarkdownContext);
14
+ exports.useMarkdownOptions = useMarkdownOptions;
15
+ function MarkdownProvider({ children, options = defaultOptions }) {
16
+ return (0, jsx_runtime_1.jsx)(exports.MarkdownContext.Provider, { value: options, children: children });
17
+ }
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const jsx_runtime_1 = require("react/jsx-runtime");
30
+ const react_1 = require("@iconify/react");
31
+ const material_1 = require("@mui/material");
32
+ const react_2 = __importDefault(require("react"));
33
+ const react_markdown_1 = require("react-markdown");
34
+ const rehype_mermaid_1 = __importDefault(require("rehype-mermaid"));
35
+ const remark_gfm_1 = __importDefault(require("remark-gfm"));
36
+ const action_button_1 = __importDefault(require("./action-button"));
37
+ const markdown_context_1 = require("./markdown-context");
38
+ const ReactSyntaxHighlighter = react_2.default.lazy(() => Promise.resolve().then(() => __importStar(require('react-syntax-highlighter'))).then((m) => ({ default: m.Prism })));
39
+ const matchLanguage = (className) => {
40
+ const match = /language-(\w+)/.exec(className || '');
41
+ return match?.[1];
42
+ };
43
+ function MarkdownCode({ node, inline, className, children, ...props }) {
44
+ const { codeOptions } = (0, markdown_context_1.useMarkdownOptions)();
45
+ if (!children)
46
+ return null;
47
+ const language = matchLanguage(className);
48
+ return !inline ? ((0, jsx_runtime_1.jsx)(material_1.Box, { component: ReactSyntaxHighlighter, language: language, style: codeOptions?.theme, showLineNumbers: true, ...props, sx: { borderRadius: 1 }, children: String(children).replace(/\n$/, '') })) : ((0, jsx_runtime_1.jsx)(material_1.Box, { component: "code", className: className, ...props, children: children }));
49
+ }
50
+ function MarkdownTable({ className, children }) {
51
+ return ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: { overflow: 'auto', my: 1 }, children: (0, jsx_runtime_1.jsx)("table", { className: className, children: children }) }));
52
+ }
53
+ function MarkdownPre({ children }) {
54
+ const { codeOptions } = (0, markdown_context_1.useMarkdownOptions)();
55
+ const childrenProps = children?.props;
56
+ if (!childrenProps?.children)
57
+ return null;
58
+ const language = matchLanguage(childrenProps.className);
59
+ const showActionButton = codeOptions?.showActionButton !== false;
60
+ if (!showActionButton) {
61
+ return children;
62
+ }
63
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, { component: "div", sx: {
64
+ fontSize: 14,
65
+ borderRadius: 1,
66
+ bgcolor: 'rgb(245, 242, 240)',
67
+ '> pre': { mt: '0 !important' },
68
+ }, children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", alignItems: "center", p: 0.5, pl: 1.5, borderBottom: 1, borderColor: "grey.200", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { children: language }), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), (0, jsx_runtime_1.jsx)(action_button_1.default, { autoReset: true, title: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:copy" }), titleSucceed: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:copy-check" }), sx: { minWidth: 32, minHeight: 32, p: 0, fontSize: 18 }, onClick: () => {
69
+ window.navigator.clipboard.writeText(childrenProps.children);
70
+ } })] }), children] }));
71
+ }
72
+ function MarkdownRenderer(props) {
73
+ const { codeOptions = { showActionButton: true }, ...rest } = props;
74
+ const options = {
75
+ codeOptions,
76
+ };
77
+ return ((0, jsx_runtime_1.jsx)(StyledBox, { children: (0, jsx_runtime_1.jsx)(markdown_context_1.MarkdownProvider, { options: options, children: (0, jsx_runtime_1.jsx)(react_markdown_1.MarkdownHooks, { ...rest, remarkPlugins: [remark_gfm_1.default], rehypePlugins: [rehype_mermaid_1.default], components: {
78
+ pre: MarkdownPre,
79
+ code: MarkdownCode,
80
+ table: MarkdownTable,
81
+ } }) }) }));
82
+ }
83
+ const StyledBox = (0, material_1.styled)(material_1.Box) `
84
+ width: 100%;
85
+ overflow: hidden;
86
+ word-break: break-word;
87
+
88
+ > * {
89
+ &:first-child /* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ {
90
+ margin-top: 0;
91
+ }
92
+ &:last-child /* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ {
93
+ margin-bottom: 0;
94
+ }
95
+ }
96
+
97
+ pre {
98
+ overflow: auto;
99
+ }
100
+
101
+ li {
102
+ margin: 0;
103
+ padding: 0;
104
+ }
105
+
106
+ li p {
107
+ display: inline-block;
108
+ vertical-align: top;
109
+ margin: 0;
110
+ padding: 0;
111
+ }
112
+
113
+ table {
114
+ border-collapse: collapse;
115
+ white-space: nowrap;
116
+
117
+ th,
118
+ td {
119
+ border: 1px solid grey;
120
+ padding: 4px 8px;
121
+ }
122
+ }
123
+
124
+ a {
125
+ color: ${({ theme }) => theme.palette.primary.main};
126
+
127
+ :hover {
128
+ text-decoration: underline;
129
+ }
130
+ }
131
+
132
+ &.writing > *:last-child {
133
+ &:after {
134
+ content: '';
135
+ display: inline-block;
136
+ vertical-align: middle;
137
+ height: 1.2em;
138
+ margin-top: -0.2em;
139
+ margin-left: 0.1em;
140
+ border-right: 0.2em solid orange;
141
+ border-radius: 10px;
142
+ animation: blink-caret 0.75s step-end infinite;
143
+
144
+ @keyframes blink-caret {
145
+ from,
146
+ to {
147
+ border-color: transparent;
148
+ }
149
+ 50% {
150
+ border-color: ${({ theme }) => theme.palette.secondary.main};
151
+ }
152
+ }
153
+ }
154
+ }
155
+ `;
156
+ exports.default = MarkdownRenderer;