Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix: refine table editing

tianma-iffd02b75f9d55
diff --git a/apps/mobile/app.json b/apps/mobile/app.json
index 972f12ac..72bb98e4 100644
--- a/apps/mobile/app.json
+++ b/apps/mobile/app.json
@@ -3,7 +3,7 @@
"name": "EdgeEver",
"slug": "edgeever",
"scheme": "edgeever",
- "version": "1.3.0",
+ "version": "1.3.1",
"runtimeVersion": {
"policy": "appVersion"
},
@@ -28,7 +28,7 @@
},
"android": {
"package": "org.edgeever.mobile",
- "versionCode": 28,
+ "versionCode": 29,
"adaptiveIcon": {
"backgroundColor": "#d1fae5",
"backgroundImage": "./assets/icon.png",
diff --git a/apps/mobile/src/components/LocalTiptapEditor.tsx b/apps/mobile/src/components/LocalTiptapEditor.tsx
index 0b7a9981..0c2e9cad 100644
--- a/apps/mobile/src/components/LocalTiptapEditor.tsx
+++ b/apps/mobile/src/components/LocalTiptapEditor.tsx
@@ -21,6 +21,7 @@ import {
getMobileEditorPlaceholder,
getMobileEditorToolbarActionLabel,
getMobileEditorToolbarLabel,
+ isMobileEditorActionDisabledInTableHeader,
type MobileEditorTableActionId,
type MobileEditorToolbarActionId,
} from "@edgeever/shared/mobile-editor";
@@ -256,7 +257,8 @@ export default function LocalTiptapEditor(props: LocalTiptapEditorProps) {
(activeEditor?.isActive("bold") ? MOBILE_EDITOR_ACTIVE_FLAGS.bold : 0) |
(activeEditor?.isActive("bulletList") ? MOBILE_EDITOR_ACTIVE_FLAGS.bulletList : 0) |
(activeEditor?.isActive("blockquote") ? MOBILE_EDITOR_ACTIVE_FLAGS.blockquote : 0) |
- (activeEditor?.isActive("table") ? MOBILE_EDITOR_ACTIVE_FLAGS.table : 0),
+ (activeEditor?.isActive("table") ? MOBILE_EDITOR_ACTIVE_FLAGS.table : 0) |
+ (activeEditor?.isActive("tableHeader") ? MOBILE_EDITOR_ACTIVE_FLAGS.tableHeader : 0),
});
const insertImage = async () => {
@@ -292,7 +294,9 @@ export default function LocalTiptapEditor(props: LocalTiptapEditorProps) {
chain.addRowAfter().run();
return;
case "deleteTableRow":
- chain.deleteRow().run();
+ if (!editor?.isActive("tableHeader")) {
+ chain.deleteRow().run();
+ }
return;
case "addTableColumn":
chain.addColumnAfter().run();
@@ -349,7 +353,10 @@ export default function LocalTiptapEditor(props: LocalTiptapEditorProps) {
<ToolbarButton
key={action.id}
active={action.activeFlag > 0 && Boolean(toolbarState & action.activeFlag)}
- disabled={(action.requiresTable && !(toolbarState & MOBILE_EDITOR_ACTIVE_FLAGS.table)) || (action.id === "insertTable" && Boolean(toolbarState & MOBILE_EDITOR_ACTIVE_FLAGS.table))}
+ disabled={(action.requiresTable && !(toolbarState & MOBILE_EDITOR_ACTIVE_FLAGS.table))
+ || (action.id === "insertTable" && Boolean(toolbarState & MOBILE_EDITOR_ACTIVE_FLAGS.table))
+ || (isMobileEditorActionDisabledInTableHeader(action.id)
+ && Boolean(toolbarState & MOBILE_EDITOR_ACTIVE_FLAGS.tableHeader))}
icon={toolbarIcons[action.id]}
label={getMobileEditorToolbarActionLabel(action.id, props.locale)}
onRun={toolbarHandlers[action.id]}
@@ -912,10 +919,10 @@ const getEditorStyles = (theme: "light" | "dark") => `
.edgeever-editor-content code { border-radius: 4px; padding: 2px 4px; background: ${theme === "dark" ? "#1e293b" : "#f1f5f9"}; }
.edgeever-editor-content pre code { padding: 0; background: transparent; }
.edgeever-editor-content img { display: block; max-width: 100%; height: auto; margin: 14px auto; border-radius: 10px; }
- .edgeever-editor-content .tableWrapper { width: fit-content; max-width: 100%; overflow-x: auto; margin-top: 20px; margin-right: auto; margin-bottom: 20px; margin-left: auto; border: 1px solid ${theme === "dark" ? "#334155" : "#d8d8d8"}; border-radius: 2px; background: ${theme === "dark" ? "#0f172a" : "#fff"}; overscroll-behavior-inline: contain; scrollbar-color: rgba(100, 116, 139, 0.28) transparent; }
- .edgeever-editor-content table { width: 42rem; min-width: 42rem !important; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
- .edgeever-editor-content table col { width: auto !important; }
- .edgeever-editor-content th, .edgeever-editor-content td { position: relative; min-width: 7.5rem; border: 0; border-right: 1px solid ${theme === "dark" ? "#334155" : "#dedede"}; border-bottom: 1px solid ${theme === "dark" ? "#334155" : "#dedede"}; padding: 7px 12px; text-align: left; vertical-align: top; overflow-wrap: anywhere; line-height: 1.4; transition: background-color 120ms ease; }
+ .edgeever-editor-content .tableWrapper { width: fit-content; max-width: 100%; overflow-x: auto; margin-top: 20px; margin-right: auto; margin-bottom: 20px; margin-left: 0; border: 1px solid ${theme === "dark" ? "#334155" : "#d8d8d8"}; border-radius: 2px; background: ${theme === "dark" ? "#0f172a" : "#fff"}; overscroll-behavior-inline: contain; scrollbar-color: rgba(100, 116, 139, 0.28) transparent; }
+ .edgeever-editor-content table { width: max-content; min-width: 42rem !important; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
+ .edgeever-editor-content table col { width: 14rem !important; }
+ .edgeever-editor-content th, .edgeever-editor-content td { position: relative; width: 14rem; min-width: 14rem; border: 0; border-right: 1px solid ${theme === "dark" ? "#334155" : "#dedede"}; border-bottom: 1px solid ${theme === "dark" ? "#334155" : "#dedede"}; padding: 7px 12px; text-align: left; vertical-align: top; overflow-wrap: anywhere; line-height: 1.4; transition: background-color 120ms ease; }
.edgeever-editor-content th { background: ${theme === "dark" ? "#27303f" : "#f0f0f0"}; color: ${theme === "dark" ? "#f8fafc" : "#111827"}; font-size: 14px; font-weight: 700; }
.edgeever-editor-content th:last-child, .edgeever-editor-content td:last-child { border-right: 0; }
.edgeever-editor-content tr:last-child td { border-bottom: 0; }
diff --git a/apps/web/src/components/EditorTableMenu.tsx b/apps/web/src/components/EditorTableMenu.tsx
index 112e2ba6..680524c8 100644
--- a/apps/web/src/components/EditorTableMenu.tsx
+++ b/apps/web/src/components/EditorTableMenu.tsx
@@ -21,9 +21,12 @@ export const EditorTableMenu = ({ editor, readOnly }: EditorTableMenuProps) => {
const ready = Boolean(editor && !editor.isDestroyed);
const tableActiveState = useEditorState({
editor,
- selector: ({ editor: activeEditor }) => Boolean(activeEditor?.isActive("table")),
+ selector: ({ editor: activeEditor }) =>
+ (activeEditor?.isActive("table") ? 1 : 0)
+ | (activeEditor?.isActive("tableHeader") ? 2 : 0),
});
- const inTable = Boolean(tableActiveState);
+ const inTable = Boolean((tableActiveState ?? 0) & 1);
+ const inTableHeader = Boolean((tableActiveState ?? 0) & 2);
const disabled = readOnly || !ready;
const run = (command: (activeEditor: Editor) => void) => {
@@ -68,7 +71,14 @@ export const EditorTableMenu = ({ editor, readOnly }: EditorTableMenuProps) => {
<DropdownMenuItem disabled={!inTable} onSelect={() => run((activeEditor) => activeEditor.chain().focus().addRowAfter().run())}>
{t("editorToolbar.addTableRow")}
</DropdownMenuItem>
- <DropdownMenuItem disabled={!inTable} onSelect={() => run((activeEditor) => activeEditor.chain().focus().deleteRow().run())}>
+ <DropdownMenuItem
+ disabled={!inTable || inTableHeader}
+ onSelect={() => run((activeEditor) => {
+ if (!activeEditor.isActive("tableHeader")) {
+ activeEditor.chain().focus().deleteRow().run();
+ }
+ })}
+ >
{t("editorToolbar.deleteTableRow")}
</DropdownMenuItem>
<DropdownMenuItem disabled={!inTable} onSelect={() => run((activeEditor) => activeEditor.chain().focus().addColumnAfter().run())}>
diff --git a/apps/web/src/components/MobileStandaloneEditorParts.tsx b/apps/web/src/components/MobileStandaloneEditorParts.tsx
index cb60282c..616c9bb0 100644
--- a/apps/web/src/components/MobileStandaloneEditorParts.tsx
+++ b/apps/web/src/components/MobileStandaloneEditorParts.tsx
@@ -2,6 +2,7 @@ import { Bold, Check, ChevronDown, ImagePlus, List, Minus, Quote } from "lucide-
import {
MOBILE_EDITOR_TOOLBAR_ACTIONS,
getMobileEditorToolbarActionLabel,
+ isMobileEditorActionDisabledInTableHeader,
type MobileEditorTableActionId,
type MobileEditorToolbarActionId,
} from "@edgeever/shared/mobile-editor";
@@ -39,6 +40,7 @@ export const MobileEditorToolbar = ({
bulletListActive,
blockquoteActive,
tableActive,
+ tableHeaderActive,
onPickImage,
onToggleBold,
onToggleBulletList,
@@ -51,6 +53,7 @@ export const MobileEditorToolbar = ({
bulletListActive: boolean;
blockquoteActive: boolean;
tableActive: boolean;
+ tableHeaderActive: boolean;
onPickImage: () => void;
onToggleBold: () => void;
onToggleBulletList: () => void;
@@ -107,7 +110,10 @@ export const MobileEditorToolbar = ({
aria-label={label}
title={label}
aria-pressed={activeStates[id]}
- disabled={disabled || (requiresTable && !tableActive) || (id === "insertTable" && tableActive)}
+ disabled={disabled
+ || (requiresTable && !tableActive)
+ || (id === "insertTable" && tableActive)
+ || (isMobileEditorActionDisabledInTableHeader(id) && tableHeaderActive)}
onPointerDown={(event) => event.preventDefault()}
onClick={handlers[id]}
>
diff --git a/apps/web/src/components/MobileStandaloneTiptapEditor.tsx b/apps/web/src/components/MobileStandaloneTiptapEditor.tsx
index dbc8ef5b..24d86d89 100644
--- a/apps/web/src/components/MobileStandaloneTiptapEditor.tsx
+++ b/apps/web/src/components/MobileStandaloneTiptapEditor.tsx
@@ -797,6 +797,7 @@ export const MobileStandaloneTiptapEditor = ({
const fallbackMarkdown = memo ? docToMarkdown(contentJsonRef.current) : "";
const tableActive = Boolean(editor?.isActive("table"));
+ const tableHeaderActive = Boolean(editor?.isActive("tableHeader"));
const runEditorCommand = (command: () => boolean) => {
if (editorActionDisabled || !editor) {
@@ -820,7 +821,7 @@ export const MobileStandaloneTiptapEditor = ({
case "addTableRow":
return chain.addRowAfter().run();
case "deleteTableRow":
- return chain.deleteRow().run();
+ return editor?.isActive("tableHeader") ? false : chain.deleteRow().run();
case "addTableColumn":
return chain.addColumnAfter().run();
case "deleteTableColumn":
@@ -871,6 +872,7 @@ export const MobileStandaloneTiptapEditor = ({
bulletListActive={Boolean(editor?.isActive("bulletList"))}
blockquoteActive={Boolean(editor?.isActive("blockquote"))}
tableActive={tableActive}
+ tableHeaderActive={tableHeaderActive}
onPickImage={() => imageInputRef.current?.click()}
onToggleBold={() => runEditorCommand(() => editor?.chain().focus().toggleBold().run() ?? false)}
onToggleBulletList={() => runEditorCommand(() => editor?.chain().focus().toggleBulletList().run() ?? false)}
diff --git a/apps/web/src/styles/globals.css b/apps/web/src/styles/globals.css
index eca9a5b4..016eefed 100644
--- a/apps/web/src/styles/globals.css
+++ b/apps/web/src/styles/globals.css
@@ -540,7 +540,7 @@ textarea {
margin-top: 1.25rem;
margin-right: auto;
margin-bottom: 1.25rem;
- margin-left: auto;
+ margin-left: 0;
border: 1px solid #d8d8d8;
border-radius: 2px;
background: #fff;
@@ -550,7 +550,7 @@ textarea {
.ProseMirror table,
.markdown-content table {
- width: 42rem;
+ width: max-content;
min-width: 42rem !important;
border-collapse: separate;
border-spacing: 0;
@@ -559,7 +559,7 @@ textarea {
.ProseMirror table col,
.markdown-content table col {
- width: auto !important;
+ width: 14rem !important;
}
.ProseMirror th,
@@ -567,7 +567,8 @@ textarea {
.markdown-content th,
.markdown-content td {
position: relative;
- min-width: 7.5rem;
+ width: 14rem;
+ min-width: 14rem;
border: 0;
border-right: 1px solid #dedede;
border-bottom: 1px solid #dedede;
diff --git a/apps/web/src/styles/mobile-markdown-editor.css b/apps/web/src/styles/mobile-markdown-editor.css
index 24455ff5..0ced2679 100644
--- a/apps/web/src/styles/mobile-markdown-editor.css
+++ b/apps/web/src/styles/mobile-markdown-editor.css
@@ -461,7 +461,7 @@ input {
margin-top: 1.25rem;
margin-right: auto;
margin-bottom: 1.25rem;
- margin-left: auto;
+ margin-left: 0;
border: 1px solid #d8d8d8;
border-radius: 2px;
background: #fff;
@@ -470,7 +470,7 @@ input {
}
.edgeever-mobile-tiptap-content table {
- width: 42rem;
+ width: max-content;
min-width: 42rem !important;
border-collapse: separate;
border-spacing: 0;
@@ -478,13 +478,14 @@ input {
}
.edgeever-mobile-tiptap-content table col {
- width: auto !important;
+ width: 14rem !important;
}
.edgeever-mobile-tiptap-content th,
.edgeever-mobile-tiptap-content td {
position: relative;
- min-width: 7.5rem;
+ width: 14rem;
+ min-width: 14rem;
border: 0;
border-right: 1px solid #dedede;
border-bottom: 1px solid #dedede;
diff --git a/packages/shared/src/mobile-editor.test.mjs b/packages/shared/src/mobile-editor.test.mjs
index fb4d9214..2c0b7632 100644
--- a/packages/shared/src/mobile-editor.test.mjs
+++ b/packages/shared/src/mobile-editor.test.mjs
@@ -8,6 +8,7 @@ import {
getMobileEditorPlaceholder,
getMobileEditorToolbarActionLabel,
getMobileEditorToolbarLabel,
+ isMobileEditorActionDisabledInTableHeader,
} from "./mobile-editor.ts";
describe("mobile editor contract", () => {
@@ -29,6 +30,9 @@ describe("mobile editor contract", () => {
expect(MOBILE_EDITOR_TOOLBAR_ACTIONS.find(({ id }) => id === "bold")?.activeFlag).toBe(
MOBILE_EDITOR_ACTIVE_FLAGS.bold
);
+ expect(isMobileEditorActionDisabledInTableHeader("deleteTableRow")).toBe(true);
+ expect(isMobileEditorActionDisabledInTableHeader("deleteTableColumn")).toBe(false);
+ expect(MOBILE_EDITOR_ACTIVE_FLAGS.tableHeader & MOBILE_EDITOR_ACTIVE_FLAGS.table).toBe(0);
});
test("provides the same localized copy to both mobile clients", () => {
diff --git a/packages/shared/src/mobile-editor.ts b/packages/shared/src/mobile-editor.ts
index eae932e2..202f1c4e 100644
--- a/packages/shared/src/mobile-editor.ts
+++ b/packages/shared/src/mobile-editor.ts
@@ -24,6 +24,7 @@ export const MOBILE_EDITOR_ACTIVE_FLAGS = {
bulletList: 8,
blockquote: 16,
table: 32,
+ tableHeader: 64,
} as const;
export const MOBILE_EDITOR_TOOLBAR_ACTIONS = [
@@ -45,6 +46,10 @@ export const MOBILE_EDITOR_TOOLBAR_ACTIONS = [
requiresTable: boolean;
}>;
+export const isMobileEditorActionDisabledInTableHeader = (
+ action: MobileEditorToolbarActionId
+): boolean => action === "deleteTableRow";
+
const MOBILE_EDITOR_COPY = {
"zh-CN": {
placeholder: "开始记录...",