-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
343 additions
and
24 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,5 +1,6 @@ | ||
export default { | ||
plugins: { | ||
"tailwindcss/nesting": {}, | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,35 @@ | ||
import { NodeViewContent, NodeViewWrapper } from "@tiptap/react"; | ||
|
||
import { HiPlus } from "react-icons/hi2"; | ||
import props from "./types"; | ||
|
||
const TableView: React.FC<props> = ({ editor }) => { | ||
return ( | ||
<NodeViewWrapper> | ||
<div className="flex" autoCorrect="false" autoCapitalize="false"> | ||
<div> | ||
<NodeViewContent /> | ||
<button | ||
className="absolute w-[calc(100%-30px)] cursor-pointer border border-black/70 text-sm text-center bg-white border-dashed mt-1 py-1 opacity-0 hover:opacity-100 select-none" | ||
onClick={() => { | ||
editor.commands.addRowAfter(); | ||
}} | ||
> | ||
<HiPlus size={17} className="inline" /> | ||
</button> | ||
</div> | ||
|
||
<button | ||
className="block border border-black/70 text-sm text-center bg-white border-dashed opacity-0 hover:opacity-100 ml-1 px-1 select-none" | ||
onClick={() => { | ||
editor.commands.addColumnAfter(); | ||
}} | ||
> | ||
<HiPlus size={17} className="inline" /> | ||
</button> | ||
</div> | ||
</NodeViewWrapper> | ||
); | ||
}; | ||
|
||
export default TableView; |
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,57 @@ | ||
import { | ||
findParentNodeClosestToPos, | ||
KeyboardShortcutCommand, | ||
} from "@tiptap/core"; | ||
|
||
import { CellSelection } from "@tiptap/pm/tables"; | ||
|
||
export function isCellSelection(value: unknown): value is CellSelection { | ||
return value instanceof CellSelection; | ||
} | ||
|
||
export const DeleteCells: KeyboardShortcutCommand = ({ editor }) => { | ||
const { selection } = editor.state; | ||
|
||
if (!isCellSelection(selection)) { | ||
return false; | ||
} | ||
|
||
let cellCount = 0; | ||
const table = findParentNodeClosestToPos( | ||
selection.ranges[0].$from, | ||
(node) => { | ||
return node.type.name === "table"; | ||
}, | ||
); | ||
let numRows = 0; | ||
let numCols = 0; | ||
|
||
table?.node.descendants((node) => { | ||
if (node.type.name === "table") { | ||
return false; | ||
} | ||
if (node.type.name == "tableRow") { | ||
//@ts-ignore | ||
numCols = node.content.content.length; | ||
numRows += 1; | ||
} | ||
if (["tableCell", "tableHeader"].includes(node.type.name)) { | ||
cellCount += 1; | ||
} | ||
}); | ||
|
||
const allCellsSelected = cellCount === selection.ranges.length; | ||
if (allCellsSelected) { | ||
editor.commands.deleteTable(); | ||
return true; | ||
} else if (selection.ranges.length == numRows) { | ||
// delete column | ||
editor.commands.deleteColumn(); | ||
return true; | ||
} else if (selection.ranges.length == numCols) { | ||
// delete row | ||
editor.commands.deleteRow(); | ||
return true; | ||
} | ||
return false; | ||
}; |
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,6 +1,6 @@ | ||
import { type ClassValue, clsx } from "clsx" | ||
import { twMerge } from "tailwind-merge" | ||
import { type ClassValue, clsx } from "clsx"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
export function cn(...inputs: ClassValue[]) { | ||
return twMerge(clsx(inputs)) | ||
return twMerge(clsx(inputs)); | ||
} |
Oops, something went wrong.