|
|
@@ -1,6 +1,5 @@
|
|
|
import { create } from "zustand";
|
|
|
-import type { ClockBlock, ClockRow } from "../assets/types";
|
|
|
-import type { Signal } from "../assets/SelectSignal";
|
|
|
+import type { ClockBlock, ClockRow, Signal } from "../assets/types";
|
|
|
|
|
|
export const defaultClockSignal: Signal = {
|
|
|
type: "virtual-signal",
|
|
|
@@ -12,8 +11,11 @@ export const defaultClockSignal: Signal = {
|
|
|
interface ClockState {
|
|
|
// Global Settings
|
|
|
duration: number;
|
|
|
- clockSignal: Signal;
|
|
|
+ pixelsPerTick: number;
|
|
|
setDuration: (duration: number) => void;
|
|
|
+ setZoom: (val: number) => void;
|
|
|
+
|
|
|
+ clockSignal: Signal;
|
|
|
setClockSignal: (signal: Signal | null) => void;
|
|
|
|
|
|
// Normalized Data Models
|
|
|
@@ -42,14 +44,13 @@ interface ClockState {
|
|
|
removeBlocks: (ids: string[]) => void;
|
|
|
|
|
|
// Selection
|
|
|
- selectBlocks: (
|
|
|
- ids: Set<string> | ((prev: Set<string>) => Set<string>),
|
|
|
- ) => void;
|
|
|
+ selectBlocks: (ids: Set<string> | ((prev: Set<string>) => Set<string>)) => void;
|
|
|
clearSelection: () => void;
|
|
|
}
|
|
|
|
|
|
export const useClockStore = create<ClockState>((set) => ({
|
|
|
duration: 256,
|
|
|
+ pixelsPerTick: 4,
|
|
|
clockSignal: defaultClockSignal, // Set your default signal here
|
|
|
|
|
|
rows: {},
|
|
|
@@ -62,6 +63,7 @@ export const useClockStore = create<ClockState>((set) => ({
|
|
|
loadState: (state: Partial<ClockState>) => set(() => ({ ...state })),
|
|
|
|
|
|
setDuration: (duration) => set({ duration }),
|
|
|
+ setZoom: (val) => set({ pixelsPerTick: val }),
|
|
|
setClockSignal: (clockSignal) => {
|
|
|
if (clockSignal) set({ clockSignal });
|
|
|
},
|
|
|
@@ -87,9 +89,7 @@ export const useClockStore = create<ClockState>((set) => ({
|
|
|
delete newRows[id];
|
|
|
|
|
|
// Also clean up orphan blocks
|
|
|
- const newBlocks = Object.fromEntries(
|
|
|
- Object.entries(state.blocks).filter(([_, block]) => block.rowId !== id),
|
|
|
- );
|
|
|
+ const newBlocks = Object.fromEntries(Object.entries(state.blocks).filter(([_, block]) => block.rowId !== id));
|
|
|
|
|
|
return {
|
|
|
rows: newRows,
|
|
|
@@ -139,10 +139,7 @@ export const useClockStore = create<ClockState>((set) => ({
|
|
|
|
|
|
selectBlocks: (idsOrUpdater) =>
|
|
|
set((state) => ({
|
|
|
- selectedBlockIds:
|
|
|
- typeof idsOrUpdater === "function"
|
|
|
- ? idsOrUpdater(state.selectedBlockIds)
|
|
|
- : idsOrUpdater,
|
|
|
+ selectedBlockIds: typeof idsOrUpdater === "function" ? idsOrUpdater(state.selectedBlockIds) : idsOrUpdater,
|
|
|
})),
|
|
|
|
|
|
clearSelection: () => set({ selectedBlockIds: new Set() }),
|