@datawhale/prosemirror-render 0.0.1
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.
- package/dist/AttachmentBlock-ChMNTUOo.mjs +351 -0
- package/dist/AttachmentBlock-DsmJP3Kw.js +1 -0
- package/dist/AttachmentInline-Dc3dp0g-.js +1 -0
- package/dist/AttachmentInline-tbC8BJBy.mjs +52 -0
- package/dist/AttachmentMenu-B5x8P9_n.mjs +541 -0
- package/dist/AttachmentMenu-ExoCOe4B.js +1 -0
- package/dist/Blockquote-BamWUQND.mjs +15 -0
- package/dist/Blockquote-CQSBFnsu.js +1 -0
- package/dist/BulletList-BQTUD69X.mjs +15 -0
- package/dist/BulletList-CFjF3U-l.js +1 -0
- package/dist/Callout-Cu6HI-xq.mjs +28 -0
- package/dist/Callout-DPdOqTb4.js +1 -0
- package/dist/CellOutput-C33VK0df.mjs +981 -0
- package/dist/CellOutput-DiKZlIFa.js +6 -0
- package/dist/CodeBlock-Cjuxuq7B.mjs +8359 -0
- package/dist/CodeBlock-DWniNUQB.js +148 -0
- package/dist/Doc-6s4VMDsx.mjs +15 -0
- package/dist/Doc-D2yvlSII.js +1 -0
- package/dist/FoldBlock-DRdlU-DX.mjs +75 -0
- package/dist/FoldBlock-ZPMf0QsR.js +1 -0
- package/dist/Grid-GfmJxM93.mjs +31 -0
- package/dist/Grid-QToZdaRT.js +1 -0
- package/dist/HardBreak-B2tFO31P.mjs +13 -0
- package/dist/HardBreak-Dbf5Zg5o.js +1 -0
- package/dist/Heading-BElRvhGn.mjs +21 -0
- package/dist/Heading-BUnffIAz.js +1 -0
- package/dist/HorizontalRule-BRG45oT0.mjs +13 -0
- package/dist/HorizontalRule-CE09LZGf.js +1 -0
- package/dist/IFrame-CaAOVLGN.mjs +17 -0
- package/dist/IFrame-DcCpSoDC.js +1 -0
- package/dist/Image-C8v5dCij.mjs +105 -0
- package/dist/Image-cHL85CXs.js +1 -0
- package/dist/ListItem-BrjxeGxz.js +1 -0
- package/dist/ListItem-X0T7a_z8.mjs +15 -0
- package/dist/MathDisplay-CESKZV46.js +1 -0
- package/dist/MathDisplay-CoGsFzXW.mjs +30 -0
- package/dist/MathInline-0xTZoIIq.mjs +30 -0
- package/dist/MathInline-C_1SJUVz.js +1 -0
- package/dist/McChoices-Aj394G5E.mjs +52 -0
- package/dist/McChoices-B4euzY7M.js +1 -0
- package/dist/McQuestion-Dq0aM5tC.js +1 -0
- package/dist/McQuestion-DvD-J47M.mjs +38 -0
- package/dist/McSolution-C5sTXz3y.mjs +24 -0
- package/dist/McSolution-N79CllH9.js +1 -0
- package/dist/MultipleChoice-DTCF3Q8m.js +1 -0
- package/dist/MultipleChoice-Dv-k1zUU.mjs +47 -0
- package/dist/OrderedList-B8v1gchv.mjs +17 -0
- package/dist/OrderedList-DMl3tvwP.js +1 -0
- package/dist/Paragraph-CzRSCJNr.js +1 -0
- package/dist/Paragraph-DGcZy8t_.mjs +16 -0
- package/dist/SlotNode-6OpoUcOa.mjs +10 -0
- package/dist/SlotNode-DMG0R6Vf.js +1 -0
- package/dist/TableCell-BY9gdldc.js +1 -0
- package/dist/TableCell-Bp52L368.mjs +20 -0
- package/dist/TableContainer-C5KXY6f7.js +1 -0
- package/dist/TableContainer-C9PhNGlz.mjs +29 -0
- package/dist/TableHeader-BTuqvorM.js +1 -0
- package/dist/TableHeader-C7KKz3e1.mjs +17 -0
- package/dist/TableRow-D4F6AKFt.js +1 -0
- package/dist/TableRow-OzpVq1qW.mjs +15 -0
- package/dist/Text-Br_pcGz4.mjs +78 -0
- package/dist/Text-DlUfrsNI.js +1 -0
- package/dist/emoji-Bk6FG72F.js +1 -0
- package/dist/emoji-CmOToDEU.mjs +3711 -0
- package/dist/index-D2CtpNvR.js +1 -0
- package/dist/index-DVmWCrQE.mjs +159 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.es.js +4 -0
- package/dist/katex-CS0ZfoxP.js +261 -0
- package/dist/katex-r9TeExgs.mjs +11690 -0
- package/dist/prosemirror-render.css +1 -0
- package/dist/types/apis/monitor.d.ts +9 -0
- package/dist/types/apis/tingwu.d.ts +14 -0
- package/dist/types/apis/types.d.ts +23 -0
- package/dist/types/components/TreeRecursive.vue.d.ts +7 -0
- package/dist/types/components/TreeRender.vue.d.ts +9 -0
- package/dist/types/components/collections/async/AsyncError.vue.d.ts +3 -0
- package/dist/types/components/collections/async/AsyncLoading.vue.d.ts +3 -0
- package/dist/types/components/collections/attachment/AttachmentBlock.vue.d.ts +7 -0
- package/dist/types/components/collections/attachment/AttachmentInline.vue.d.ts +7 -0
- package/dist/types/components/collections/attachment/AttachmentMenu.vue.d.ts +16 -0
- package/dist/types/components/collections/attachment/VideoDetail.vue.d.ts +7 -0
- package/dist/types/components/collections/attachment/index.d.ts +1 -0
- package/dist/types/components/collections/basic/Blockquote.vue.d.ts +17 -0
- package/dist/types/components/collections/basic/BulletList.vue.d.ts +17 -0
- package/dist/types/components/collections/basic/HardBreak.vue.d.ts +7 -0
- package/dist/types/components/collections/basic/Heading.vue.d.ts +17 -0
- package/dist/types/components/collections/basic/HorizontalRule.vue.d.ts +7 -0
- package/dist/types/components/collections/basic/ListItem.vue.d.ts +17 -0
- package/dist/types/components/collections/basic/OrderedList.vue.d.ts +17 -0
- package/dist/types/components/collections/basic/Paragraph.vue.d.ts +17 -0
- package/dist/types/components/collections/basic/Text.vue.d.ts +7 -0
- package/dist/types/components/collections/basic/index.d.ts +1 -0
- package/dist/types/components/collections/callout/Callout.vue.d.ts +7 -0
- package/dist/types/components/collections/callout/index.d.ts +1 -0
- package/dist/types/components/collections/code/CellOutput.vue.d.ts +7 -0
- package/dist/types/components/collections/code/CodeBlock.vue.d.ts +7 -0
- package/dist/types/components/collections/code/index.d.ts +1 -0
- package/dist/types/components/collections/fold/FoldBlock.vue.d.ts +7 -0
- package/dist/types/components/collections/fold/index.d.ts +1 -0
- package/dist/types/components/collections/grid/Grid.vue.d.ts +7 -0
- package/dist/types/components/collections/grid/index.d.ts +1 -0
- package/dist/types/components/collections/iframe/IFrame.vue.d.ts +7 -0
- package/dist/types/components/collections/iframe/index.d.ts +1 -0
- package/dist/types/components/collections/img/Image.vue.d.ts +7 -0
- package/dist/types/components/collections/img/index.d.ts +1 -0
- package/dist/types/components/collections/index.d.ts +1 -0
- package/dist/types/components/collections/math/MathDisplay.vue.d.ts +7 -0
- package/dist/types/components/collections/math/MathInline.vue.d.ts +7 -0
- package/dist/types/components/collections/math/index.d.ts +1 -0
- package/dist/types/components/collections/multipleChoice/McChoices.vue.d.ts +16 -0
- package/dist/types/components/collections/multipleChoice/McQuestion.vue.d.ts +7 -0
- package/dist/types/components/collections/multipleChoice/McSolution.vue.d.ts +8 -0
- package/dist/types/components/collections/multipleChoice/MultipleChoice.vue.d.ts +7 -0
- package/dist/types/components/collections/multipleChoice/index.d.ts +1 -0
- package/dist/types/components/collections/table/TableCell.vue.d.ts +17 -0
- package/dist/types/components/collections/table/TableContainer.vue.d.ts +17 -0
- package/dist/types/components/collections/table/TableHeader.vue.d.ts +17 -0
- package/dist/types/components/collections/table/TableRow.vue.d.ts +17 -0
- package/dist/types/components/collections/table/index.d.ts +1 -0
- package/dist/types/components/collections/utils.d.ts +2 -0
- package/dist/types/components/collections/wrapper/Doc.vue.d.ts +17 -0
- package/dist/types/components/collections/wrapper/SlotNode.vue.d.ts +13 -0
- package/dist/types/components/collections/wrapper/index.d.ts +1 -0
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/icons/Attachment/CardView.vue.d.ts +9 -0
- package/dist/types/icons/Attachment/Code/Bat.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/C.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Cpp.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Css.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Go.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Html.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Java.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Js.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Json.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Jsx.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Md.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Php.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Python.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Rb.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Sh.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Sql.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Swift.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Ts.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Tsx.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Code/Vue.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Excel.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Eye.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/FullScreen.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/InlineView.vue.d.ts +9 -0
- package/dist/types/icons/Attachment/Pdf.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Ppt.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/PreviewView.vue.d.ts +9 -0
- package/dist/types/icons/Attachment/UnknownFile.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/VideoIcon.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/VideoPlay.vue.d.ts +3 -0
- package/dist/types/icons/Attachment/Word.vue.d.ts +3 -0
- package/dist/types/icons/Code/Confirm.vue.d.ts +3 -0
- package/dist/types/icons/Code/Paste.vue.d.ts +3 -0
- package/dist/types/icons/Common/Choice.vue.d.ts +3 -0
- package/dist/types/icons/Common/Close.vue.d.ts +3 -0
- package/dist/types/icons/Common/Comment.vue.d.ts +3 -0
- package/dist/types/icons/Common/CopyAnchorLink.vue.d.ts +3 -0
- package/dist/types/icons/Common/Delete.vue.d.ts +3 -0
- package/dist/types/icons/Common/Download.vue.d.ts +3 -0
- package/dist/types/icons/Common/FoldClose.vue.d.ts +3 -0
- package/dist/types/icons/Common/FoldOpen.vue.d.ts +3 -0
- package/dist/types/icons/Common/Plate.vue.d.ts +3 -0
- package/dist/types/icons/Common/Question.vue.d.ts +3 -0
- package/dist/types/icons/Common/ShareTextLink.vue.d.ts +3 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/types.d.ts +269 -0
- package/dist/types/utils/common.d.ts +1 -0
- package/dist/types/utils/emoji.d.ts +10 -0
- package/dist/types/utils/globalStatus.d.ts +16 -0
- package/dist/types/utils/shiki.d.ts +3 -0
- package/dist/types/utils/useAttachment.d.ts +8 -0
- package/package.json +29 -0
- package/src/apis/monitor.ts +8 -0
- package/src/apis/tingwu.ts +22 -0
- package/src/apis/types.ts +45 -0
- package/src/components/TreeRecursive.vue +47 -0
- package/src/components/TreeRender.vue +404 -0
- package/src/components/collections/async/AsyncError.vue +17 -0
- package/src/components/collections/async/AsyncLoading.vue +1 -0
- package/src/components/collections/attachment/AttachmentBlock.vue +561 -0
- package/src/components/collections/attachment/AttachmentInline.vue +90 -0
- package/src/components/collections/attachment/AttachmentMenu.vue +359 -0
- package/src/components/collections/attachment/VideoDetail.vue +375 -0
- package/src/components/collections/attachment/index.ts +6 -0
- package/src/components/collections/basic/Blockquote.vue +15 -0
- package/src/components/collections/basic/BulletList.vue +15 -0
- package/src/components/collections/basic/HardBreak.vue +11 -0
- package/src/components/collections/basic/Heading.vue +15 -0
- package/src/components/collections/basic/HorizontalRule.vue +11 -0
- package/src/components/collections/basic/ListItem.vue +15 -0
- package/src/components/collections/basic/OrderedList.vue +15 -0
- package/src/components/collections/basic/Paragraph.vue +19 -0
- package/src/components/collections/basic/Text.vue +73 -0
- package/src/components/collections/basic/index.ts +13 -0
- package/src/components/collections/callout/Callout.vue +77 -0
- package/src/components/collections/callout/index.ts +5 -0
- package/src/components/collections/code/CellOutput.vue +72 -0
- package/src/components/collections/code/CodeBlock.vue +83 -0
- package/src/components/collections/code/index.ts +6 -0
- package/src/components/collections/fold/FoldBlock.vue +130 -0
- package/src/components/collections/fold/index.ts +5 -0
- package/src/components/collections/grid/Grid.vue +70 -0
- package/src/components/collections/grid/index.ts +5 -0
- package/src/components/collections/iframe/IFrame.vue +19 -0
- package/src/components/collections/iframe/index.ts +5 -0
- package/src/components/collections/img/Image.vue +318 -0
- package/src/components/collections/img/index.ts +5 -0
- package/src/components/collections/index.ts +29 -0
- package/src/components/collections/math/MathDisplay.vue +42 -0
- package/src/components/collections/math/MathInline.vue +42 -0
- package/src/components/collections/math/index.ts +6 -0
- package/src/components/collections/multipleChoice/McChoices.vue +72 -0
- package/src/components/collections/multipleChoice/McQuestion.vue +61 -0
- package/src/components/collections/multipleChoice/McSolution.vue +47 -0
- package/src/components/collections/multipleChoice/MultipleChoice.vue +62 -0
- package/src/components/collections/multipleChoice/index.ts +8 -0
- package/src/components/collections/table/TableCell.vue +20 -0
- package/src/components/collections/table/TableContainer.vue +32 -0
- package/src/components/collections/table/TableHeader.vue +15 -0
- package/src/components/collections/table/TableRow.vue +15 -0
- package/src/components/collections/table/index.ts +8 -0
- package/src/components/collections/utils.ts +17 -0
- package/src/components/collections/wrapper/Doc.vue +15 -0
- package/src/components/collections/wrapper/SlotNode.vue +5 -0
- package/src/components/collections/wrapper/index.ts +6 -0
- package/src/components/index.ts +1 -0
- package/src/icons/Attachment/CardView.vue +21 -0
- package/src/icons/Attachment/Code/Bat.vue +26 -0
- package/src/icons/Attachment/Code/C.vue +26 -0
- package/src/icons/Attachment/Code/Cpp.vue +26 -0
- package/src/icons/Attachment/Code/Css.vue +34 -0
- package/src/icons/Attachment/Code/Go.vue +26 -0
- package/src/icons/Attachment/Code/Html.vue +34 -0
- package/src/icons/Attachment/Code/Java.vue +42 -0
- package/src/icons/Attachment/Code/Js.vue +26 -0
- package/src/icons/Attachment/Code/Json.vue +26 -0
- package/src/icons/Attachment/Code/Jsx.vue +30 -0
- package/src/icons/Attachment/Code/Md.vue +26 -0
- package/src/icons/Attachment/Code/Php.vue +26 -0
- package/src/icons/Attachment/Code/Python.vue +30 -0
- package/src/icons/Attachment/Code/Rb.vue +26 -0
- package/src/icons/Attachment/Code/Sh.vue +30 -0
- package/src/icons/Attachment/Code/Sql.vue +30 -0
- package/src/icons/Attachment/Code/Swift.vue +26 -0
- package/src/icons/Attachment/Code/Ts.vue +26 -0
- package/src/icons/Attachment/Code/Tsx.vue +30 -0
- package/src/icons/Attachment/Code/Vue.vue +24 -0
- package/src/icons/Attachment/Excel.vue +26 -0
- package/src/icons/Attachment/Eye.vue +15 -0
- package/src/icons/Attachment/FullScreen.vue +15 -0
- package/src/icons/Attachment/InlineView.vue +21 -0
- package/src/icons/Attachment/Pdf.vue +25 -0
- package/src/icons/Attachment/Ppt.vue +26 -0
- package/src/icons/Attachment/PreviewView.vue +21 -0
- package/src/icons/Attachment/UnknownFile.vue +26 -0
- package/src/icons/Attachment/VideoIcon.vue +25 -0
- package/src/icons/Attachment/VideoPlay.vue +15 -0
- package/src/icons/Attachment/Word.vue +26 -0
- package/src/icons/Code/Confirm.vue +38 -0
- package/src/icons/Code/Paste.vue +8 -0
- package/src/icons/Common/Choice.vue +28 -0
- package/src/icons/Common/Close.vue +15 -0
- package/src/icons/Common/Comment.vue +16 -0
- package/src/icons/Common/CopyAnchorLink.vue +15 -0
- package/src/icons/Common/Delete.vue +15 -0
- package/src/icons/Common/Download.vue +15 -0
- package/src/icons/Common/FoldClose.vue +9 -0
- package/src/icons/Common/FoldOpen.vue +9 -0
- package/src/icons/Common/Plate.vue +23 -0
- package/src/icons/Common/Question.vue +8 -0
- package/src/icons/Common/ShareTextLink.vue +15 -0
- package/src/index.ts +3 -0
- package/src/types.ts +236 -0
- package/src/utils/common.ts +6 -0
- package/src/utils/emoji.ts +3715 -0
- package/src/utils/globalStatus.ts +19 -0
- package/src/utils/shiki.ts +25 -0
- package/src/utils/useAttachment.ts +215 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +23 -0
- package/vite.config.ts +24 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import type { PMNode } from "@datawhale/dipwap-types/index";
|
|
3
|
+
|
|
4
|
+
export const imageNodes = ref<PMNode[]>([]);
|
|
5
|
+
export const imageNodesKey = Symbol();
|
|
6
|
+
|
|
7
|
+
export const getAllImageNodes = (node: PMNode): PMNode[] => {
|
|
8
|
+
const imageNodes: PMNode[] = [];
|
|
9
|
+
const traverse = (currentNode: PMNode) => {
|
|
10
|
+
if (currentNode.type === "image") {
|
|
11
|
+
imageNodes.push(currentNode);
|
|
12
|
+
}
|
|
13
|
+
if (currentNode.content) {
|
|
14
|
+
currentNode.content.forEach((child: PMNode) => traverse(child));
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
traverse(node);
|
|
18
|
+
return imageNodes;
|
|
19
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type HighlighterCore, createHighlighterCoreSync } from 'shiki/core';
|
|
2
|
+
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
|
|
3
|
+
import bash from 'shiki/langs/bash.mjs';
|
|
4
|
+
import c from 'shiki/langs/c.mjs';
|
|
5
|
+
import json from 'shiki/langs/json.mjs';
|
|
6
|
+
import markdown from 'shiki/langs/markdown.mjs';
|
|
7
|
+
import python from 'shiki/langs/python.mjs';
|
|
8
|
+
import sql from 'shiki/langs/sql.mjs';
|
|
9
|
+
import minLight from 'shiki/themes/min-light.mjs';
|
|
10
|
+
|
|
11
|
+
const jsEngine = createJavaScriptRegexEngine();
|
|
12
|
+
const langs = { python, sql, json, bash, markdown, c };
|
|
13
|
+
export const supportedLangs = ['text', ...Object.keys(langs)];
|
|
14
|
+
let highlighter: HighlighterCore | null = null;
|
|
15
|
+
|
|
16
|
+
export function getHighlighter() {
|
|
17
|
+
if (!highlighter) {
|
|
18
|
+
highlighter = createHighlighterCoreSync({
|
|
19
|
+
themes: [minLight],
|
|
20
|
+
langs: Object.values(langs),
|
|
21
|
+
engine: jsEngine,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return highlighter;
|
|
25
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { type Component } from 'vue';
|
|
2
|
+
import BatIcon from '../icons/Attachment/Code/Bat.vue';
|
|
3
|
+
import CIcon from '../icons/Attachment/Code/C.vue';
|
|
4
|
+
import CppIcon from '../icons/Attachment/Code/Cpp.vue';
|
|
5
|
+
import CssIcon from '../icons/Attachment/Code/Css.vue';
|
|
6
|
+
import GoIcon from '../icons/Attachment/Code/Go.vue';
|
|
7
|
+
import HtmlIcon from '../icons/Attachment/Code/Html.vue';
|
|
8
|
+
import JavaIcon from '../icons/Attachment/Code/Java.vue';
|
|
9
|
+
import JsIcon from '../icons/Attachment/Code/Js.vue';
|
|
10
|
+
import JsonIcon from '../icons/Attachment/Code/Json.vue';
|
|
11
|
+
import JsxIcon from '../icons/Attachment/Code/Jsx.vue';
|
|
12
|
+
import MdIcon from '../icons/Attachment/Code/Md.vue';
|
|
13
|
+
import PhpIcon from '../icons/Attachment/Code/Php.vue';
|
|
14
|
+
import PythonIcon from '../icons/Attachment/Code/Python.vue';
|
|
15
|
+
import RbIcon from '../icons/Attachment/Code/Rb.vue';
|
|
16
|
+
import ShIcon from '../icons/Attachment/Code/Sh.vue';
|
|
17
|
+
import SqlIcon from '../icons/Attachment/Code/Sql.vue';
|
|
18
|
+
import SwiftIcon from '../icons/Attachment/Code/Swift.vue';
|
|
19
|
+
import TsIcon from '../icons/Attachment/Code/Ts.vue';
|
|
20
|
+
import TsxIcon from '../icons/Attachment/Code/Tsx.vue';
|
|
21
|
+
import VueIcon from '../icons/Attachment/Code/Vue.vue';
|
|
22
|
+
import ExcelIcon from '../icons/Attachment/Excel.vue';
|
|
23
|
+
import PdfIcon from '../icons/Attachment/Pdf.vue';
|
|
24
|
+
import PptIcon from '../icons/Attachment/Ppt.vue';
|
|
25
|
+
import CommonIcon from '../icons/Attachment/UnknownFile.vue';
|
|
26
|
+
import VideoIcon from '../icons/Attachment/VideoIcon.vue';
|
|
27
|
+
import WordIcon from '../icons/Attachment/Word.vue';
|
|
28
|
+
|
|
29
|
+
export function useAttachment(fileType: string, fileSize: number) {
|
|
30
|
+
// TODO: 需要补充更多文件类型的图标
|
|
31
|
+
const icons: { type: string; icon: Component }[] = [
|
|
32
|
+
{
|
|
33
|
+
type: 'pdf',
|
|
34
|
+
icon: PdfIcon,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'docx',
|
|
38
|
+
icon: WordIcon,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
type: 'doc',
|
|
42
|
+
icon: WordIcon,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'xlsx',
|
|
46
|
+
icon: ExcelIcon,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: 'xls',
|
|
50
|
+
icon: ExcelIcon,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'pptx',
|
|
54
|
+
icon: PptIcon,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: 'ppt',
|
|
58
|
+
icon: PptIcon,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: 'mp4',
|
|
62
|
+
icon: VideoIcon,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'avi',
|
|
66
|
+
icon: VideoIcon,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'mkv',
|
|
70
|
+
icon: VideoIcon,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: 'mov',
|
|
74
|
+
icon: VideoIcon,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
type: 'py',
|
|
78
|
+
icon: PythonIcon,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
type: 'js',
|
|
82
|
+
icon: JsIcon,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
type: 'ts',
|
|
86
|
+
icon: TsIcon,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
type: 'jsx',
|
|
90
|
+
icon: JsxIcon,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
type: 'tsx',
|
|
94
|
+
icon: TsxIcon,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
type: 'html',
|
|
98
|
+
icon: HtmlIcon,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
type: 'css',
|
|
102
|
+
icon: CssIcon,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
type: 'vue',
|
|
106
|
+
icon: VueIcon,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: 'json',
|
|
110
|
+
icon: JsonIcon,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
type: 'md',
|
|
114
|
+
icon: MdIcon,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
type: 'cpp',
|
|
118
|
+
icon: CppIcon,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
type: 'c',
|
|
122
|
+
icon: CIcon,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
type: 'java',
|
|
126
|
+
icon: JavaIcon,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
type: 'sql',
|
|
130
|
+
icon: SqlIcon,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
type: 'php',
|
|
134
|
+
icon: PhpIcon,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
type: 'go',
|
|
138
|
+
icon: GoIcon,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
type: 'swift',
|
|
142
|
+
icon: SwiftIcon,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
type: 'rb',
|
|
146
|
+
icon: RbIcon,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
type: 'sh',
|
|
150
|
+
icon: ShIcon,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
type: 'bat',
|
|
154
|
+
icon: BatIcon,
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
type: 'common',
|
|
158
|
+
icon: CommonIcon,
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
const icon = icons.find((item) => item.type === fileType)?.icon || CommonIcon;
|
|
163
|
+
|
|
164
|
+
const previewRules = [
|
|
165
|
+
{
|
|
166
|
+
// 可以通过iframe直接传入文件url进行预览的文件类型
|
|
167
|
+
allowTypes: ['pdf', 'json', 'mp4', 'avi', 'mkv', 'mov'],
|
|
168
|
+
srcRule: (src: string) => src,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
// 可以通过officeapps预览的文件类型
|
|
172
|
+
allowTypes: ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'],
|
|
173
|
+
srcRule: (src: string) => `https://view.officeapps.live.com/op/embed.aspx?src=${src}`,
|
|
174
|
+
},
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
// 是否可以预览
|
|
178
|
+
const canPreview = previewRules.some((rule) => rule.allowTypes.includes(fileType));
|
|
179
|
+
|
|
180
|
+
// 生成预览链接
|
|
181
|
+
const genPreviewSrc = (src: string) => {
|
|
182
|
+
for (const rule of previewRules) {
|
|
183
|
+
if (rule.allowTypes.includes(fileType)) {
|
|
184
|
+
return rule.srcRule(src);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return '';
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// 文件无法预览的图片的base64
|
|
191
|
+
const cannotPreviewImgDataUrl =
|
|
192
|
+
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCIgdmlld0JveD0iMCAwIDEyMCAxMjAiIGZpbGw9Im5vbmU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xsPSIjMDBENkI5Ii8+PHBhdGggZD0iTTQzLjI3OCAxMDcuMDkydi04LjY5NEMzMC4xIDk2LjI4NCAxOC4wNzUgOTMuOTAzIDcuMDEgODUuMDU1Yy0uMzM0LS4yNjgtLjY2Ny0uNTQtMS0uODJ2OS41MjRjNy45OCA3LjY5NyAyMy44NTcgMTEuMjA1IDM2LjI3IDEzLjE3Ni4zMzUuMDU0LjY2OS4xMDYgMSAuMTU3Wk03LjAxIDkzLjMyOXYtNy4wMDFjMTAuODc1IDguNDM2IDIyLjY0NCAxMC44NzYgMzUuMjcgMTIuOTIxdjYuNjc0Yy01Ljk4LS45NTQtMTIuNzItMi4yNjItMTguOTY5LTQuMjE2LTYuNTAzLTIuMDMzLTEyLjM3LTQuNzM1LTE2LjMtOC4zNzhaIiBmaWxsPSIjMEMyOTZFIi8+PC9zdmc+';
|
|
193
|
+
|
|
194
|
+
// 根据文件大小选择合适的单位
|
|
195
|
+
const calculateFileSize = (fileSize: number) => {
|
|
196
|
+
if (fileSize === undefined) {
|
|
197
|
+
return '未知大小';
|
|
198
|
+
}
|
|
199
|
+
if (fileSize / 1024 / 1024 < 1) {
|
|
200
|
+
return (fileSize / 1024).toFixed(2) + 'KB';
|
|
201
|
+
} else if (fileSize / 1024 / 1024 / 1024 < 1) {
|
|
202
|
+
return (fileSize / 1024 / 1024).toFixed(2) + 'MB';
|
|
203
|
+
} else {
|
|
204
|
+
return (fileSize / 1024 / 1024 / 1024).toFixed(2) + 'GB';
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
icon,
|
|
210
|
+
canPreview,
|
|
211
|
+
genPreviewSrc,
|
|
212
|
+
cannotPreviewImgDataUrl,
|
|
213
|
+
calculatedFileSize: calculateFileSize(fileSize),
|
|
214
|
+
};
|
|
215
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@vue/tsconfig/tsconfig.dom.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
5
|
+
"types": ["vite/client", "node"],
|
|
6
|
+
|
|
7
|
+
/* Linting */
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noUnusedLocals": true,
|
|
10
|
+
"noUnusedParameters": true,
|
|
11
|
+
"erasableSyntaxOnly": false,
|
|
12
|
+
"noFallthroughCasesInSwitch": true,
|
|
13
|
+
"noUncheckedSideEffectImports": true,
|
|
14
|
+
|
|
15
|
+
"baseUrl": ".",
|
|
16
|
+
"paths": {
|
|
17
|
+
"@datawhale/dipwap-types/index": ["src/types.ts"],
|
|
18
|
+
"@datawhale/dipwap-render/*": ["src/*"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
|
|
22
|
+
"exclude": ["node_modules", "dist"]
|
|
23
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
import vue from "@vitejs/plugin-vue";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [vue()],
|
|
7
|
+
resolve: {
|
|
8
|
+
alias: {
|
|
9
|
+
"@datawhale/dipwap-types/index": path.resolve(__dirname, "src/types.ts"),
|
|
10
|
+
"@datawhale/dipwap-render": path.resolve(__dirname, "src"),
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
build: {
|
|
14
|
+
lib: {
|
|
15
|
+
entry: path.resolve(__dirname, "src/index.ts"),
|
|
16
|
+
name: "MyLib",
|
|
17
|
+
formats: ["es", "cjs"],
|
|
18
|
+
fileName: (format) => `index.${format}.js`,
|
|
19
|
+
},
|
|
20
|
+
rollupOptions: {
|
|
21
|
+
external: ["vue"], // vue 不要打进你的库
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
});
|