1 import {EditorBasicButtonDefinition, EditorButtonDefinition} from "../../framework/buttons";
2 import tableIcon from "@icons/editor/table.svg";
3 import deleteIcon from "@icons/editor/table-delete.svg";
4 import deleteColumnIcon from "@icons/editor/table-delete-column.svg";
5 import deleteRowIcon from "@icons/editor/table-delete-row.svg";
6 import insertColumnAfterIcon from "@icons/editor/table-insert-column-after.svg";
7 import insertColumnBeforeIcon from "@icons/editor/table-insert-column-before.svg";
8 import insertRowAboveIcon from "@icons/editor/table-insert-row-above.svg";
9 import insertRowBelowIcon from "@icons/editor/table-insert-row-below.svg";
10 import {EditorUiContext} from "../../framework/core";
12 $getNodeFromSelection,
13 $selectionContainsNodeType
14 } from "../../../helpers";
15 import {$getSelection} from "lexical";
16 import {$isCustomTableNode} from "../../../nodes/custom-table";
18 $deleteTableColumn__EXPERIMENTAL,
19 $deleteTableRow__EXPERIMENTAL,
20 $insertTableColumn__EXPERIMENTAL,
21 $insertTableRow__EXPERIMENTAL,
23 } from "@lexical/table";
26 export const table: EditorBasicButtonDefinition = {
31 export const deleteTable: EditorButtonDefinition = {
32 label: 'Delete table',
34 action(context: EditorUiContext) {
35 context.editor.update(() => {
36 const table = $getNodeFromSelection($getSelection(), $isCustomTableNode);
47 export const deleteTableMenuAction: EditorButtonDefinition = {
50 isDisabled(selection) {
51 return !$selectionContainsNodeType(selection, $isTableNode);
55 export const insertRowAbove: EditorButtonDefinition = {
56 label: 'Insert row above',
57 icon: insertRowAboveIcon,
58 action(context: EditorUiContext) {
59 context.editor.update(() => {
60 $insertTableRow__EXPERIMENTAL(false);
68 export const insertRowBelow: EditorButtonDefinition = {
69 label: 'Insert row below',
70 icon: insertRowBelowIcon,
71 action(context: EditorUiContext) {
72 context.editor.update(() => {
73 $insertTableRow__EXPERIMENTAL(true);
81 export const deleteRow: EditorButtonDefinition = {
84 action(context: EditorUiContext) {
85 context.editor.update(() => {
86 $deleteTableRow__EXPERIMENTAL();
94 export const insertColumnBefore: EditorButtonDefinition = {
95 label: 'Insert column before',
96 icon: insertColumnBeforeIcon,
97 action(context: EditorUiContext) {
98 context.editor.update(() => {
99 $insertTableColumn__EXPERIMENTAL(false);
107 export const insertColumnAfter: EditorButtonDefinition = {
108 label: 'Insert column after',
109 icon: insertColumnAfterIcon,
110 action(context: EditorUiContext) {
111 context.editor.update(() => {
112 $insertTableColumn__EXPERIMENTAL(true);
120 export const deleteColumn: EditorButtonDefinition = {
121 label: 'Delete column',
122 icon: deleteColumnIcon,
123 action(context: EditorUiContext) {
124 context.editor.update(() => {
125 $deleteTableColumn__EXPERIMENTAL();