-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
paragraph 和 garagraph 初分离,可能存在某些 bug
- Loading branch information
Showing
28 changed files
with
331 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
import styles from "./App.module.css"; | ||
import Editor from "../Editor/Editor"; | ||
import Sidebar from "../Sidebar/Sidebar"; | ||
import Debug from "../Debug/Debug"; | ||
import { useEffect, useState } from "react"; | ||
import { configTable } from "../../data/db"; | ||
import { newDocument, UUID } from "../../data/block"; | ||
import { Table } from "dexie"; | ||
import { DcConfigEntry } from "../../data/config"; | ||
import meta from "../../data/meta"; | ||
|
||
export default function App(){ | ||
const | ||
[cursorAnchor, setCursorAnchor] = useState(0), | ||
[cursorFocus, setCursorFocus] = useState(0), | ||
[docSize, setDocSize] = useState(0), | ||
[documentId, setDocumentId] = useState<UUID>("" as UUID); | ||
useEffect(()=>{(async ()=>{ | ||
const currentDocument = await (configTable as Table<DcConfigEntry<"currentDocument">, "currentDocument">).get("currentDocument"); | ||
if(!currentDocument || currentDocument.value === null) setDocumentId(await newDocument()); | ||
//检查文档是否是有效的。目前先不检查了 | ||
//else if() | ||
else setDocumentId(currentDocument.value); | ||
})()}, []); | ||
return(<> | ||
{meta.dev ? <Debug cursorAnchor={cursorAnchor} cursorFocus={cursorFocus} docSize={docSize} /> : null} | ||
<Sidebar /> | ||
<Editor /> | ||
<Editor debug={{setCursorAnchor, setDocSize, setCursorFocus}} documentId={documentId} /> | ||
</>); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
| ||
type Props = { | ||
cursorAnchor :number; | ||
cursorFocus :number; | ||
docSize :number; | ||
}; | ||
|
||
export default function Debug({cursorAnchor, cursorFocus, docSize} :Props){ | ||
return(<div style={{ | ||
position: "absolute", | ||
fontSize: ".9rem", | ||
top: "2rem", | ||
left: "2rem", | ||
zIndex: "6666666" | ||
}}> | ||
<div>pos: {cursorAnchor === cursorFocus ? cursorAnchor : `${cursorAnchor}-${cursorFocus}`}</div> | ||
<div>size: {docSize}</div> | ||
</div>); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { mergeAttributes, Node } from "@tiptap/core"; | ||
|
||
declare module "@tiptap/core"{ | ||
interface Commands<ReturnType>{ | ||
garagraph :{ | ||
setGaragraph :()=>ReturnType; | ||
} | ||
} | ||
} | ||
|
||
const Garagraph = Node.create({ | ||
name: "garagraph", | ||
content: "paragraph block*", | ||
group: "block groupable", | ||
draggable: true, | ||
parseHTML: ()=>[ | ||
{tag: "div.dc-gp"}, | ||
{tag: "div:has(div.dc-p)"} | ||
], | ||
renderHTML: ({HTMLAttributes})=>["div", mergeAttributes(HTMLAttributes, {class: "dc-gp"}), 0], | ||
addCommands(){return{ | ||
setGaragraph: ()=>({commands})=>commands.setNode(this.name), | ||
}}, | ||
}); | ||
|
||
export default Garagraph; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/components/Editor/extensions/technical/appendParagraph.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Extension } from "@tiptap/react"; | ||
|
||
declare module "@tiptap/core"{ | ||
interface Commands<ReturnType>{ | ||
appendParagraph :{ | ||
appendParagraph :()=>ReturnType; | ||
} | ||
} | ||
} | ||
|
||
const AppendParagraph = Extension.create({ | ||
name: "appendParagraph", | ||
addCommands(){return{ | ||
appendParagraph: ()=>({dispatch, tr, state, commands})=>{ | ||
if(!dispatch) return true; | ||
commands.insertContentAt(state.doc.content.size, {type: "paragraph"}); | ||
return true; | ||
} | ||
}} | ||
}); | ||
|
||
export default AppendParagraph; |
Oops, something went wrong.