Skip to content

Commit

Permalink
feat: ✨ add table
Browse files Browse the repository at this point in the history
  • Loading branch information
isboyjc committed Dec 9, 2024
1 parent 5e8f197 commit b328799
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
"@tiptap/extension-strike": "^2.9.1",
"@tiptap/extension-subscript": "^2.9.1",
"@tiptap/extension-superscript": "^2.9.1",
"@tiptap/extension-table": "^2.10.3",
"@tiptap/extension-table-cell": "^2.10.3",
"@tiptap/extension-table-header": "^2.10.3",
"@tiptap/extension-table-row": "^2.10.3",
"@tiptap/extension-task-item": "^2.9.1",
"@tiptap/extension-task-list": "^2.9.1",
"@tiptap/extension-text": "^2.9.1",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/extensions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ export { default as Blockquote } from "./blockquote.js";
export { default as Divider } from "./divider.js";
export { default as HardBreak } from "./hard-break.js";
export { default as CodeBlock } from "./code-block.js";
export { default as Table } from "./table.js";
43 changes: 43 additions & 0 deletions packages/core/src/extensions/table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Table from "@tiptap/extension-table";
import TableRow from "@tiptap/extension-table-row";
import TableHeader from "@tiptap/extension-table-header";
import TableCell from "@tiptap/extension-table-cell";

export default Table.extend({
addOptions() {
return {
...this.parent?.(),
slash: true,
name: "table",
resizable: true,
desc: "",
command: ({ editor, range, params }) => {
range
? editor
.chain()
.focus()
.deleteRange(range)
.insertTable({
rows: params?.rows || 3,
cols: params?.cols || 3,
withHeaderRow: params?.withHeaderRow || false,
})
.run()
: editor.commands.insertTable({
rows: params?.rows || 3,
cols: params?.cols || 3,
withHeaderRow: params?.withHeaderRow || false,
});
},
isActive: ({ editor }) => editor.isActive("table"),
isDisabled: ({ editor }) => !editor.can().insertTable(),
HTMLAttributes: {
class: "table",
},
};
},

addExtensions() {
return [TableRow, TableHeader, TableCell];
},
});
5 changes: 5 additions & 0 deletions packages/core/src/kit/notion-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
Background,
TextStyle,
CodeBlock,
Table,
} from "@/extensions";

export default BasicKit.extend({
Expand Down Expand Up @@ -144,6 +145,10 @@ export default BasicKit.extend({
extensions.push(CodeBlock.configure(this.options?.codeBlock));
}

if (this.options.table !== false) {
extensions.push(Table.configure(this.options?.table));
}

return extensions;
},
});
1 change: 1 addition & 0 deletions packages/core/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"alignCenter": "Align Center",
"alignRight": "Align Right",
"alignJustify": "Align Justify",
"table": "Table",

"edit": "Edit",
"textClear": "Clear",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"alignCenter": "居中对齐",
"alignRight": "右对齐",
"alignJustify": "两端对齐",
"table": "表格",

"edit": "编辑",
"textClear": "清除",
Expand Down
1 change: 1 addition & 0 deletions packages/vue3/src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@use "link";
@use "selection";
@use "code-block";
@use "table";

@use "menu";
@use "ui";
3 changes: 2 additions & 1 deletion packages/vue3/src/styles/placeholder.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
text-align: inherit;
}

.#{$prefix}-node-empty::before {
pre.#{$prefix}-node-empty::before,
p.#{$prefix}-node-empty::before {
content: attr(data-placeholder);
float: left;
color: var(--#{$prefix}-text-color-2);
Expand Down
63 changes: 63 additions & 0 deletions packages/vue3/src/styles/table.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@use "config" as *;

.#{$prefix}.ProseMirror {
table {
border-collapse: collapse;
table-layout: fixed;
width: 100%;
margin: 0;
margin-top: var(--#{$prefix}-margin);
overflow-x: auto;
overflow-y: hidden;

td,
th {
min-width: 1em;
vertical-align: top;
box-sizing: border-box;
position: relative;
border: 1px solid rgba(var(--isle-editor-border-color-val), 1);
padding: 3px 5px;
box-sizing: border-box;

> * {
margin-bottom: 0;
}
}

th {
font-weight: bold;
text-align: left;
background-color: rgba(var(--isle-editor-border-color-val), 0.4);
}

.selectedCell:after {
z-index: 2;
position: absolute;
content: "";
left: 0;
right: 0;
top: 0;
bottom: 0;
background: rgba(var(--isle-editor-theme-primary-val), 0.3);
pointer-events: none;
}

.column-resize-handle {
position: absolute;
right: -2px;
top: 0;
bottom: -2px;
width: 4px;
background-color: var(--isle-editor-theme-selected);
cursor: col-resize;
}
.column-resize-handle:visited {
cursor: col-resize;
}

p {
margin: 0;
}
}
}
2 changes: 2 additions & 0 deletions packages/vue3/src/utils/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
WrapText as HardBreak,
ChevronDown as Down,
CodeXml as CodeBlock,
Table,
} from "lucide-vue-next";
const ICONS = {
Bold,
Expand Down Expand Up @@ -83,6 +84,7 @@ const ICONS = {
HardBreak,
Down,
CodeBlock,
Table,
};

export const getIcon = (name) => {
Expand Down
50 changes: 50 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b328799

Please sign in to comment.