/** * @file Settings Editor Example * @description Demonstrates how to use SettingsManager to configure editor behavior */ import * as React from "react"; import { NodeEditor, SettingsManager, createNodeDefinition } from "../../../../core"; import type { EditorSettingKey, SettingValue } from "../../../../settings/types"; import type { NodeEditorData } from "../../../../types/core"; import { PropertySection } from "../../../../components/inspector/parts/PropertySection"; import { InspectorFieldRow } from "../../../../components/inspector/parts/InspectorFieldRow"; import { InspectorInput } from "../../../../components/inspector/parts/InspectorInput"; import { InspectorSelect } from "../../../../components/inspector/parts/InspectorSelect"; import { InspectorButton } from "../../../../components/inspector/parts/InspectorButton"; import { InspectorButtonGroup } from "../../../../components/inspector/parts/InspectorButtonGroup"; import { InspectorSectionTitle } from "../../../../components/inspector/parts/InspectorSectionTitle"; import styles from "./SettingsEditorExample.module.css"; const sampleNodeDefinitions = [ createNodeDefinition({ type: "input", displayName: "Input", category: "Basic", defaultSize: { width: 180, height: 80 }, ports: [{ id: "out", type: "output", label: "Output", position: "right" }], }), createNodeDefinition({ type: "process", displayName: "Process", category: "Basic", defaultSize: { width: 200, height: 100 }, ports: [ { id: "in", type: "input", label: "Input", position: "left" }, { id: "out", type: "output", label: "Output", position: "right" }, ], }), createNodeDefinition({ type: "output", displayName: "Output", category: "Basic", defaultSize: { width: 180, height: 80 }, ports: [{ id: "in", type: "input", label: "Input", position: "left" }], }), ]; const initialData: NodeEditorData = { nodes: { "node-1": { id: "node-1", type: "input", position: { x: 100, y: 150 }, data: { title: "Input Node" }, }, "node-2": { id: "node-2", type: "process", position: { x: 350, y: 130 }, data: { title: "Process Node" }, }, "node-3": { id: "node-3", type: "output", position: { x: 620, y: 150 }, data: { title: "Output Node" }, }, }, connections: { "conn-1": { id: "conn-1", fromNodeId: "node-1", fromPortId: "out", toNodeId: "node-2", toPortId: "in", }, "conn-2": { id: "conn-2", fromNodeId: "node-2", fromPortId: "out", toNodeId: "node-3", toPortId: "in", }, }, }; const booleanOptions = [ { value: "true", label: "On" }, { value: "false", label: "Off" }, ]; export const SettingsEditorExample: React.FC = () => { const settingsManager = React.useMemo(() => new SettingsManager(), []); // Local state for UI updates const [, setUpdateCounter] = React.useState(0); // Subscribe to settings changes React.useEffect(() => { const unsubscribe = settingsManager.on("change", () => { setUpdateCounter((c) => c + 1); }); return unsubscribe; }, [settingsManager]); const getValue = (key: EditorSettingKey): SettingValue | undefined => { return settingsManager.getValue(key); }; const getBoolean = (key: EditorSettingKey, fallback: boolean): boolean => { const value = getValue(key); if (typeof value === "boolean") { return value; } return fallback; }; const getNumber = (key: EditorSettingKey, fallback: number): number => { const value = getValue(key); if (typeof value === "number") { return value; } return fallback; }; const getTheme = (key: EditorSettingKey, fallback: "light" | "dark" | "auto"): "light" | "dark" | "auto" => { const value = getValue(key); if (value === "light" || value === "dark" || value === "auto") { return value; } return fallback; }; const getNodeSearchViewMode = (key: EditorSettingKey, fallback: "list" | "split"): "list" | "split" => { const value = getValue(key); if (value === "list" || value === "split") { return value; } return fallback; }; const getNodeSearchFilterMode = ( key: EditorSettingKey, fallback: "filter" | "highlight", ): "filter" | "highlight" => { const value = getValue(key); if (value === "filter" || value === "highlight") { return value; } return fallback; }; // Appearance settings const theme = getTheme("appearance.theme", "light"); const showGrid = getBoolean("appearance.showGrid", true); const gridSize = getNumber("appearance.gridSize", 20); const gridOpacity = getNumber("appearance.gridOpacity", 0.3); const showMinimap = getBoolean("appearance.showMinimap", true); const showStatusBar = getBoolean("appearance.showStatusBar", true); // Behavior settings const smoothAnimations = getBoolean("behavior.smoothAnimations", true); const doubleClickToEdit = getBoolean("behavior.doubleClickToEdit", true); const nodeSearchViewMode = getNodeSearchViewMode("behavior.nodeSearchViewMode", "list"); const nodeSearchFilterMode = getNodeSearchFilterMode("behavior.nodeSearchFilterMode", "filter"); const nodeSearchMenuWidth = getNumber("behavior.nodeSearchMenuWidth", 360); return (