mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
Add Tables feature to the Editor (#340)
* Install table extension * Add the table extension to editor * Add table button to toolbar * Fix packages * Add table icon * Add table style * Change table style * Add buttons to add rows and columns * Add buttons to remove columns and rows * Fix resize icon
This commit is contained in:
parent
e6979ed1b4
commit
ba6d17827b
4 changed files with 154 additions and 0 deletions
|
|
@ -25,6 +25,10 @@ import { ComputerIcon, Eye, Monitor } from 'lucide-react'
|
|||
import MathEquationBlock from './Extensions/MathEquation/MathEquationBlock'
|
||||
import PDFBlock from './Extensions/PDF/PDFBlock'
|
||||
import QuizBlock from './Extensions/Quiz/QuizBlock'
|
||||
import Table from '@tiptap/extension-table'
|
||||
import TableCell from '@tiptap/extension-table-cell'
|
||||
import TableHeader from '@tiptap/extension-table-header'
|
||||
import TableRow from '@tiptap/extension-table-row'
|
||||
import ToolTip from '@components/StyledElements/Tooltip/Tooltip'
|
||||
import Link from 'next/link'
|
||||
import { getCourseThumbnailMediaDirectory } from '@services/media/media'
|
||||
|
|
@ -149,6 +153,12 @@ function Editor(props: Editor) {
|
|||
editable: true,
|
||||
activity: props.activity,
|
||||
}),
|
||||
Table.configure({
|
||||
resizable: true,
|
||||
}),
|
||||
TableRow,
|
||||
TableHeader,
|
||||
TableCell,
|
||||
|
||||
// Add Collaboration and CollaborationCursor only if isCollabEnabledOnThisOrg is true
|
||||
...(props.isCollabEnabledOnThisOrg ? [
|
||||
|
|
@ -551,6 +561,16 @@ export const EditorContentWrapper = styled.div`
|
|||
font-weight: 700;
|
||||
}
|
||||
}
|
||||
|
||||
&.resize-cursor {
|
||||
cursor: ew-resize;
|
||||
cursor: col-resize;
|
||||
}
|
||||
|
||||
.tableWrapper {
|
||||
margin: 1.5rem 0;
|
||||
overflow-x: auto;
|
||||
}
|
||||
}
|
||||
|
||||
iframe {
|
||||
|
|
@ -570,6 +590,53 @@ export const EditorContentWrapper = styled.div`
|
|||
padding-left: 20px;
|
||||
list-style-type: decimal;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
table-layout: fixed;
|
||||
width: 100%;
|
||||
|
||||
td,
|
||||
th {
|
||||
border: 1px solid rgba(139, 139, 139, 0.4);
|
||||
box-sizing: border-box;
|
||||
min-width: 1em;
|
||||
padding: 6px 8px;
|
||||
position: relative;
|
||||
vertical-align: top;
|
||||
|
||||
> * {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: rgba(217, 217, 217, 0.4);
|
||||
font-weight: bold;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.selectedCell:after {
|
||||
background: rgba(139, 139, 139, 0.2);
|
||||
content: "";
|
||||
left: 0; right: 0; top: 0; bottom: 0;
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.column-resize-handle {
|
||||
background-color: #8d78eb;
|
||||
bottom: -2px;
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
right: -2px;
|
||||
top: 0;
|
||||
width: 4px;
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export default Editor
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@ import {
|
|||
ArrowRightIcon,
|
||||
DividerVerticalIcon,
|
||||
ListBulletIcon,
|
||||
TableIcon,
|
||||
RowsIcon,
|
||||
ColumnsIcon,
|
||||
SectionIcon,
|
||||
ContainerIcon,
|
||||
} from '@radix-ui/react-icons'
|
||||
import {
|
||||
AlertCircle,
|
||||
|
|
@ -92,6 +97,34 @@ export const ToolbarButtons = ({ editor, props }: any) => {
|
|||
<option value="5">Heading 5</option>
|
||||
<option value="6">Heading 6</option>
|
||||
</ToolSelect>
|
||||
<DividerVerticalIcon
|
||||
style={{ marginTop: 'auto', marginBottom: 'auto', color: 'grey' }}
|
||||
/>
|
||||
<ToolBtn content={'Create table'}
|
||||
onClick={() => editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run()}
|
||||
>
|
||||
<TableIcon/>
|
||||
</ToolBtn>
|
||||
<ToolBtn content={'Insert row'}
|
||||
onClick={() => editor.chain().focus().addRowAfter().run()}
|
||||
>
|
||||
<RowsIcon/>
|
||||
</ToolBtn>
|
||||
<ToolBtn content={'Insert column'}
|
||||
onClick={() => editor.chain().focus().addColumnAfter().run()}
|
||||
>
|
||||
<ColumnsIcon/>
|
||||
</ToolBtn>
|
||||
<ToolBtn content={'Remove column'}
|
||||
onClick={() => editor.chain().focus().deleteColumn().run()}
|
||||
>
|
||||
<ContainerIcon/>
|
||||
</ToolBtn>
|
||||
<ToolBtn content={'Remove row'}
|
||||
onClick={() => editor.chain().focus().deleteRow().run()}
|
||||
>
|
||||
<SectionIcon/>
|
||||
</ToolBtn>
|
||||
{/* TODO: fix this : toggling only works one-way */}
|
||||
<DividerVerticalIcon
|
||||
style={{ marginTop: 'auto', marginBottom: 'auto', color: 'grey' }}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@
|
|||
"@tiptap/extension-code-block-lowlight": "^2.8.0",
|
||||
"@tiptap/extension-collaboration": "^2.8.0",
|
||||
"@tiptap/extension-collaboration-cursor": "^2.8.0",
|
||||
"@tiptap/extension-table": "^2.8.0",
|
||||
"@tiptap/extension-table-cell": "^2.8.0",
|
||||
"@tiptap/extension-table-header": "^2.8.0",
|
||||
"@tiptap/extension-table-row": "^2.8.0",
|
||||
"@tiptap/extension-youtube": "^2.8.0",
|
||||
"@tiptap/html": "^2.8.0",
|
||||
"@tiptap/pm": "^2.8.0",
|
||||
|
|
|
|||
50
apps/web/pnpm-lock.yaml
generated
50
apps/web/pnpm-lock.yaml
generated
|
|
@ -65,6 +65,18 @@ importers:
|
|||
'@tiptap/extension-collaboration-cursor':
|
||||
specifier: ^2.8.0
|
||||
version: 2.8.0(@tiptap/core@2.8.0(@tiptap/pm@2.8.0))(y-prosemirror@1.2.12(prosemirror-model@1.23.0)(prosemirror-state@1.4.3)(prosemirror-view@1.34.3)(y-protocols@1.0.6(yjs@13.6.19))(yjs@13.6.19))
|
||||
'@tiptap/extension-table':
|
||||
specifier: ^2.8.0
|
||||
version: 2.8.0(@tiptap/core@2.8.0(@tiptap/pm@2.8.0))(@tiptap/pm@2.8.0)
|
||||
'@tiptap/extension-table-cell':
|
||||
specifier: ^2.8.0
|
||||
version: 2.8.0(@tiptap/core@2.8.0(@tiptap/pm@2.8.0))
|
||||
'@tiptap/extension-table-header':
|
||||
specifier: ^2.8.0
|
||||
version: 2.8.0(@tiptap/core@2.8.0(@tiptap/pm@2.8.0))
|
||||
'@tiptap/extension-table-row':
|
||||
specifier: ^2.8.0
|
||||
version: 2.8.0(@tiptap/core@2.8.0(@tiptap/pm@2.8.0))
|
||||
'@tiptap/extension-youtube':
|
||||
specifier: ^2.8.0
|
||||
version: 2.8.0(@tiptap/core@2.8.0(@tiptap/pm@2.8.0))
|
||||
|
|
@ -1586,6 +1598,27 @@ packages:
|
|||
peerDependencies:
|
||||
'@tiptap/core': ^2.7.0
|
||||
|
||||
'@tiptap/extension-table-cell@2.8.0':
|
||||
resolution: {integrity: sha512-IZpxONWyOd474L8+k4bHrFNRhbsl9eRwbNs5O877JkVFItc2WUz1DIhbJzjmBRsqExtWQJuOsiqWFab1kpiwGQ==}
|
||||
peerDependencies:
|
||||
'@tiptap/core': ^2.7.0
|
||||
|
||||
'@tiptap/extension-table-header@2.8.0':
|
||||
resolution: {integrity: sha512-B67A96yMQlG96IFzZBc7D5dnn7O29hcjuDLtjyZkKvU5D/RlFKPMmC9nVphCV3CnbkvEOZUdK9pNaOpen64naw==}
|
||||
peerDependencies:
|
||||
'@tiptap/core': ^2.7.0
|
||||
|
||||
'@tiptap/extension-table-row@2.8.0':
|
||||
resolution: {integrity: sha512-Iezej6l7X+WqKzGLmCgAwmpL+QsfjFv1g8yVH5d0/3Pkcj3G9nDn+GSm4bZnbfYFyqInHG94PZ5PMReiALrJtA==}
|
||||
peerDependencies:
|
||||
'@tiptap/core': ^2.7.0
|
||||
|
||||
'@tiptap/extension-table@2.8.0':
|
||||
resolution: {integrity: sha512-dm9CitjacXyJuE5SZfV2lUc3uOiP2sxo6fygIzMz7iuxHqQueyONWG+TBkK7HjqzXOiMPsvOf/25NazzIG8HMg==}
|
||||
peerDependencies:
|
||||
'@tiptap/core': ^2.7.0
|
||||
'@tiptap/pm': ^2.7.0
|
||||
|
||||
'@tiptap/extension-text-style@2.8.0':
|
||||
resolution: {integrity: sha512-jJp0vcZ2Ty7RvIL0VU6dm1y+fTfXq1lN2GwtYzYM0ueFuESa+Qo8ticYOImyWZ3wGJGVrjn7OV9r0ReW0/NYkQ==}
|
||||
peerDependencies:
|
||||
|
|
@ -5492,6 +5525,23 @@ snapshots:
|
|||
dependencies:
|
||||
'@tiptap/core': 2.8.0(@tiptap/pm@2.8.0)
|
||||
|
||||
'@tiptap/extension-table-cell@2.8.0(@tiptap/core@2.8.0(@tiptap/pm@2.8.0))':
|
||||
dependencies:
|
||||
'@tiptap/core': 2.8.0(@tiptap/pm@2.8.0)
|
||||
|
||||
'@tiptap/extension-table-header@2.8.0(@tiptap/core@2.8.0(@tiptap/pm@2.8.0))':
|
||||
dependencies:
|
||||
'@tiptap/core': 2.8.0(@tiptap/pm@2.8.0)
|
||||
|
||||
'@tiptap/extension-table-row@2.8.0(@tiptap/core@2.8.0(@tiptap/pm@2.8.0))':
|
||||
dependencies:
|
||||
'@tiptap/core': 2.8.0(@tiptap/pm@2.8.0)
|
||||
|
||||
'@tiptap/extension-table@2.8.0(@tiptap/core@2.8.0(@tiptap/pm@2.8.0))(@tiptap/pm@2.8.0)':
|
||||
dependencies:
|
||||
'@tiptap/core': 2.8.0(@tiptap/pm@2.8.0)
|
||||
'@tiptap/pm': 2.8.0
|
||||
|
||||
'@tiptap/extension-text-style@2.8.0(@tiptap/core@2.8.0(@tiptap/pm@2.8.0))':
|
||||
dependencies:
|
||||
'@tiptap/core': 2.8.0(@tiptap/pm@2.8.0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue