Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

[WEB-459] fix: tables row color retention, images in tables and css fixes (#3748)

M. Palanikannane0a4d7a12a46
diff --git a/packages/editor/core/src/lib/editor-commands.ts b/packages/editor/core/src/lib/editor-commands.ts
index 4a56f07c2d..6524d1ff58 100644
--- a/packages/editor/core/src/lib/editor-commands.ts
+++ b/packages/editor/core/src/lib/editor-commands.ts
@@ -97,8 +97,8 @@ export const insertTableCommand = (editor: Editor, range?: Range) => {
}
}
}
- if (range) editor.chain().focus().deleteRange(range).insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run();
- else editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run();
+ if (range) editor.chain().focus().deleteRange(range).insertTable({ rows: 3, cols: 3 }).run();
+ else editor.chain().focus().insertTable({ rows: 3, cols: 3 }).run();
};
export const unsetLinkEditor = (editor: Editor) => {
diff --git a/packages/editor/core/src/styles/editor.css b/packages/editor/core/src/styles/editor.css
index b0d2a10213..dbbea671eb 100644
--- a/packages/editor/core/src/styles/editor.css
+++ b/packages/editor/core/src/styles/editor.css
@@ -170,68 +170,6 @@ ul[data-type="taskList"] li[data-checked="true"] > div > p {
}
}
-#editor-container {
- table {
- border-collapse: collapse;
- table-layout: fixed;
- margin: 0.5em 0 0.5em 0;
-
- border: 1px solid rgb(var(--color-border-200));
- width: 100%;
-
- td,
- th {
- min-width: 1em;
- border: 1px solid rgb(var(--color-border-200));
- padding: 10px 15px;
- vertical-align: top;
- box-sizing: border-box;
- position: relative;
- transition: background-color 0.3s ease;
-
- > * {
- margin-bottom: 0;
- }
- }
-
- th {
- font-weight: bold;
- text-align: left;
- background-color: rgb(var(--color-primary-100));
- }
-
- td:hover {
- background-color: rgba(var(--color-primary-300), 0.1);
- }
-
- .selectedCell:after {
- z-index: 2;
- position: absolute;
- content: "";
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- background-color: rgba(var(--color-primary-300), 0.1);
- pointer-events: none;
- }
-
- .column-resize-handle {
- position: absolute;
- right: -2px;
- top: 0;
- bottom: -2px;
- width: 2px;
- background-color: rgb(var(--color-primary-400));
- pointer-events: none;
- }
- }
-}
-
-.tableWrapper {
- overflow-x: auto;
-}
-
.resize-cursor {
cursor: ew-resize;
cursor: col-resize;
diff --git a/packages/editor/core/src/styles/table.css b/packages/editor/core/src/styles/table.css
index 8a47a8c59f..ca384d34fc 100644
--- a/packages/editor/core/src/styles/table.css
+++ b/packages/editor/core/src/styles/table.css
@@ -9,15 +9,15 @@
border-collapse: collapse;
table-layout: fixed;
margin: 0;
- margin-bottom: 3rem;
- border: 1px solid rgba(var(--color-border-200));
+ margin-bottom: 1rem;
+ border: 2px solid rgba(var(--color-border-300));
width: 100%;
}
.tableWrapper table td,
.tableWrapper table th {
min-width: 1em;
- border: 1px solid rgba(var(--color-border-200));
+ border: 1px solid rgba(var(--color-border-300));
padding: 10px 15px;
vertical-align: top;
box-sizing: border-box;
@@ -43,7 +43,8 @@
.tableWrapper table th {
font-weight: bold;
text-align: left;
- background-color: rgba(var(--color-primary-100));
+ background-color: #d9e4ff;
+ color: #171717;
}
.tableWrapper table th * {
@@ -62,6 +63,35 @@
pointer-events: none;
}
+.colorPicker {
+ display: grid;
+ padding: 8px 8px;
+ grid-template-columns: repeat(6, 1fr);
+ gap: 5px;
+}
+
+.colorPickerLabel {
+ font-size: 0.85rem;
+ color: #6b7280;
+ padding: 8px 8px;
+ padding-bottom: 0px;
+}
+
+.colorPickerItem {
+ margin: 2px 0px;
+ width: 24px;
+ height: 24px;
+ border-radius: 4px;
+ border: none;
+ cursor: pointer;
+}
+
+.divider {
+ background-color: #e5e7eb;
+ height: 1px;
+ margin: 3px 0;
+}
+
.tableWrapper table .column-resize-handle {
position: absolute;
right: -2px;
@@ -69,7 +99,7 @@
bottom: -2px;
width: 4px;
z-index: 99;
- background-color: rgba(var(--color-primary-400));
+ background-color: #d9e4ff;
pointer-events: none;
}
@@ -112,7 +142,7 @@
}
.tableWrapper .tableControls .rowsControlDiv {
- background-color: rgba(var(--color-primary-100));
+ background-color: #d9e4ff;
border: 1px solid rgba(var(--color-border-200));
border-radius: 2px;
background-size: 1.25rem;
@@ -127,7 +157,7 @@
}
.tableWrapper .tableControls .columnsControlDiv {
- background-color: rgba(var(--color-primary-100));
+ background-color: #d9e4ff;
border: 1px solid rgba(var(--color-border-200));
border-radius: 2px;
background-size: 1.25rem;
@@ -144,10 +174,12 @@
.tableWrapper .tableControls .tableColorPickerToolbox {
border: 1px solid rgba(var(--color-border-300));
background-color: rgba(var(--color-background-100));
+ border-radius: 5px;
+ box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
padding: 0.25rem;
display: flex;
flex-direction: column;
- width: 200px;
+ width: max-content;
gap: 0.25rem;
}
@@ -158,7 +190,7 @@
align-items: center;
gap: 0.5rem;
border: none;
- padding: 0.1rem;
+ padding: 0.3rem 0.5rem 0.1rem 0.1rem;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s;
@@ -173,9 +205,7 @@
.tableWrapper .tableControls .tableColorPickerToolbox .toolboxItem .iconContainer,
.tableWrapper .tableControls .tableToolbox .toolboxItem .colorContainer,
.tableWrapper .tableControls .tableColorPickerToolbox .toolboxItem .colorContainer {
- border: 1px solid rgba(var(--color-border-300));
- border-radius: 3px;
- padding: 4px;
+ padding: 4px 0px;
display: flex;
align-items: center;
justify-content: center;
@@ -187,8 +217,8 @@
.tableWrapper .tableControls .tableColorPickerToolbox .toolboxItem .iconContainer svg,
.tableWrapper .tableControls .tableToolbox .toolboxItem .colorContainer svg,
.tableWrapper .tableControls .tableColorPickerToolbox .toolboxItem .colorContainer svg {
- width: 2rem;
- height: 2rem;
+ width: 1rem;
+ height: 1rem;
}
.tableToolbox {
diff --git a/packages/editor/core/src/ui/extensions/table/table-cell/table-cell.ts b/packages/editor/core/src/ui/extensions/table/table-cell/table-cell.ts
index aedb59411a..403bd3f02c 100644
--- a/packages/editor/core/src/ui/extensions/table/table-cell/table-cell.ts
+++ b/packages/editor/core/src/ui/extensions/table/table-cell/table-cell.ts
@@ -13,7 +13,7 @@ export const TableCell = Node.create<TableCellOptions>({
};
},
- content: "paragraph+",
+ content: "block+",
addAttributes() {
return {
@@ -33,7 +33,10 @@ export const TableCell = Node.create<TableCellOptions>({
},
},
background: {
- default: "none",
+ default: null,
+ },
+ textColor: {
+ default: null,
},
};
},
@@ -50,7 +53,7 @@ export const TableCell = Node.create<TableCellOptions>({
return [
"td",
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
- style: `background-color: ${node.attrs.background}`,
+ style: `background-color: ${node.attrs.background}; color: ${node.attrs.textColor}`,
}),
0,
];
diff --git a/packages/editor/core/src/ui/extensions/table/table-header/table-header.ts b/packages/editor/core/src/ui/extensions/table/table-header/table-header.ts
index c0decdbf80..bd994f467d 100644
--- a/packages/editor/core/src/ui/extensions/table/table-header/table-header.ts
+++ b/packages/editor/core/src/ui/extensions/table/table-header/table-header.ts
@@ -33,7 +33,7 @@ export const TableHeader = Node.create<TableHeaderOptions>({
},
},
background: {
- default: "rgb(var(--color-primary-100))",
+ default: "none",
},
};
},
diff --git a/packages/editor/core/src/ui/extensions/table/table-row/table-row.ts b/packages/editor/core/src/ui/extensions/table/table-row/table-row.ts
index 28c9a9a48e..f961c05824 100644
--- a/packages/editor/core/src/ui/extensions/table/table-row/table-row.ts
+++ b/packages/editor/core/src/ui/extensions/table/table-row/table-row.ts
@@ -13,6 +13,17 @@ export const TableRow = Node.create<TableRowOptions>({
};
},
+ addAttributes() {
+ return {
+ background: {
+ default: null,
+ },
+ textColor: {
+ default: null,
+ },
+ };
+ },
+
content: "(tableCell | tableHeader)*",
tableRole: "row",
@@ -22,6 +33,12 @@ export const TableRow = Node.create<TableRowOptions>({
},
renderHTML({ HTMLAttributes }) {
- return ["tr", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
+ const style = HTMLAttributes.background
+ ? `background-color: ${HTMLAttributes.background}; color: ${HTMLAttributes.textColor}`
+ : "";
+
+ const attributes = mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { style });
+
+ return ["tr", attributes, 0];
},
});
diff --git a/packages/editor/core/src/ui/extensions/table/table/icons.ts b/packages/editor/core/src/ui/extensions/table/table/icons.ts
index c08710ec32..f73c55c09f 100644
--- a/packages/editor/core/src/ui/extensions/table/table/icons.ts
+++ b/packages/editor/core/src/ui/extensions/table/table/icons.ts
@@ -1,7 +1,7 @@
export const icons = {
colorPicker: `<svg xmlns="http://www.w3.org/2000/svg" length="24" viewBox="0 0 24 24" style="transform: ;msFilter:;"><path fill="rgb(var(--color-text-300))" d="M20 14c-.092.064-2 2.083-2 3.5 0 1.494.949 2.448 2 2.5.906.044 2-.891 2-2.5 0-1.5-1.908-3.436-2-3.5zM9.586 20c.378.378.88.586 1.414.586s1.036-.208 1.414-.586l7-7-.707-.707L11 4.586 8.707 2.293 7.293 3.707 9.586 6 4 11.586c-.378.378-.586.88-.586 1.414s.208 1.036.586 1.414L9.586 20zM11 7.414 16.586 13H5.414L11 7.414z"></path></svg>`,
- deleteColumn: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" length="24"><path fill="#e53e3e" d="M0 0H24V24H0z"/><path d="M12 3c.552 0 1 .448 1 1v8c.835-.628 1.874-1 3-1 2.761 0 5 2.239 5 5s-2.239 5-5 5c-1.032 0-1.99-.313-2.787-.848L13 20c0 .552-.448 1-1 1H6c-.552 0-1-.448-1-1V4c0-.552.448-1 1-1h6zm-1 2H7v14h4V5zm8 10h-6v2h6v-2z"/></svg>`,
- deleteRow: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" length="24"><path fill="#e53e3e" d="M0 0H24V24H0z"/><path d="M20 5c.552 0 1 .448 1 1v6c0 .552-.448 1-1 1 .628.835 1 1.874 1 3 0 2.761-2.239 5-5 5s-5-2.239-5-5c0-1.126.372-2.165 1-3H4c-.552 0-1-.448-1-1V6c0-.552.448-1 1-1h16zm-7 10v2h6v-2h-6zm6-8H5v4h14V7z"/></svg>`,
+ deleteColumn: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trash-2"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg>`,
+ deleteRow: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trash-2"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg>`,
insertLeftTableIcon: `<svg
xmlns="http://www.w3.org/2000/svg"
length={24}
@@ -35,6 +35,8 @@ export const icons = {
/>
</svg>
`,
+ toggleColumnHeader: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="rgb(var(--color-text-300))" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-toggle-right"><rect width="20" height="12" x="2" y="6" rx="6" ry="6"/><circle cx="16" cy="12" r="2"/></svg>`,
+ toggleRowHeader: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="rgb(var(--color-text-300))" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-toggle-right"><rect width="20" height="12" x="2" y="6" rx="6" ry="6"/><circle cx="16" cy="12" r="2"/></svg>`,
insertBottomTableIcon: `<svg
xmlns="http://www.w3.org/2000/svg"
length={24}
diff --git a/packages/editor/core/src/ui/extensions/table/table/table-view.tsx b/packages/editor/core/src/ui/extensions/table/table/table-view.tsx
index bd96ff1b1d..674a8e1150 100644
--- a/packages/editor/core/src/ui/extensions/table/table/table-view.tsx
+++ b/packages/editor/core/src/ui/extensions/table/table/table-view.tsx
@@ -81,53 +81,75 @@ const defaultTippyOptions: Partial<Props> = {
placement: "right",
};
-function setCellsBackgroundColor(editor: Editor, backgroundColor: string) {
+function setCellsBackgroundColor(editor: Editor, color: { backgroundColor: string; textColor: string }) {
return editor
.chain()
.focus()
.updateAttributes("tableCell", {
- background: backgroundColor,
- })
- .updateAttributes("tableHeader", {
- background: backgroundColor,
+ background: color.backgroundColor,
+ textColor: color.textColor,
})
.run();
}
+function setTableRowBackgroundColor(editor: Editor, color: { backgroundColor: string; textColor: string }) {
+ const { state, dispatch } = editor.view;
+ const { selection } = state;
+ if (!(selection instanceof CellSelection)) {
+ return false;
+ }
+
+ // Get the position of the hovered cell in the selection to determine the row.
+ const hoveredCell = selection.$headCell || selection.$anchorCell;
+
+ // Find the depth of the table row node
+ let rowDepth = hoveredCell.depth;
+ while (rowDepth > 0 && hoveredCell.node(rowDepth).type.name !== "tableRow") {
+ rowDepth--;
+ }
+
+ // If we couldn't find a tableRow node, we can't set the background color
+ if (hoveredCell.node(rowDepth).type.name !== "tableRow") {
+ return false;
+ }
+
+ // Get the position where the table row starts
+ const rowStartPos = hoveredCell.start(rowDepth);
+
+ // Create a transaction that sets the background color on the tableRow node.
+ const tr = state.tr.setNodeMarkup(rowStartPos - 1, null, {
+ ...hoveredCell.node(rowDepth).attrs,
+ background: color.backgroundColor,
+ textColor: color.textColor,
+ });
+
+ dispatch(tr);
+ return true;
+}
+
const columnsToolboxItems: ToolboxItem[] = [
{
- label: "Add Column Before",
+ label: "Toggle column header",
+ icon: icons.toggleColumnHeader,
+ action: ({ editor }: { editor: Editor }) => editor.chain().focus().toggleHeaderColumn().run(),
+ },
+ {
+ label: "Add column before",
icon: icons.insertLeftTableIcon,
action: ({ editor }: { editor: Editor }) => editor.chain().focus().addColumnBefore().run(),
},
{
- label: "Add Column After",
+ label: "Add column after",
icon: icons.insertRightTableIcon,
action: ({ editor }: { editor: Editor }) => editor.chain().focus().addColumnAfter().run(),
},
{
- label: "Pick Column Color",
- icon: icons.colorPicker,
- action: ({
- editor,
- triggerButton,
- controlsContainer,
- }: {
- editor: Editor;
- triggerButton: HTMLElement;
- controlsContainer: Element;
- }) => {
- createColorPickerToolbox({
- triggerButton,
- tippyOptions: {
- appendTo: controlsContainer,
- },
- onSelectColor: (color) => setCellsBackgroundColor(editor, color),
- });
- },
+ label: "Pick color",
+ icon: "", // No icon needed for color picker
+ action: (args: any) => {}, // Placeholder action; actual color picking is handled in `createToolbox`
},
{
- label: "Delete Column",
+ label: "Delete column",
icon: icons.deleteColumn,
action: ({ editor }: { editor: Editor }) => editor.chain().focus().deleteColumn().run(),
},
@@ -135,35 +157,24 @@ const columnsToolboxItems: ToolboxItem[] = [
const rowsToolboxItems: ToolboxItem[] = [
{
- label: "Add Row Above",
+ label: "Toggle row header",
+ icon: icons.toggleRowHeader,
+ action: ({ editor }: { editor: Editor }) => editor.chain().focus().toggleHeaderRow().run(),
+ },
+ {
+ label: "Add row above",
icon: icons.insertTopTableIcon,
action: ({ editor }: { editor: Editor }) => editor.chain().focus().addRowBefore().run(),
},
{
- label: "Add Row Below",
+ label: "Add row below",
icon: icons.insertBottomTableIcon,
action: ({ editor }: { editor: Editor }) => editor.chain().focus().addRowAfter().run(),
},
{
- label: "Pick Row Color",
- icon: icons.colorPicker,
- action: ({
- editor,
- triggerButton,
- controlsContainer,
- }: {
- editor: Editor;
- triggerButton: HTMLButtonElement;
- controlsContainer: Element | "parent" | ((ref: Element) => Element) | undefined;
- }) => {
- createColorPickerToolbox({
- triggerButton,
- tippyOptions: {
- appendTo: controlsContainer,
- },
- onSelectColor: (color) => setCellsBackgroundColor(editor, color),
- });
- },
+ label: "Pick color",
+ icon: "",
+ action: (args: any) => {}, // Placeholder action; actual color picking is handled in `createToolbox`
},
{
label: "Delete Row",
@@ -176,107 +187,62 @@ function createToolbox({
triggerButton,
items,
tippyOptions,
+ onSelectColor,
onClickItem,
+ colors,
}: {
triggerButton: Element | null;
items: ToolboxItem[];
tippyOptions: any;
onClickItem: (item: ToolboxItem) => void;
+ onSelectColor: (color: { backgroundColor: string; textColor: string }) => void;
+ colors: { [key: string]: { backgroundColor: string; textColor: string; icon?: string } };
}): Instance<Props> {
// @ts-expect-error
const toolbox = tippy(triggerButton, {
content: h(
"div",
{ className: "tableToolbox" },
- items.map((item) =>
- h(
- "div",
- {
- className: "toolboxItem",
- itemType: "button",
- onClick() {
- onClickItem(item);
- },
- },
- [
- h("div", {
- className: "iconContainer",
- innerHTML: item.icon,
- }),
- h("div", { className: "label" }, item.label),
- ]
- )
- )
- ),
- ...tippyOptions,
- });
-
- return Array.isArray(toolbox) ? toolbox[0] : toolbox;
-}
-
-function createColorPickerToolbox({
- triggerButton,
- tippyOptions,
- onSelectColor = () => {},
-}: {
- triggerButton: HTMLElement;
- tippyOptions: Partial<Props>;
- onSelectColor?: (color: string) => void;
-}) {
- const items = {
- Default: "rgb(var(--color-primary-100))",
- Orange: "#FFE5D1",
- Grey: "#F1F1F1",
- Yellow: "#FEF3C7",
- Green: "#DCFCE7",
- Red: "#FFDDDD",
- Blue: "#D9E4FF",
- Pink: "#FFE8FA",
- Purple: "#E8DAFB",
- };
-
- const colorPicker = tippy(triggerButton, {
- ...defaultTippyOptions,
- content: h(
- "div",
- { className: "tableColorPickerToolbox" },
- Object.entries(items).map(([key, value]) =>
- h(
- "div",
- {
- className: "toolboxItem",
- itemType: "button",
- onClick: () => {
- onSelectColor(value);
- colorPicker.hide();
- },
- },
- [
- h("div", {
- className: "colorContainer",
- style: {
- backgroundColor: value,
- },
- }),
+ items.map((item, index) => {
+ if (item.label === "Pick color") {
+ return h("div", { className: "flex flex-col" }, [
+ h("div", { className: "divider" }),
+ h("div", { className: "colorPickerLabel" }, item.label),
h(
"div",
- {
- className: "label",
- },
- key
+ { className: "colorPicker grid" },
+ Object.entries(colors).map(([colorName, colorValue]) =>
+ h("div", {
+ className: "colorPickerItem",
+ style: `background-color: ${colorValue.backgroundColor};
+ color: ${colorValue.textColor || "inherit"};`,
+ innerHTML: colorValue?.icon || "",
+ onClick: () => onSelectColor(colorValue),
+ })
+ )
),
- ]
- )
- )
+ h("div", { className: "divider" }),
+ ]);
+ } else {
+ return h(
+ "div",
+ {
+ className: "toolboxItem",
+ itemType: "div",
+ onClick: () => onClickItem(item),
+ },
+ [
+ h("div", { className: "iconContainer", innerHTML: item.icon }),
+ h("div", { className: "label" }, item.label),
+ ]
+ );
+ }
+ })
),
- onHidden: (instance) => {
- instance.destroy();
- },
- showOnCreate: true,
...tippyOptions,
});
- return colorPicker;
+ return Array.isArray(toolbox) ? toolbox[0] : toolbox;
}
export class TableView implements NodeView {
@@ -347,10 +313,27 @@ export class TableView implements NodeView {
this.rowsControl,
this.columnsControl
);
+ const columnColors = {
+ Blue: { backgroundColor: "#D9E4FF", textColor: "#171717" },
+ Orange: { backgroundColor: "#FFEDD5", textColor: "#171717" },
+ Grey: { backgroundColor: "#F1F1F1", textColor: "#171717" },
+ Yellow: { backgroundColor: "#FEF3C7", textColor: "#171717" },
+ Green: { backgroundColor: "#DCFCE7", textColor: "#171717" },
+ Red: { backgroundColor: "#FFDDDD", textColor: "#171717" },
+ Pink: { backgroundColor: "#FFE8FA", textColor: "#171717" },
+ Purple: { backgroundColor: "#E8DAFB", textColor: "#171717" },
+ None: {
+ backgroundColor: "none",
+ textColor: "none",
+ icon: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="gray" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-ban"><circle cx="12" cy="12" r="10"/><path d="m4.9 4.9 14.2 14.2"/></svg>`,
+ },
+ };
this.columnsToolbox = createToolbox({
triggerButton: this.columnsControl.querySelector(".columnsControlDiv"),
items: columnsToolboxItems,
+ colors: columnColors,
+ onSelectColor: (color) => setCellsBackgroundColor(this.editor, color),
tippyOptions: {
...defaultTippyOptions,
appendTo: this.controls,
@@ -368,10 +351,12 @@ export class TableView implements NodeView {
this.rowsToolbox = createToolbox({
triggerButton: this.rowsControl.firstElementChild,
items: rowsToolboxItems,
+ colors: columnColors,
tippyOptions: {
...defaultTippyOptions,
appendTo: this.controls,
},
+ onSelectColor: (color) => setTableRowBackgroundColor(editor, color),
onClickItem: (item) => {
item.action({
editor: this.editor,
@@ -383,8 +368,6 @@ export class TableView implements NodeView {
});
}
- // Table
-
this.colgroup = h(
"colgroup",
null,
@@ -437,16 +420,19 @@ export class TableView implements NodeView {
}
updateControls() {
- const { hoveredTable: table, hoveredCell: cell } = Object.values(this.decorations).reduce((acc, curr) => {
- if (curr.spec.hoveredCell !== undefined) {
- acc["hoveredCell"] = curr.spec.hoveredCell;
- }
+ const { hoveredTable: table, hoveredCell: cell } = Object.values(this.decorations).reduce(
+ (acc, curr) => {
+ if (curr.spec.hoveredCell !== undefined) {
+ acc["hoveredCell"] = curr.spec.hoveredCell;
+ }
- if (curr.spec.hoveredTable !== undefined) {
- acc["hoveredTable"] = curr.spec.hoveredTable;
- }
- return acc;
- }, {} as Record<string, HTMLElement>) as any;
+ if (curr.spec.hoveredTable !== undefined) {
+ acc["hoveredTable"] = curr.spec.hoveredTable;
+ }
+ return acc;
+ },
+ {} as Record<string, HTMLElement>
+ ) as any;
if (table === undefined || cell === undefined) {
return this.root.classList.add("controls--disabled");
@@ -457,12 +443,12 @@ export class TableView implements NodeView {
const cellDom = this.editor.view.nodeDOM(cell.pos) as HTMLElement;
- if (!this.table) {
+ if (!this.table || !cellDom) {
return;
}
- const tableRect = this.table.getBoundingClientRect();
- const cellRect = cellDom.getBoundingClientRect();
+ const tableRect = this.table?.getBoundingClientRect();
+ const cellRect = cellDom?.getBoundingClientRect();
if (this.columnsControl) {
this.columnsControl.style.left = `${cellRect.left - tableRect.left - this.table.parentElement!.scrollLeft}px`;
diff --git a/packages/editor/core/src/ui/extensions/table/table/table.ts b/packages/editor/core/src/ui/extensions/table/table/table.ts
index 5600fd82a7..ef595eee20 100644
--- a/packages/editor/core/src/ui/extensions/table/table/table.ts
+++ b/packages/editor/core/src/ui/extensions/table/table/table.ts
@@ -107,10 +107,9 @@ export const Table = Node.create({
addCommands() {
return {
insertTable:
- ({ rows = 3, cols = 3, withHeaderRow = true } = {}) =>
+ ({ rows = 3, cols = 3, withHeaderRow = false } = {}) =>
({ tr, dispatch, editor }) => {
const node = createTable(editor.schema, rows, cols, withHeaderRow);
-
if (dispatch) {
const offset = tr.selection.anchor + 1;
diff --git a/packages/editor/core/src/ui/props.tsx b/packages/editor/core/src/ui/props.tsx
index 2aaeb4264c..1846efe475 100644
--- a/packages/editor/core/src/ui/props.tsx
+++ b/packages/editor/core/src/ui/props.tsx
@@ -42,15 +42,6 @@ export function CoreEditorProps(
return false;
},
handleDrop: (view, event, _slice, moved) => {
- if (typeof window !== "undefined") {
- const selection: any = window?.getSelection();
- if (selection.rangeCount !== 0) {
- const range = selection.getRangeAt(0);
- if (findTableAncestor(range.startContainer)) {
- return;
- }
- }
- }
if (!moved && event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {
event.preventDefault();
const file = event.dataTransfer.files[0];
diff --git a/packages/editor/document-editor/src/ui/menu/fixed-menu.tsx b/packages/editor/document-editor/src/ui/menu/fixed-menu.tsx
index be57a4a91c..397e8c576d 100644
--- a/packages/editor/document-editor/src/ui/menu/fixed-menu.tsx
+++ b/packages/editor/document-editor/src/ui/menu/fixed-menu.tsx
@@ -48,34 +48,12 @@ export const FixedMenu = (props: EditorBubbleMenuProps) => {
function getComplexItems(): BubbleMenuItem[] {
const items: BubbleMenuItem[] = [TableItem(editor)];
- if (shouldShowImageItem()) {
- items.push(ImageItem(editor, uploadFile, setIsSubmitting));
- }
-
+ items.push(ImageItem(editor, uploadFile, setIsSubmitting));
return items;
}
const complexItems: BubbleMenuItem[] = getComplexItems();
- function shouldShowImageItem(): boolean {
- if (typeof window !== "undefined") {
- const selectionRange: any = window?.getSelection();
- const { selection } = props.editor.state;
-
- if (selectionRange.rangeCount !== 0) {
- const range = selectionRange.getRangeAt(0);
- if (findTableAncestor(range.startContainer)) {
- return false;
- }
- if (isCellSelection(selection)) {
- return false;
- }
- }
- return true;
- }
- return false;
- }
-
return (
<div className="flex flex-wrap items-center divide-x divide-custom-border-200">
<div className="flex items-center gap-0.5 pr-2">
diff --git a/packages/editor/extensions/src/extensions/drag-drop.tsx b/packages/editor/extensions/src/extensions/drag-drop.tsx
index af99fec61f..ce4088413c 100644
--- a/packages/editor/extensions/src/extensions/drag-drop.tsx
+++ b/packages/editor/extensions/src/extensions/drag-drop.tsx
@@ -35,7 +35,7 @@ export interface DragHandleOptions {
}
function absoluteRect(node: Element) {
- const data = node.getBoundingClientRect();
+ const data = node?.getBoundingClientRect();
return {
top: data.top,
@@ -65,7 +65,7 @@ function nodeDOMAtCoords(coords: { x: number; y: number }) {
}
function nodePosAtDOM(node: Element, view: EditorView) {
- const boundingRect = node.getBoundingClientRect();
+ const boundingRect = node?.getBoundingClientRect();
if (node.nodeName === "IMG") {
return view.posAtCoords({
diff --git a/packages/editor/lite-text-editor/src/ui/menus/fixed-menu/index.tsx b/packages/editor/lite-text-editor/src/ui/menus/fixed-menu/index.tsx
index 71ad4e0e1c..c6786698dd 100644
--- a/packages/editor/lite-text-editor/src/ui/menus/fixed-menu/index.tsx
+++ b/packages/editor/lite-text-editor/src/ui/menus/fixed-menu/index.tsx
@@ -60,34 +60,13 @@ export const FixedMenu = (props: EditorBubbleMenuProps) => {
function getComplexItems(): BubbleMenuItem[] {
const items: BubbleMenuItem[] = [TableItem(props.editor)];
- if (shouldShowImageItem()) {
- items.push(ImageItem(props.editor, props.uploadFile, props.setIsSubmitting));
- }
+ items.push(ImageItem(props.editor, props.uploadFile, props.setIsSubmitting));
return items;
}
const complexItems: BubbleMenuItem[] = getComplexItems();
- function shouldShowImageItem(): boolean {
- if (typeof window !== "undefined") {
- const selectionRange: any = window?.getSelection();
- const { selection } = props.editor.state;
-
- if (selectionRange.rangeCount !== 0) {
- const range = selectionRange.getRangeAt(0);
- if (findTableAncestor(range.startContainer)) {
- return false;
- }
- if (isCellSelection(selection)) {
- return false;
- }
- }
- return true;
- }
- return false;
- }
-
const handleAccessChange = (accessKey: string) => {
props.commentAccessSpecifier?.onAccessChange(accessKey);
};