From 69e93bdfd4520d61024f4dcd00052556d69bd2b0 Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Thu, 19 Nov 2026 20:30:26 +0900 Subject: [PATCH 1/8] feat(tutorial): keep the pins a stage placed from being deleted or renamed The check finds a stage's pins by name, and a player who deleted one could only get it back by resetting the whole stage. The editor now takes nodes to protect: the context menu leaves them out of deleting and of creating a new component, and their pins cannot be renamed on the node or in the properties dialog. A stage protects its Input and Output nodes. Co-Authored-By: Claude Opus 5.5 --- src/components/ComponentPropertyDialog.tsx | 13 ++++++++- .../edit/Editor/components/ContextMenu.tsx | 8 ++--- src/pages/edit/Editor/index.tsx | 15 ++++++++-- .../Node/components/Interface/index.tsx | 14 +++++---- src/pages/edit/Editor/store/index.tsx | 18 ++++++++++-- .../store/slices/contextMenu/index.test.ts | 27 +++++++++++++++-- .../Editor/store/slices/contextMenu/items.ts | 10 +++++-- src/pages/edit/Editor/store/types.ts | 3 ++ src/pages/tutorial/stage.tsx | 4 +++ src/tutorial/stages.test.ts | 29 +++++++++++++++++++ src/tutorial/stages.ts | 14 +++++++++ 11 files changed, 135 insertions(+), 20 deletions(-) create mode 100644 src/tutorial/stages.test.ts diff --git a/src/components/ComponentPropertyDialog.tsx b/src/components/ComponentPropertyDialog.tsx index e2d6b9f..38b4775 100644 --- a/src/components/ComponentPropertyDialog.tsx +++ b/src/components/ComponentPropertyDialog.tsx @@ -15,11 +15,14 @@ import { z } from "zod"; import { useMessages } from "../i18n"; import type CCStore from "../store"; import type { CCComponentId } from "../store/component"; -import type { CCComponentPinId } from "../store/componentPin"; +import type { CCComponentPin, CCComponentPinId } from "../store/componentPin"; +import type { CCNodeId } from "../store/node"; import { useStore } from "../store/react"; export type ComponentPropertyDialogProps = { componentId: CCComponentId; + /** the nodes whose pins keep their names */ + isProtectedNode: (nodeId: CCNodeId) => boolean; onClose(): void; }; @@ -54,6 +57,7 @@ function applyStateToStore( export function ComponentPropertyDialog({ componentId, + isProtectedNode, onClose, }: ComponentPropertyDialogProps) { const { store } = useStore(); @@ -63,6 +67,11 @@ export function ComponentPropertyDialog({ extractStateFromStore(store, componentId), ); const result = stateSchema.safeParse(state); + const isPinProtected = (pin: CCComponentPin) => { + const nodePin = + pin.implementation && store.nodePins.get(pin.implementation); + return !!nodePin && isProtectedNode(nodePin.nodeId); + }; return ( @@ -110,6 +119,7 @@ export function ComponentPropertyDialog({ size="small" value={state.pinNameById.get(pin.id)} fullWidth + disabled={isPinProtected(pin)} onChange={(e) => setState({ ...state, @@ -135,6 +145,7 @@ export function ComponentPropertyDialog({ size="small" value={state.pinNameById.get(pin.id)} fullWidth + disabled={isPinProtected(pin)} onChange={(e) => setState({ ...state, diff --git a/src/pages/edit/Editor/components/ContextMenu.tsx b/src/pages/edit/Editor/components/ContextMenu.tsx index dc4c3e6..3cb7c1c 100644 --- a/src/pages/edit/Editor/components/ContextMenu.tsx +++ b/src/pages/edit/Editor/components/ContextMenu.tsx @@ -32,8 +32,8 @@ export default function CCComponentEditorContextMenu({ const items = getContextMenuItems(store, componentEditorState); if (!hasContextMenuItems(items)) return null; const { - selectedNodeIds, selectedConnectionIds, + removableNodeIds, canExtract, canDelete, componentToEdit, @@ -60,7 +60,7 @@ export default function CCComponentEditorContextMenu({ componentEditorState.closeContextMenu(); const newComponent = await extractNodesIntoNewComponent( store, - selectedNodeIds, + removableNodeIds, messages.common.newComponentName, ); onComponentCreated(newComponent.id); @@ -72,8 +72,8 @@ export default function CCComponentEditorContextMenu({ {canDelete && ( { - if (selectedNodeIds.length > 0) - store.nodes.unregister(selectedNodeIds); + if (removableNodeIds.length > 0) + store.nodes.unregister(removableNodeIds); if (selectedConnectionIds.length > 0) store.connections.unregister(selectedConnectionIds); componentEditorState.selectConnection([], true); diff --git a/src/pages/edit/Editor/index.tsx b/src/pages/edit/Editor/index.tsx index 0d32904..099bfcd 100644 --- a/src/pages/edit/Editor/index.tsx +++ b/src/pages/edit/Editor/index.tsx @@ -11,10 +11,15 @@ import CCComponentEditorNotifications from "./components/Notifications"; import CCComponentEditorTitleBar from "./components/TitleBar"; import CCComponentEditorViewModeSwitcher from "./components/ViewModeSwitcher"; import CCComponentEditorRenderer from "./renderer"; -import { ComponentEditorStoreProvider } from "./store"; +import { + ComponentEditorStoreProvider, + type EditorStoreOptions, + useComponentEditorStore, +} from "./store"; export type CCComponentEditorProps = { componentId: CCComponentId; + options?: EditorStoreOptions; onEditComponent: (componentId: CCComponentId) => void; onClose: () => void; }; @@ -26,6 +31,9 @@ function CCComponentEditorContent({ }: CCComponentEditorProps) { const [propertyDialogComponentId, setPropertyDialogComponentId] = useState(null); + const isProtectedNode = useComponentEditorStore()( + (state) => state.isProtectedNode, + ); return ( setPropertyDialogComponentId(null)} /> )} @@ -74,9 +83,9 @@ function CCComponentEditorContent({ } export default function CCComponentEditor(props: CCComponentEditorProps) { - const { componentId } = props; + const { componentId, options = {} } = props; return ( - + ); diff --git a/src/pages/edit/Editor/renderer/Node/components/Interface/index.tsx b/src/pages/edit/Editor/renderer/Node/components/Interface/index.tsx index 303bf22..7361e66 100644 --- a/src/pages/edit/Editor/renderer/Node/components/Interface/index.tsx +++ b/src/pages/edit/Editor/renderer/Node/components/Interface/index.tsx @@ -68,12 +68,14 @@ export function CCComponentEditorRendererNodeInterfaceRenderer( {simulation === null ? (
{componentPin.name} - - store.componentPins.update(componentPin.id, { name }) - } - /> + {!editorState.isProtectedNode(props.node.id) && ( + + store.componentPins.update(componentPin.id, { name }) + } + /> + )}
) : (
diff --git a/src/pages/edit/Editor/store/index.tsx b/src/pages/edit/Editor/store/index.tsx index 590a0e7..f3c4b62 100644 --- a/src/pages/edit/Editor/store/index.tsx +++ b/src/pages/edit/Editor/store/index.tsx @@ -3,19 +3,29 @@ import invariant from "tiny-invariant"; import { create } from "zustand"; import type CCStore from "../../../../store"; import type { CCComponentId } from "../../../../store/component"; +import type { CCNodeId } from "../../../../store/node"; import { useStore } from "../../../../store/react"; import createComponentEditorStoreContextMenuSlice from "./slices/contextMenu"; import { createComponentEditorStoreCoreSlice } from "./slices/core"; import createComponentEditorStorePerspectiveSlice from "./slices/perspective"; import type { ComponentEditorStoreValue } from "./types"; -export function createEditorStore(componentId: CCComponentId, store: CCStore) { +export type EditorStoreOptions = { + isProtectedNode?: (nodeId: CCNodeId) => boolean; +}; + +export function createEditorStore( + componentId: CCComponentId, + store: CCStore, + { isProtectedNode = () => false }: EditorStoreOptions = {}, +) { const props = { store, componentId }; const coreSlice = createComponentEditorStoreCoreSlice(props); const perspectiveSlice = createComponentEditorStorePerspectiveSlice(props); const contextMenuSlice = createComponentEditorStoreContextMenuSlice(props); const editorStore = create((set, get) => ({ componentId, + isProtectedNode, ...coreSlice.define(set, get), ...perspectiveSlice.define(set, get), ...contextMenuSlice.define(set, get), @@ -32,13 +42,17 @@ const context = createContext(null); export function ComponentEditorStoreProvider({ componentId, + options, children, }: { componentId: CCComponentId; + options: EditorStoreOptions; children: React.ReactNode; }) { const { store } = useStore(); - const [editorStore] = useState(() => createEditorStore(componentId, store)); + const [editorStore] = useState(() => + createEditorStore(componentId, store, options), + ); return {children}; } diff --git a/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts b/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts index 534c5e5..b0ab09b 100644 --- a/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts +++ b/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts @@ -11,12 +11,13 @@ import { } from "../../../../../../store/testUtils"; import { createEditorStore } from "../.."; import { stubResizeObserver } from "../../testUtils"; +import { getContextMenuItems } from "./items"; stubResizeObserver(); const rightClick = { nativeEvent: { offsetX: 10, offsetY: 20 } } as MouseEvent; -function setUp() { +function setUp(options: Parameters[2] = {}) { const store = createTestStore(); const sub = registerTestComponent(store, "Sub"); const root = registerTestComponent(store, "Root"); @@ -30,9 +31,11 @@ function setUp() { testNodePin(store, inverter, not.inputPin.In), ); const [connection] = store.connections.getMany(); - const editorStore = createEditorStore(root.id, store); + const editorStore = createEditorStore(root.id, store, options); return { + store, editorStore, + inverter, intrinsicNode, subNode, connectionId: nullthrows(connection).id, @@ -106,4 +109,24 @@ describe("Context menu slice", () => { expect(editorStore.getState().contextMenuState).not.toBeNull(); }); + + it("leaves protected nodes out of what it deletes or moves", () => { + let protectedNodeId: string | null = null; + const { store, editorStore, intrinsicNode, inverter } = setUp({ + isProtectedNode: (nodeId) => nodeId === protectedNodeId, + }); + protectedNodeId = intrinsicNode.id; + editorStore.getState().selectNode([intrinsicNode.id, inverter.id], true); + + expect(getContextMenuItems(store, editorStore.getState())).toMatchObject({ + removableNodeIds: [inverter.id], + canDelete: true, + canExtract: true, + }); + + editorStore.getState().selectNode([intrinsicNode.id], true); + editorStore.getState().openContextMenu(rightClick); + + expect(editorStore.getState().contextMenuState).toBeNull(); + }); }); diff --git a/src/pages/edit/Editor/store/slices/contextMenu/items.ts b/src/pages/edit/Editor/store/slices/contextMenu/items.ts index 56d827b..7d7164e 100644 --- a/src/pages/edit/Editor/store/slices/contextMenu/items.ts +++ b/src/pages/edit/Editor/store/slices/contextMenu/items.ts @@ -9,6 +9,8 @@ import type { ComponentEditorStoreValue } from "../../types"; export type ContextMenuItems = { selectedNodeIds: CCNodeId[]; selectedConnectionIds: CCConnectionId[]; + /** the selected nodes that may be deleted or moved into a new component */ + removableNodeIds: CCNodeId[]; canExtract: boolean; canDelete: boolean; componentToEdit: CCComponent | null; @@ -26,6 +28,9 @@ export function getContextMenuItems( (connectionId) => store.connections.get(connectionId), ); const isEditMode = state.editorMode === "edit"; + const removableNodeIds = selectedNodeIds.filter( + (nodeId) => !state.isProtectedNode(nodeId), + ); const [targetNodeId] = selectedNodeIds; const targetComponent = selectedNodeIds.length === 1 && targetNodeId @@ -38,11 +43,12 @@ export function getContextMenuItems( return { selectedNodeIds, selectedConnectionIds, + removableNodeIds, canExtract: - isEditMode && getExtractableNodeIds(store, selectedNodeIds).length > 0, + isEditMode && getExtractableNodeIds(store, removableNodeIds).length > 0, canDelete: isEditMode && - (selectedNodeIds.length > 0 || selectedConnectionIds.length > 0), + (removableNodeIds.length > 0 || selectedConnectionIds.length > 0), componentToEdit: targetComponent?.intrinsicType ? null : targetComponent, }; } diff --git a/src/pages/edit/Editor/store/types.ts b/src/pages/edit/Editor/store/types.ts index a3acc55..087ec07 100644 --- a/src/pages/edit/Editor/store/types.ts +++ b/src/pages/edit/Editor/store/types.ts @@ -1,12 +1,15 @@ import type { StoreApi } from "zustand"; import type CCStore from "../../../../store"; import type { CCComponentId } from "../../../../store/component"; +import type { CCNodeId } from "../../../../store/node"; import type { ContextMenuStoreSlice } from "./slices/contextMenu/types"; import type { EditorStoreCoreSlice } from "./slices/core/types"; import type { PerspectiveStoreSlice } from "./slices/perspective/types"; export type ComponentEditorStoreValue = { readonly componentId: CCComponentId; + /** a node the player can neither delete nor rename the pin of */ + readonly isProtectedNode: (nodeId: CCNodeId) => boolean; } & EditorStoreCoreSlice & PerspectiveStoreSlice & ContextMenuStoreSlice; diff --git a/src/pages/tutorial/stage.tsx b/src/pages/tutorial/stage.tsx index 169d9d7..b0e3d34 100644 --- a/src/pages/tutorial/stage.tsx +++ b/src/pages/tutorial/stage.tsx @@ -30,6 +30,7 @@ import { } from "../../tutorial/stageStore"; import { findTutorialStage, + isStagePinNode, type TutorialStage, tutorialStages, } from "../../tutorial/stages"; @@ -203,6 +204,9 @@ function StageView({ stage }: { stage: TutorialStage }) { isStagePinNode(store, stage, nodeId), + }} onEditComponent={setEditedComponentId} onClose={() => { if (shownComponentId === stage.componentId) navigate("/tutorial"); diff --git a/src/tutorial/stages.test.ts b/src/tutorial/stages.test.ts new file mode 100644 index 0000000..1fe519f --- /dev/null +++ b/src/tutorial/stages.test.ts @@ -0,0 +1,29 @@ +import { describe, expect, it } from "vitest"; +import { and, input } from "../store/intrinsics/definitions"; +import { + createTestStore, + registerTestComponent, + registerTestNode, +} from "../store/testUtils"; +import { isStagePinNode, setUpTutorialStage, tutorialStages } from "./stages"; + +const [stage] = tutorialStages; +if (!stage) throw new Error("No stage"); + +describe("isStagePinNode", () => { + it("tells the pins the stage placed from the nodes the player adds", () => { + const store = createTestStore(); + setUpTutorialStage(store, stage, "Lamp"); + const placed = store.nodes.getManyByParentComponentId(stage.componentId); + const gate = registerTestNode(store, stage.componentId, and.component.id); + const own = registerTestComponent(store, "Mine"); + const pinOfOwn = registerTestNode(store, own.id, input.component.id); + + expect(placed).toHaveLength(3); + for (const node of placed) { + expect(isStagePinNode(store, stage, node.id)).toBe(true); + } + expect(isStagePinNode(store, stage, gate.id)).toBe(false); + expect(isStagePinNode(store, stage, pinOfOwn.id)).toBe(false); + }); +}); diff --git a/src/tutorial/stages.ts b/src/tutorial/stages.ts index 8fd175e..5fb82d9 100644 --- a/src/tutorial/stages.ts +++ b/src/tutorial/stages.ts @@ -52,6 +52,20 @@ export function findTutorialStage(id: string | undefined) { return tutorialStages.find((stage) => stage.id === id); } +/** The pins the stage placed, which the check looks for by name */ +export function isStagePinNode( + store: CCStore, + stage: TutorialStage, + nodeId: CCNodeId, +): boolean { + const node = store.nodes.get(nodeId); + return ( + node?.parentComponentId === stage.componentId && + (node.componentId === input.component.id || + node.componentId === output.component.id) + ); +} + function renamePinOfNode( store: CCStore, nodeId: CCNodeId, From f01a35c20e152d5a3f6b701af5819dd18daf89da Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Thu, 19 Nov 2026 20:33:55 +0900 Subject: [PATCH 2/8] fix(editor): check a dropped component like the side panel does A drop placed any component id it carried, so one dragged from another tab could name a component missing from this store, one that includes the edited component, or in a stage a part the stage does not offer, such as an Input that would then be protected. The side panel and the drop now share one check. Also drops comments that restated the code, and covers protecting nothing by default and protecting an Input next to a gate. Co-Authored-By: Claude Opus 5.5 --- src/components/ComponentPropertyDialog.tsx | 1 - src/pages/edit/Editor/renderer/index.tsx | 12 ++++- src/pages/edit/Editor/store/index.tsx | 10 +++- .../store/slices/contextMenu/index.test.ts | 36 +++++++++---- .../Editor/store/slices/contextMenu/items.ts | 3 -- src/pages/edit/Editor/store/types.ts | 5 +- src/pages/edit/SidePanel.tsx | 24 ++++----- src/pages/edit/placement.test.ts | 51 +++++++++++++++++++ src/pages/edit/placement.ts | 22 ++++++++ src/pages/tutorial/stage.tsx | 7 ++- src/tutorial/check.ts | 5 -- src/tutorial/stages.test.ts | 21 +++++++- src/tutorial/stages.ts | 11 +++- 13 files changed, 165 insertions(+), 43 deletions(-) create mode 100644 src/pages/edit/placement.test.ts create mode 100644 src/pages/edit/placement.ts diff --git a/src/components/ComponentPropertyDialog.tsx b/src/components/ComponentPropertyDialog.tsx index 38b4775..0890636 100644 --- a/src/components/ComponentPropertyDialog.tsx +++ b/src/components/ComponentPropertyDialog.tsx @@ -21,7 +21,6 @@ import { useStore } from "../store/react"; export type ComponentPropertyDialogProps = { componentId: CCComponentId; - /** the nodes whose pins keep their names */ isProtectedNode: (nodeId: CCNodeId) => boolean; onClose(): void; }; diff --git a/src/pages/edit/Editor/renderer/index.tsx b/src/pages/edit/Editor/renderer/index.tsx index b0a9cf7..39994c1 100644 --- a/src/pages/edit/Editor/renderer/index.tsx +++ b/src/pages/edit/Editor/renderer/index.tsx @@ -6,6 +6,7 @@ import { useConnectionIds, useNodeIds, } from "../../../../store/react/selectors"; +import { canPlaceComponent } from "../../placement"; import { useComponentEditorStore } from "../store"; import CCComponentEditorRendererBackground from "./Background"; import CCComponentEditorRendererConnection from "./Connection"; @@ -61,7 +62,16 @@ export default function CCComponentEditorRenderer() { }} onDrop={(e) => { const droppedComponentId = parseDataTransferAsComponent(e.dataTransfer); - if (!droppedComponentId || componentEditorState.editorMode === "play") + if ( + !droppedComponentId || + componentEditorState.editorMode === "play" || + !canPlaceComponent( + store, + componentEditorState.componentId, + droppedComponentId, + componentEditorState.isOffered, + ) + ) return; store.nodes.register( CCNodeStore.create({ diff --git a/src/pages/edit/Editor/store/index.tsx b/src/pages/edit/Editor/store/index.tsx index f3c4b62..bc7d941 100644 --- a/src/pages/edit/Editor/store/index.tsx +++ b/src/pages/edit/Editor/store/index.tsx @@ -2,7 +2,7 @@ import { createContext, useContext, useState } from "react"; import invariant from "tiny-invariant"; import { create } from "zustand"; import type CCStore from "../../../../store"; -import type { CCComponentId } from "../../../../store/component"; +import type { CCComponent, CCComponentId } from "../../../../store/component"; import type { CCNodeId } from "../../../../store/node"; import { useStore } from "../../../../store/react"; import createComponentEditorStoreContextMenuSlice from "./slices/contextMenu"; @@ -12,12 +12,16 @@ import type { ComponentEditorStoreValue } from "./types"; export type EditorStoreOptions = { isProtectedNode?: (nodeId: CCNodeId) => boolean; + isOffered?: (component: CCComponent) => boolean; }; export function createEditorStore( componentId: CCComponentId, store: CCStore, - { isProtectedNode = () => false }: EditorStoreOptions = {}, + { + isProtectedNode = () => false, + isOffered = () => true, + }: EditorStoreOptions = {}, ) { const props = { store, componentId }; const coreSlice = createComponentEditorStoreCoreSlice(props); @@ -26,6 +30,7 @@ export function createEditorStore( const editorStore = create((set, get) => ({ componentId, isProtectedNode, + isOffered, ...coreSlice.define(set, get), ...perspectiveSlice.define(set, get), ...contextMenuSlice.define(set, get), @@ -50,6 +55,7 @@ export function ComponentEditorStoreProvider({ children: React.ReactNode; }) { const { store } = useStore(); + // Read once, so a caller changes them by remounting with another key const [editorStore] = useState(() => createEditorStore(componentId, store, options), ); diff --git a/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts b/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts index b0ab09b..ad2cdd0 100644 --- a/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts +++ b/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts @@ -1,7 +1,11 @@ import nullthrows from "nullthrows"; import type { MouseEvent } from "react"; import { describe, expect, it } from "vitest"; -import { not, true_ } from "../../../../../../store/intrinsics/definitions"; +import { + input, + not, + true_, +} from "../../../../../../store/intrinsics/definitions"; import { connectTestNodePins, createTestStore, @@ -17,7 +21,7 @@ stubResizeObserver(); const rightClick = { nativeEvent: { offsetX: 10, offsetY: 20 } } as MouseEvent; -function setUp(options: Parameters[2] = {}) { +function setUp() { const store = createTestStore(); const sub = registerTestComponent(store, "Sub"); const root = registerTestComponent(store, "Root"); @@ -31,7 +35,7 @@ function setUp(options: Parameters[2] = {}) { testNodePin(store, inverter, not.inputPin.In), ); const [connection] = store.connections.getMany(); - const editorStore = createEditorStore(root.id, store, options); + const editorStore = createEditorStore(root.id, store); return { store, editorStore, @@ -110,21 +114,31 @@ describe("Context menu slice", () => { expect(editorStore.getState().contextMenuState).not.toBeNull(); }); + it("protects nothing unless told to", () => { + const { store, editorStore, intrinsicNode, inverter } = setUp(); + editorStore.getState().selectNode([intrinsicNode.id, inverter.id], true); + + expect(getContextMenuItems(store, editorStore.getState())).toMatchObject({ + removableNodeIds: [intrinsicNode.id, inverter.id], + }); + }); + it("leaves protected nodes out of what it deletes or moves", () => { - let protectedNodeId: string | null = null; - const { store, editorStore, intrinsicNode, inverter } = setUp({ - isProtectedNode: (nodeId) => nodeId === protectedNodeId, + const store = createTestStore(); + const root = registerTestComponent(store, "Root"); + const pin = registerTestNode(store, root.id, input.component.id); + const gate = registerTestNode(store, root.id, not.component.id); + const editorStore = createEditorStore(root.id, store, { + isProtectedNode: (nodeId) => nodeId === pin.id, }); - protectedNodeId = intrinsicNode.id; - editorStore.getState().selectNode([intrinsicNode.id, inverter.id], true); + editorStore.getState().selectNode([pin.id, gate.id], true); expect(getContextMenuItems(store, editorStore.getState())).toMatchObject({ - removableNodeIds: [inverter.id], + removableNodeIds: [gate.id], canDelete: true, - canExtract: true, }); - editorStore.getState().selectNode([intrinsicNode.id], true); + editorStore.getState().selectNode([pin.id], true); editorStore.getState().openContextMenu(rightClick); expect(editorStore.getState().contextMenuState).toBeNull(); diff --git a/src/pages/edit/Editor/store/slices/contextMenu/items.ts b/src/pages/edit/Editor/store/slices/contextMenu/items.ts index 7d7164e..897897f 100644 --- a/src/pages/edit/Editor/store/slices/contextMenu/items.ts +++ b/src/pages/edit/Editor/store/slices/contextMenu/items.ts @@ -7,9 +7,7 @@ import type { CCNodeId } from "../../../../../../store/node"; import type { ComponentEditorStoreValue } from "../../types"; export type ContextMenuItems = { - selectedNodeIds: CCNodeId[]; selectedConnectionIds: CCConnectionId[]; - /** the selected nodes that may be deleted or moved into a new component */ removableNodeIds: CCNodeId[]; canExtract: boolean; canDelete: boolean; @@ -41,7 +39,6 @@ export function getContextMenuItems( ) : null; return { - selectedNodeIds, selectedConnectionIds, removableNodeIds, canExtract: diff --git a/src/pages/edit/Editor/store/types.ts b/src/pages/edit/Editor/store/types.ts index 087ec07..94a7705 100644 --- a/src/pages/edit/Editor/store/types.ts +++ b/src/pages/edit/Editor/store/types.ts @@ -1,6 +1,6 @@ import type { StoreApi } from "zustand"; import type CCStore from "../../../../store"; -import type { CCComponentId } from "../../../../store/component"; +import type { CCComponent, CCComponentId } from "../../../../store/component"; import type { CCNodeId } from "../../../../store/node"; import type { ContextMenuStoreSlice } from "./slices/contextMenu/types"; import type { EditorStoreCoreSlice } from "./slices/core/types"; @@ -8,8 +8,9 @@ import type { PerspectiveStoreSlice } from "./slices/perspective/types"; export type ComponentEditorStoreValue = { readonly componentId: CCComponentId; - /** a node the player can neither delete nor rename the pin of */ + /** neither deleted nor its pin renamed */ readonly isProtectedNode: (nodeId: CCNodeId) => boolean; + readonly isOffered: (component: CCComponent) => boolean; } & EditorStoreCoreSlice & PerspectiveStoreSlice & ContextMenuStoreSlice; diff --git a/src/pages/edit/SidePanel.tsx b/src/pages/edit/SidePanel.tsx index 5d97b98..dce5a58 100644 --- a/src/pages/edit/SidePanel.tsx +++ b/src/pages/edit/SidePanel.tsx @@ -4,16 +4,16 @@ import { useState } from "react"; import invariant from "tiny-invariant"; import { setDataTransferAsComponent } from "../../common/serialization"; import { useMessages } from "../../i18n"; -import { type CCComponentId, isIncluding } from "../../store/component"; +import type { CCComponent, CCComponentId } from "../../store/component"; import { ccPinTypes } from "../../store/componentPin"; import { useStore } from "../../store/react"; import { useComponents } from "../../store/react/selectors"; import { theme } from "../../style"; +import { canPlaceComponent } from "./placement"; export type SidePanelProps = { editedComponentId: CCComponentId; - /** the intrinsic components to offer, if not all of them */ - parts?: readonly CCComponentId[]; + isOffered?: (component: CCComponent) => boolean; }; function ComponentRenderer({ componentId }: { componentId: CCComponentId }) { @@ -90,7 +90,7 @@ function ComponentRenderer({ componentId }: { componentId: CCComponentId }) { } export default function SidePanel(sidePanelProps: SidePanelProps) { - const { editedComponentId, parts } = sidePanelProps; + const { editedComponentId, isOffered = () => true } = sidePanelProps; const { store } = useStore(); const messages = useMessages(); const components = useComponents(); @@ -119,16 +119,14 @@ export default function SidePanel(sidePanelProps: SidePanelProps) { /> {components - .filter( - (component) => - !parts || - !component.intrinsicType || - parts.includes(component.id), - ) .filter((component) => component.name.includes(searchText)) - .filter((component) => component.id !== editedComponentId) - .filter( - (component) => !isIncluding(store, component.id, editedComponentId), + .filter((component) => + canPlaceComponent( + store, + editedComponentId, + component.id, + isOffered, + ), ) .map((component) => ( { + const anything = () => true; + + it("places a component that exists and is offered", () => { + const store = createTestStore(); + const edited = registerTestComponent(store, "Edited"); + + expect( + canPlaceComponent(store, edited.id, and.component.id, anything), + ).toBe(true); + expect( + canPlaceComponent(store, edited.id, and.component.id, () => false), + ).toBe(false); + }); + + it("refuses an id this store does not know, as from another tab", () => { + const store = createTestStore(); + const edited = registerTestComponent(store, "Edited"); + + expect( + canPlaceComponent( + store, + edited.id, + "elsewhere" as CCComponentId, + anything, + ), + ).toBe(false); + }); + + it("refuses the edited component and those that use it", () => { + const store = createTestStore(); + const edited = registerTestComponent(store, "Edited"); + const user = registerTestComponent(store, "User"); + registerTestNode(store, user.id, edited.id); + + expect(canPlaceComponent(store, edited.id, edited.id, anything)).toBe( + false, + ); + expect(canPlaceComponent(store, edited.id, user.id, anything)).toBe(false); + }); +}); diff --git a/src/pages/edit/placement.ts b/src/pages/edit/placement.ts new file mode 100644 index 0000000..f39d3a0 --- /dev/null +++ b/src/pages/edit/placement.ts @@ -0,0 +1,22 @@ +import type CCStore from "../../store"; +import { + type CCComponent, + type CCComponentId, + isIncluding, +} from "../../store/component"; + +// A drop can carry any id, e.g. one dragged from another tab +export function canPlaceComponent( + store: CCStore, + editedComponentId: CCComponentId, + componentId: CCComponentId, + isOffered: (component: CCComponent) => boolean, +): boolean { + const component = store.components.get(componentId); + return ( + !!component && + component.id !== editedComponentId && + !isIncluding(store, component.id, editedComponentId) && + isOffered(component) + ); +} diff --git a/src/pages/tutorial/stage.tsx b/src/pages/tutorial/stage.tsx index b0e3d34..19a98ac 100644 --- a/src/pages/tutorial/stage.tsx +++ b/src/pages/tutorial/stage.tsx @@ -30,6 +30,7 @@ import { } from "../../tutorial/stageStore"; import { findTutorialStage, + isStagePart, isStagePinNode, type TutorialStage, tutorialStages, @@ -198,7 +199,10 @@ function StageView({ stage }: { stage: TutorialStage }) { > {texts.parts} - + isStagePart(stage, component)} + /> isStagePinNode(store, stage, nodeId), + isOffered: (component) => isStagePart(stage, component), }} onEditComponent={setEditedComponentId} onClose={() => { diff --git a/src/tutorial/check.ts b/src/tutorial/check.ts index 13106ee..41a5fdc 100644 --- a/src/tutorial/check.ts +++ b/src/tutorial/check.ts @@ -56,11 +56,6 @@ function isSameValue(a: SimulationValue, b: SimulationValue | undefined) { ); } -/** - * Simulate the component for every combination of its inputs and compare its outputs - * with `check`. Its pins are found by name, as the player may have removed or renamed - * the ones the stage placed. - */ export function checkCombinational( store: CCStore, componentId: CCComponentId, diff --git a/src/tutorial/stages.test.ts b/src/tutorial/stages.test.ts index 1fe519f..ad01614 100644 --- a/src/tutorial/stages.test.ts +++ b/src/tutorial/stages.test.ts @@ -1,11 +1,16 @@ import { describe, expect, it } from "vitest"; -import { and, input } from "../store/intrinsics/definitions"; +import { and, input, xor } from "../store/intrinsics/definitions"; import { createTestStore, registerTestComponent, registerTestNode, } from "../store/testUtils"; -import { isStagePinNode, setUpTutorialStage, tutorialStages } from "./stages"; +import { + isStagePart, + isStagePinNode, + setUpTutorialStage, + tutorialStages, +} from "./stages"; const [stage] = tutorialStages; if (!stage) throw new Error("No stage"); @@ -27,3 +32,15 @@ describe("isStagePinNode", () => { expect(isStagePinNode(store, stage, pinOfOwn.id)).toBe(false); }); }); + +describe("isStagePart", () => { + it("offers the stage's parts and the components the player made", () => { + const store = createTestStore(); + const own = registerTestComponent(store, "Mine"); + + expect(isStagePart(stage, and.component)).toBe(true); + expect(isStagePart(stage, own)).toBe(true); + expect(isStagePart(stage, xor.component)).toBe(false); + expect(isStagePart(stage, input.component)).toBe(false); + }); +}); diff --git a/src/tutorial/stages.ts b/src/tutorial/stages.ts index 5fb82d9..f7a26b7 100644 --- a/src/tutorial/stages.ts +++ b/src/tutorial/stages.ts @@ -1,6 +1,10 @@ import nullthrows from "nullthrows"; import type CCStore from "../store"; -import { type CCComponentId, CCComponentStore } from "../store/component"; +import { + type CCComponent, + type CCComponentId, + CCComponentStore, +} from "../store/component"; import type { CCComponentPin } from "../store/componentPin"; import { and, input, not, or, output } from "../store/intrinsics/definitions"; import { type CCNodeId, CCNodeStore } from "../store/node"; @@ -52,7 +56,10 @@ export function findTutorialStage(id: string | undefined) { return tutorialStages.find((stage) => stage.id === id); } -/** The pins the stage placed, which the check looks for by name */ +export function isStagePart(stage: TutorialStage, component: CCComponent) { + return !component.intrinsicType || stage.parts.includes(component.id); +} + export function isStagePinNode( store: CCStore, stage: TutorialStage, From 892a9b68edd5018c7f085f55637ae4d41c56cabb Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Thu, 19 Nov 2026 20:52:54 +0900 Subject: [PATCH 3/8] feat(tutorial): hide the properties button on a stage's own component Its pins can no longer be renamed, which leaves only its name, the stage's title, to change there. Components the player made keep the button. Co-Authored-By: Claude Opus 5.5 --- src/pages/edit/Editor/components/TitleBar.tsx | 16 +++++++++------- src/pages/edit/Editor/store/index.tsx | 3 +++ src/pages/edit/Editor/store/types.ts | 1 + src/pages/tutorial/stage.tsx | 1 + 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pages/edit/Editor/components/TitleBar.tsx b/src/pages/edit/Editor/components/TitleBar.tsx index 9dae22c..0e978e4 100644 --- a/src/pages/edit/Editor/components/TitleBar.tsx +++ b/src/pages/edit/Editor/components/TitleBar.tsx @@ -54,13 +54,15 @@ export default function CCComponentEditorTitleBar({ > {component.name} - - - + {componentEditorState.hasProperties(component.id) && ( + + + + )}
boolean; isOffered?: (component: CCComponent) => boolean; + hasProperties?: (componentId: CCComponentId) => boolean; }; export function createEditorStore( @@ -21,6 +22,7 @@ export function createEditorStore( { isProtectedNode = () => false, isOffered = () => true, + hasProperties = () => true, }: EditorStoreOptions = {}, ) { const props = { store, componentId }; @@ -31,6 +33,7 @@ export function createEditorStore( componentId, isProtectedNode, isOffered, + hasProperties, ...coreSlice.define(set, get), ...perspectiveSlice.define(set, get), ...contextMenuSlice.define(set, get), diff --git a/src/pages/edit/Editor/store/types.ts b/src/pages/edit/Editor/store/types.ts index 94a7705..8c22926 100644 --- a/src/pages/edit/Editor/store/types.ts +++ b/src/pages/edit/Editor/store/types.ts @@ -11,6 +11,7 @@ export type ComponentEditorStoreValue = { /** neither deleted nor its pin renamed */ readonly isProtectedNode: (nodeId: CCNodeId) => boolean; readonly isOffered: (component: CCComponent) => boolean; + readonly hasProperties: (componentId: CCComponentId) => boolean; } & EditorStoreCoreSlice & PerspectiveStoreSlice & ContextMenuStoreSlice; diff --git a/src/pages/tutorial/stage.tsx b/src/pages/tutorial/stage.tsx index 19a98ac..6b267b8 100644 --- a/src/pages/tutorial/stage.tsx +++ b/src/pages/tutorial/stage.tsx @@ -211,6 +211,7 @@ function StageView({ stage }: { stage: TutorialStage }) { options={{ isProtectedNode: (nodeId) => isStagePinNode(store, stage, nodeId), isOffered: (component) => isStagePart(stage, component), + hasProperties: (componentId) => componentId !== stage.componentId, }} onEditComponent={setEditedComponentId} onClose={() => { From 02a879a77689f501b38d433c2e4c94751e9adc35 Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Thu, 19 Nov 2026 21:06:39 +0900 Subject: [PATCH 4/8] feat(tutorial): tell under Delete why the stage's pins stay Right-clicking a selection with a stage's Input or Output nodes now shows Delete with a note naming them: greyed out with "cannot be deleted" when nothing else can go, or "stay" when the rest of the selection is deleted. Co-Authored-By: Claude Opus 5.5 --- src/i18n/en.ts | 8 +++++ src/i18n/ja.ts | 2 ++ .../edit/Editor/components/ContextMenu.tsx | 19 +++++++++-- .../store/slices/contextMenu/index.test.ts | 32 ++++++++++++------- .../Editor/store/slices/contextMenu/items.ts | 23 ++++++++++++- 5 files changed, 69 insertions(+), 15 deletions(-) diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 20d85b5..834289e 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -1,6 +1,10 @@ import { englishSimulationErrorTexts } from "../store/simulationErrorTexts"; const bitWidths = (widths: readonly number[]) => `${widths.join("/")} bit`; +const listOf = (names: readonly string[]) => + names.length < 2 + ? names.join("") + : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`; export const en = { languageName: "English", @@ -137,6 +141,10 @@ export const en = { contextMenu: { createComponent: "Create a new component...", edit: "Edit...", + cannotDelete: (names: readonly string[]) => + `${listOf(names)} ${names.length === 1 ? "is" : "are"} used by the stage and cannot be deleted`, + keptOnDelete: (names: readonly string[]) => + `${listOf(names)} ${names.length === 1 ? "is" : "are"} used by the stage and stay`, }, frameControl: { auto: "Auto", diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index 6000958..ba155a6 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -133,6 +133,8 @@ export const ja: Messages = { contextMenu: { createComponent: "新しいコンポーネントにまとめる...", edit: "編集...", + cannotDelete: (names) => `${names.join("・")} は課題で使うので消せません`, + keptOnDelete: (names) => `${names.join("・")} は課題で使うので残ります`, }, frameControl: { auto: "自動", diff --git a/src/pages/edit/Editor/components/ContextMenu.tsx b/src/pages/edit/Editor/components/ContextMenu.tsx index 3cb7c1c..318944e 100644 --- a/src/pages/edit/Editor/components/ContextMenu.tsx +++ b/src/pages/edit/Editor/components/ContextMenu.tsx @@ -1,6 +1,7 @@ import { ClickAwayListener, Divider, + ListItemText, MenuItem, MenuList, Paper, @@ -34,6 +35,7 @@ export default function CCComponentEditorContextMenu({ const { selectedConnectionIds, removableNodeIds, + keptNodeNames, canExtract, canDelete, componentToEdit, @@ -69,8 +71,9 @@ export default function CCComponentEditorContextMenu({ {messages.editor.contextMenu.createComponent} )} - {canDelete && ( + {(canDelete || keptNodeNames.length > 0) && ( { if (removableNodeIds.length > 0) store.nodes.unregister(removableNodeIds); @@ -80,10 +83,20 @@ export default function CCComponentEditorContextMenu({ componentEditorState.closeContextMenu(); }} > - {messages.common.delete} + )} - {componentToEdit && (canExtract || canDelete) && } + {componentToEdit && + (canExtract || canDelete || keptNodeNames.length > 0) && } {componentToEdit && ( { diff --git a/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts b/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts index ad2cdd0..d876ff1 100644 --- a/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts +++ b/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts @@ -1,15 +1,12 @@ import nullthrows from "nullthrows"; import type { MouseEvent } from "react"; import { describe, expect, it } from "vitest"; -import { - input, - not, - true_, -} from "../../../../../../store/intrinsics/definitions"; +import { not, true_ } from "../../../../../../store/intrinsics/definitions"; import { connectTestNodePins, createTestStore, registerTestComponent, + registerTestInputNode, registerTestNode, testNodePin, } from "../../../../../../store/testUtils"; @@ -123,24 +120,37 @@ describe("Context menu slice", () => { }); }); - it("leaves protected nodes out of what it deletes or moves", () => { + it("keeps protected nodes from deleting and moving, and names them", () => { const store = createTestStore(); const root = registerTestComponent(store, "Root"); - const pin = registerTestNode(store, root.id, input.component.id); + const pin = registerTestInputNode(store, root.id, "A"); const gate = registerTestNode(store, root.id, not.component.id); + connectTestNodePins( + store, + root.id, + pin.out, + testNodePin(store, gate, not.inputPin.In), + ); const editorStore = createEditorStore(root.id, store, { - isProtectedNode: (nodeId) => nodeId === pin.id, + isProtectedNode: (nodeId) => nodeId === pin.node.id, }); - editorStore.getState().selectNode([pin.id, gate.id], true); + const items = () => getContextMenuItems(store, editorStore.getState()); - expect(getContextMenuItems(store, editorStore.getState())).toMatchObject({ + editorStore.getState().selectNode([pin.node.id, gate.id], true); + expect(items()).toMatchObject({ removableNodeIds: [gate.id], + keptNodeNames: ["A"], canDelete: true, }); - editorStore.getState().selectNode([pin.id], true); + editorStore.getState().selectNode([pin.node.id], true); + expect(items()).toMatchObject({ keptNodeNames: ["A"], canDelete: false }); editorStore.getState().openContextMenu(rightClick); + expect(editorStore.getState().contextMenuState).not.toBeNull(); + editorStore.getState().setEditorMode("play"); + expect(editorStore.getState().editorMode).toBe("play"); + editorStore.getState().openContextMenu(rightClick); expect(editorStore.getState().contextMenuState).toBeNull(); }); }); diff --git a/src/pages/edit/Editor/store/slices/contextMenu/items.ts b/src/pages/edit/Editor/store/slices/contextMenu/items.ts index 897897f..07d9d9d 100644 --- a/src/pages/edit/Editor/store/slices/contextMenu/items.ts +++ b/src/pages/edit/Editor/store/slices/contextMenu/items.ts @@ -9,11 +9,22 @@ import type { ComponentEditorStoreValue } from "../../types"; export type ContextMenuItems = { selectedConnectionIds: CCConnectionId[]; removableNodeIds: CCNodeId[]; + keptNodeNames: string[]; canExtract: boolean; canDelete: boolean; componentToEdit: CCComponent | null; }; +function nameOfNode(store: CCStore, nodeId: CCNodeId): string { + const exposedPin = store.nodePins + .getManyByNodeId(nodeId) + .map((nodePin) => store.componentPins.getByImplementation(nodePin.id)) + .find((componentPin) => componentPin !== undefined); + if (exposedPin) return exposedPin.name; + const node = nullthrows(store.nodes.get(nodeId)); + return nullthrows(store.components.get(node.componentId)).name; +} + export function getContextMenuItems( store: CCStore, state: ComponentEditorStoreValue, @@ -41,6 +52,11 @@ export function getContextMenuItems( return { selectedConnectionIds, removableNodeIds, + keptNodeNames: isEditMode + ? selectedNodeIds + .filter((nodeId) => state.isProtectedNode(nodeId)) + .map((nodeId) => nameOfNode(store, nodeId)) + : [], canExtract: isEditMode && getExtractableNodeIds(store, removableNodeIds).length > 0, canDelete: @@ -51,5 +67,10 @@ export function getContextMenuItems( } export function hasContextMenuItems(items: ContextMenuItems): boolean { - return items.canExtract || items.canDelete || items.componentToEdit !== null; + return ( + items.canExtract || + items.canDelete || + items.keptNodeNames.length > 0 || + items.componentToEdit !== null + ); } From a848258f0b7942286e3081abe5a5a2530d9280aa Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Thu, 19 Nov 2026 21:08:25 +0900 Subject: [PATCH 5/8] fix(editor): wrap the note under Delete instead of widening the menu Menu items do not wrap, so a note naming many nodes would stretch the menu without end. The menu now has a maximum width and the note wraps within it. Co-Authored-By: Claude Opus 5.5 --- src/pages/edit/Editor/components/ContextMenu.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/edit/Editor/components/ContextMenu.tsx b/src/pages/edit/Editor/components/ContextMenu.tsx index 318944e..7fd6bac 100644 --- a/src/pages/edit/Editor/components/ContextMenu.tsx +++ b/src/pages/edit/Editor/components/ContextMenu.tsx @@ -51,6 +51,7 @@ export default function CCComponentEditorContextMenu({ top: `${componentEditorState.contextMenuState.position.y}px`, left: `${componentEditorState.contextMenuState.position.x}px`, minWidth: "200px", + maxWidth: "280px", }} > {/* @@ -84,6 +85,7 @@ export default function CCComponentEditorContextMenu({ }} > Date: Thu, 19 Nov 2026 21:25:43 +0900 Subject: [PATCH 6/8] feat(tutorial): let each stage decide whether new components can be made Grouping nodes into a new component turns them into a box that cannot be undone, which the first stages do not need. A stage now says whether it allows that, and the first two do not. Inside a component the player made, the stage also offers Input and Output nodes, so a stage that allows new components lets them get more pins. Co-Authored-By: Claude Opus 5.5 --- src/pages/edit/Editor/store/index.tsx | 8 +++++- .../store/slices/contextMenu/index.test.ts | 21 ++++++++++++++++ .../Editor/store/slices/contextMenu/items.ts | 4 ++- src/pages/edit/Editor/store/types.ts | 6 ++++- src/pages/edit/SidePanel.tsx | 5 +++- src/pages/edit/placement.ts | 7 ++++-- src/pages/tutorial/stage.tsx | 8 ++++-- src/tutorial/check.test.ts | 25 +++++++++++++++++++ src/tutorial/stages.test.ts | 21 ++++++++++++---- src/tutorial/stages.ts | 18 +++++++++++-- 10 files changed, 108 insertions(+), 15 deletions(-) diff --git a/src/pages/edit/Editor/store/index.tsx b/src/pages/edit/Editor/store/index.tsx index 9f75236..05f2a4e 100644 --- a/src/pages/edit/Editor/store/index.tsx +++ b/src/pages/edit/Editor/store/index.tsx @@ -12,7 +12,11 @@ import type { ComponentEditorStoreValue } from "./types"; export type EditorStoreOptions = { isProtectedNode?: (nodeId: CCNodeId) => boolean; - isOffered?: (component: CCComponent) => boolean; + isOffered?: ( + component: CCComponent, + editedComponentId: CCComponentId, + ) => boolean; + canCreateComponents?: boolean; hasProperties?: (componentId: CCComponentId) => boolean; }; @@ -23,6 +27,7 @@ export function createEditorStore( isProtectedNode = () => false, isOffered = () => true, hasProperties = () => true, + canCreateComponents = true, }: EditorStoreOptions = {}, ) { const props = { store, componentId }; @@ -34,6 +39,7 @@ export function createEditorStore( isProtectedNode, isOffered, hasProperties, + canCreateComponents, ...coreSlice.define(set, get), ...perspectiveSlice.define(set, get), ...contextMenuSlice.define(set, get), diff --git a/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts b/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts index d876ff1..1d61bec 100644 --- a/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts +++ b/src/pages/edit/Editor/store/slices/contextMenu/index.test.ts @@ -153,4 +153,25 @@ describe("Context menu slice", () => { editorStore.getState().openContextMenu(rightClick); expect(editorStore.getState().contextMenuState).toBeNull(); }); + + it("offers no new component when the editor is told not to", () => { + const { store, editorStore, inverter } = setUp(); + const closed = createEditorStore( + editorStore.getState().componentId, + store, + { + canCreateComponents: false, + }, + ); + editorStore.getState().selectNode([inverter.id], true); + closed.getState().selectNode([inverter.id], true); + + expect(getContextMenuItems(store, editorStore.getState()).canExtract).toBe( + true, + ); + expect(getContextMenuItems(store, closed.getState())).toMatchObject({ + canExtract: false, + canDelete: true, + }); + }); }); diff --git a/src/pages/edit/Editor/store/slices/contextMenu/items.ts b/src/pages/edit/Editor/store/slices/contextMenu/items.ts index 07d9d9d..1caa845 100644 --- a/src/pages/edit/Editor/store/slices/contextMenu/items.ts +++ b/src/pages/edit/Editor/store/slices/contextMenu/items.ts @@ -58,7 +58,9 @@ export function getContextMenuItems( .map((nodeId) => nameOfNode(store, nodeId)) : [], canExtract: - isEditMode && getExtractableNodeIds(store, removableNodeIds).length > 0, + isEditMode && + state.canCreateComponents && + getExtractableNodeIds(store, removableNodeIds).length > 0, canDelete: isEditMode && (removableNodeIds.length > 0 || selectedConnectionIds.length > 0), diff --git a/src/pages/edit/Editor/store/types.ts b/src/pages/edit/Editor/store/types.ts index 8c22926..a7bc0e0 100644 --- a/src/pages/edit/Editor/store/types.ts +++ b/src/pages/edit/Editor/store/types.ts @@ -10,7 +10,11 @@ export type ComponentEditorStoreValue = { readonly componentId: CCComponentId; /** neither deleted nor its pin renamed */ readonly isProtectedNode: (nodeId: CCNodeId) => boolean; - readonly isOffered: (component: CCComponent) => boolean; + readonly isOffered: ( + component: CCComponent, + editedComponentId: CCComponentId, + ) => boolean; + readonly canCreateComponents: boolean; readonly hasProperties: (componentId: CCComponentId) => boolean; } & EditorStoreCoreSlice & PerspectiveStoreSlice & diff --git a/src/pages/edit/SidePanel.tsx b/src/pages/edit/SidePanel.tsx index dce5a58..1f9688b 100644 --- a/src/pages/edit/SidePanel.tsx +++ b/src/pages/edit/SidePanel.tsx @@ -13,7 +13,10 @@ import { canPlaceComponent } from "./placement"; export type SidePanelProps = { editedComponentId: CCComponentId; - isOffered?: (component: CCComponent) => boolean; + isOffered?: ( + component: CCComponent, + editedComponentId: CCComponentId, + ) => boolean; }; function ComponentRenderer({ componentId }: { componentId: CCComponentId }) { diff --git a/src/pages/edit/placement.ts b/src/pages/edit/placement.ts index f39d3a0..a1c56e8 100644 --- a/src/pages/edit/placement.ts +++ b/src/pages/edit/placement.ts @@ -10,13 +10,16 @@ export function canPlaceComponent( store: CCStore, editedComponentId: CCComponentId, componentId: CCComponentId, - isOffered: (component: CCComponent) => boolean, + isOffered: ( + component: CCComponent, + editedComponentId: CCComponentId, + ) => boolean, ): boolean { const component = store.components.get(componentId); return ( !!component && component.id !== editedComponentId && !isIncluding(store, component.id, editedComponentId) && - isOffered(component) + isOffered(component, editedComponentId) ); } diff --git a/src/pages/tutorial/stage.tsx b/src/pages/tutorial/stage.tsx index 6b267b8..ee03859 100644 --- a/src/pages/tutorial/stage.tsx +++ b/src/pages/tutorial/stage.tsx @@ -201,7 +201,9 @@ function StageView({ stage }: { stage: TutorialStage }) { isStagePart(stage, component)} + isOffered={(component, componentId) => + isStagePart(stage, component, componentId) + } /> @@ -210,7 +212,9 @@ function StageView({ stage }: { stage: TutorialStage }) { componentId={shownComponentId} options={{ isProtectedNode: (nodeId) => isStagePinNode(store, stage, nodeId), - isOffered: (component) => isStagePart(stage, component), + isOffered: (component, componentId) => + isStagePart(stage, component, componentId), + canCreateComponents: stage.allowsNewComponents, hasProperties: (componentId) => componentId !== stage.componentId, }} onEditComponent={setEditedComponentId} diff --git a/src/tutorial/check.test.ts b/src/tutorial/check.test.ts index 4b58b79..0499f0d 100644 --- a/src/tutorial/check.test.ts +++ b/src/tutorial/check.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from "vitest"; +import { extractNodesIntoNewComponent } from "../store/extractComponent"; import { and, not, or } from "../store/intrinsics/definitions"; import { connectTestNodePins, @@ -106,6 +107,30 @@ describe("checkCombinational", () => { }); }); + it("passes a circuit grouped into a component of the player's own", async () => { + const store = wireGate(andStage, and); + const gates = store.nodes + .getManyByParentComponentId(andStage.componentId) + .filter((node) => node.componentId === and.component.id); + + await extractNodesIntoNewComponent( + store, + gates.map((node) => node.id), + "Mine", + ); + + expect( + store.nodes + .getManyByParentComponentId(andStage.componentId) + .some((node) => node.componentId === and.component.id), + ).toBe(false); + expect( + checkCombinational(store, andStage.componentId, andStage.check), + ).toEqual({ + type: "passed", + }); + }); + it("tells the first inputs for which an output is wrong", () => { const store = wireGate(andStage, or); diff --git a/src/tutorial/stages.test.ts b/src/tutorial/stages.test.ts index ad01614..086dd98 100644 --- a/src/tutorial/stages.test.ts +++ b/src/tutorial/stages.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { and, input, xor } from "../store/intrinsics/definitions"; +import { and, input, output, xor } from "../store/intrinsics/definitions"; import { createTestStore, registerTestComponent, @@ -37,10 +37,21 @@ describe("isStagePart", () => { it("offers the stage's parts and the components the player made", () => { const store = createTestStore(); const own = registerTestComponent(store, "Mine"); + const inStage = (component: Parameters[1]) => + isStagePart(stage, component, stage.componentId); - expect(isStagePart(stage, and.component)).toBe(true); - expect(isStagePart(stage, own)).toBe(true); - expect(isStagePart(stage, xor.component)).toBe(false); - expect(isStagePart(stage, input.component)).toBe(false); + expect(inStage(and.component)).toBe(true); + expect(inStage(own)).toBe(true); + expect(inStage(xor.component)).toBe(false); + expect(inStage(input.component)).toBe(false); + }); + + it("offers pins inside a component the player made", () => { + const store = createTestStore(); + const own = registerTestComponent(store, "Mine"); + + expect(isStagePart(stage, input.component, own.id)).toBe(true); + expect(isStagePart(stage, output.component, own.id)).toBe(true); + expect(isStagePart(stage, xor.component, own.id)).toBe(false); }); }); diff --git a/src/tutorial/stages.ts b/src/tutorial/stages.ts index f7a26b7..c086665 100644 --- a/src/tutorial/stages.ts +++ b/src/tutorial/stages.ts @@ -19,6 +19,7 @@ export type TutorialStage = { componentId: CCComponentId; /** the intrinsic components the side panel offers */ parts: readonly CCComponentId[]; + allowsNewComponents: boolean; /** also the input and output pins the stage starts with */ check: CombinationalCheck; }; @@ -34,6 +35,7 @@ function twoSwitchesStage( id, componentId: `tutorial-${id}` as CCComponentId, parts: [and.component.id, or.component.id, not.component.id], + allowsNewComponents: false, check: { inputs: [ { name: "A", bitWidth: 1 }, @@ -56,8 +58,20 @@ export function findTutorialStage(id: string | undefined) { return tutorialStages.find((stage) => stage.id === id); } -export function isStagePart(stage: TutorialStage, component: CCComponent) { - return !component.intrinsicType || stage.parts.includes(component.id); +export function isStagePart( + stage: TutorialStage, + component: CCComponent, + editedComponentId: CCComponentId, +) { + if (!component.intrinsicType || stage.parts.includes(component.id)) { + return true; + } + // A component of the player's own gets its pins from Input and Output nodes + return ( + editedComponentId !== stage.componentId && + (component.id === input.component.id || + component.id === output.component.id) + ); } export function isStagePinNode( From c395e831d4191258cd30a6eb30f487bc7cdfcabb Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Thu, 19 Nov 2026 21:29:18 +0900 Subject: [PATCH 7/8] refactor: tidy the stage protections after review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drops the properties dialog's protected pins, which it can no longer be opened for, and a condition that could not matter. One type now describes which components are offered, the context menu splits the selection in one pass, and the Delete item keeps the height of the others. The notes on kept nodes read better in English and use 、 in Japanese, like the other lists. Co-Authored-By: Claude Opus 5.5 --- src/components/ComponentPropertyDialog.tsx | 12 +----------- src/i18n/en.ts | 6 ++++-- src/i18n/ja.ts | 4 ++-- src/i18n/messages.test.ts | 19 +++++++++++++++++++ .../edit/Editor/components/ContextMenu.tsx | 4 ++-- src/pages/edit/Editor/index.tsx | 10 +--------- src/pages/edit/Editor/store/index.tsx | 8 +++----- .../Editor/store/slices/contextMenu/items.ts | 9 ++++----- src/pages/edit/Editor/store/types.ts | 9 +++------ src/pages/edit/SidePanel.tsx | 9 +++------ src/pages/edit/placement.ts | 10 ++++++---- src/pages/tutorial/stage.tsx | 11 ++++++----- 12 files changed, 54 insertions(+), 57 deletions(-) diff --git a/src/components/ComponentPropertyDialog.tsx b/src/components/ComponentPropertyDialog.tsx index 0890636..e2d6b9f 100644 --- a/src/components/ComponentPropertyDialog.tsx +++ b/src/components/ComponentPropertyDialog.tsx @@ -15,13 +15,11 @@ import { z } from "zod"; import { useMessages } from "../i18n"; import type CCStore from "../store"; import type { CCComponentId } from "../store/component"; -import type { CCComponentPin, CCComponentPinId } from "../store/componentPin"; -import type { CCNodeId } from "../store/node"; +import type { CCComponentPinId } from "../store/componentPin"; import { useStore } from "../store/react"; export type ComponentPropertyDialogProps = { componentId: CCComponentId; - isProtectedNode: (nodeId: CCNodeId) => boolean; onClose(): void; }; @@ -56,7 +54,6 @@ function applyStateToStore( export function ComponentPropertyDialog({ componentId, - isProtectedNode, onClose, }: ComponentPropertyDialogProps) { const { store } = useStore(); @@ -66,11 +63,6 @@ export function ComponentPropertyDialog({ extractStateFromStore(store, componentId), ); const result = stateSchema.safeParse(state); - const isPinProtected = (pin: CCComponentPin) => { - const nodePin = - pin.implementation && store.nodePins.get(pin.implementation); - return !!nodePin && isProtectedNode(nodePin.nodeId); - }; return ( @@ -118,7 +110,6 @@ export function ComponentPropertyDialog({ size="small" value={state.pinNameById.get(pin.id)} fullWidth - disabled={isPinProtected(pin)} onChange={(e) => setState({ ...state, @@ -144,7 +135,6 @@ export function ComponentPropertyDialog({ size="small" value={state.pinNameById.get(pin.id)} fullWidth - disabled={isPinProtected(pin)} onChange={(e) => setState({ ...state, diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 834289e..66e0a7d 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -5,6 +5,8 @@ const listOf = (names: readonly string[]) => names.length < 2 ? names.join("") : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`; +const themOf = (names: readonly string[]) => + names.length === 1 ? "it" : "them"; export const en = { languageName: "English", @@ -142,9 +144,9 @@ export const en = { createComponent: "Create a new component...", edit: "Edit...", cannotDelete: (names: readonly string[]) => - `${listOf(names)} ${names.length === 1 ? "is" : "are"} used by the stage and cannot be deleted`, + `${listOf(names)} cannot be deleted, as the stage uses ${themOf(names)}`, keptOnDelete: (names: readonly string[]) => - `${listOf(names)} ${names.length === 1 ? "is" : "are"} used by the stage and stay`, + `${listOf(names)} ${names.length === 1 ? "is" : "are"} kept, as the stage uses ${themOf(names)}`, }, frameControl: { auto: "Auto", diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index ba155a6..d0a09c7 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -133,8 +133,8 @@ export const ja: Messages = { contextMenu: { createComponent: "新しいコンポーネントにまとめる...", edit: "編集...", - cannotDelete: (names) => `${names.join("・")} は課題で使うので消せません`, - keptOnDelete: (names) => `${names.join("・")} は課題で使うので残ります`, + cannotDelete: (names) => `${names.join("、")} は課題で使うので消せません`, + keptOnDelete: (names) => `${names.join("、")} は課題で使うので残ります`, }, frameControl: { auto: "自動", diff --git a/src/i18n/messages.test.ts b/src/i18n/messages.test.ts index 9588d08..8c91644 100644 --- a/src/i18n/messages.test.ts +++ b/src/i18n/messages.test.ts @@ -112,3 +112,22 @@ describe("English messages", () => { ); }); }); + +describe("the note on nodes a delete keeps", () => { + it("lists the nodes in a sentence", () => { + const { en, ja } = messagesByLanguage; + + expect(en.editor.contextMenu.cannotDelete(["A"])).toBe( + "A cannot be deleted, as the stage uses it", + ); + expect(en.editor.contextMenu.keptOnDelete(["A", "Out"])).toBe( + "A and Out are kept, as the stage uses them", + ); + expect(en.editor.contextMenu.cannotDelete(["A", "B", "Out"])).toBe( + "A, B and Out cannot be deleted, as the stage uses them", + ); + expect(ja.editor.contextMenu.keptOnDelete(["A", "B", "Out"])).toBe( + "A、B、Out は課題で使うので残ります", + ); + }); +}); diff --git a/src/pages/edit/Editor/components/ContextMenu.tsx b/src/pages/edit/Editor/components/ContextMenu.tsx index 7fd6bac..9c2123b 100644 --- a/src/pages/edit/Editor/components/ContextMenu.tsx +++ b/src/pages/edit/Editor/components/ContextMenu.tsx @@ -85,6 +85,7 @@ export default function CCComponentEditorContextMenu({ }} > )} - {componentToEdit && - (canExtract || canDelete || keptNodeNames.length > 0) && } + {componentToEdit && (canExtract || canDelete) && } {componentToEdit && ( { diff --git a/src/pages/edit/Editor/index.tsx b/src/pages/edit/Editor/index.tsx index 099bfcd..cf4ab63 100644 --- a/src/pages/edit/Editor/index.tsx +++ b/src/pages/edit/Editor/index.tsx @@ -11,11 +11,7 @@ import CCComponentEditorNotifications from "./components/Notifications"; import CCComponentEditorTitleBar from "./components/TitleBar"; import CCComponentEditorViewModeSwitcher from "./components/ViewModeSwitcher"; import CCComponentEditorRenderer from "./renderer"; -import { - ComponentEditorStoreProvider, - type EditorStoreOptions, - useComponentEditorStore, -} from "./store"; +import { ComponentEditorStoreProvider, type EditorStoreOptions } from "./store"; export type CCComponentEditorProps = { componentId: CCComponentId; @@ -31,9 +27,6 @@ function CCComponentEditorContent({ }: CCComponentEditorProps) { const [propertyDialogComponentId, setPropertyDialogComponentId] = useState(null); - const isProtectedNode = useComponentEditorStore()( - (state) => state.isProtectedNode, - ); return ( setPropertyDialogComponentId(null)} /> )} diff --git a/src/pages/edit/Editor/store/index.tsx b/src/pages/edit/Editor/store/index.tsx index 05f2a4e..55463e3 100644 --- a/src/pages/edit/Editor/store/index.tsx +++ b/src/pages/edit/Editor/store/index.tsx @@ -2,9 +2,10 @@ import { createContext, useContext, useState } from "react"; import invariant from "tiny-invariant"; import { create } from "zustand"; import type CCStore from "../../../../store"; -import type { CCComponent, CCComponentId } from "../../../../store/component"; +import type { CCComponentId } from "../../../../store/component"; import type { CCNodeId } from "../../../../store/node"; import { useStore } from "../../../../store/react"; +import type { OffersComponent } from "../../placement"; import createComponentEditorStoreContextMenuSlice from "./slices/contextMenu"; import { createComponentEditorStoreCoreSlice } from "./slices/core"; import createComponentEditorStorePerspectiveSlice from "./slices/perspective"; @@ -12,10 +13,7 @@ import type { ComponentEditorStoreValue } from "./types"; export type EditorStoreOptions = { isProtectedNode?: (nodeId: CCNodeId) => boolean; - isOffered?: ( - component: CCComponent, - editedComponentId: CCComponentId, - ) => boolean; + isOffered?: OffersComponent; canCreateComponents?: boolean; hasProperties?: (componentId: CCComponentId) => boolean; }; diff --git a/src/pages/edit/Editor/store/slices/contextMenu/items.ts b/src/pages/edit/Editor/store/slices/contextMenu/items.ts index 1caa845..c98a9b6 100644 --- a/src/pages/edit/Editor/store/slices/contextMenu/items.ts +++ b/src/pages/edit/Editor/store/slices/contextMenu/items.ts @@ -1,3 +1,4 @@ +import { partition } from "es-toolkit"; import nullthrows from "nullthrows"; import type CCStore from "../../../../../../store"; import type { CCComponent } from "../../../../../../store/component"; @@ -37,8 +38,8 @@ export function getContextMenuItems( (connectionId) => store.connections.get(connectionId), ); const isEditMode = state.editorMode === "edit"; - const removableNodeIds = selectedNodeIds.filter( - (nodeId) => !state.isProtectedNode(nodeId), + const [keptNodeIds, removableNodeIds] = partition(selectedNodeIds, (nodeId) => + state.isProtectedNode(nodeId), ); const [targetNodeId] = selectedNodeIds; const targetComponent = @@ -53,9 +54,7 @@ export function getContextMenuItems( selectedConnectionIds, removableNodeIds, keptNodeNames: isEditMode - ? selectedNodeIds - .filter((nodeId) => state.isProtectedNode(nodeId)) - .map((nodeId) => nameOfNode(store, nodeId)) + ? keptNodeIds.map((nodeId) => nameOfNode(store, nodeId)) : [], canExtract: isEditMode && diff --git a/src/pages/edit/Editor/store/types.ts b/src/pages/edit/Editor/store/types.ts index a7bc0e0..cb5ad00 100644 --- a/src/pages/edit/Editor/store/types.ts +++ b/src/pages/edit/Editor/store/types.ts @@ -1,19 +1,16 @@ import type { StoreApi } from "zustand"; import type CCStore from "../../../../store"; -import type { CCComponent, CCComponentId } from "../../../../store/component"; +import type { CCComponentId } from "../../../../store/component"; import type { CCNodeId } from "../../../../store/node"; +import type { OffersComponent } from "../../placement"; import type { ContextMenuStoreSlice } from "./slices/contextMenu/types"; import type { EditorStoreCoreSlice } from "./slices/core/types"; import type { PerspectiveStoreSlice } from "./slices/perspective/types"; export type ComponentEditorStoreValue = { readonly componentId: CCComponentId; - /** neither deleted nor its pin renamed */ readonly isProtectedNode: (nodeId: CCNodeId) => boolean; - readonly isOffered: ( - component: CCComponent, - editedComponentId: CCComponentId, - ) => boolean; + readonly isOffered: OffersComponent; readonly canCreateComponents: boolean; readonly hasProperties: (componentId: CCComponentId) => boolean; } & EditorStoreCoreSlice & diff --git a/src/pages/edit/SidePanel.tsx b/src/pages/edit/SidePanel.tsx index 1f9688b..fa9c0a2 100644 --- a/src/pages/edit/SidePanel.tsx +++ b/src/pages/edit/SidePanel.tsx @@ -4,19 +4,16 @@ import { useState } from "react"; import invariant from "tiny-invariant"; import { setDataTransferAsComponent } from "../../common/serialization"; import { useMessages } from "../../i18n"; -import type { CCComponent, CCComponentId } from "../../store/component"; +import type { CCComponentId } from "../../store/component"; import { ccPinTypes } from "../../store/componentPin"; import { useStore } from "../../store/react"; import { useComponents } from "../../store/react/selectors"; import { theme } from "../../style"; -import { canPlaceComponent } from "./placement"; +import { canPlaceComponent, type OffersComponent } from "./placement"; export type SidePanelProps = { editedComponentId: CCComponentId; - isOffered?: ( - component: CCComponent, - editedComponentId: CCComponentId, - ) => boolean; + isOffered?: OffersComponent; }; function ComponentRenderer({ componentId }: { componentId: CCComponentId }) { diff --git a/src/pages/edit/placement.ts b/src/pages/edit/placement.ts index a1c56e8..832a2b9 100644 --- a/src/pages/edit/placement.ts +++ b/src/pages/edit/placement.ts @@ -5,15 +5,17 @@ import { isIncluding, } from "../../store/component"; +export type OffersComponent = ( + component: CCComponent, + editedComponentId: CCComponentId, +) => boolean; + // A drop can carry any id, e.g. one dragged from another tab export function canPlaceComponent( store: CCStore, editedComponentId: CCComponentId, componentId: CCComponentId, - isOffered: ( - component: CCComponent, - editedComponentId: CCComponentId, - ) => boolean, + isOffered: OffersComponent, ): boolean { const component = store.components.get(componentId); return ( diff --git a/src/pages/tutorial/stage.tsx b/src/pages/tutorial/stage.tsx index ee03859..15e67d7 100644 --- a/src/pages/tutorial/stage.tsx +++ b/src/pages/tutorial/stage.tsx @@ -36,6 +36,7 @@ import { tutorialStages, } from "../../tutorial/stages"; import CCComponentEditor from "../edit/Editor"; +import type { OffersComponent } from "../edit/placement"; import SidePanel from "../edit/SidePanel"; function formatValue(value: SimulationValue, texts: Messages["tutorial"]) { @@ -122,6 +123,9 @@ function StageView({ stage }: { stage: TutorialStage }) { } }; + const isOffered: OffersComponent = (component, componentId) => + isStagePart(stage, component, componentId); + const shownComponentId = store.components.get(editedComponentId) ? editedComponentId : stage.componentId; @@ -201,9 +205,7 @@ function StageView({ stage }: { stage: TutorialStage }) { - isStagePart(stage, component, componentId) - } + isOffered={isOffered} /> @@ -212,8 +214,7 @@ function StageView({ stage }: { stage: TutorialStage }) { componentId={shownComponentId} options={{ isProtectedNode: (nodeId) => isStagePinNode(store, stage, nodeId), - isOffered: (component, componentId) => - isStagePart(stage, component, componentId), + isOffered, canCreateComponents: stage.allowsNewComponents, hasProperties: (componentId) => componentId !== stage.componentId, }} From 485e3e15b0af024489c4bc279e6124710a185a02 Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Thu, 19 Nov 2026 22:02:40 +0900 Subject: [PATCH 8/8] test: cover every form of the notes on kept nodes Also keeps the divider above Edit when only protected nodes are selected, which the editor's option allows for any node, not only Input and Output. Co-Authored-By: Claude Opus 5.5 --- src/i18n/messages.test.ts | 6 ++++++ src/pages/edit/Editor/components/ContextMenu.tsx | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/i18n/messages.test.ts b/src/i18n/messages.test.ts index 8c91644..e7db275 100644 --- a/src/i18n/messages.test.ts +++ b/src/i18n/messages.test.ts @@ -120,12 +120,18 @@ describe("the note on nodes a delete keeps", () => { expect(en.editor.contextMenu.cannotDelete(["A"])).toBe( "A cannot be deleted, as the stage uses it", ); + expect(en.editor.contextMenu.keptOnDelete(["A"])).toBe( + "A is kept, as the stage uses it", + ); expect(en.editor.contextMenu.keptOnDelete(["A", "Out"])).toBe( "A and Out are kept, as the stage uses them", ); expect(en.editor.contextMenu.cannotDelete(["A", "B", "Out"])).toBe( "A, B and Out cannot be deleted, as the stage uses them", ); + expect(ja.editor.contextMenu.cannotDelete(["A"])).toBe( + "A は課題で使うので消せません", + ); expect(ja.editor.contextMenu.keptOnDelete(["A", "B", "Out"])).toBe( "A、B、Out は課題で使うので残ります", ); diff --git a/src/pages/edit/Editor/components/ContextMenu.tsx b/src/pages/edit/Editor/components/ContextMenu.tsx index 9c2123b..0198baa 100644 --- a/src/pages/edit/Editor/components/ContextMenu.tsx +++ b/src/pages/edit/Editor/components/ContextMenu.tsx @@ -98,7 +98,8 @@ export default function CCComponentEditorContextMenu({ /> )} - {componentToEdit && (canExtract || canDelete) && } + {componentToEdit && + (canExtract || canDelete || keptNodeNames.length > 0) && } {componentToEdit && ( {