Skip to content

Commit

Permalink
fix:文件复制粘贴报错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
luoluoTH committed Jan 8, 2025
1 parent 357afd8 commit 5b663b6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {useNodeViewContext} from "@prosemirror-adapter/react"
import {useInViewport, useMemoizedFn} from "ahooks"
import React, {useState, useEffect, useRef} from "react"
import {TextSelection} from "@milkdown/kit/prose/state"
import {useInstance} from "@milkdown/react"
import {paragraphSchema} from "@milkdown/kit/preset/commonmark"

export const CustomCodeComponent: React.FC = () => {
const {node, view, getPos} = useNodeViewContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ $fileDivHeight: 64px;
user-select: none;
position: relative;
cursor: pointer;
margin-bottom: 20px;
.file-custom-content {
display: flex;
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {getHttpFileLinkInfo, getLocalFileLinkInfo} from "./utils"
import {setClipboardText} from "@/utils/clipboard"
import {getFileNameByUrl} from "../utils/trackDeletePlugin"
import {httpDeleteOSSResource} from "@/apiUtils/http"
import {useInstance} from "@milkdown/react"
import {useStore} from "@/store"
import {YakitSpin} from "@/components/yakitUI/YakitSpin/YakitSpin"

Expand Down Expand Up @@ -279,6 +278,7 @@ export const CustomFile: React.FC<CustomFileProps> = (props) => {
return (
<>
<div
contentEditable={false}
className={classNames(styles["file-custom"], {
[styles["file-custom-selected"]]: selected
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export const fileCustomAttr = $nodeAttr("file-custom", () => ({
}))

export const fileCustomSchema = $nodeSchema(fileCustomId, (ctx) => ({
inline: true,
group: "inline",
group: "block",
content: "",
atom: true,
draggable: false,
Expand All @@ -32,14 +31,20 @@ export const fileCustomSchema = $nodeSchema(fileCustomId, (ctx) => ({

// 将节点转为 DOM 结构,动态设置样式
toDOM: (node) => {
// console.log("toDOM", node)
return ["div", 0]
const attrs = {
...ctx.get(fileCustomAttr.key)(node),
"data-file-id": node.attrs.fileId,
"data-path": node.attrs.path,
"data-notepad-hash": node.attrs.notepadHash,
"data-upload-user-id": node.attrs.uploadUserId
}
return ["div", {...attrs}]
},

parseMarkdown: {
match: (node) => {
const {type, name} = node
return type === "textDirective" && name === "file"
return type === "containerDirective" && name === "file"
},
runner: (state, node, type) => {
if (type.name === fileCustomId) {
Expand All @@ -53,14 +58,12 @@ export const fileCustomSchema = $nodeSchema(fileCustomId, (ctx) => ({

toMarkdown: {
match: (node) => {
// console.log("toMarkdown-match", node)
return node.type.name === fileCustomId
},
runner: (state, node) => {
// console.log("toMarkdown-runner", node)
if (node.attrs.fileId) {
state
.openNode("textDirective", undefined, {
.openNode("containerDirective", undefined, {
name: "file",
attributes: {
fileId: node.attrs.fileId,
Expand Down

0 comments on commit 5b663b6

Please sign in to comment.