@ai-group/chat-sdk 3.3.11 → 3.4.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 (37) hide show
  1. package/dist/cjs/components/FolderTree/DirectoryTree.d.ts +20 -0
  2. package/dist/cjs/components/FolderTree/DirectoryTree.js +161 -0
  3. package/dist/cjs/components/FolderTree/DirectoryTree.js.map +7 -0
  4. package/dist/cjs/components/FolderTree/FilePreview.d.ts +17 -0
  5. package/dist/cjs/components/FolderTree/FilePreview.js +163 -0
  6. package/dist/cjs/components/FolderTree/FilePreview.js.map +7 -0
  7. package/dist/cjs/components/FolderTree/index.d.ts +5 -0
  8. package/dist/cjs/components/FolderTree/index.js +235 -0
  9. package/dist/cjs/components/FolderTree/index.js.map +7 -0
  10. package/dist/cjs/components/FolderTree/styles.d.ts +48 -0
  11. package/dist/cjs/components/FolderTree/styles.js +149 -0
  12. package/dist/cjs/components/FolderTree/styles.js.map +7 -0
  13. package/dist/cjs/components/FolderTree/types.d.ts +81 -0
  14. package/dist/cjs/components/FolderTree/types.js +18 -0
  15. package/dist/cjs/components/FolderTree/types.js.map +7 -0
  16. package/dist/cjs/index.d.ts +3 -0
  17. package/dist/cjs/index.js +3 -0
  18. package/dist/cjs/index.js.map +3 -3
  19. package/dist/esm/components/FolderTree/DirectoryTree.d.ts +20 -0
  20. package/dist/esm/components/FolderTree/DirectoryTree.js +118 -0
  21. package/dist/esm/components/FolderTree/DirectoryTree.js.map +1 -0
  22. package/dist/esm/components/FolderTree/FilePreview.d.ts +17 -0
  23. package/dist/esm/components/FolderTree/FilePreview.js +160 -0
  24. package/dist/esm/components/FolderTree/FilePreview.js.map +1 -0
  25. package/dist/esm/components/FolderTree/index.d.ts +5 -0
  26. package/dist/esm/components/FolderTree/index.js +271 -0
  27. package/dist/esm/components/FolderTree/index.js.map +1 -0
  28. package/dist/esm/components/FolderTree/styles.d.ts +48 -0
  29. package/dist/esm/components/FolderTree/styles.js +22 -0
  30. package/dist/esm/components/FolderTree/styles.js.map +1 -0
  31. package/dist/esm/components/FolderTree/types.d.ts +81 -0
  32. package/dist/esm/components/FolderTree/types.js +2 -0
  33. package/dist/esm/components/FolderTree/types.js.map +1 -0
  34. package/dist/esm/index.d.ts +3 -0
  35. package/dist/esm/index.js +3 -0
  36. package/dist/esm/index.js.map +1 -1
  37. package/package.json +1 -1
@@ -0,0 +1,20 @@
1
+ import React from "react";
2
+ import type { TreeProps } from "antd";
3
+ import type { FolderTreeData, FolderTreeProps } from "./types";
4
+ export interface DirectoryTreeComponentProps {
5
+ treeData: FolderTreeData[];
6
+ directoryIcons?: FolderTreeProps["directoryIcons"];
7
+ selectedKeys?: string[];
8
+ expandedKeys?: string[];
9
+ onSelect?: TreeProps["onSelect"];
10
+ onExpand?: TreeProps["onExpand"];
11
+ showLine?: FolderTreeProps["showLine"];
12
+ switcherIcon?: FolderTreeProps["switcherIcon"];
13
+ defaultExpandAll?: boolean;
14
+ className?: string;
15
+ directoryTitle?: FolderTreeProps["directoryTitle"];
16
+ moreActions?: FolderTreeProps["moreActions"];
17
+ width?: number | string;
18
+ }
19
+ declare const DirectoryTreeComponent: React.FC<DirectoryTreeComponentProps>;
20
+ export default DirectoryTreeComponent;
@@ -0,0 +1,161 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/components/FolderTree/DirectoryTree.tsx
30
+ var DirectoryTree_exports = {};
31
+ __export(DirectoryTree_exports, {
32
+ default: () => DirectoryTree_default
33
+ });
34
+ module.exports = __toCommonJS(DirectoryTree_exports);
35
+ var import_react = require("react");
36
+ var import_antd = require("antd");
37
+ var import_icons = require("@ant-design/icons");
38
+ var import_clsx = __toESM(require("clsx"));
39
+ var import_styles = require("./styles");
40
+ var import_jsx_runtime = require("react/jsx-runtime");
41
+ var { DirectoryTree: AntDirectoryTree } = import_antd.Tree;
42
+ var DirectoryTreeComponent = ({
43
+ treeData,
44
+ selectedKeys,
45
+ expandedKeys,
46
+ onSelect,
47
+ onExpand,
48
+ showLine = false,
49
+ switcherIcon,
50
+ defaultExpandAll = true,
51
+ className,
52
+ directoryIcons,
53
+ directoryTitle,
54
+ moreActions,
55
+ width
56
+ }) => {
57
+ const styles = (0, import_styles.useStyles)();
58
+ const isFolder = (node) => {
59
+ return !!node.children && node.children.length > 0;
60
+ };
61
+ const getIcon = (0, import_react.useCallback)(
62
+ (node) => {
63
+ if (directoryIcons === false || directoryIcons === null) {
64
+ return null;
65
+ }
66
+ if (isFolder(node)) {
67
+ const icon = directoryIcons == null ? void 0 : directoryIcons.directory;
68
+ if (typeof icon === "function")
69
+ return icon();
70
+ return icon || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FolderOutlined, {});
71
+ }
72
+ const filePath = node.path.toLowerCase();
73
+ const extension = filePath.split(".").pop();
74
+ if (extension) {
75
+ const icon = directoryIcons == null ? void 0 : directoryIcons[extension];
76
+ if (icon)
77
+ return typeof icon === "function" ? icon() : icon;
78
+ }
79
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FileOutlined, {});
80
+ },
81
+ [directoryIcons]
82
+ );
83
+ const buildPathSegments = (0, import_react.useCallback)(
84
+ (node, parentSegments = []) => {
85
+ if (node.path === "/" && parentSegments.length === 0) {
86
+ return ["/"];
87
+ }
88
+ return [...parentSegments, node.path].filter((s) => s !== "");
89
+ },
90
+ []
91
+ );
92
+ const convertToTreeData = (0, import_react.useCallback)(
93
+ (nodes, parentSegments = []) => {
94
+ return nodes.map((node) => {
95
+ const pathSegments = buildPathSegments(node, parentSegments);
96
+ const fullPath = pathSegments.join("/").replace(/^\/+/, "");
97
+ const titleContent = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
98
+ "span",
99
+ {
100
+ className: (0, import_clsx.default)(
101
+ styles.treeNodeTitle,
102
+ moreActions && styles.treeNodeTitleHover
103
+ ),
104
+ children: [
105
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: node.title }),
106
+ moreActions && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
107
+ import_antd.Dropdown,
108
+ {
109
+ menu: moreActions(node),
110
+ trigger: ["click"],
111
+ placement: "bottomRight",
112
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
113
+ "span",
114
+ {
115
+ className: (0, import_clsx.default)(styles.moreIcon, "folder-tree-more-icon"),
116
+ onClick: (e) => e.stopPropagation(),
117
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.MoreOutlined, {})
118
+ }
119
+ )
120
+ }
121
+ )
122
+ ]
123
+ }
124
+ );
125
+ return {
126
+ ...node,
127
+ key: fullPath,
128
+ path: fullPath,
129
+ pathSegments,
130
+ title: titleContent,
131
+ icon: getIcon(node),
132
+ isLeaf: !isFolder(node),
133
+ children: node.children ? convertToTreeData(node.children, pathSegments) : void 0
134
+ };
135
+ });
136
+ },
137
+ [buildPathSegments, getIcon, moreActions, styles]
138
+ );
139
+ const treeDataConverted = convertToTreeData(treeData);
140
+ const titleNode = directoryTitle === false || directoryTitle === null ? null : typeof directoryTitle === "function" ? directoryTitle() : directoryTitle;
141
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_clsx.default)(styles.directoryPanel, className), style: { width }, children: [
142
+ titleNode && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.directoryTitle, children: titleNode }),
143
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.directoryTreeContent, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
144
+ AntDirectoryTree,
145
+ {
146
+ treeData: treeDataConverted,
147
+ selectedKeys,
148
+ expandedKeys,
149
+ onSelect,
150
+ onExpand,
151
+ multiple: false,
152
+ blockNode: true,
153
+ showLine,
154
+ switcherIcon,
155
+ defaultExpandAll
156
+ }
157
+ ) })
158
+ ] });
159
+ };
160
+ var DirectoryTree_default = DirectoryTreeComponent;
161
+ //# sourceMappingURL=DirectoryTree.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/components/FolderTree/DirectoryTree.tsx"],
4
+ "sourcesContent": ["import React, { useCallback } from \"react\";\nimport { Tree, Dropdown } from \"antd\";\nimport {\n FileOutlined,\n FolderOutlined,\n MoreOutlined,\n} from \"@ant-design/icons\";\nimport type { TreeProps } from \"antd\";\nimport type { DataNode } from \"antd/es/tree\";\nimport clsx from \"clsx\";\nimport type { FolderTreeData, FolderTreeProps } from \"./types\";\nimport { useStyles } from \"./styles\";\n\nconst { DirectoryTree: AntDirectoryTree } = Tree;\n\nexport interface DirectoryTreeComponentProps {\n treeData: FolderTreeData[];\n directoryIcons?: FolderTreeProps[\"directoryIcons\"];\n selectedKeys?: string[];\n expandedKeys?: string[];\n onSelect?: TreeProps[\"onSelect\"];\n onExpand?: TreeProps[\"onExpand\"];\n showLine?: FolderTreeProps[\"showLine\"];\n switcherIcon?: FolderTreeProps[\"switcherIcon\"];\n defaultExpandAll?: boolean;\n className?: string;\n directoryTitle?: FolderTreeProps[\"directoryTitle\"];\n moreActions?: FolderTreeProps[\"moreActions\"];\n width?: number | string;\n}\n\nconst DirectoryTreeComponent: React.FC<DirectoryTreeComponentProps> = ({\n treeData,\n selectedKeys,\n expandedKeys,\n onSelect,\n onExpand,\n showLine = false,\n switcherIcon,\n defaultExpandAll = true,\n className,\n directoryIcons,\n directoryTitle,\n moreActions,\n width,\n}) => {\n const styles = useStyles();\n\n const isFolder = (node: FolderTreeData): boolean => {\n return !!node.children && node.children.length > 0;\n };\n\n const getIcon = useCallback(\n (node: FolderTreeData) => {\n if (directoryIcons === false || directoryIcons === null) {\n return null;\n }\n if (isFolder(node)) {\n const icon = directoryIcons?.directory;\n if (typeof icon === \"function\") return icon();\n return icon || <FolderOutlined />;\n }\n const filePath = node.path.toLowerCase();\n const extension = filePath.split(\".\").pop();\n if (extension) {\n const icon = directoryIcons?.[extension];\n if (icon) return typeof icon === \"function\" ? icon() : icon;\n }\n return <FileOutlined />;\n },\n [directoryIcons]\n );\n\n const buildPathSegments = useCallback(\n (node: FolderTreeData, parentSegments: string[] = []): string[] => {\n if (node.path === \"/\" && parentSegments.length === 0) {\n return [\"/\"];\n }\n return [...parentSegments, node.path].filter((s) => s !== \"\");\n },\n []\n );\n\n const convertToTreeData = useCallback(\n (nodes: FolderTreeData[], parentSegments: string[] = []): DataNode[] => {\n return nodes.map((node) => {\n const pathSegments = buildPathSegments(node, parentSegments);\n const fullPath = pathSegments.join(\"/\").replace(/^\\/+/, \"\");\n\n const titleContent = (\n <span\n className={clsx(\n styles.treeNodeTitle,\n moreActions && styles.treeNodeTitleHover\n )}\n >\n <span>{node.title}</span>\n {moreActions && (\n <Dropdown\n menu={moreActions(node)}\n trigger={[\"click\"]}\n placement=\"bottomRight\"\n >\n <span\n className={clsx(styles.moreIcon, \"folder-tree-more-icon\")}\n onClick={(e) => e.stopPropagation()}\n >\n <MoreOutlined />\n </span>\n </Dropdown>\n )}\n </span>\n );\n\n return {\n ...node,\n key: fullPath,\n path: fullPath,\n pathSegments,\n title: titleContent,\n icon: getIcon(node),\n isLeaf: !isFolder(node),\n children: node.children\n ? convertToTreeData(node.children, pathSegments)\n : undefined,\n };\n });\n },\n [buildPathSegments, getIcon, moreActions, styles]\n );\n\n const treeDataConverted = convertToTreeData(treeData);\n\n const titleNode =\n directoryTitle === false || directoryTitle === null\n ? null\n : typeof directoryTitle === \"function\"\n ? directoryTitle()\n : directoryTitle;\n\n return (\n <div className={clsx(styles.directoryPanel, className)} style={{ width }}>\n {titleNode && <div className={styles.directoryTitle}>{titleNode}</div>}\n <div className={styles.directoryTreeContent}>\n <AntDirectoryTree\n treeData={treeDataConverted}\n selectedKeys={selectedKeys}\n expandedKeys={expandedKeys}\n onSelect={onSelect}\n onExpand={onExpand}\n multiple={false}\n blockNode\n showLine={showLine as any}\n switcherIcon={switcherIcon}\n defaultExpandAll={defaultExpandAll}\n />\n </div>\n </div>\n );\n};\n\nexport default DirectoryTreeComponent;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmC;AACnC,kBAA+B;AAC/B,mBAIO;AAGP,kBAAiB;AAEjB,oBAA0B;AAiDH;AA/CvB,IAAM,EAAE,eAAe,iBAAiB,IAAI;AAkB5C,IAAM,yBAAgE,CAAC;AAAA,EACrE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA,mBAAmB;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,aAAS,yBAAU;AAEzB,QAAM,WAAW,CAAC,SAAk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TreeData, FolderTreeProps } from "./types";
3
+ export interface FilePreviewProps {
4
+ selectedFile?: string[] | null;
5
+ fileContent?: string;
6
+ loading?: boolean;
7
+ previewTitle?: FolderTreeProps["previewTitle"];
8
+ previewRender?: FolderTreeProps["previewRender"];
9
+ emptyRender?: FolderTreeProps["emptyRender"];
10
+ getFileNode?: (path: string[]) => {
11
+ title: FolderTreeData["title"];
12
+ path: string;
13
+ content?: string;
14
+ } | undefined;
15
+ }
16
+ declare const FilePreview: React.FC<FilePreviewProps>;
17
+ export default FilePreview;
@@ -0,0 +1,163 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/components/FolderTree/FilePreview.tsx
30
+ var FilePreview_exports = {};
31
+ __export(FilePreview_exports, {
32
+ default: () => FilePreview_default
33
+ });
34
+ module.exports = __toCommonJS(FilePreview_exports);
35
+ var import_antd = require("antd");
36
+ var import_icons = require("@ant-design/icons");
37
+ var import_react_syntax_highlighter = require("react-syntax-highlighter");
38
+ var import_prism = require("react-syntax-highlighter/dist/esm/styles/prism");
39
+ var import_clsx = __toESM(require("clsx"));
40
+ var import_copy_to_clipboard = __toESM(require("copy-to-clipboard"));
41
+ var import_styles = require("./styles");
42
+ var import_jsx_runtime = require("react/jsx-runtime");
43
+ var customOneLight = {
44
+ ...import_prism.oneLight,
45
+ 'pre[class*="language-"]': {
46
+ ...import_prism.oneLight['pre[class*="language-"]'],
47
+ margin: 0,
48
+ background: "transparent",
49
+ padding: 0,
50
+ borderRadius: 0
51
+ }
52
+ };
53
+ var getFileExtension = (path = "") => {
54
+ const parts = path.split(".");
55
+ return parts[parts.length - 1] || "";
56
+ };
57
+ var EXTENSION_LANGUAGE_MAP = {
58
+ ts: "typescript",
59
+ tsx: "tsx",
60
+ js: "javascript",
61
+ jsx: "jsx",
62
+ md: "markdown",
63
+ json: "json",
64
+ css: "css",
65
+ scss: "scss",
66
+ less: "less",
67
+ html: "html",
68
+ xml: "xml",
69
+ yaml: "yaml",
70
+ yml: "yaml",
71
+ py: "python",
72
+ java: "java",
73
+ go: "go",
74
+ rs: "rust",
75
+ sh: "bash",
76
+ bash: "bash",
77
+ sql: "sql",
78
+ graphql: "graphql",
79
+ vue: "html",
80
+ svelte: "html"
81
+ };
82
+ var getLanguageFromExtension = (ext) => {
83
+ const lower = ext.toLowerCase();
84
+ return EXTENSION_LANGUAGE_MAP[lower] || lower || "text";
85
+ };
86
+ var FilePreview = ({
87
+ selectedFile,
88
+ fileContent = "",
89
+ loading = false,
90
+ previewTitle,
91
+ previewRender,
92
+ emptyRender,
93
+ getFileNode
94
+ }) => {
95
+ const styles = (0, import_styles.useStyles)();
96
+ if (loading) {
97
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_clsx.default)(styles.previewPanel), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.loadingContainer, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Spin, {}) }) });
98
+ }
99
+ if (!selectedFile || selectedFile.length === 0) {
100
+ if (emptyRender === false || emptyRender === null) {
101
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.previewPanel });
102
+ }
103
+ const emptyNode = typeof emptyRender === "function" ? emptyRender() : emptyRender || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
104
+ import_antd.Empty,
105
+ {
106
+ image: import_antd.Empty.PRESENTED_IMAGE_SIMPLE,
107
+ description: "请选择文件查看内容"
108
+ }
109
+ );
110
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.previewPanel, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.emptyContainer, children: emptyNode }) });
111
+ }
112
+ const fileNode = getFileNode == null ? void 0 : getFileNode(selectedFile);
113
+ const title = (fileNode == null ? void 0 : fileNode.title) || selectedFile[selectedFile.length - 1];
114
+ const fileName = selectedFile[selectedFile.length - 1];
115
+ const extension = getFileExtension(fileName);
116
+ const language = getLanguageFromExtension(extension);
117
+ let headerNode;
118
+ if (previewTitle === false || previewTitle === null) {
119
+ headerNode = null;
120
+ } else if (previewTitle) {
121
+ headerNode = typeof previewTitle === "function" ? previewTitle({ title, path: selectedFile, content: fileContent }) : previewTitle;
122
+ } else {
123
+ headerNode = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: styles.previewTitle, children: [
124
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: title }),
125
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
126
+ import_icons.CopyOutlined,
127
+ {
128
+ className: styles.copyBtn,
129
+ onClick: () => (0, import_copy_to_clipboard.default)(fileContent)
130
+ }
131
+ )
132
+ ] });
133
+ }
134
+ const originContentNode = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
135
+ import_react_syntax_highlighter.Prism,
136
+ {
137
+ language,
138
+ wrapLines: true,
139
+ style: customOneLight,
140
+ codeTagProps: { style: { background: "transparent" } },
141
+ children: fileContent.replace(/\n$/, "")
142
+ }
143
+ );
144
+ let contentNode;
145
+ if (previewRender) {
146
+ if (typeof previewRender === "function") {
147
+ contentNode = previewRender(
148
+ { content: fileContent, path: selectedFile, title: fileNode == null ? void 0 : fileNode.title, language },
149
+ { originNode: originContentNode }
150
+ );
151
+ } else {
152
+ contentNode = previewRender;
153
+ }
154
+ } else {
155
+ contentNode = originContentNode;
156
+ }
157
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: styles.previewPanel, children: [
158
+ headerNode,
159
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.previewContent, children: contentNode })
160
+ ] });
161
+ };
162
+ var FilePreview_default = FilePreview;
163
+ //# sourceMappingURL=FilePreview.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/components/FolderTree/FilePreview.tsx"],
4
+ "sourcesContent": ["import React from \"react\";\nimport { Empty, Spin } from \"antd\";\nimport { CopyOutlined } from \"@ant-design/icons\";\nimport { Prism as SyntaxHighlighter } from \"react-syntax-highlighter\";\nimport { oneLight } from \"react-syntax-highlighter/dist/esm/styles/prism\";\nimport clsx from \"clsx\";\nimport copyToClipboard from \"copy-to-clipboard\";\nimport type { FolderTreeData, FolderTreeProps } from \"./types\";\nimport { useStyles } from \"./styles\";\n\nexport interface FilePreviewProps {\n selectedFile?: string[] | null;\n fileContent?: string;\n loading?: boolean;\n previewTitle?: FolderTreeProps[\"previewTitle\"];\n previewRender?: FolderTreeProps[\"previewRender\"];\n emptyRender?: FolderTreeProps[\"emptyRender\"];\n getFileNode?: (\n path: string[]\n ) =>\n | { title: FolderTreeData[\"title\"]; path: string; content?: string }\n | undefined;\n}\n\nconst customOneLight = {\n ...oneLight,\n 'pre[class*=\"language-\"]': {\n ...oneLight['pre[class*=\"language-\"]'],\n margin: 0,\n background: \"transparent\",\n padding: 0,\n borderRadius: 0,\n },\n};\n\nconst getFileExtension = (path = \"\") => {\n const parts = path.split(\".\");\n return parts[parts.length - 1] || \"\";\n};\n\nconst EXTENSION_LANGUAGE_MAP: Record<string, string> = {\n ts: \"typescript\",\n tsx: \"tsx\",\n js: \"javascript\",\n jsx: \"jsx\",\n md: \"markdown\",\n json: \"json\",\n css: \"css\",\n scss: \"scss\",\n less: \"less\",\n html: \"html\",\n xml: \"xml\",\n yaml: \"yaml\",\n yml: \"yaml\",\n py: \"python\",\n java: \"java\",\n go: \"go\",\n rs: \"rust\",\n sh: \"bash\",\n bash: \"bash\",\n sql: \"sql\",\n graphql: \"graphql\",\n vue: \"html\",\n svelte: \"html\",\n};\n\nconst getLanguageFromExtension = (ext: string) => {\n const lower = ext.toLowerCase();\n return EXTENSION_LANGUAGE_MAP[lower] || lower || \"text\";\n};\n\nconst FilePreview: React.FC<FilePreviewProps> = ({\n selectedFile,\n fileContent = \"\",\n loading = false,\n previewTitle,\n previewRender,\n emptyRender,\n getFileNode,\n}) => {\n const styles = useStyles();\n\n if (loading) {\n return (\n <div className={clsx(styles.previewPanel)}>\n <div className={styles.loadingContainer}>\n <Spin />\n </div>\n </div>\n );\n }\n\n if (!selectedFile || selectedFile.length === 0) {\n if (emptyRender === false || emptyRender === null) {\n return <div className={styles.previewPanel} />;\n }\n const emptyNode =\n typeof emptyRender === \"function\"\n ? emptyRender()\n : emptyRender || (\n <Empty\n image={Empty.PRESENTED_IMAGE_SIMPLE}\n description=\"请选择文件查看内容\"\n />\n );\n return (\n <div className={styles.previewPanel}>\n <div className={styles.emptyContainer}>{emptyNode}</div>\n </div>\n );\n }\n\n const fileNode = getFileNode?.(selectedFile);\n const title = fileNode?.title || selectedFile[selectedFile.length - 1];\n const fileName = selectedFile[selectedFile.length - 1];\n const extension = getFileExtension(fileName);\n const language = getLanguageFromExtension(extension);\n\n // 标题区域\n let headerNode: React.ReactNode;\n if (previewTitle === false || previewTitle === null) {\n headerNode = null;\n } else if (previewTitle) {\n headerNode =\n typeof previewTitle === \"function\"\n ? previewTitle({ title, path: selectedFile, content: fileContent })\n : previewTitle;\n } else {\n headerNode = (\n <div className={styles.previewTitle}>\n <span>{title}</span>\n <CopyOutlined\n className={styles.copyBtn}\n onClick={() => copyToClipboard(fileContent)}\n />\n </div>\n );\n }\n\n // 内容区域\n const originContentNode = (\n <SyntaxHighlighter\n language={language}\n wrapLines\n style={customOneLight}\n codeTagProps={{ style: { background: \"transparent\" } }}\n >\n {fileContent.replace(/\\n$/, \"\")}\n </SyntaxHighlighter>\n );\n\n let contentNode: React.ReactNode;\n if (previewRender) {\n if (typeof previewRender === \"function\") {\n contentNode = previewRender(\n { content: fileContent, path: selectedFile, title: fileNode?.title, language },\n { originNode: originContentNode }\n );\n } else {\n contentNode = previewRender;\n }\n } else {\n contentNode = originContentNode;\n }\n\n return (\n <div className={styles.previewPanel}>\n {headerNode}\n <div className={styles.previewContent}>{contentNode}</div>\n </div>\n );\n};\n\nexport default FilePreview;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAA4B;AAC5B,mBAA6B;AAC7B,sCAA2C;AAC3C,mBAAyB;AACzB,kBAAiB;AACjB,+BAA4B;AAE5B,oBAA0B;AA8EhB;AA9DV,IAAM,iBAAiB;AAAA,EACrB,GAAG;AAAA,EACH,2BAA2B;AAAA,IACzB,GAAG,sBAAS,yBAAyB;AAAA,IACrC,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,cAAc;AAAA,EAChB;AACF;AAEA,IAAM,mBAAmB,CAAC,OAAO,OAAO;AACtC,QAAM,QAAQ,KAAK,MAAM,GAAG;AAC5B,SAAO,MAAM,MAAM,SAAS,CAAC,KAAK;AACpC;AAEA,IAAM,yBAAiD;AAAA,EACrD,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+ import React from "react";
2
+ import type { FolderTreeProps } from "./types";
3
+ export type { FolderTreeData, FolderTreeProps, FileContentService } from "./types";
4
+ declare const FolderTree: React.FC<FolderTreeProps>;
5
+ export default FolderTree;
@@ -0,0 +1,235 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/components/FolderTree/index.tsx
30
+ var FolderTree_exports = {};
31
+ __export(FolderTree_exports, {
32
+ default: () => FolderTree_default
33
+ });
34
+ module.exports = __toCommonJS(FolderTree_exports);
35
+ var import_react = require("react");
36
+ var import_clsx = __toESM(require("clsx"));
37
+ var import_DirectoryTree = __toESM(require("./DirectoryTree"));
38
+ var import_FilePreview = __toESM(require("./FilePreview"));
39
+ var import_styles = require("./styles");
40
+ var import_jsx_runtime = require("react/jsx-runtime");
41
+ var FolderTree = (props) => {
42
+ const {
43
+ className,
44
+ style,
45
+ treeData,
46
+ directoryIcons,
47
+ previewRender,
48
+ directoryTitle,
49
+ previewTitle,
50
+ selectable = true,
51
+ defaultSelectedFile,
52
+ defaultExpandAll = true,
53
+ selectedFile,
54
+ onSelectedFileChange,
55
+ directoryTreeWidth = 280,
56
+ emptyRender,
57
+ defaultExpandedPaths,
58
+ expandedPaths,
59
+ onExpandedPathsChange,
60
+ onFileClick,
61
+ onFolderClick,
62
+ fileContentService,
63
+ moreActions,
64
+ showLine,
65
+ switcherIcon,
66
+ showPreview = true
67
+ } = props;
68
+ const styles = (0, import_styles.useStyles)();
69
+ const findNodeAndValidate = (0, import_react.useCallback)(
70
+ (path, validateAsFile = false) => {
71
+ if (!path)
72
+ return { node: void 0, isValid: false };
73
+ const segments = Array.isArray(path) ? path.filter(Boolean) : path.split("/").filter(Boolean);
74
+ if (segments.length === 0)
75
+ return { node: void 0, isValid: false };
76
+ const findNode = (nodes, index = 0) => {
77
+ if (index >= segments.length)
78
+ return void 0;
79
+ const currentSegment = segments[index];
80
+ for (const node2 of nodes) {
81
+ if (node2.path === currentSegment) {
82
+ return index === segments.length - 1 ? node2 : node2.children ? findNode(node2.children, index + 1) : void 0;
83
+ }
84
+ }
85
+ return void 0;
86
+ };
87
+ const node = findNode(treeData);
88
+ const isValid = validateAsFile ? !!node && (!(node == null ? void 0 : node.children) || node.children.length === 0) : !!node;
89
+ return { node, isValid };
90
+ },
91
+ [treeData]
92
+ );
93
+ const isValidSelectedFile = (filePath) => !!(filePath && filePath.length > 0 && findNodeAndValidate(filePath, true).isValid);
94
+ const [selectedFileState, setSelectedFileState] = (0, import_react.useState)(
95
+ () => isValidSelectedFile(selectedFile || defaultSelectedFile) ? selectedFile || defaultSelectedFile || [] : []
96
+ );
97
+ const [expandedPathsState, setExpandedPaths] = (0, import_react.useState)(
98
+ expandedPaths || defaultExpandedPaths
99
+ );
100
+ const [validSelectedFile, setValidSelectedFile] = (0, import_react.useState)(
101
+ isValidSelectedFile(selectedFile || defaultSelectedFile)
102
+ );
103
+ const [fileContent, setFileContent] = (0, import_react.useState)("");
104
+ const [loadingContent, setLoadingContent] = (0, import_react.useState)(false);
105
+ (0, import_react.useEffect)(() => {
106
+ if (selectedFile !== void 0) {
107
+ setSelectedFileState(selectedFile);
108
+ setValidSelectedFile(isValidSelectedFile(selectedFile));
109
+ }
110
+ }, [selectedFile, treeData]);
111
+ (0, import_react.useEffect)(() => {
112
+ if (expandedPaths !== void 0) {
113
+ setExpandedPaths(expandedPaths);
114
+ }
115
+ }, [expandedPaths]);
116
+ (0, import_react.useEffect)(() => {
117
+ const loadContent = async () => {
118
+ if (!validSelectedFile || selectedFileState.length === 0) {
119
+ setFileContent("");
120
+ setLoadingContent(false);
121
+ return;
122
+ }
123
+ const filePath = selectedFileState.join("/");
124
+ const segments = filePath.split("/").filter((s) => s !== "");
125
+ const { node } = findNodeAndValidate(segments);
126
+ if (fileContentService) {
127
+ setLoadingContent(true);
128
+ try {
129
+ const content = await fileContentService.loadFileContent(filePath);
130
+ setFileContent(content);
131
+ } catch (error) {
132
+ setFileContent(
133
+ `// 加载错误: ${error instanceof Error ? error.message : "Unknown error"}`
134
+ );
135
+ } finally {
136
+ setLoadingContent(false);
137
+ }
138
+ } else if (node == null ? void 0 : node.content) {
139
+ setFileContent(node.content);
140
+ setLoadingContent(false);
141
+ } else {
142
+ setFileContent("");
143
+ setLoadingContent(false);
144
+ }
145
+ };
146
+ loadContent();
147
+ }, [validSelectedFile, selectedFileState, treeData, fileContentService, findNodeAndValidate]);
148
+ const handleSelect = (_keys, info) => {
149
+ var _a;
150
+ const keys = _keys;
151
+ const nodes = Array.isArray(info.selectedNodes) ? info.selectedNodes : [info.selectedNodes];
152
+ const isFolder = nodes.some((node) => !node.isLeaf);
153
+ if (isFolder) {
154
+ if (nodes.length === 1) {
155
+ const node = nodes[0];
156
+ onFolderClick == null ? void 0 : onFolderClick(node.path);
157
+ }
158
+ return;
159
+ }
160
+ const pathArray = ((_a = keys[0]) == null ? void 0 : _a.split("/").filter(Boolean)) || [];
161
+ if (pathArray.length === 0)
162
+ return;
163
+ const selectedNode = nodes[0];
164
+ const fileName = selectedNode == null ? void 0 : selectedNode.title;
165
+ const nodeContent = selectedNode == null ? void 0 : selectedNode.content;
166
+ onSelectedFileChange == null ? void 0 : onSelectedFileChange({
167
+ path: pathArray,
168
+ title: fileName,
169
+ content: nodeContent
170
+ });
171
+ const isControlled = selectedFile !== void 0;
172
+ if (!isControlled) {
173
+ setValidSelectedFile(true);
174
+ setSelectedFileState(pathArray);
175
+ }
176
+ if (nodes.length === 1) {
177
+ const node = nodes[0];
178
+ onFileClick == null ? void 0 : onFileClick(node.path, node.content);
179
+ }
180
+ };
181
+ const handleExpand = (keys) => {
182
+ const newPaths = keys;
183
+ setExpandedPaths(newPaths);
184
+ onExpandedPathsChange == null ? void 0 : onExpandedPathsChange(newPaths);
185
+ };
186
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
187
+ "div",
188
+ {
189
+ className: (0, import_clsx.default)(styles.container, className),
190
+ style: {
191
+ ...style,
192
+ ...(style == null ? void 0 : style.background) ? { "--folder-tree-directory-bg": style.background } : {},
193
+ ...(style == null ? void 0 : style.backgroundColor) ? { "--folder-tree-directory-bg": style.backgroundColor } : {}
194
+ },
195
+ children: [
196
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
197
+ import_DirectoryTree.default,
198
+ {
199
+ treeData,
200
+ directoryIcons,
201
+ selectedKeys: selectable && selectedFileState && validSelectedFile ? [selectedFileState.join("/")] : [],
202
+ expandedKeys: expandedPathsState,
203
+ onSelect: handleSelect,
204
+ onExpand: handleExpand,
205
+ defaultExpandAll,
206
+ directoryTitle,
207
+ moreActions,
208
+ showLine,
209
+ switcherIcon,
210
+ width: directoryTreeWidth
211
+ }
212
+ ),
213
+ showPreview && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
214
+ import_FilePreview.default,
215
+ {
216
+ selectedFile: validSelectedFile ? selectedFileState : [],
217
+ fileContent,
218
+ loading: loadingContent,
219
+ previewTitle,
220
+ previewRender,
221
+ emptyRender,
222
+ getFileNode: (path) => {
223
+ if (!path || path.length === 0)
224
+ return void 0;
225
+ const { node } = findNodeAndValidate(path);
226
+ return node ? { title: node.title, path: node.path, content: node.content } : void 0;
227
+ }
228
+ }
229
+ )
230
+ ]
231
+ }
232
+ );
233
+ };
234
+ var FolderTree_default = FolderTree;
235
+ //# sourceMappingURL=index.js.map