Skip to content

Commit 0e335ca

Browse files
committed
refactor: 重构 logStore/logEditorStore
- 将 id/index 等结构不变量提取到不依赖 pinia 的 normalize 中集中维护 - 移除 logStore 对 historyStore 的依赖,只保留查询/生命周期操作 - 将 logEditorStore 重命名为 logCommands - 将删除/重命名等用户编辑全部移动到 logCommands 中管理,不再由组件单独负责 - 所有 command 统一返回是否产生实际修改,no-op 不产生历史快照
1 parent ca60a29 commit 0e335ca

13 files changed

Lines changed: 328 additions & 428 deletions

File tree

src/components/desktop/SidebarRight.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ import { useActiveContext } from '@/composables/application/useActiveContext';
8181
import { useDraftValues } from '@/composables/application/useDraftValues';
8282
import { usePanelResize } from '@/composables/ui/usePanelResize';
8383
import { useLogStore } from '@/stores/project/logStore';
84-
import { useLogEditorStore } from '@/stores/project/logEditorStore';
84+
import { useLogCommands } from '@/stores/project/logCommands';
8585
import { useEditorSessionStore } from '@/stores/editor/editorSessionStore';
8686
import { useUiStore } from '@/stores/ui/uiStore';
8787
import type { Message } from '@/types/log';
8888
8989
const activeContext = useActiveContext();
9090
const logStore = useLogStore();
91-
const logEditorStore = useLogEditorStore();
91+
const logCommands = useLogCommands();
9292
const editorSessionStore = useEditorSessionStore();
9393
const uiStore = useUiStore();
9494
const { startResize } = usePanelResize({
@@ -156,7 +156,7 @@ function commitDraft(
156156
field: MessageDetailTextField,
157157
) {
158158
messageDrafts.commit(messageId, field, (value) => {
159-
logEditorStore.updateMessage(chunkId, messageId, {
159+
logCommands.updateMessage(chunkId, messageId, {
160160
[field]: value,
161161
});
162162
});
@@ -170,7 +170,7 @@ function updateField(
170170
value: unknown,
171171
) {
172172
editorSessionStore.startEditing({ kind: 'message', chunkId, messageId });
173-
logEditorStore.updateMessage(chunkId, messageId, {
173+
logCommands.updateMessage(chunkId, messageId, {
174174
[field]: value,
175175
});
176176
}

src/components/mobile/MobileActiveSheet.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import type {
7777
MessageDetailTextField,
7878
MessageDetailValues,
7979
} from '@/components/common/MessageDetailEditor.vue';
80-
import { useLogEditorStore } from '@/stores/project/logEditorStore';
80+
import { useLogCommands } from '@/stores/project/logCommands';
8181
import { useLogStore } from '@/stores/project/logStore';
8282
import { useMobileUiStore } from '@/stores/ui/mobileUiStore';
8383
import { useEditorSessionStore } from '@/stores/editor/editorSessionStore';
@@ -90,7 +90,7 @@ const MessageDetailEditor = defineAsyncComponent(
9090
const mobileUiStore = useMobileUiStore();
9191
const editorSessionStore = useEditorSessionStore();
9292
const logStore = useLogStore();
93-
const editorStore = useLogEditorStore();
93+
const logCommands = useLogCommands();
9494
const editingMessage = computed(() => {
9595
const target = editorSessionStore.activeTarget;
9696
if (target?.kind !== 'message') return null;
@@ -147,7 +147,7 @@ function updateMessageDraftText(field: MessageDetailTextField, value: string) {
147147
function commitMessageDraftText(field: MessageDetailTextField) {
148148
const target = editorSessionStore.activeTarget;
149149
if (target?.kind !== 'message') return;
150-
editorStore.updateMessage(target.chunkId, target.messageId, {
150+
logCommands.updateMessage(target.chunkId, target.messageId, {
151151
[field]: messageDraft[field],
152152
});
153153
}
@@ -159,7 +159,7 @@ function updateMessageDraftField<K extends keyof MessageDetailValues>(
159159
messageDraft[field] = value;
160160
const target = editorSessionStore.activeTarget;
161161
if (target?.kind !== 'message') return;
162-
editorStore.updateMessage(target.chunkId, target.messageId, {
162+
logCommands.updateMessage(target.chunkId, target.messageId, {
163163
[field]: value,
164164
});
165165
}
@@ -171,7 +171,7 @@ function commitProjectName() {
171171
function commitChunkName() {
172172
const target = editorSessionStore.activeTarget;
173173
if (target?.kind !== 'chunkName') return;
174-
editorStore.updateChunk(target.chunkId, {
174+
logCommands.updateChunk(target.chunkId, {
175175
chunkName: chunkNameDraft.value.trim() || '未命名场景',
176176
});
177177
}

src/components/mobile/MobileWorkspace.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import { computed } from 'vue';
3434
import { MessagesSquare } from '@lucide/vue';
3535
import MobileMessageList from '@/components/mobile/MobileMessageList.vue';
36-
import { useLogEditorStore } from '@/stores/project/logEditorStore';
36+
import { useLogCommands } from '@/stores/project/logCommands';
3737
import { useLogStore } from '@/stores/project/logStore';
3838
import { useMobileUiStore } from '@/stores/ui/mobileUiStore';
3939
import { useEditorSessionStore } from '@/stores/editor/editorSessionStore';
@@ -47,7 +47,7 @@ const logStore = useLogStore();
4747
const uiStore = useUiStore();
4848
const styleStore = useStyleStore();
4949
const windowStore = useWindowStore();
50-
const editorStore = useLogEditorStore();
50+
const logCommands = useLogCommands();
5151
const mobileUiStore = useMobileUiStore();
5252
const editorSessionStore = useEditorSessionStore();
5353
@@ -85,7 +85,7 @@ function startMessageEdit(message: Message) {
8585
8686
function insertAfter(message: Message, index: number) {
8787
if (!activeChunk.value) return;
88-
editorStore.insertNewMessageAfter(
88+
logCommands.insertNewMessageAfter(
8989
activeChunk.value.chunkId,
9090
message,
9191
index,
@@ -94,13 +94,13 @@ function insertAfter(message: Message, index: number) {
9494
9595
function mergeWithNext(messageId: string) {
9696
if (!activeChunk.value) return;
97-
editorStore.mergeWithNextMessage(activeChunk.value.chunkId, messageId);
97+
logCommands.mergeWithNextMessage(activeChunk.value.chunkId, messageId);
9898
}
9999
100100
function deleteMessage(messageId: string) {
101101
if (!activeChunk.value) return;
102102
if (!window.confirm('确定要删除这条消息吗?')) return;
103-
editorStore.deleteMessage(activeChunk.value.chunkId, messageId);
103+
logCommands.deleteMessage(activeChunk.value.chunkId, messageId);
104104
if (activeContext.selectedMessageIds.value.has(messageId)) {
105105
activeContext.clearMessageSelection();
106106
}

src/components/panels/ChunkListPanel.vue

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,17 @@
219219
import { ChevronRight, ChevronsDown, Trash2 } from '@lucide/vue';
220220
import { nextTick, reactive, ref, watch } from 'vue';
221221
import { useChunkDragDrop } from '@/composables/interaction/useDragDrop';
222-
import { useLogEditorStore } from '@/stores/project/logEditorStore';
222+
import { useLogCommands } from '@/stores/project/logCommands';
223223
import { useLogStore } from '@/stores/project/logStore';
224-
import { useStyleStore } from '@/stores/project/styleStore';
225224
import { useWindowStore } from '@/stores/ui/windowStore';
226225
import { useEditorSessionStore } from '@/stores/editor/editorSessionStore';
227226
import type { Chunk, LogDocument } from '@/types/log';
228227
import { useActiveContext } from '@/composables/application/useActiveContext';
229228
import { vClickOutside } from '@/directives/clickOutside';
230229
231230
const logStore = useLogStore();
232-
const styleStore = useStyleStore();
233231
const windowStore = useWindowStore();
234-
const logEditorStore = useLogEditorStore();
232+
const logCommands = useLogCommands();
235233
const editorSessionStore = useEditorSessionStore();
236234
const chunkDrag = useChunkDragDrop();
237235
const activeContext = useActiveContext('chunkList');
@@ -283,13 +281,12 @@ function resetProjectNameDraft() {
283281
}
284282
285283
function handleToggleExpand(doc: LogDocument) {
286-
logStore.updateDocument(doc.docId, { isExpanded: !doc.isExpanded });
284+
logCommands.setDocumentExpanded(doc.docId, !doc.isExpanded);
287285
}
288286
289287
function handleRemoveDoc(docId: string) {
290288
if (confirm('确定要删除这个文档及其所有消息吗?这不会删除原始文件。')) {
291-
logStore.removeDocument(docId);
292-
styleStore.syncSystemRulesFromMessages(logStore.allMessages);
289+
logCommands.deleteDocument(docId);
293290
}
294291
}
295292
@@ -331,9 +328,9 @@ function submitRename(kind: 'document' | 'chunk', id: string) {
331328
}
332329
333330
if (kind === 'document') {
334-
logEditorStore.renameDocument(id, nextName);
331+
logCommands.renameDocument(id, nextName);
335332
} else {
336-
logEditorStore.updateChunk(id, { chunkName: nextName });
333+
logCommands.updateChunk(id, { chunkName: nextName });
337334
}
338335
339336
cancelRename();
@@ -355,7 +352,7 @@ function isRenamingChunk(chunk: Chunk) {
355352
356353
function handleMerge(currentChunkId: string, nextChunkId: string) {
357354
withScrollAnchor(() => {
358-
logEditorStore.mergeChunks([currentChunkId, nextChunkId]);
355+
logCommands.mergeChunks([currentChunkId, nextChunkId]);
359356
});
360357
}
361358
@@ -390,7 +387,7 @@ function handleDelete(chunkId: string) {
390387
)
391388
) {
392389
targets.forEach((id) => {
393-
logEditorStore.deleteChunk(id);
390+
logCommands.deleteChunk(id);
394391
if (windowStore.isWindowOpen(id)) {
395392
windowStore.unregisterWindow(id);
396393
}

src/components/panels/IdentityPanel.vue

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,13 @@ import { ref, computed } from 'vue';
9494
import { IdCard, UserRound } from '@lucide/vue';
9595
import { useStyleStore } from '@/stores/project/styleStore';
9696
import { useLogStore } from '@/stores/project/logStore';
97-
import { useHistoryStore } from '@/stores/editor/historyStore';
98-
import { useLogEditorStore } from '@/stores/project/logEditorStore';
97+
import { useLogCommands } from '@/stores/project/logCommands';
9998
import type { RoleType } from '@/types/log';
10099
import type { ColorMode, ColorRule } from '@/types/style';
101100
import { useWindowStore } from '@/stores/ui/windowStore';
102101
import {
103102
buildIdentityStats,
104103
collectMessageIdsByIdentity,
105-
findFirstRoleByIdentity,
106104
} from '@/editor/identity';
107105
import { vClickOutside } from '@/directives/clickOutside';
108106
@@ -115,8 +113,7 @@ interface IdentityListItem {
115113
116114
const styleStore = useStyleStore();
117115
const logStore = useLogStore();
118-
const historyStore = useHistoryStore();
119-
const logEditorStore = useLogEditorStore();
116+
const logCommands = useLogCommands();
120117
const windowStore = useWindowStore();
121118
const localDisplayMode = ref<ColorMode>(styleStore.viewSettings.colorMode);
122119
const editingId = ref<string | null>(null);
@@ -163,44 +160,14 @@ function saveRename(oldVal: string) {
163160
}
164161
165162
const mode = localDisplayMode.value;
166-
const sourceIds = getMessageIdsForIdentity(oldVal);
167-
const existingTargetIds = getMessageIdsForIdentity(newVal);
168-
169-
const mergedRole =
170-
existingTargetIds.size > 0
171-
? (getRoleForIdentity(newVal) ?? getRoleForIdentity(oldVal))
172-
: null;
173-
174-
if (sourceIds.size > 0) {
175-
historyStore.captureSnapshot();
176-
historyStore.runWithoutCapture(() => {
177-
logEditorStore.batchUpdateMessages(
178-
sourceIds,
179-
buildRenameUpdate(mode, newVal),
180-
);
181-
const isMerged = styleStore.updateSystemRuleTarget(
182-
mode,
183-
oldVal,
184-
newVal,
185-
);
186-
if (isMerged && mergedRole) {
187-
const mergedIds = new Set<string>([
188-
...sourceIds,
189-
...existingTargetIds,
190-
]);
191-
logEditorStore.batchUpdateMessages(mergedIds, {
192-
role: mergedRole,
193-
});
194-
}
195-
});
196-
}
163+
logCommands.renameIdentity(mode, oldVal, newVal);
197164
editingId.value = null;
198165
}
199166
200167
function updateRole(id: string, newRole: RoleType) {
201168
const targetIds = getMessageIdsForIdentity(id);
202169
if (targetIds.size > 0) {
203-
logEditorStore.batchUpdateMessages(targetIds, { role: newRole });
170+
logCommands.batchUpdateMessages(targetIds, { role: newRole });
204171
}
205172
}
206173
@@ -215,16 +182,6 @@ function getMessageIdsForIdentity(id: string) {
215182
id,
216183
);
217184
}
218-
function getRoleForIdentity(id: string): RoleType | null {
219-
return findFirstRoleByIdentity(
220-
logStore.allMessages,
221-
localDisplayMode.value,
222-
id,
223-
);
224-
}
225-
function buildRenameUpdate(mode: ColorMode, value: string) {
226-
return mode === 'playerName' ? { playerName: value } : { account: value };
227-
}
228185
function getRoleFromSelectEvent(event: Event): RoleType {
229186
const value = (event.target as HTMLSelectElement).value;
230187
return value as RoleType;

src/components/workspace/ChunkView.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ import MessageItem from '@/components/common/MessageItem.vue';
118118
import { useActiveContext } from '@/composables/application/useActiveContext';
119119
import { useCommandDispatcher } from '@/composables/application/useCommandDispatcher';
120120
import { useMessageDragDrop } from '@/composables/interaction/useDragDrop';
121-
import { useLogEditorStore } from '@/stores/project/logEditorStore';
121+
import { useLogCommands } from '@/stores/project/logCommands';
122122
import { useEditorSessionStore } from '@/stores/editor/editorSessionStore';
123123
import { useLogStore } from '@/stores/project/logStore';
124124
import { useStyleStore } from '@/stores/project/styleStore';
@@ -149,7 +149,7 @@ const logStore = useLogStore();
149149
const uiStore = useUiStore();
150150
const styleStore = useStyleStore();
151151
const windowStore = useWindowStore();
152-
const logEditorStore = useLogEditorStore();
152+
const logCommands = useLogCommands();
153153
const editorSessionStore = useEditorSessionStore();
154154
const activeContext = useActiveContext(effectiveWindowId);
155155
const dragDropTool = useMessageDragDrop();
@@ -310,7 +310,7 @@ function handleSaveEdit(messageId: string) {
310310
(item) => item.messageId === messageId,
311311
);
312312
if (message && message.content !== editingContent.value) {
313-
logEditorStore.updateMessage(currentChunkId.value, messageId, {
313+
logCommands.updateMessage(currentChunkId.value, messageId, {
314314
content: editingContent.value,
315315
});
316316
}
@@ -381,14 +381,14 @@ function handleContainerDrop(event: DragEvent) {
381381
}
382382
383383
function handleActionInsert(message: Message, index: number) {
384-
logEditorStore.insertNewMessageAfter(currentChunkId.value, message, index);
384+
logCommands.insertNewMessageAfter(currentChunkId.value, message, index);
385385
}
386386
387387
function handleActionMerge(message: Message) {
388388
withScrollAnchor(() => {
389389
const selectedIds = activeContext.selectedMessageIds.value;
390390
if (selectedIds.has(message.messageId) && selectedIds.size > 1) {
391-
logEditorStore.mergeMessages(
391+
logCommands.mergeMessages(
392392
currentChunkId.value,
393393
Array.from(selectedIds),
394394
message.messageId,
@@ -397,27 +397,27 @@ function handleActionMerge(message: Message) {
397397
return;
398398
}
399399
400-
logEditorStore.mergeWithNextMessage(
400+
logCommands.mergeWithNextMessage(
401401
currentChunkId.value,
402402
message.messageId,
403403
);
404404
});
405405
}
406406
407407
function handleActionSplit(messageId: string) {
408-
logEditorStore.splitChunk(currentChunkId.value, messageId);
408+
logCommands.splitChunk(currentChunkId.value, messageId);
409409
}
410410
411411
function handleActionDelete(messageId: string) {
412412
const selectedIds = activeContext.selectedMessageIds.value;
413413
414414
if (selectedIds.has(messageId)) {
415-
logEditorStore.batchDeleteMessages(selectedIds);
415+
logCommands.batchDeleteMessages(selectedIds);
416416
activeContext.clearMessageSelection();
417417
return;
418418
}
419419
420-
logEditorStore.deleteMessage(currentChunkId.value, messageId);
420+
logCommands.deleteMessage(currentChunkId.value, messageId);
421421
}
422422
</script>
423423

0 commit comments

Comments
 (0)