From bff944bba2a76d3906c62aabdc06576dfc163258 Mon Sep 17 00:00:00 2001 From: an-lee Date: Mon, 2 Dec 2024 09:25:51 +0800 Subject: [PATCH] Feat document layout (#1218) * add layout config for document * may config document layout for player * set default * update shadow media layout per document layout --- enjoy/src/i18n/en.json | 5 +++- enjoy/src/i18n/zh-CN.json | 5 +++- enjoy/src/main/db/models/document.ts | 6 +++++ .../documents/document-config-form.tsx | 27 +++++++++++++++++++ .../renderer/context/document-provider.tsx | 2 +- enjoy/src/renderer/pages/document.tsx | 9 +++++-- enjoy/src/types/document.d.ts | 1 + 7 files changed, 50 insertions(+), 5 deletions(-) diff --git a/enjoy/src/i18n/en.json b/enjoy/src/i18n/en.json index 60480c45..698b3a15 100644 --- a/enjoy/src/i18n/en.json +++ b/enjoy/src/i18n/en.json @@ -933,5 +933,8 @@ "myPronunciation": "My pronunciation", "originalPronunciation": "Original pronunciation", "reloadApp": "reload app", - "exit": "Exit" + "exit": "Exit", + "layout": "Layout", + "horizontal": "Horizontal", + "vertical": "Vertical" } diff --git a/enjoy/src/i18n/zh-CN.json b/enjoy/src/i18n/zh-CN.json index 25ccd18d..954f0f32 100644 --- a/enjoy/src/i18n/zh-CN.json +++ b/enjoy/src/i18n/zh-CN.json @@ -933,5 +933,8 @@ "myPronunciation": "我的发音", "originalPronunciation": "原始发音", "reloadApp": "重载应用", - "exit": "退出" + "exit": "退出", + "layout": "布局", + "horizontal": "水平", + "vertical": "垂直" } diff --git a/enjoy/src/main/db/models/document.ts b/enjoy/src/main/db/models/document.ts index 370fab76..c8e68c30 100644 --- a/enjoy/src/main/db/models/document.ts +++ b/enjoy/src/main/db/models/document.ts @@ -83,6 +83,11 @@ export class Document extends Model { return this.config.autoNextSpeech || false; } + @Column(DataType.VIRTUAL) + get layout(): "horizontal" | "vertical" { + return this.config.layout || "horizontal"; + } + @Column(DataType.VIRTUAL) get ttsConfig(): Record { return this.config.tts || {}; @@ -310,6 +315,7 @@ export class Document extends Model { config = { autoTranslate: false, autoNextSpeech: true, + layout: "horizontal", tts: { engine: "enjoyai", model: "openai/tts-1", diff --git a/enjoy/src/renderer/components/documents/document-config-form.tsx b/enjoy/src/renderer/components/documents/document-config-form.tsx index 6837601e..ea3703a3 100644 --- a/enjoy/src/renderer/components/documents/document-config-form.tsx +++ b/enjoy/src/renderer/components/documents/document-config-form.tsx @@ -7,6 +7,11 @@ import { FormField, FormItem, FormLabel, + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, Switch, } from "@renderer/components/ui"; import { t } from "i18next"; @@ -19,6 +24,7 @@ const documentConfigSchema = z.object({ config: z.object({ autoTranslate: z.boolean(), autoNextSpeech: z.boolean(), + layout: z.enum(["horizontal", "vertical"]), tts: z.object({ engine: z.string(), model: z.string(), @@ -92,6 +98,27 @@ export const DocumentConfigForm = (props: { )} /> + ( + + {t("layout")} + + + )} + /> + diff --git a/enjoy/src/renderer/context/document-provider.tsx b/enjoy/src/renderer/context/document-provider.tsx index b4b7fab8..b8afc810 100644 --- a/enjoy/src/renderer/context/document-provider.tsx +++ b/enjoy/src/renderer/context/document-provider.tsx @@ -254,7 +254,7 @@ export function DocumentProvider({ }} > togglePlayingSegment(null)} >
{children}
diff --git a/enjoy/src/renderer/pages/document.tsx b/enjoy/src/renderer/pages/document.tsx index 2dc9983f..e160995f 100644 --- a/enjoy/src/renderer/pages/document.tsx +++ b/enjoy/src/renderer/pages/document.tsx @@ -58,7 +58,10 @@ const DocumentComponent = () => { - + { ; config: Record; + layout: "horizontal" | "vertical"; autoTranslate: boolean; autoNextSpeech: boolean; ttsConfig: Record;