@sqlrooms/cosmos 0.26.0-rc.3 → 0.26.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"CosmosSimulationControls.d.ts","sourceRoot":"","sources":["../src/CosmosSimulationControls.tsx"],"names":[],"mappings":"AASA,OAAO,EAAC,EAAE,EAAC,MAAM,OAAO,CAAC;AAKzB;;GAEG;AACH,UAAU,6BAA6B;IACrC;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAuDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,wBAAwB,EAAE,EAAE,CAAC,6BAA6B,CA+FtE,CAAC"}
1
+ {"version":3,"file":"CosmosSimulationControls.d.ts","sourceRoot":"","sources":["../src/CosmosSimulationControls.tsx"],"names":[],"mappings":"AASA,OAAO,EAAC,EAAE,EAAC,MAAM,OAAO,CAAC;AAKzB;;GAEG;AACH,UAAU,6BAA6B;IACrC;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAuDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,wBAAwB,EAAE,EAAE,CAAC,6BAA6B,CA6FtE,CAAC"}
@@ -110,10 +110,10 @@ const simulationSliders = [
110
110
  */
111
111
  export const CosmosSimulationControls = ({ className, }) => {
112
112
  const { isSimulationRunning, toggleSimulation, startWithEnergy, updateSimulationConfig, } = useStoreWithCosmos((s) => s.cosmos);
113
- const config = useStoreWithCosmos((s) => s.config.cosmos);
113
+ const config = useStoreWithCosmos((s) => s.cosmos.config);
114
114
  const handleParameterChange = (paramKey, value) => {
115
115
  updateSimulationConfig({ [paramKey]: value[0] });
116
116
  };
117
- return (_jsxs("div", { className: cn('bg-card/90 dark:bg-card/90 w-48 space-y-4 rounded-lg p-3 shadow-lg', className), children: [_jsxs("div", { className: "flex gap-2", children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx(Button, { onClick: toggleSimulation, variant: "outline", size: "sm", className: "flex-1", children: isSimulationRunning ? (_jsx(Pause, { className: "h-4 w-4" })) : (_jsx(Play, { className: "h-4 w-4" })) }) }), _jsx(TooltipContent, { side: "bottom", children: isSimulationRunning ? 'Pause simulation' : 'Start simulation' })] }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx(Button, { onClick: startWithEnergy, variant: "outline", size: "sm", className: "flex-1", children: _jsx(Wind, { className: "h-4 w-4" }) }) }), _jsx(TooltipContent, { side: "bottom", children: "Push energy into simulation" })] })] }), simulationSliders.map(({ key, label, min, max, step }) => (_jsxs("div", { className: "space-y-2", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsxs(Label, { htmlFor: key, className: "flex cursor-help items-center gap-1 text-xs font-medium", children: [_jsx(Info, { className: "text-muted-foreground/50 h-3 w-3" }), label] }) }), _jsx(TooltipContent, { side: "left", className: "max-w-[200px]", children: CosmosSliceConfig.shape.cosmos.shape[key].description })] }), _jsx("span", { className: "text-muted-foreground text-xs tabular-nums", children: config[key].toFixed(2) })] }), _jsx(Slider, { id: key, min: min, max: max, step: step, value: [config[key]], onValueChange: (value) => handleParameterChange(key, value), className: "w-full" })] }, key)))] }));
117
+ return (_jsxs("div", { className: cn('bg-card/90 dark:bg-card/90 w-48 space-y-4 rounded-lg p-3 shadow-lg', className), children: [_jsxs("div", { className: "flex gap-2", children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx(Button, { onClick: toggleSimulation, variant: "outline", size: "sm", className: "flex-1", children: isSimulationRunning ? (_jsx(Pause, { className: "h-4 w-4" })) : (_jsx(Play, { className: "h-4 w-4" })) }) }), _jsx(TooltipContent, { side: "bottom", children: isSimulationRunning ? 'Pause simulation' : 'Start simulation' })] }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx(Button, { onClick: startWithEnergy, variant: "outline", size: "sm", className: "flex-1", children: _jsx(Wind, { className: "h-4 w-4" }) }) }), _jsx(TooltipContent, { side: "bottom", children: "Push energy into simulation" })] })] }), simulationSliders.map(({ key, label, min, max, step }) => (_jsxs("div", { className: "space-y-2", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsxs(Label, { htmlFor: key, className: "flex cursor-help items-center gap-1 text-xs font-medium", children: [_jsx(Info, { className: "text-muted-foreground/50 h-3 w-3" }), label] }) }), _jsx(TooltipContent, { side: "left", className: "max-w-[200px]", children: CosmosSliceConfig.shape[key].description })] }), _jsx("span", { className: "text-muted-foreground text-xs tabular-nums", children: config[key].toFixed(2) })] }), _jsx(Slider, { id: key, min: min, max: max, step: step, value: [config[key]], onValueChange: (value) => handleParameterChange(key, value), className: "w-full" })] }, key)))] }));
118
118
  };
119
119
  //# sourceMappingURL=CosmosSimulationControls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CosmosSimulationControls.js","sourceRoot":"","sources":["../src/CosmosSimulationControls.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,EAAE,EACF,MAAM,EACN,KAAK,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,MAAM,GACP,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AACrD,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACjD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAmBtD;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG;IACxB;QACE,GAAG,EAAE,mBAAmB;QACxB,KAAK,EAAE,SAAS;QAChB,G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AC,IAAI,IAAC,SAAS,EAAC,kCAAkC,GAAG,EACpD,KAAK,IACA,GACO,EACjB,KAAC,cAAc,IAAC,IAAI,EAAC,MAAM,EAAC,SAAS,EAAC,eAAe,YAClD,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,WAAW,GACvC,IACT,EACV,eAAM,SAAS,EAAC,4CAA4C,YACzD,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAClB,IACH,EACN,KAAC,MAAM,IACL,EAAE,EAAE,GAAG,EACP,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EACpB,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,qBAAqB,CAAC,GAAG,EAAE,KAAK,CAAC,EAC3D,SAAS,EAAC,QAAQ,GAClB,KA5BM,GAAG,CA6BP,CACP,CAAC,IACE,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n cn,\n Slider,\n Label,\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n Button,\n} from '@sqlrooms/ui';\nimport {FC} from 'react';\nimport {Info, Pause, Play, Wind} from 'lucide-react';\nimport {useStoreWithCosmos} from './CosmosSlice';\nimport {CosmosSliceConfig} from './CosmosSliceConfig';\n\n/**\n * Props for the CosmosSimulationControls component.\n */\ninterface CosmosSimulationControlsProps {\n /**\n * Optional className to override the default positioning and styling of the controls container.\n * By default, controls are positioned at the top-right corner.\n *\n * @example\n * ```tsx\n * // Position controls at the bottom-right\n * <CosmosSimulationControls className=\"absolute bottom-4 right-4\" />\n * ```\n */\n className?: string;\n}\n\n/**\n * Configuration for each simulation parameter slider.\n * These values define the range and step size for each parameter.\n *\n * @internal\n */\nconst simulationSliders = [\n {\n key: 'simulationGravity',\n label: 'Gravity',\n min: 0,\n max: 0.5,\n step: 0.01,\n },\n {\n key: 'simulationRepulsion',\n label: 'Repulsion',\n min: 0,\n max: 2,\n step: 0.01,\n },\n {\n key: 'simulationLinkSpring',\n label: 'Link Strength',\n min: 0,\n max: 2,\n step: 0.01,\n },\n {\n key: 'simulationLinkDistance',\n label: 'Link Distance',\n min: 1,\n max: 20,\n step: 1,\n },\n {\n key: 'simulationFriction',\n label: 'Friction',\n min: 0,\n max: 1,\n step: 0.01,\n },\n {\n key: 'simulationDecay',\n label: 'Decay',\n min: 100,\n max: 10000,\n step: 100,\n },\n] as const;\n\ntype SimulationKey = (typeof simulationSliders)[number]['key'];\n\n/**\n * A component that provides fine-grained controls for adjusting graph simulation parameters.\n * Uses the zustand store to access and control the graph state.\n *\n * Features:\n * - Slider controls for all simulation parameters\n * - Real-time parameter adjustment\n * - Tooltips with parameter descriptions\n * - Customizable positioning\n * - Default values optimized for common use cases\n *\n * Available parameters:\n * - Gravity (0-0.5): Controls how strongly nodes are pulled toward the center\n * - Repulsion (0-2): Controls how strongly nodes push away from each other\n * - Link Strength (0-2): Controls the spring force between connected nodes\n * - Link Distance (1-20): Sets the natural length of links between nodes\n * - Friction (0-1): Controls how quickly node movement decays\n * - Decay (100-10000): Controls how quickly the simulation \"cools down\"\n *\n * @example Basic usage\n * ```tsx\n * import { CosmosGraph, CosmosSimulationControls } from '@sqlrooms/cosmos';\n *\n * const MyGraph = () => {\n * return (\n * <CosmosGraph {...graphProps}>\n * <CosmosSimulationControls />\n * </CosmosGraph>\n * );\n * };\n * ```\n *\n * @example Custom positioning with other controls\n * ```tsx\n * import { CosmosGraph, CosmosGraphControls, CosmosSimulationControls } from '@sqlrooms/cosmos';\n *\n * const MyGraph = () => {\n * return (\n * <CosmosGraph {...graphProps}>\n * <CosmosGraphControls className=\"absolute top-4 left-4\" />\n * <CosmosSimulationControls className=\"absolute top-4 right-4\" />\n * </CosmosGraph>\n * );\n * };\n * ```\n *\n * @example With custom styling\n * ```tsx\n * <CosmosGraph {...graphProps}>\n * <CosmosSimulationControls\n * className=\"absolute bottom-4 right-4 bg-opacity-75 backdrop-blur-sm\"\n * />\n * </CosmosGraph>\n * ```\n */\nexport const CosmosSimulationControls: FC<CosmosSimulationControlsProps> = ({\n className,\n}) => {\n const {\n isSimulationRunning,\n toggleSimulation,\n startWithEnergy,\n updateSimulationConfig,\n } = useStoreWithCosmos((s) => s.cosmos);\n\n const config = useStoreWithCosmos(\n (s) => s.config.cosmos,\n ) as CosmosSliceConfig['cosmos'];\n\n const handleParameterChange = (paramKey: SimulationKey, value: number[]) => {\n updateSimulationConfig({[paramKey]: value[0]});\n };\n\n return (\n <div\n className={cn(\n 'bg-card/90 dark:bg-card/90 w-48 space-y-4 rounded-lg p-3 shadow-lg',\n className,\n )}\n >\n <div className=\"flex gap-2\">\n <Tooltip>\n <TooltipTrigger asChild>\n <Button\n onClick={toggleSimulation}\n variant=\"outline\"\n size=\"sm\"\n className=\"flex-1\"\n >\n {isSimulationRunning ? (\n <Pause className=\"h-4 w-4\" />\n ) : (\n <Play className=\"h-4 w-4\" />\n )}\n </Button>\n </TooltipTrigger>\n <TooltipContent side=\"bottom\">\n {isSimulationRunning ? 'Pause simulation' : 'Start simulation'}\n </TooltipContent>\n </Tooltip>\n <Tooltip>\n <TooltipTrigger asChild>\n <Button\n onClick={startWithEnergy}\n variant=\"outline\"\n size=\"sm\"\n className=\"flex-1\"\n >\n <Wind className=\"h-4 w-4\" />\n </Button>\n </TooltipTrigger>\n <TooltipContent side=\"bottom\">\n Push energy into simulation\n </TooltipContent>\n </Tooltip>\n </div>\n {simulationSliders.map(({key, label, min, max, step}) => (\n <div key={key} className=\"space-y-2\">\n <div className=\"flex items-center justify-between\">\n <Tooltip>\n <TooltipTrigger asChild>\n <Label\n htmlFor={key}\n className=\"flex cursor-help items-center gap-1 text-xs font-medium\"\n >\n <Info className=\"text-muted-foreground/50 h-3 w-3\" />\n {label}\n </Label>\n </TooltipTrigger>\n <TooltipContent side=\"left\" className=\"max-w-[200px]\">\n {CosmosSliceConfig.shape.cosmos.shape[key].description}\n </TooltipContent>\n </Tooltip>\n <span className=\"text-muted-foreground text-xs tabular-nums\">\n {config[key].toFixed(2)}\n </span>\n </div>\n <Slider\n id={key}\n min={min}\n max={max}\n step={step}\n value={[config[key]]}\n onValueChange={(value) => handleParameterChange(key, value)}\n className=\"w-full\"\n />\n </div>\n ))}\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"CosmosSimulationControls.js","sourceRoot":"","sources":["../src/CosmosSimulationControls.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,EAAE,EACF,MAAM,EACN,KAAK,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,MAAM,GACP,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AACrD,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACjD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAmBtD;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG;IACxB;QACE,GAAG,EAAE,mBAAmB;QACxB,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,GAAG;QACR,IAAI,EAAE,IAAI;KACX;IACD;QACE,GAAG,EAAE,qBAAqB;QAC1B,KAAK,EAAE,WAAW;QAClB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;QACN,IAAI,EAAE,IAAI;KACX;IACD;QACE,GAAG,EAAE,sBAAsB;QAC3B,KAAK,EAAE,eAAe;QACtB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;QACN,IAAI,EAAE,IAAI;KACX;IACD;QACE,GAAG,EAAE,wBAAwB;QAC7B,KAAK,EAAE,eAAe;QACtB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,EAAE;QACP,IAAI,EAAE,CAAC;KACR;IACD;QACE,GAAG,EAAE,oBAAoB;QACzB,KAAK,EAAE,UAA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qBAAqB,CAAC,GAAG,EAAE,KAAK,CAAC,EAC3D,SAAS,EAAC,QAAQ,GAClB,KA5BM,GAAG,CA6BP,CACP,CAAC,IACE,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n cn,\n Slider,\n Label,\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n Button,\n} from '@sqlrooms/ui';\nimport {FC} from 'react';\nimport {Info, Pause, Play, Wind} from 'lucide-react';\nimport {useStoreWithCosmos} from './CosmosSlice';\nimport {CosmosSliceConfig} from './CosmosSliceConfig';\n\n/**\n * Props for the CosmosSimulationControls component.\n */\ninterface CosmosSimulationControlsProps {\n /**\n * Optional className to override the default positioning and styling of the controls container.\n * By default, controls are positioned at the top-right corner.\n *\n * @example\n * ```tsx\n * // Position controls at the bottom-right\n * <CosmosSimulationControls className=\"absolute bottom-4 right-4\" />\n * ```\n */\n className?: string;\n}\n\n/**\n * Configuration for each simulation parameter slider.\n * These values define the range and step size for each parameter.\n *\n * @internal\n */\nconst simulationSliders = [\n {\n key: 'simulationGravity',\n label: 'Gravity',\n min: 0,\n max: 0.5,\n step: 0.01,\n },\n {\n key: 'simulationRepulsion',\n label: 'Repulsion',\n min: 0,\n max: 2,\n step: 0.01,\n },\n {\n key: 'simulationLinkSpring',\n label: 'Link Strength',\n min: 0,\n max: 2,\n step: 0.01,\n },\n {\n key: 'simulationLinkDistance',\n label: 'Link Distance',\n min: 1,\n max: 20,\n step: 1,\n },\n {\n key: 'simulationFriction',\n label: 'Friction',\n min: 0,\n max: 1,\n step: 0.01,\n },\n {\n key: 'simulationDecay',\n label: 'Decay',\n min: 100,\n max: 10000,\n step: 100,\n },\n] as const;\n\ntype SimulationKey = (typeof simulationSliders)[number]['key'];\n\n/**\n * A component that provides fine-grained controls for adjusting graph simulation parameters.\n * Uses the zustand store to access and control the graph state.\n *\n * Features:\n * - Slider controls for all simulation parameters\n * - Real-time parameter adjustment\n * - Tooltips with parameter descriptions\n * - Customizable positioning\n * - Default values optimized for common use cases\n *\n * Available parameters:\n * - Gravity (0-0.5): Controls how strongly nodes are pulled toward the center\n * - Repulsion (0-2): Controls how strongly nodes push away from each other\n * - Link Strength (0-2): Controls the spring force between connected nodes\n * - Link Distance (1-20): Sets the natural length of links between nodes\n * - Friction (0-1): Controls how quickly node movement decays\n * - Decay (100-10000): Controls how quickly the simulation \"cools down\"\n *\n * @example Basic usage\n * ```tsx\n * import { CosmosGraph, CosmosSimulationControls } from '@sqlrooms/cosmos';\n *\n * const MyGraph = () => {\n * return (\n * <CosmosGraph {...graphProps}>\n * <CosmosSimulationControls />\n * </CosmosGraph>\n * );\n * };\n * ```\n *\n * @example Custom positioning with other controls\n * ```tsx\n * import { CosmosGraph, CosmosGraphControls, CosmosSimulationControls } from '@sqlrooms/cosmos';\n *\n * const MyGraph = () => {\n * return (\n * <CosmosGraph {...graphProps}>\n * <CosmosGraphControls className=\"absolute top-4 left-4\" />\n * <CosmosSimulationControls className=\"absolute top-4 right-4\" />\n * </CosmosGraph>\n * );\n * };\n * ```\n *\n * @example With custom styling\n * ```tsx\n * <CosmosGraph {...graphProps}>\n * <CosmosSimulationControls\n * className=\"absolute bottom-4 right-4 bg-opacity-75 backdrop-blur-sm\"\n * />\n * </CosmosGraph>\n * ```\n */\nexport const CosmosSimulationControls: FC<CosmosSimulationControlsProps> = ({\n className,\n}) => {\n const {\n isSimulationRunning,\n toggleSimulation,\n startWithEnergy,\n updateSimulationConfig,\n } = useStoreWithCosmos((s) => s.cosmos);\n\n const config = useStoreWithCosmos((s) => s.cosmos.config);\n\n const handleParameterChange = (paramKey: SimulationKey, value: number[]) => {\n updateSimulationConfig({[paramKey]: value[0]});\n };\n\n return (\n <div\n className={cn(\n 'bg-card/90 dark:bg-card/90 w-48 space-y-4 rounded-lg p-3 shadow-lg',\n className,\n )}\n >\n <div className=\"flex gap-2\">\n <Tooltip>\n <TooltipTrigger asChild>\n <Button\n onClick={toggleSimulation}\n variant=\"outline\"\n size=\"sm\"\n className=\"flex-1\"\n >\n {isSimulationRunning ? (\n <Pause className=\"h-4 w-4\" />\n ) : (\n <Play className=\"h-4 w-4\" />\n )}\n </Button>\n </TooltipTrigger>\n <TooltipContent side=\"bottom\">\n {isSimulationRunning ? 'Pause simulation' : 'Start simulation'}\n </TooltipContent>\n </Tooltip>\n <Tooltip>\n <TooltipTrigger asChild>\n <Button\n onClick={startWithEnergy}\n variant=\"outline\"\n size=\"sm\"\n className=\"flex-1\"\n >\n <Wind className=\"h-4 w-4\" />\n </Button>\n </TooltipTrigger>\n <TooltipContent side=\"bottom\">\n Push energy into simulation\n </TooltipContent>\n </Tooltip>\n </div>\n {simulationSliders.map(({key, label, min, max, step}) => (\n <div key={key} className=\"space-y-2\">\n <div className=\"flex items-center justify-between\">\n <Tooltip>\n <TooltipTrigger asChild>\n <Label\n htmlFor={key}\n className=\"flex cursor-help items-center gap-1 text-xs font-medium\"\n >\n <Info className=\"text-muted-foreground/50 h-3 w-3\" />\n {label}\n </Label>\n </TooltipTrigger>\n <TooltipContent side=\"left\" className=\"max-w-[200px]\">\n {CosmosSliceConfig.shape[key].description}\n </TooltipContent>\n </Tooltip>\n <span className=\"text-muted-foreground text-xs tabular-nums\">\n {config[key].toFixed(2)}\n </span>\n </div>\n <Slider\n id={key}\n min={min}\n max={max}\n step={step}\n value={[config[key]]}\n onValueChange={(value) => handleParameterChange(key, value)}\n className=\"w-full\"\n />\n </div>\n ))}\n </div>\n );\n};\n"]}
@@ -3,7 +3,7 @@
3
3
  * This module provides state management and control functions for the Cosmos graph visualization.
4
4
  */
5
5
  import { Graph, GraphConfigInterface } from '@cosmograph/cosmos';
6
- import { type RoomShellSliceState, BaseRoomConfig } from '@sqlrooms/room-shell';
6
+ import { type RoomShellSliceState } from '@sqlrooms/room-shell';
7
7
  import type { StateCreator } from 'zustand';
8
8
  import { CosmosSliceConfig } from './CosmosSliceConfig';
9
9
  /**
@@ -12,10 +12,13 @@ import { CosmosSliceConfig } from './CosmosSliceConfig';
12
12
  */
13
13
  export type CosmosSliceState = {
14
14
  cosmos: {
15
+ config: CosmosSliceConfig;
15
16
  /** The current graph instance */
16
17
  graph: Graph | null;
17
18
  /** Whether the physics simulation is currently running */
18
19
  isSimulationRunning: boolean;
20
+ /** Sets the config for the cosmos slice */
21
+ setConfig: (config: CosmosSliceConfig) => void;
19
22
  /** Creates a new graph instance in the specified container */
20
23
  createGraph: (container: HTMLDivElement) => void;
21
24
  /** Toggles the physics simulation on/off */
@@ -27,7 +30,7 @@ export type CosmosSliceState = {
27
30
  /** Cleans up and removes the current graph */
28
31
  destroyGraph: () => void;
29
32
  /** Updates the simulation configuration parameters */
30
- updateSimulationConfig: (config: Partial<CosmosSliceConfig['cosmos']>) => void;
33
+ updateSimulationConfig: (config: Partial<CosmosSliceConfig>) => void;
31
34
  /** Updates the graph's visual configuration */
32
35
  updateGraphConfig: (config: Partial<GraphConfigInterface>) => void;
33
36
  /** Updates the graph's data (points, links, colors, etc.) */
@@ -44,11 +47,6 @@ export type CosmosSliceState = {
44
47
  setZoomLevel: (level: number) => void;
45
48
  };
46
49
  };
47
- /**
48
- * Combined type representing the full room state including Cosmos functionality.
49
- * Merges the base room state with Cosmos-specific state and configuration.
50
- */
51
- export type RoomStateWithCosmos = RoomShellSliceState<BaseRoomConfig & CosmosSliceConfig> & CosmosSliceState;
52
50
  /**
53
51
  * Creates a Zustand slice for managing Cosmos graph state.
54
52
  * This slice handles graph creation, destruction, configuration, and data updates.
@@ -56,6 +54,11 @@ export type RoomStateWithCosmos = RoomShellSliceState<BaseRoomConfig & CosmosSli
56
54
  * @returns A state creator function for the Cosmos slice
57
55
  */
58
56
  export declare function createCosmosSlice(): StateCreator<CosmosSliceState>;
57
+ /**
58
+ * Combined type representing the full room state including Cosmos functionality.
59
+ * Merges the base room state with Cosmos-specific state and configuration.
60
+ */
61
+ export type RoomStateWithCosmos = RoomShellSliceState & CosmosSliceState;
59
62
  /**
60
63
  * Hook to access the Cosmos store with proper typing.
61
64
  * Provides type-safe access to the combined room and Cos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, useBaseRoomShellStore, } from '@sqlrooms/room-shell';
7
7
  import { produce } from 'immer';
8
+ import { createDefaultCosmosConfig, } from './CosmosSliceConfig';
8
9
  /**
9
10
  * Creates a Zustand slice for managing Cosmos graph state.
10
11
  * This slice handles graph creation, destruction, configuration, and data updates.
@@ -16,6 +17,12 @@ export function createCosmosSlice() {
16
17
  cosmos: {
17
18
  graph: null,
18
19
  isSimulationRunning: true,
20
+ config: createDefaultCosmosConfig(),
21
+ setConfig: (config) => {
22
+ set((state) => produce(state, (draft) => {
23
+ draft.cosmos.config = config;
24
+ }));
25
+ },
19
26
  createGraph: (container) => {
20
27
  // Clean up old graph if it exists
21
28
  const oldGraph = get().cosmos.graph;
@@ -25,7 +32,7 @@ export function createCosmosSlice() {
25
32
  }
26
33
  // Create and configure new graph
27
34
  const graph = new Graph(container);
28
- const config = get().config.cosmos;
35
+ const config = get().cosmos.config;
29
36
  graph.setConfig(config);
30
37
  graph.start();
31
38
  set((state) => produce(state, (draft) => {
@@ -67,18 +74,18 @@ export function createCosmosSlice() {
67
74
  updateSimulationConfig: (config) => {
68
75
  const { graph } = get().cosmos;
69
76
  set((state) => produce(state, (draft) => {
70
- Object.assign(draft.config.cosmos, config);
77
+ Object.assign(draft.cosmos.config, config);
71
78
  if (graph) {
72
- graph.setConfig(draft.config.cosmos);
79
+ graph.setConfig(draft.cosmos.config);
73
80
  }
74
81
  }));
75
82
  },
76
83
  updateGraphConfig: (config) => {
77
84
  const { graph } = get().cosmos;
78
85
  set((state) => produce(state, (draft) => {
79
- Object.assign(draft.config.cosmos, config);
86
+ Object.assign(draft.cosmos.config, config);
80
87
  if (graph) {
81
- graph.setConfig(draft.config.cosmos);
88
+ graph.setConfig(draft.cosmos.config);
82
89
  }
83
90
  }));
84
91
  },
@@ -1 +1 @@
1
- {"version":3,"file":"CosmosSlice.js","sourceRoot":"","sources":["../src/CosmosSlice.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,KAAK,EAAuB,M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B,GAAG,KAAK,CAAC;gBAC3C,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA2C;IAE3C,OAAO,qBAAqB,CAI1B,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAA4B,CAAC,CAAC,CAAC;AACvD,CAAC","sourcesContent":["/**\n * @fileoverview Cosmos graph visualization state management using Zustand.\n * This module provides state management and control functions for the Cosmos graph visualization.\n */\n\nimport {Graph, GraphConfigInterface} from '@cosmograph/cosmos';\nimport {\n createSlice,\n useBaseRoomShellStore,\n type RoomShellSliceState,\n BaseRoomConfig,\n} from '@sqlrooms/room-shell';\nimport type {StateCreator} from 'zustand';\nimport {CosmosSliceConfig} from './CosmosSliceConfig';\nimport {produce} from 'immer';\n\n/**\n * Core state interface for the Cosmos graph visualization.\n * Contains the graph instance, simulation state, and all control functions.\n */\nexport type CosmosSliceState = {\n cosmos: {\n /** The current graph instance */\n graph: Graph | null;\n /** Whether the physics simulation is currently running */\n isSimulationRunning: boolean;\n /** Creates a new graph instance in the specified container */\n createGraph: (container: HTMLDivElement) => void;\n /** Toggles the physics simulation on/off */\n toggleSimulation: () => void;\n /** Adjusts the view to fit all nodes */\n fitView: () => void;\n /** Starts the simulation with initial energy */\n startWithEnergy: () => void;\n /** Cleans up and removes the current graph */\n destroyGraph: () => void;\n /** Updates the simulation configuration parameters */\n updateSimulationConfig: (\n config: Partial<CosmosSliceConfig['cosmos']>,\n ) => void;\n /** Updates the graph's visual configuration */\n updateGraphConfig: (config: Partial<GraphConfigInterface>) => void;\n /** Updates the graph's data (points, links, colors, etc.) */\n updateGraphData: (data: {\n pointPositions?: Float32Array;\n pointColors?: Float32Array;\n pointSizes?: Float32Array;\n linkIndexes?: Float32Array;\n linkColors?: Float32Array;\n }) => void;\n /** Sets the currently focused point by its index */\n setFocusedPoint: (index: number | undefined) => void;\n /** Sets the zoom level of the graph view */\n setZoomLevel: (level: number) => void;\n };\n};\n\n/**\n * Combined type representing the full room state including Cosmos functionality.\n * Merges the base room state with Cosmos-specific state and configuration.\n */\nexport type RoomStateWithCosmos = RoomShellSliceState<\n BaseRoomConfig & CosmosSliceConfig\n> &\n CosmosSliceState;\n\n/**\n * Creates a Zustand slice for managing Cosmos graph state.\n * This slice handles graph creation, destruction, configuration, and data updates.\n *\n * @returns A state creator function for the Cosmos slice\n */\nexport function createCosmosSlice(): StateCreator<CosmosSliceState> {\n return createSlice<BaseRoomConfig & CosmosSliceConfig, CosmosSliceState>(\n (set, get) => ({\n cosmos: {\n graph: null,\n isSimulationRunning: true,\n\n createGraph: (container: HTMLDivElement) => {\n // Clean up old graph if it exists\n const oldGraph = get().cosmos.graph;\n if (oldGraph) {\n oldGraph.pause();\n oldGraph.destroy();\n }\n\n // Create and configure new graph\n const graph = new Graph(container);\n const config = get().config.cosmos;\n graph.setConfig(config);\n graph.start();\n\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.graph = graph;\n }),\n );\n },\n\n toggleSimulation: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n\n if (graph.isSimulationRunning) {\n graph.pause();\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.isSimulationRunning = false;\n }),\n );\n } else {\n graph.restart();\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.isSimulationRunning = true;\n }),\n );\n }\n },\n\n fitView: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.fitView();\n },\n\n startWithEnergy: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.start(1);\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.isSimulationRunning = true;\n }),\n );\n },\n\n updateSimulationConfig: (\n config: Partial<CosmosSliceConfig['cosmos']>,\n ) => {\n const {graph} = get().cosmos;\n\n set((state) =>\n produce(state, (draft) => {\n Object.assign(draft.config.cosmos, config);\n if (graph) {\n graph.setConfig(draft.config.cosmos);\n }\n }),\n );\n },\n\n updateGraphConfig: (config: Partial<GraphConfigInterface>) => {\n const {graph} = get().cosmos;\n\n set((state) =>\n produce(state, (draft) => {\n Object.assign(draft.config.cosmos, config);\n if (graph) {\n graph.setConfig(draft.config.cosmos);\n }\n }),\n );\n },\n\n updateGraphData: (data) => {\n const {graph} = get().cosmos;\n if (!graph) return;\n\n if (data.pointPositions) {\n graph.setPointPositions(data.pointPositions);\n }\n if (data.pointColors) {\n graph.setPointColors(data.pointColors);\n }\n if (data.pointSizes) {\n graph.setPointSizes(data.pointSizes);\n }\n if (data.linkIndexes) {\n graph.setLinks(data.linkIndexes);\n }\n if (data.linkColors) {\n graph.setLinkColors(data.linkColors);\n }\n\n graph.render();\n },\n\n setFocusedPoint: (index) => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.setFocusedPointByIndex(index);\n },\n\n setZoomLevel: (level) => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.setZoomLevel(level);\n },\n\n destroyGraph: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n // TODO: this should be happening in cosmos\n if ((graph as any).store.div?.firstChild) {\n (graph as any).store.div.innerHTML = '';\n }\n graph.pause();\n graph.destroy();\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.graph = null;\n draft.cosmos.isSimulationRunning = false;\n }),\n );\n },\n },\n }),\n );\n}\n\n/**\n * Hook to access the Cosmos store with proper typing.\n * Provides type-safe access to the combined room and Cosmos state.\n *\n * @template T The type of the selected state slice\n * @param selector A function that selects a portion of the state\n * @returns The selected state portion\n *\n * @example\n * ```typescript\n * const graph = useStoreWithCosmos(state => state.cosmos.graph);\n * const isRunning = useStoreWithCosmos(state => state.cosmos.isSimulationRunning);\n * ```\n */\nexport function useStoreWithCosmos<T>(\n selector: (state: RoomStateWithCosmos) => T,\n): T {\n return useBaseRoomShellStore<\n BaseRoomConfig & CosmosSliceConfig,\n RoomStateWithCosmos,\n T\n >((state) => selector(state as RoomStateWithCosmos));\n}\n"]}
1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,KAAK;oBAAE,OAAO;gBACnB,2CAA2C;gBAC3C,IAAK,KAAa,CAAC,KAAK,CAAC,GAAG,EAAE,UAAU,EAAE,CAAC;oBACxC,KAAa,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,GAAG,EAAE,CAAC;gBAC1C,CAAC;gBACD,KAAK,CAAC,KAAK,EAAE,CAAC;gBACd,KAAK,CAAC,OAAO,EAAE,CAAC;gBAChB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACZ,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;oBACvB,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;oBAC1B,KAAK,CAAC,MAAM,CAAC,mBAAmB,GAAG,KAAK,CAAC;gBAC3C,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;SACF;KACF,CAAC,CAAC,CAAC;AACN,CAAC;AAQD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA2C;IAE3C,OAAO,qBAAqB,CAAyB,CAAC,KAAK,EAAE,EAAE,CAC7D,QAAQ,CAAC,KAA4B,CAAC,CACvC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * @fileoverview Cosmos graph visualization state management using Zustand.\n * This module provides state management and control functions for the Cosmos graph visualization.\n */\n\nimport {Graph, GraphConfigInterface} from '@cosmograph/cosmos';\nimport {\n createSlice,\n useBaseRoomShellStore,\n type RoomShellSliceState,\n} from '@sqlrooms/room-shell';\nimport {produce} from 'immer';\nimport type {StateCreator} from 'zustand';\nimport {\n CosmosSliceConfig,\n createDefaultCosmosConfig,\n} from './CosmosSliceConfig';\n\n/**\n * Core state interface for the Cosmos graph visualization.\n * Contains the graph instance, simulation state, and all control functions.\n */\nexport type CosmosSliceState = {\n cosmos: {\n config: CosmosSliceConfig;\n /** The current graph instance */\n graph: Graph | null;\n /** Whether the physics simulation is currently running */\n isSimulationRunning: boolean;\n /** Sets the config for the cosmos slice */\n setConfig: (config: CosmosSliceConfig) => void;\n /** Creates a new graph instance in the specified container */\n createGraph: (container: HTMLDivElement) => void;\n /** Toggles the physics simulation on/off */\n toggleSimulation: () => void;\n /** Adjusts the view to fit all nodes */\n fitView: () => void;\n /** Starts the simulation with initial energy */\n startWithEnergy: () => void;\n /** Cleans up and removes the current graph */\n destroyGraph: () => void;\n /** Updates the simulation configuration parameters */\n updateSimulationConfig: (config: Partial<CosmosSliceConfig>) => void;\n /** Updates the graph's visual configuration */\n updateGraphConfig: (config: Partial<GraphConfigInterface>) => void;\n /** Updates the graph's data (points, links, colors, etc.) */\n updateGraphData: (data: {\n pointPositions?: Float32Array;\n pointColors?: Float32Array;\n pointSizes?: Float32Array;\n linkIndexes?: Float32Array;\n linkColors?: Float32Array;\n }) => void;\n /** Sets the currently focused point by its index */\n setFocusedPoint: (index: number | undefined) => void;\n /** Sets the zoom level of the graph view */\n setZoomLevel: (level: number) => void;\n };\n};\n\n/**\n * Creates a Zustand slice for managing Cosmos graph state.\n * This slice handles graph creation, destruction, configuration, and data updates.\n *\n * @returns A state creator function for the Cosmos slice\n */\nexport function createCosmosSlice(): StateCreator<CosmosSliceState> {\n return createSlice<CosmosSliceState>((set, get) => ({\n cosmos: {\n graph: null,\n isSimulationRunning: true,\n config: createDefaultCosmosConfig(),\n\n setConfig: (config) => {\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.config = config;\n }),\n );\n },\n\n createGraph: (container: HTMLDivElement) => {\n // Clean up old graph if it exists\n const oldGraph = get().cosmos.graph;\n if (oldGraph) {\n oldGraph.pause();\n oldGraph.destroy();\n }\n\n // Create and configure new graph\n const graph = new Graph(container);\n const config = get().cosmos.config;\n graph.setConfig(config);\n graph.start();\n\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.graph = graph;\n }),\n );\n },\n\n toggleSimulation: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n\n if (graph.isSimulationRunning) {\n graph.pause();\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.isSimulationRunning = false;\n }),\n );\n } else {\n graph.restart();\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.isSimulationRunning = true;\n }),\n );\n }\n },\n\n fitView: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.fitView();\n },\n\n startWithEnergy: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.start(1);\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.isSimulationRunning = true;\n }),\n );\n },\n\n updateSimulationConfig: (config: Partial<CosmosSliceConfig>) => {\n const {graph} = get().cosmos;\n\n set((state) =>\n produce(state, (draft) => {\n Object.assign(draft.cosmos.config, config);\n if (graph) {\n graph.setConfig(draft.cosmos.config);\n }\n }),\n );\n },\n\n updateGraphConfig: (config: Partial<GraphConfigInterface>) => {\n const {graph} = get().cosmos;\n\n set((state) =>\n produce(state, (draft) => {\n Object.assign(draft.cosmos.config, config);\n if (graph) {\n graph.setConfig(draft.cosmos.config);\n }\n }),\n );\n },\n\n updateGraphData: (data) => {\n const {graph} = get().cosmos;\n if (!graph) return;\n\n if (data.pointPositions) {\n graph.setPointPositions(data.pointPositions);\n }\n if (data.pointColors) {\n graph.setPointColors(data.pointColors);\n }\n if (data.pointSizes) {\n graph.setPointSizes(data.pointSizes);\n }\n if (data.linkIndexes) {\n graph.setLinks(data.linkIndexes);\n }\n if (data.linkColors) {\n graph.setLinkColors(data.linkColors);\n }\n\n graph.render();\n },\n\n setFocusedPoint: (index) => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.setFocusedPointByIndex(index);\n },\n\n setZoomLevel: (level) => {\n const {graph} = get().cosmos;\n if (!graph) return;\n graph.setZoomLevel(level);\n },\n\n destroyGraph: () => {\n const {graph} = get().cosmos;\n if (!graph) return;\n // TODO: this should be happening in cosmos\n if ((graph as any).store.div?.firstChild) {\n (graph as any).store.div.innerHTML = '';\n }\n graph.pause();\n graph.destroy();\n set((state) =>\n produce(state, (draft) => {\n draft.cosmos.graph = null;\n draft.cosmos.isSimulationRunning = false;\n }),\n );\n },\n },\n }));\n}\n\n/**\n * Combined type representing the full room state including Cosmos functionality.\n * Merges the base room state with Cosmos-specific state and configuration.\n */\nexport type RoomStateWithCosmos = RoomShellSliceState & CosmosSliceState;\n\n/**\n * Hook to access the Cosmos store with proper typing.\n * Provides type-safe access to the combined room and Cosmos state.\n *\n * @template T The type of the selected state slice\n * @param selector A function that selects a portion of the state\n * @returns The selected state portion\n *\n * @example\n * ```typescript\n * const graph = useStoreWithCosmos(state => state.cosmos.graph);\n * const isRunning = useStoreWithCosmos(state => state.cosmos.isSimulationRunning);\n * ```\n */\nexport function useStoreWithCosmos<T>(\n selector: (state: RoomStateWithCosmos) => T,\n): T {\n return useBaseRoomShellStore<RoomStateWithCosmos, T>((state) =>\n selector(state as RoomStateWithCosmos),\n );\n}\n"]}
@@ -64,21 +64,19 @@ import { z } from 'zod';
64
64
  * ```
65
65
  */
66
66
  export declare const CosmosSliceConfig: z.ZodObject<{
67
- cosmos: z.ZodObject<{
68
- pointSizeScale: z.ZodNumber;
69
- scalePointsOnZoom: z.ZodBoolean;
70
- renderLinks: z.ZodBoolean;
71
- linkWidthScale: z.ZodNumber;
72
- linkArrowsSizeScale: z.ZodNumber;
73
- linkArrows: z.ZodBoolean;
74
- curvedLinks: z.ZodBoolean;
75
- simulationGravity: z.ZodNumber;
76
- simulationRepulsion: z.ZodNumber;
77
- simulationLinkSpring: z.ZodNumber;
78
- simulationLinkDistance: z.ZodNumber;
79
- simulationFriction: z.ZodNumber;
80
- simulationDecay: z.ZodNumber;
81
- }, z.core.$strip>;
67
+ pointSizeScale: z.ZodNumber;
68
+ scalePointsOnZoom: z.ZodBoolean;
69
+ renderLinks: z.ZodBoolean;
70
+ linkWidthScale: z.ZodNumber;
71
+ linkArrowsSizeScale: z.ZodNumber;
72
+ linkArrows: z.ZodBoolean;
73
+ curvedLinks: z.ZodBoolean;
74
+ simulationGravity: z.ZodNumber;
75
+ simulationRepulsion: z.ZodNumber;
76
+ simulationLinkSpring: z.ZodNumber;
77
+ simulationLinkDistance: z.ZodNumber;
78
+ simulationFriction: z.ZodNumber;
79
+ simulationDecay: z.ZodNumber;
82
80
  }, z.core.$strip>;
83
81
  export type CosmosSliceConfig = z.infer<typeof CosmosSliceConfig>;
84
82
  export declare function createDefaultCosmosConfig(): CosmosSliceConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"CosmosSliceConfig.d.ts","sourceRoot":"","sources":["../src/CosmosSliceConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAuBtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;iBAgH5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE,wBAAgB,yBAAyB,IAAI,iBAAiB,CAI7D"}
1
+ {"version":3,"file":"CosmosSliceConfig.d.ts","sourceRoot":"","sources":["../src/CosmosSliceConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAuBtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;iBAwGmC,CAAC;AAClE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE,wBAAgB,yBAAyB,IAAI,iBAAiB,CAE7D"}
@@ -83,105 +83,97 @@ const DEFAULT_COSMOS_CONFIG = {
83
83
  * ```
84
84
  */
85
85
  export const CosmosSliceConfig = z.object({
86
- cosmos: z.object({
87
- /**
88
- * Scale factor for point (node) sizes in the graph.
89
- * Values > 1 make nodes larger, values < 1 make them smaller.
90
- * @default 1.1
91
- */
92
- pointSizeScale: z.number().describe('Scale factor for point sizes'),
93
- /**
94
- * When true, nodes will dynamically resize based on the current zoom level.
95
- * This helps maintain visual clarity at different zoom levels.
96
- * @default true
97
- */
98
- scalePointsOnZoom: z
99
- .boolean()
100
- .describe('Dynamically resize points based on zoom level'),
101
- /**
102
- * Controls whether links (edges) between nodes are displayed.
103
- * @default true
104
- */
105
- renderLinks: z.boolean().describe('Control links displaying'),
106
- /**
107
- * Scale factor for link (edge) width.
108
- * Values > 1 make links thicker, values < 1 make them thinner.
109
- * @default 1
110
- */
111
- linkWidthScale: z.number().describe('Scale factor for link width'),
112
- /**
113
- * Scale factor for the size of directional arrows on links.
114
- * Only applies when linkArrows is true.
115
- * @default 1
116
- */
117
- linkArrowsSizeScale: z
118
- .number()
119
- .describe('Scale factor for link arrows size'),
120
- /**
121
- * When true, displays arrows indicating link direction.
122
- * Useful for directed graphs.
123
- * @default false
124
- */
125
- linkArrows: z
126
- .boolean()
127
- .describe('Control displaying link direction arrows'),
128
- /**
129
- * When true, links are rendered as curved Bezier paths.
130
- * When false, links are straight lines.
131
- * @default false
132
- */
133
- curvedLinks: z
134
- .boolean()
135
- .describe('Render links as curved bezier paths instead of straight lines'),
136
- /**
137
- * Controls the strength of the central gravitational force.
138
- * Higher values pull nodes more strongly toward the center.
139
- * @default 0.25
140
- */
141
- simulationGravity: z.number().describe('Gravity force in the simulation'),
142
- /**
143
- * Controls how strongly nodes repel each other.
144
- * Higher values create more space between unconnected nodes.
145
- * @default 1.0
146
- */
147
- simulationRepulsion: z.number().describe('Repulsion force between nodes'),
148
- /**
149
- * Controls the strength of the spring force between linked nodes.
150
- * Higher values pull connected nodes more tightly together.
151
- * @default 1.0
152
- */
153
- simulationLinkSpring: z
154
- .number()
155
- .describe('Spring force for links between nodes'),
156
- /**
157
- * The natural or resting length of links between nodes.
158
- * Higher values create more spacing between connected nodes.
159
- * @default 10
160
- */
161
- simulationLinkDistance: z
162
- .number()
163
- .describe('Target distance between linked nodes'),
164
- /**
165
- * Controls how quickly node movement decays.
166
- * Higher values (closer to 1) create more damped movement.
167
- * @default 0.85
168
- */
169
- simulationFriction: z
170
- .number()
171
- .describe('Friction coefficient in the simulation'),
172
- /**
173
- * Controls how quickly the simulation stabilizes.
174
- * Lower values result in longer, smoother transitions.
175
- * @default 1000
176
- */
177
- simulationDecay: z
178
- .number()
179
- .describe('Decay coefficient in the simulation. Use smaller values if you want the simulation to "cool down" slower.'),
180
- }),
86
+ /**
87
+ * Scale factor for point (node) sizes in the graph.
88
+ * Values > 1 make nodes larger, values < 1 make them smaller.
89
+ * @default 1.1
90
+ */
91
+ pointSizeScale: z.number().describe('Scale factor for point sizes'),
92
+ /**
93
+ * When true, nodes will dynamically resize based on the current zoom level.
94
+ * This helps maintain visual clarity at different zoom levels.
95
+ * @default true
96
+ */
97
+ scalePointsOnZoom: z
98
+ .boolean()
99
+ .describe('Dynamically resize points based on zoom level'),
100
+ /**
101
+ * Controls whether links (edges) between nodes are displayed.
102
+ * @default true
103
+ */
104
+ renderLinks: z.boolean().describe('Control links displaying'),
105
+ /**
106
+ * Scale factor for link (edge) width.
107
+ * Values > 1 make links thicker, values < 1 make them thinner.
108
+ * @default 1
109
+ */
110
+ linkWidthScale: z.number().describe('Scale factor for link width'),
111
+ /**
112
+ * Scale factor for the size of directional arrows on links.
113
+ * Only applies when linkArrows is true.
114
+ * @default 1
115
+ */
116
+ linkArrowsSizeScale: z.number().describe('Scale factor for link arrows size'),
117
+ /**
118
+ * When true, displays arrows indicating link direction.
119
+ * Useful for directed graphs.
120
+ * @default false
121
+ */
122
+ linkArrows: z.boolean().describe('Control displaying link direction arrows'),
123
+ /**
124
+ * When true, links are rendered as curved Bezier paths.
125
+ * When false, links are straight lines.
126
+ * @default false
127
+ */
128
+ curvedLinks: z
129
+ .boolean()
130
+ .describe('Render links as curved bezier paths instead of straight lines'),
131
+ /**
132
+ * Controls the strength of the central gravitational force.
133
+ * Higher values pull nodes more strongly toward the center.
134
+ * @default 0.25
135
+ */
136
+ simulationGravity: z.number().describe('Gravity force in the simulation'),
137
+ /**
138
+ * Controls how strongly nodes repel each other.
139
+ * Higher values create more space between unconnected nodes.
140
+ * @default 1.0
141
+ */
142
+ simulationRepulsion: z.number().describe('Repulsion force between nodes'),
143
+ /**
144
+ * Controls the strength of the spring force between linked nodes.
145
+ * Higher values pull connected nodes more tightly together.
146
+ * @default 1.0
147
+ */
148
+ simulationLinkSpring: z
149
+ .number()
150
+ .describe('Spring force for links between nodes'),
151
+ /**
152
+ * The natural or resting length of links between nodes.
153
+ * Higher values create more spacing between connected nodes.
154
+ * @default 10
155
+ */
156
+ simulationLinkDistance: z
157
+ .number()
158
+ .describe('Target distance between linked nodes'),
159
+ /**
160
+ * Controls how quickly node movement decays.
161
+ * Higher values (closer to 1) create more damped movement.
162
+ * @default 0.85
163
+ */
164
+ simulationFriction: z
165
+ .number()
166
+ .describe('Friction coefficient in the simulation'),
167
+ /**
168
+ * Controls how quickly the simulation stabilizes.
169
+ * Lower values result in longer, smoother transitions.
170
+ * @default 1000
171
+ */
172
+ simulationDecay: z
173
+ .number()
174
+ .describe('Decay coefficient in the simulation. Use smaller values if you want the simulation to "cool down" slower.'),
181
175
  });
182
176
  export function createDefaultCosmosConfig() {
183
- return {
184
- cosmos: DEFAULT_COSMOS_CONFIG,
185
- };
177
+ return DEFAULT_COSMOS_CONFIG;
186
178
  }
187
179
  //# sourceMappingURL=CosmosSliceConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CosmosSliceConfig.js","sourceRoot":"","sources":["../src/CosmosSliceConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB;;;GAGG;AACH,MAAM,qBAAqB,GAAgC;IACzD,cAAc,EAAE,GAAG;IACnB,iBAAiB,EAAE,IAAI;IACvB,iBAAiB,EAAE,IAAI;IACvB,mBAAmB,EAAE,GAAG;IACxB,oBAAoB,EAAE,GAAG;IACzB,sBAAsB,EAAE,EAA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AAE,CAAC;aACpB,MAAM,EAAE;aACR,QAAQ,CAAC,sCAAsC,CAAC;QAEnD;;;;WAIG;QACH,sBAAsB,EAAE,CAAC;aACtB,MAAM,EAAE;aACR,QAAQ,CAAC,sCAAsC,CAAC;QAEnD;;;;WAIG;QACH,kBAAkB,EAAE,CAAC;aAClB,MAAM,EAAE;aACR,QAAQ,CAAC,wCAAwC,CAAC;QAErD;;;;WAIG;QACH,eAAe,EAAE,CAAC;aACf,MAAM,EAAE;aACR,QAAQ,CACP,2GAA2G,CAC5G;KAC2D,CAAC;CAClE,CAAC,CAAC;AAGH,MAAM,UAAU,yBAAyB;IACvC,OAAO;QACL,MAAM,EAAE,qBAAqB;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import {z} from 'zod';\nimport {GraphConfigInterface} from '@cosmograph/cosmos';\n\n/**\n * Default configuration values for the Cosmos graph visualization.\n * These values provide a balanced starting point for most graph visualizations.\n */\nconst DEFAULT_COSMOS_CONFIG: CosmosSliceConfig['cosmos'] = {\n pointSizeScale: 1.1,\n scalePointsOnZoom: true,\n simulationGravity: 0.25,\n simulationRepulsion: 1.0,\n simulationLinkSpring: 1.0,\n simulationLinkDistance: 10,\n simulationFriction: 0.85,\n simulationDecay: 1000,\n renderLinks: true,\n linkArrows: false,\n curvedLinks: false,\n linkWidthScale: 1,\n linkArrowsSizeScale: 1,\n} as const satisfies Partial<GraphConfigInterface>;\n\n/**\n * Zod schema for validating and configuring the Cosmos graph visualization.\n * This schema defines all available configuration options and their types.\n *\n * The configuration is divided into several categories:\n *\n * Node Appearance:\n * - `pointSizeScale`: Controls the size of nodes\n * - `scalePointsOnZoom`: Enables dynamic node sizing based on zoom level\n *\n * Link Appearance:\n * - `renderLinks`: Toggles link visibility\n * - `linkWidthScale`: Controls link thickness\n * - `linkArrows`: Toggles directional arrows\n * - `linkArrowsSizeScale`: Controls arrow size\n * - `curvedLinks`: Toggles curved/straight links\n *\n * Physics Simulation:\n * - `simulationGravity`: Central gravitational force (0.25)\n * - `simulationRepulsion`: Node repulsion force (1.0)\n * - `simulationLinkSpring`: Link spring force (1.0)\n * - `simulationLinkDistance`: Natural link length (10)\n * - `simulationFriction`: Movement damping (0.85)\n * - `simulationDecay`: Simulation cooling rate (1000)\n *\n * @example Basic configuration\n * ```typescript\n * const config: CosmosSliceConfig = {\n * cosmos: {\n * pointSizeScale: 1.2,\n * scalePointsOnZoom: true,\n * renderLinks: true,\n * linkWidthScale: 1.5,\n * simulationGravity: 0.25\n * }\n * };\n * ```\n *\n * @example Directed graph with curved links\n * ```typescript\n * const directedGraphConfig: CosmosSliceConfig = {\n * cosmos: {\n * linkArrows: true,\n * linkArrowsSizeScale: 1.2,\n * curvedLinks: true,\n * simulationLinkDistance: 15,\n * simulationLinkSpring: 1.2\n * }\n * };\n * ```\n *\n * @example High-performance configuration for large graphs\n * ```typescript\n * const largeGraphConfig: CosmosSliceConfig = {\n * cosmos: {\n * simulationGravity: 0.1,\n * simulationRepulsion: 0.8,\n * simulationFriction: 0.9,\n * simulationDecay: 2000,\n * scalePointsOnZoom: false\n * }\n * };\n * ```\n */\nexport const CosmosSliceConfig = z.object({\n cosmos: z.object({\n /**\n * Scale factor for point (node) sizes in the graph.\n * Values > 1 make nodes larger, values < 1 make them smaller.\n * @default 1.1\n */\n pointSizeScale: z.number().describe('Scale factor for point sizes'),\n\n /**\n * When true, nodes will dynamically resize based on the current zoom level.\n * This helps maintain visual clarity at different zoom levels.\n * @default true\n */\n scalePointsOnZoom: z\n .boolean()\n .describe('Dynamically resize points based on zoom level'),\n\n /**\n * Controls whether links (edges) between nodes are displayed.\n * @default true\n */\n renderLinks: z.boolean().describe('Control links displaying'),\n\n /**\n * Scale factor for link (edge) width.\n * Values > 1 make links thicker, values < 1 make them thinner.\n * @default 1\n */\n linkWidthScale: z.number().describe('Scale factor for link width'),\n\n /**\n * Scale factor for the size of directional arrows on links.\n * Only applies when linkArrows is true.\n * @default 1\n */\n linkArrowsSizeScale: z\n .number()\n .describe('Scale factor for link arrows size'),\n\n /**\n * When true, displays arrows indicating link direction.\n * Useful for directed graphs.\n * @default false\n */\n linkArrows: z\n .boolean()\n .describe('Control displaying link direction arrows'),\n\n /**\n * When true, links are rendered as curved Bezier paths.\n * When false, links are straight lines.\n * @default false\n */\n curvedLinks: z\n .boolean()\n .describe(\n 'Render links as curved bezier paths instead of straight lines',\n ),\n\n /**\n * Controls the strength of the central gravitational force.\n * Higher values pull nodes more strongly toward the center.\n * @default 0.25\n */\n simulationGravity: z.number().describe('Gravity force in the simulation'),\n\n /**\n * Controls how strongly nodes repel each other.\n * Higher values create more space between unconnected nodes.\n * @default 1.0\n */\n simulationRepulsion: z.number().describe('Repulsion force between nodes'),\n\n /**\n * Controls the strength of the spring force between linked nodes.\n * Higher values pull connected nodes more tightly together.\n * @default 1.0\n */\n simulationLinkSpring: z\n .number()\n .describe('Spring force for links between nodes'),\n\n /**\n * The natural or resting length of links between nodes.\n * Higher values create more spacing between connected nodes.\n * @default 10\n */\n simulationLinkDistance: z\n .number()\n .describe('Target distance between linked nodes'),\n\n /**\n * Controls how quickly node movement decays.\n * Higher values (closer to 1) create more damped movement.\n * @default 0.85\n */\n simulationFriction: z\n .number()\n .describe('Friction coefficient in the simulation'),\n\n /**\n * Controls how quickly the simulation stabilizes.\n * Lower values result in longer, smoother transitions.\n * @default 1000\n */\n simulationDecay: z\n .number()\n .describe(\n 'Decay coefficient in the simulation. Use smaller values if you want the simulation to \"cool down\" slower.',\n ),\n } satisfies Partial<Record<keyof GraphConfigInterface, unknown>>),\n});\nexport type CosmosSliceConfig = z.infer<typeof CosmosSliceConfig>;\n\nexport function createDefaultCosmosConfig(): CosmosSliceConfig {\n return {\n cosmos: DEFAULT_COSMOS_CONFIG,\n };\n}\n"]}
1
+ {"version":3,"file":"CosmosSliceConfig.js","sourceRoot":"","sources":["../src/CosmosSliceConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB;;;GAGG;AAC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AAC,iCAAiC,CAAC;IAEzE;;;;OAIG;IACH,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+BAA+B,CAAC;IAEzE;;;;OAIG;IACH,oBAAoB,EAAE,CAAC;SACpB,MAAM,EAAE;SACR,QAAQ,CAAC,sCAAsC,CAAC;IAEnD;;;;OAIG;IACH,sBAAsB,EAAE,CAAC;SACtB,MAAM,EAAE;SACR,QAAQ,CAAC,sCAAsC,CAAC;IAEnD;;;;OAIG;IACH,kBAAkB,EAAE,CAAC;SAClB,MAAM,EAAE;SACR,QAAQ,CAAC,wCAAwC,CAAC;IAErD;;;;OAIG;IACH,eAAe,EAAE,CAAC;SACf,MAAM,EAAE;SACR,QAAQ,CACP,2GAA2G,CAC5G;CAC2D,CAAC,CAAC;AAGlE,MAAM,UAAU,yBAAyB;IACvC,OAAO,qBAAqB,CAAC;AAC/B,CAAC","sourcesContent":["import {z} from 'zod';\nimport {GraphConfigInterface} from '@cosmograph/cosmos';\n\n/**\n * Default configuration values for the Cosmos graph visualization.\n * These values provide a balanced starting point for most graph visualizations.\n */\nconst DEFAULT_COSMOS_CONFIG: CosmosSliceConfig = {\n pointSizeScale: 1.1,\n scalePointsOnZoom: true,\n simulationGravity: 0.25,\n simulationRepulsion: 1.0,\n simulationLinkSpring: 1.0,\n simulationLinkDistance: 10,\n simulationFriction: 0.85,\n simulationDecay: 1000,\n renderLinks: true,\n linkArrows: false,\n curvedLinks: false,\n linkWidthScale: 1,\n linkArrowsSizeScale: 1,\n} as const satisfies Partial<GraphConfigInterface>;\n\n/**\n * Zod schema for validating and configuring the Cosmos graph visualization.\n * This schema defines all available configuration options and their types.\n *\n * The configuration is divided into several categories:\n *\n * Node Appearance:\n * - `pointSizeScale`: Controls the size of nodes\n * - `scalePointsOnZoom`: Enables dynamic node sizing based on zoom level\n *\n * Link Appearance:\n * - `renderLinks`: Toggles link visibility\n * - `linkWidthScale`: Controls link thickness\n * - `linkArrows`: Toggles directional arrows\n * - `linkArrowsSizeScale`: Controls arrow size\n * - `curvedLinks`: Toggles curved/straight links\n *\n * Physics Simulation:\n * - `simulationGravity`: Central gravitational force (0.25)\n * - `simulationRepulsion`: Node repulsion force (1.0)\n * - `simulationLinkSpring`: Link spring force (1.0)\n * - `simulationLinkDistance`: Natural link length (10)\n * - `simulationFriction`: Movement damping (0.85)\n * - `simulationDecay`: Simulation cooling rate (1000)\n *\n * @example Basic configuration\n * ```typescript\n * const config: CosmosSliceConfig = {\n * cosmos: {\n * pointSizeScale: 1.2,\n * scalePointsOnZoom: true,\n * renderLinks: true,\n * linkWidthScale: 1.5,\n * simulationGravity: 0.25\n * }\n * };\n * ```\n *\n * @example Directed graph with curved links\n * ```typescript\n * const directedGraphConfig: CosmosSliceConfig = {\n * cosmos: {\n * linkArrows: true,\n * linkArrowsSizeScale: 1.2,\n * curvedLinks: true,\n * simulationLinkDistance: 15,\n * simulationLinkSpring: 1.2\n * }\n * };\n * ```\n *\n * @example High-performance configuration for large graphs\n * ```typescript\n * const largeGraphConfig: CosmosSliceConfig = {\n * cosmos: {\n * simulationGravity: 0.1,\n * simulationRepulsion: 0.8,\n * simulationFriction: 0.9,\n * simulationDecay: 2000,\n * scalePointsOnZoom: false\n * }\n * };\n * ```\n */\nexport const CosmosSliceConfig = z.object({\n /**\n * Scale factor for point (node) sizes in the graph.\n * Values > 1 make nodes larger, values < 1 make them smaller.\n * @default 1.1\n */\n pointSizeScale: z.number().describe('Scale factor for point sizes'),\n\n /**\n * When true, nodes will dynamically resize based on the current zoom level.\n * This helps maintain visual clarity at different zoom levels.\n * @default true\n */\n scalePointsOnZoom: z\n .boolean()\n .describe('Dynamically resize points based on zoom level'),\n\n /**\n * Controls whether links (edges) between nodes are displayed.\n * @default true\n */\n renderLinks: z.boolean().describe('Control links displaying'),\n\n /**\n * Scale factor for link (edge) width.\n * Values > 1 make links thicker, values < 1 make them thinner.\n * @default 1\n */\n linkWidthScale: z.number().describe('Scale factor for link width'),\n\n /**\n * Scale factor for the size of directional arrows on links.\n * Only applies when linkArrows is true.\n * @default 1\n */\n linkArrowsSizeScale: z.number().describe('Scale factor for link arrows size'),\n\n /**\n * When true, displays arrows indicating link direction.\n * Useful for directed graphs.\n * @default false\n */\n linkArrows: z.boolean().describe('Control displaying link direction arrows'),\n\n /**\n * When true, links are rendered as curved Bezier paths.\n * When false, links are straight lines.\n * @default false\n */\n curvedLinks: z\n .boolean()\n .describe('Render links as curved bezier paths instead of straight lines'),\n\n /**\n * Controls the strength of the central gravitational force.\n * Higher values pull nodes more strongly toward the center.\n * @default 0.25\n */\n simulationGravity: z.number().describe('Gravity force in the simulation'),\n\n /**\n * Controls how strongly nodes repel each other.\n * Higher values create more space between unconnected nodes.\n * @default 1.0\n */\n simulationRepulsion: z.number().describe('Repulsion force between nodes'),\n\n /**\n * Controls the strength of the spring force between linked nodes.\n * Higher values pull connected nodes more tightly together.\n * @default 1.0\n */\n simulationLinkSpring: z\n .number()\n .describe('Spring force for links between nodes'),\n\n /**\n * The natural or resting length of links between nodes.\n * Higher values create more spacing between connected nodes.\n * @default 10\n */\n simulationLinkDistance: z\n .number()\n .describe('Target distance between linked nodes'),\n\n /**\n * Controls how quickly node movement decays.\n * Higher values (closer to 1) create more damped movement.\n * @default 0.85\n */\n simulationFriction: z\n .number()\n .describe('Friction coefficient in the simulation'),\n\n /**\n * Controls how quickly the simulation stabilizes.\n * Lower values result in longer, smoother transitions.\n * @default 1000\n */\n simulationDecay: z\n .number()\n .describe(\n 'Decay coefficient in the simulation. Use smaller values if you want the simulation to \"cool down\" slower.',\n ),\n} satisfies Partial<Record<keyof GraphConfigInterface, unknown>>);\nexport type CosmosSliceConfig = z.infer<typeof CosmosSliceConfig>;\n\nexport function createDefaultCosmosConfig(): CosmosSliceConfig {\n return DEFAULT_COSMOS_CONFIG;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sqlrooms/cosmos",
3
- "version": "0.26.0-rc.3",
3
+ "version": "0.26.0-rc.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.js",
@@ -19,9 +19,9 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@cosmograph/cosmos": "2.0.0-beta.22",
22
- "@sqlrooms/room-config": "0.26.0-rc.3",
23
- "@sqlrooms/room-shell": "0.26.0-rc.3",
24
- "@sqlrooms/ui": "0.26.0-rc.3",
22
+ "@sqlrooms/room-config": "0.26.0-rc.5",
23
+ "@sqlrooms/room-shell": "0.26.0-rc.5",
24
+ "@sqlrooms/ui": "0.26.0-rc.5",
25
25
  "immer": "^10.1.3",
26
26
  "lucide-react": "^0.544.0",
27
27
  "zod": "^4.1.8",
@@ -38,5 +38,5 @@
38
38
  "typecheck": "tsc --noEmit",
39
39
  "typedoc": "typedoc"
40
40
  },
41
- "gitHead": "536764b2aa924e5bb6650fe0bc674113179ff444"
41
+ "gitHead": "dc1c3b765718c8748aa11cce3cc83f907d3e5963"
42
42
  }