init
This commit is contained in:
7
extensions/default/src/stores/index.ts
Normal file
7
extensions/default/src/stores/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export { useDisplaySetSelectorStore } from './useDisplaySetSelectorStore';
|
||||
export { useHangingProtocolStageIndexStore } from './useHangingProtocolStageIndexStore';
|
||||
export { useToggleHangingProtocolStore } from './useToggleHangingProtocolStore';
|
||||
export { useToggleOneUpViewportGridStore } from './useToggleOneUpViewportGridStore';
|
||||
export { useUIStateStore } from './useUIStateStore';
|
||||
export { useViewportGridStore } from './useViewportGridStore';
|
||||
export { useViewportsByPositionStore } from './useViewportsByPositionStore';
|
||||
83
extensions/default/src/stores/useDisplaySetSelectorStore.ts
Normal file
83
extensions/default/src/stores/useDisplaySetSelectorStore.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
|
||||
/**
|
||||
* Identifier for the display set selector store type.
|
||||
*/
|
||||
const PRESENTATION_TYPE_ID = 'displaySetSelectorId';
|
||||
|
||||
/**
|
||||
* Flag to enable or disable debug mode for the store.
|
||||
* Set to `true` to enable zustand devtools.
|
||||
*/
|
||||
const DEBUG_STORE = false;
|
||||
|
||||
/**
|
||||
* State shape for the Display Set Selector store.
|
||||
*/
|
||||
type DisplaySetSelectorState = {
|
||||
/**
|
||||
* Type identifier for the store.
|
||||
*/
|
||||
type: string;
|
||||
|
||||
/**
|
||||
* Stores a mapping from `<activeStudyUID>:<displaySetSelectorId>:<matchOffset>` to `displaySetInstanceUID`.
|
||||
*/
|
||||
displaySetSelectorMap: Record<string, string>;
|
||||
|
||||
/**
|
||||
* Sets the display set selector for a given key.
|
||||
*
|
||||
* @param key - The key.
|
||||
* @param value - The `displaySetInstanceUID` to associate with the key.
|
||||
*/
|
||||
setDisplaySetSelector: (key: string, value: string) => void;
|
||||
|
||||
/**
|
||||
* Clears the entire display set selector map.
|
||||
*/
|
||||
clearDisplaySetSelectorMap: () => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the Display Set Selector store.
|
||||
*
|
||||
* @param set - The zustand set function.
|
||||
* @returns The display set selector store state and actions.
|
||||
*/
|
||||
const createDisplaySetSelectorStore = (set): DisplaySetSelectorState => ({
|
||||
type: PRESENTATION_TYPE_ID,
|
||||
displaySetSelectorMap: {},
|
||||
|
||||
/**
|
||||
* Sets the display set selector for a given key.
|
||||
*/
|
||||
setDisplaySetSelector: (key: string, value: string) =>
|
||||
set(
|
||||
state => ({
|
||||
displaySetSelectorMap: {
|
||||
...state.displaySetSelectorMap,
|
||||
[key]: value,
|
||||
},
|
||||
}),
|
||||
false,
|
||||
'setDisplaySetSelector'
|
||||
),
|
||||
|
||||
/**
|
||||
* Clears the entire display set selector map.
|
||||
*/
|
||||
clearDisplaySetSelectorMap: () =>
|
||||
set({ displaySetSelectorMap: {} }, false, 'clearDisplaySetSelectorMap'),
|
||||
});
|
||||
|
||||
/**
|
||||
* Zustand store for managing display set selectors.
|
||||
* Applies devtools middleware when DEBUG_STORE is enabled.
|
||||
*/
|
||||
export const useDisplaySetSelectorStore = create<DisplaySetSelectorState>()(
|
||||
DEBUG_STORE
|
||||
? devtools(createDisplaySetSelectorStore, { name: 'DisplaySetSelectorStore' })
|
||||
: createDisplaySetSelectorStore
|
||||
);
|
||||
@@ -0,0 +1,76 @@
|
||||
import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
import { Types } from '@ohif/core';
|
||||
|
||||
const PRESENTATION_TYPE_ID = 'hangingProtocolStageIndexId';
|
||||
const DEBUG_STORE = false;
|
||||
|
||||
/**
|
||||
* Represents the state and actions for managing hanging protocol stage indexes.
|
||||
*/
|
||||
type HangingProtocolStageIndexState = {
|
||||
/**
|
||||
* Stores a mapping from key to `HPInfo`.
|
||||
*/
|
||||
hangingProtocolStageIndexMap: Record<string, Types.HangingProtocol.HPInfo>;
|
||||
|
||||
/**
|
||||
* Sets the hanging protocol stage index for a given key.
|
||||
*
|
||||
* @param key - The key.
|
||||
* @param value - The `HPInfo` to associate with the key.
|
||||
*/
|
||||
setHangingProtocolStageIndex: (key: string, value: Types.HangingProtocol.HPInfo) => void;
|
||||
|
||||
/**
|
||||
* Clears all hanging protocol stage indexes.
|
||||
*/
|
||||
clearHangingProtocolStageIndexMap: () => void;
|
||||
|
||||
/**
|
||||
* Type identifier for the store.
|
||||
*/
|
||||
type: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the Hanging Protocol Stage Index store.
|
||||
*
|
||||
* @param set - The zustand set function.
|
||||
* @returns The hanging protocol stage index store state and actions.
|
||||
*/
|
||||
const createHangingProtocolStageIndexStore = (set): HangingProtocolStageIndexState => ({
|
||||
hangingProtocolStageIndexMap: {},
|
||||
type: PRESENTATION_TYPE_ID,
|
||||
|
||||
/**
|
||||
* Sets the hanging protocol stage index for a given key.
|
||||
*/
|
||||
setHangingProtocolStageIndex: (key, value) =>
|
||||
set(
|
||||
state => ({
|
||||
hangingProtocolStageIndexMap: {
|
||||
...state.hangingProtocolStageIndexMap,
|
||||
[key]: value,
|
||||
},
|
||||
}),
|
||||
false,
|
||||
'setHangingProtocolStageIndex'
|
||||
),
|
||||
|
||||
/**
|
||||
* Clears all hanging protocol stage indexes.
|
||||
*/
|
||||
clearHangingProtocolStageIndexMap: () =>
|
||||
set({ hangingProtocolStageIndexMap: {} }, false, 'clearHangingProtocolStageIndexMap'),
|
||||
});
|
||||
|
||||
/**
|
||||
* Zustand store for managing hanging protocol stage indexes.
|
||||
* Applies devtools middleware when DEBUG_STORE is enabled.
|
||||
*/
|
||||
export const useHangingProtocolStageIndexStore = create<HangingProtocolStageIndexState>()(
|
||||
DEBUG_STORE
|
||||
? devtools(createHangingProtocolStageIndexStore, { name: 'HangingProtocolStageIndexStore' })
|
||||
: createHangingProtocolStageIndexStore
|
||||
);
|
||||
@@ -0,0 +1,76 @@
|
||||
import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
import { Types } from '@ohif/core';
|
||||
|
||||
const PRESENTATION_TYPE_ID = 'toggleHangingProtocolId';
|
||||
const DEBUG_STORE = false;
|
||||
|
||||
/**
|
||||
* Represents the state and actions for managing toggle hanging protocols.
|
||||
*/
|
||||
type ToggleHangingProtocolState = {
|
||||
/**
|
||||
* Stores a mapping from key to `HPInfo`.
|
||||
*/
|
||||
toggleHangingProtocol: Record<string, Types.HangingProtocol.HPInfo>;
|
||||
|
||||
/**
|
||||
* Sets the toggle hanging protocol for a given key.
|
||||
*
|
||||
* @param key - The key .
|
||||
* @param value - The `HPInfo` to associate with the key.
|
||||
*/
|
||||
setToggleHangingProtocol: (key: string, value: Types.HangingProtocol.HPInfo) => void;
|
||||
|
||||
/**
|
||||
* Clears all toggle hanging protocols.
|
||||
*/
|
||||
clearToggleHangingProtocol: () => void;
|
||||
|
||||
/**
|
||||
* Type identifier for the store.
|
||||
*/
|
||||
type: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the Toggle Hanging Protocol store.
|
||||
*
|
||||
* @param set - The zustand set function.
|
||||
* @returns The toggle hanging protocol store state and actions.
|
||||
*/
|
||||
const createToggleHangingProtocolStore = (set): ToggleHangingProtocolState => ({
|
||||
toggleHangingProtocol: {},
|
||||
type: PRESENTATION_TYPE_ID,
|
||||
|
||||
/**
|
||||
* Sets the toggle hanging protocol for a given key.
|
||||
*/
|
||||
setToggleHangingProtocol: (key, value) =>
|
||||
set(
|
||||
state => ({
|
||||
toggleHangingProtocol: {
|
||||
...state.toggleHangingProtocol,
|
||||
[key]: value,
|
||||
},
|
||||
}),
|
||||
false,
|
||||
'setToggleHangingProtocol'
|
||||
),
|
||||
|
||||
/**
|
||||
* Clears all toggle hanging protocols.
|
||||
*/
|
||||
clearToggleHangingProtocol: () =>
|
||||
set({ toggleHangingProtocol: {} }, false, 'clearToggleHangingProtocol'),
|
||||
});
|
||||
|
||||
/**
|
||||
* Zustand store for managing toggle hanging protocols.
|
||||
* Applies devtools middleware when DEBUG_STORE is enabled.
|
||||
*/
|
||||
export const useToggleHangingProtocolStore = create<ToggleHangingProtocolState>()(
|
||||
DEBUG_STORE
|
||||
? devtools(createToggleHangingProtocolStore, { name: 'ToggleHangingProtocolStore' })
|
||||
: createToggleHangingProtocolStore
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
import { create } from 'zustand';
|
||||
|
||||
const PRESENTATION_TYPE_ID = 'toggleOneUpViewportGridId';
|
||||
|
||||
type ToggleOneUpViewportGridState = {
|
||||
toggleOneUpViewportGridStore: any | null;
|
||||
setToggleOneUpViewportGridStore: (state: any) => void;
|
||||
clearToggleOneUpViewportGridStore: () => void;
|
||||
type: string;
|
||||
};
|
||||
|
||||
// Stores the entire ViewportGridService getState when toggling to one up
|
||||
// (e.g. via a double click) so that it can be restored when toggling back.
|
||||
export const useToggleOneUpViewportGridStore = create<ToggleOneUpViewportGridState>(set => ({
|
||||
toggleOneUpViewportGridStore: null,
|
||||
type: PRESENTATION_TYPE_ID,
|
||||
setToggleOneUpViewportGridStore: state => set({ toggleOneUpViewportGridStore: state }),
|
||||
clearToggleOneUpViewportGridStore: () => set({ toggleOneUpViewportGridStore: null }),
|
||||
}));
|
||||
87
extensions/default/src/stores/useUIStateStore.ts
Normal file
87
extensions/default/src/stores/useUIStateStore.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
|
||||
/**
|
||||
* Identifier for the UI State store type.
|
||||
*/
|
||||
const PRESENTATION_TYPE_ID = 'uiStateId';
|
||||
|
||||
/**
|
||||
* Flag to enable or disable debug mode for the store.
|
||||
* Set to `true` to enable zustand devtools.
|
||||
*/
|
||||
const DEBUG_STORE = false;
|
||||
|
||||
/**
|
||||
* Represents the UI state.
|
||||
*/
|
||||
type UIState = {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
/**
|
||||
* State shape for the UI State store.
|
||||
*/
|
||||
type UIStateStore = {
|
||||
/**
|
||||
* Type identifier for the store.
|
||||
*/
|
||||
type: string;
|
||||
|
||||
/**
|
||||
* Stores the UI state as a key-value mapping.
|
||||
*/
|
||||
uiState: UIState;
|
||||
|
||||
/**
|
||||
* Sets the UI state for a given key.
|
||||
*
|
||||
* @param key - The key to set in the UI state.
|
||||
* @param value - The value to associate with the key.
|
||||
*/
|
||||
setUIState: (key: string, value: unknown) => void;
|
||||
|
||||
/**
|
||||
* Clears all UI state.
|
||||
*/
|
||||
clearUIState: () => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the UI State store.
|
||||
*
|
||||
* @param set - The zustand set function.
|
||||
* @returns The UI State store state and actions.
|
||||
*/
|
||||
const createUIStateStore = (set): UIStateStore => ({
|
||||
type: PRESENTATION_TYPE_ID,
|
||||
uiState: {},
|
||||
|
||||
/**
|
||||
* Sets the UI state for a given key.
|
||||
*/
|
||||
setUIState: (key, value) =>
|
||||
set(
|
||||
state => ({
|
||||
uiState: {
|
||||
...state.uiState,
|
||||
[key]: value,
|
||||
},
|
||||
}),
|
||||
false,
|
||||
'setUIState'
|
||||
),
|
||||
|
||||
/**
|
||||
* Clears all UI state.
|
||||
*/
|
||||
clearUIState: () => set({ uiState: {} }, false, 'clearUIState'),
|
||||
});
|
||||
|
||||
/**
|
||||
* Zustand store for managing UI state.
|
||||
* Applies devtools middleware when DEBUG_STORE is enabled.
|
||||
*/
|
||||
export const useUIStateStore = create<UIStateStore>()(
|
||||
DEBUG_STORE ? devtools(createUIStateStore, { name: 'UIStateStore' }) : createUIStateStore
|
||||
);
|
||||
89
extensions/default/src/stores/useViewportGridStore.ts
Normal file
89
extensions/default/src/stores/useViewportGridStore.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
|
||||
/**
|
||||
* Identifier for the viewport grid store type.
|
||||
*/
|
||||
const PRESENTATION_TYPE_ID = 'viewportGridId';
|
||||
|
||||
/**
|
||||
* Flag to enable or disable debug mode for the store.
|
||||
* Set to `true` to enable zustand devtools.
|
||||
*/
|
||||
const DEBUG_STORE = false;
|
||||
|
||||
/**
|
||||
* Represents the state of the viewport grid.
|
||||
*/
|
||||
type ViewportGridState = {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
/**
|
||||
* State shape for the Viewport Grid store.
|
||||
*/
|
||||
type ViewportGridStore = {
|
||||
/**
|
||||
* Type identifier for the store.
|
||||
*/
|
||||
type: string;
|
||||
|
||||
/**
|
||||
* Stores the viewport grid state as a key-value mapping.
|
||||
*/
|
||||
viewportGridState: ViewportGridState;
|
||||
|
||||
/**
|
||||
* Sets the viewport grid state for a given key.
|
||||
*
|
||||
* @param key - The key to set in the viewport grid state.
|
||||
* @param value - The value to associate with the key.
|
||||
*/
|
||||
setViewportGridState: (key: string, value: unknown) => void;
|
||||
|
||||
/**
|
||||
* Clears the entire viewport grid state.
|
||||
*/
|
||||
clearViewportGridState: () => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the Viewport Grid store.
|
||||
*
|
||||
* @param set - The zustand set function.
|
||||
* @returns The Viewport Grid store state and actions.
|
||||
*/
|
||||
const createViewportGridStore = (set): ViewportGridStore => ({
|
||||
type: PRESENTATION_TYPE_ID,
|
||||
viewportGridState: {},
|
||||
|
||||
/**
|
||||
* Sets the viewport grid state for a given key.
|
||||
*/
|
||||
setViewportGridState: (key, value) =>
|
||||
set(
|
||||
state => ({
|
||||
viewportGridState: {
|
||||
...state.viewportGridState,
|
||||
[key]: value,
|
||||
},
|
||||
}),
|
||||
false,
|
||||
'setViewportGridState'
|
||||
),
|
||||
|
||||
/**
|
||||
* Clears the entire viewport grid state.
|
||||
*/
|
||||
clearViewportGridState: () => set({ viewportGridState: {} }, false, 'clearViewportGridState'),
|
||||
});
|
||||
|
||||
/**
|
||||
* Zustand store for managing viewport grid state.
|
||||
* Applies devtools middleware when DEBUG_STORE is enabled.
|
||||
*/
|
||||
export const useViewportGridStore = create<ViewportGridStore>()(
|
||||
DEBUG_STORE
|
||||
? devtools(createViewportGridStore, { name: 'ViewportGridStore' })
|
||||
: createViewportGridStore
|
||||
);
|
||||
100
extensions/default/src/stores/useViewportsByPositionStore.ts
Normal file
100
extensions/default/src/stores/useViewportsByPositionStore.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
|
||||
const PRESENTATION_TYPE_ID = 'viewportsByPositionId';
|
||||
const DEBUG_STORE = true;
|
||||
|
||||
/**
|
||||
* Represents the state and actions for managing viewports by position.
|
||||
*/
|
||||
type ViewportsByPositionState = {
|
||||
/**
|
||||
* Type identifier for the store.
|
||||
*/
|
||||
type: string;
|
||||
|
||||
/**
|
||||
* Stores viewports indexed by their position.
|
||||
*/
|
||||
viewportsByPosition: Record<string, unknown>;
|
||||
|
||||
/**
|
||||
* Stores initial display viewports as an array of strings.
|
||||
*/
|
||||
initialInDisplay: string[];
|
||||
|
||||
/**
|
||||
* Sets the viewport for a given key.
|
||||
*
|
||||
* @param key - The key identifying the viewport position.
|
||||
* @param value - The viewport data to associate with the key.
|
||||
*/
|
||||
setViewportsByPosition: (key: string, value: unknown) => void;
|
||||
|
||||
/**
|
||||
* Clears all viewports by position.
|
||||
*/
|
||||
clearViewportsByPosition: () => void;
|
||||
|
||||
/**
|
||||
* Adds an initial display viewport.
|
||||
*
|
||||
* @param value - The viewport identifier to add.
|
||||
*/
|
||||
addInitialInDisplay: (value: string) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the Viewports By Position store.
|
||||
*
|
||||
* @param set - The zustand set function.
|
||||
* @returns The Viewports By Position store state and actions.
|
||||
*/
|
||||
const createViewportsByPositionStore = (set): ViewportsByPositionState => ({
|
||||
type: PRESENTATION_TYPE_ID,
|
||||
viewportsByPosition: {},
|
||||
initialInDisplay: [],
|
||||
|
||||
/**
|
||||
* Sets the viewport for a given key.
|
||||
*/
|
||||
setViewportsByPosition: (key, value) =>
|
||||
set(
|
||||
state => ({
|
||||
viewportsByPosition: {
|
||||
...state.viewportsByPosition,
|
||||
[key]: value,
|
||||
},
|
||||
}),
|
||||
false,
|
||||
'setViewportsByPosition'
|
||||
),
|
||||
|
||||
/**
|
||||
* Clears all viewports by position.
|
||||
*/
|
||||
clearViewportsByPosition: () =>
|
||||
set({ viewportsByPosition: {} }, false, 'clearViewportsByPosition'),
|
||||
|
||||
/**
|
||||
* Adds an initial display viewport.
|
||||
*/
|
||||
addInitialInDisplay: value =>
|
||||
set(
|
||||
state => ({
|
||||
initialInDisplay: [...state.initialInDisplay, value],
|
||||
}),
|
||||
false,
|
||||
'addInitialInDisplay'
|
||||
),
|
||||
});
|
||||
|
||||
/**
|
||||
* Zustand store for managing viewports by position.
|
||||
* Applies devtools middleware when DEBUG_STORE is enabled.
|
||||
*/
|
||||
export const useViewportsByPositionStore = create<ViewportsByPositionState>()(
|
||||
DEBUG_STORE
|
||||
? devtools(createViewportsByPositionStore, { name: 'ViewportsByPositionStore' })
|
||||
: createViewportsByPositionStore
|
||||
);
|
||||
Reference in New Issue
Block a user