From d9c4b669b2d28b3ddad07f300c7f1bcf388f7399 Mon Sep 17 00:00:00 2001 From: mlogclub Date: Sat, 18 Apr 2026 13:05:39 +0800 Subject: [PATCH] refactor(content-editor): enhance mode handling and integrate allowed modes across components --- .../content-editor/editor-mode-switch.tsx | 15 +++++++- .../components/content-editor/html-editor.tsx | 8 +++- dashboard/components/content-editor/index.tsx | 38 +++++++++++++++---- .../content-editor/markdown-editor.tsx | 5 ++- dashboard/components/content-editor/types.ts | 2 + 5 files changed, 57 insertions(+), 11 deletions(-) diff --git a/dashboard/components/content-editor/editor-mode-switch.tsx b/dashboard/components/content-editor/editor-mode-switch.tsx index b41a533..34b0e00 100644 --- a/dashboard/components/content-editor/editor-mode-switch.tsx +++ b/dashboard/components/content-editor/editor-mode-switch.tsx @@ -2,10 +2,14 @@ import { cn } from "@/lib/utils" -import type { ContentMode } from "./types" +import { + CONTENT_MODE_OPTIONS, + type ContentMode, +} from "./types" type EditorModeSwitchProps = { value: ContentMode + allowedModes?: ReadonlyArray disabled?: boolean onChange: (nextMode: ContentMode) => void } @@ -17,13 +21,20 @@ const MODE_OPTIONS: Array<{ value: ContentMode; label: string }> = [ export function EditorModeSwitch({ value, + allowedModes = CONTENT_MODE_OPTIONS, disabled = false, onChange, }: EditorModeSwitchProps) { + const options = MODE_OPTIONS.filter((option) => allowedModes.includes(option.value)) + + if (options.length <= 1) { + return null + } + return (
- {MODE_OPTIONS.map((option) => { + {options.map((option) => { const active = option.value === value return (