Jon/sky 5820 make browser task block flippable with code (#3165)

This commit is contained in:
Jonathan Dobson
2025-08-11 19:57:08 -04:00
committed by GitHub
parent e5106124e3
commit 039fce0bb3
16 changed files with 663 additions and 339 deletions

View File

@@ -0,0 +1,45 @@
/**
* A store to hold the scripts for individual blocks in a workflow. As each
* workflow has uniquely (and differently) labelled blocks, and those labels
* are block identity, we'll eschew strong typing for this, and use a loose
* object literal instead.
*/
import { create } from "zustand";
interface BlockScriptStore {
scriptId?: string;
scripts: { [k: string]: string };
// --
setScript: (blockId: string, script: string) => void;
setScripts: (scripts: { [k: string]: string }) => void;
reset: () => void;
}
const useBlockScriptStore = create<BlockScriptStore>((set) => {
return {
scriptId: undefined,
scripts: {},
// --
setScript: (blockId: string, script: string) => {
set((state) => ({
scripts: {
...state.scripts,
[blockId]: script,
},
}));
},
setScripts: (scripts: { [k: string]: string }) => {
set(() => ({
scripts,
}));
},
reset: () => {
set({
scripts: {},
});
},
};
});
export { useBlockScriptStore };