From 9a366636f2b69ca082c12e78b5c1543048f8f42f Mon Sep 17 00:00:00 2001 From: YuanShiJiLoong <2450829984@qq.com> Date: Tue, 3 Mar 2026 17:11:11 +0900 Subject: [PATCH] v1.1.10: fix settings folder creation/deletion, fix pdf-parse build error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix: clicking '+' on work node now creates folder (category) instead of item - Fix: built-in categories (人物设定, 空间/地点 etc.) no longer show delete button - Fix: user-created custom folders show proper add/rename/delete options on hover - Fix: pdf-parse build error by marking it as serverExternalPackage - Add locale keys: settings.newFolder (zh/en/ru) --- app/components/SettingsPanel.js | 13 ++++++------- app/components/SettingsTree.js | 7 ++++++- app/locales/en.json | 1 + app/locales/ru.json | 1 + app/locales/zh.json | 1 + next.config.mjs | 2 ++ package.json | 2 +- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/components/SettingsPanel.js b/app/components/SettingsPanel.js index f812549..1cbe11c 100644 --- a/app/components/SettingsPanel.js +++ b/app/components/SettingsPanel.js @@ -484,14 +484,13 @@ export default function SettingsPanel() { // 节点操作 const handleAddNode = async (parentId, category) => { - let cat = category || 'custom'; - if (parentId && !category) { - const parent = nodes.find(n => n.id === parentId); - if (parent) cat = parent.category; - } + const parent = parentId ? nodes.find(n => n.id === parentId) : null; + let cat = category || (parent ? parent.category : 'custom'); + // 如果父节点是作品节点,创建文件夹(大分类);否则创建条目 + const isParentWork = parent && parent.type === 'work'; const newNode = await addSettingsNode({ - name: t('settings.newItem'), - type: 'item', + name: isParentWork ? t('settings.newFolder') : t('settings.newItem'), + type: isParentWork ? 'folder' : 'item', category: cat, parentId, enabled: true, diff --git a/app/components/SettingsTree.js b/app/components/SettingsTree.js index aa35342..3ba4ec8 100644 --- a/app/components/SettingsTree.js +++ b/app/components/SettingsTree.js @@ -30,6 +30,11 @@ function TreeNode({ node, nodes, selectedId, onSelect, onAdd, onDelete, onRename const isFolder = node.type === 'folder' || node.type === 'special' || node.type === 'work'; const isWork = node.type === 'work'; const isRoot = node.parentId === null; + // 内置子分类(作品下的固定分类,如人物设定、空间/地点等)不可删除 + const builtinSuffixes = ['bookinfo', 'characters', 'locations', 'world', 'objects', 'plot', 'rules']; + const parentNode = node.parentId ? nodes.find(n => n.id === node.parentId) : null; + const isBuiltinCategory = parentNode && parentNode.type === 'work' && builtinSuffixes.some(s => node.id.endsWith('-' + s)); + const canDelete = !isRoot && !isBuiltinCategory; const isCollapsed = collapsedIds.has(node.id); const isSelected = selectedId === node.id; const isDisabled = node.enabled === false; @@ -138,7 +143,7 @@ function TreeNode({ node, nodes, selectedId, onSelect, onAdd, onDelete, onRename )} {/* 删除 */} - {!isRoot && ( + {canDelete && ( )} diff --git a/app/locales/en.json b/app/locales/en.json index 961daf2..4044f0c 100644 --- a/app/locales/en.json +++ b/app/locales/en.json @@ -25,6 +25,7 @@ "workLabel": "📕 Project:", "confirmBtn": "Confirm", "newItem": "New Item", + "newFolder": "New Category", "workNamePlaceholder": "Project Name...", "deleteWorkPrompt": "Are you sure you want to delete the project '{name}' and all its settings? This cannot be undone.", "deleteWorkAlert": "At least one project must remain.", diff --git a/app/locales/ru.json b/app/locales/ru.json index 72ad163..cfb7323 100644 --- a/app/locales/ru.json +++ b/app/locales/ru.json @@ -25,6 +25,7 @@ "workLabel": "📕 Проект:", "confirmBtn": "Подтвердить", "newItem": "Новый элемент", + "newFolder": "Новая категория", "workNamePlaceholder": "Название проекта...", "deleteWorkPrompt": "Вы уверены, что хотите удалить проект '{name}' и все его настройки? Это действие нельзя отменить.", "deleteWorkAlert": "Должен остаться хотя бы один проект.", diff --git a/app/locales/zh.json b/app/locales/zh.json index 134a49e..12d6a56 100644 --- a/app/locales/zh.json +++ b/app/locales/zh.json @@ -25,6 +25,7 @@ "workLabel": "📕 作品:", "confirmBtn": "确定", "newItem": "新条目", + "newFolder": "新分类", "workNamePlaceholder": "作品名称…", "deleteWorkPrompt": "确定删除作品「{name}」及其所有设定?此操作不可撤销。", "deleteWorkAlert": "至少需要保留一个作品", diff --git a/next.config.mjs b/next.config.mjs index 0dbb033..9f47928 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -2,6 +2,8 @@ const nextConfig = { output: 'standalone', devIndicators: false, + // pdf-parse 仅在服务端 API 路由中使用,将其标记为外部包避免打包解析 + serverExternalPackages: ['pdf-parse'], }; export default nextConfig; diff --git a/package.json b/package.json index ec47086..bebb8c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "author-app", - "version": "1.1.9", + "version": "1.1.10", "private": true, "main": "electron/main.js", "scripts": {