()
| 30 | } |
| 31 | |
| 32 | export const createPlugins = () => { |
| 33 | const { store, setStore } = createDevtoolsContext() |
| 34 | const { setForceExpand } = createDrawContext() |
| 35 | |
| 36 | const plugins = createMemo(() => store.plugins) |
| 37 | const activePlugins = createMemo(() => store.state.activePlugins) |
| 38 | |
| 39 | createEffect(() => { |
| 40 | if (activePlugins().length === 0) { |
| 41 | setForceExpand(true) |
| 42 | } else { |
| 43 | setForceExpand(false) |
| 44 | } |
| 45 | }) |
| 46 | |
| 47 | const toggleActivePlugins = (pluginId: string) => { |
| 48 | setStore((prev) => { |
| 49 | const isActive = prev.state.activePlugins.includes(pluginId) |
| 50 | |
| 51 | const currentPlugin = store.plugins?.find( |
| 52 | (plugin) => plugin.id === pluginId, |
| 53 | ) |
| 54 | |
| 55 | if (currentPlugin?.destroy && isActive) { |
| 56 | currentPlugin.destroy(pluginId) |
| 57 | } |
| 58 | |
| 59 | const updatedPlugins = isActive |
| 60 | ? prev.state.activePlugins.filter((id) => id !== pluginId) |
| 61 | : [...prev.state.activePlugins, pluginId] |
| 62 | if (updatedPlugins.length > MAX_ACTIVE_PLUGINS) return prev |
| 63 | return { |
| 64 | ...prev, |
| 65 | state: { |
| 66 | ...prev.state, |
| 67 | activePlugins: updatedPlugins, |
| 68 | }, |
| 69 | } |
| 70 | }) |
| 71 | } |
| 72 | |
| 73 | return { plugins, toggleActivePlugins, activePlugins } |
| 74 | } |
| 75 | |
| 76 | export const createDevtoolsState = () => { |
| 77 | const { store, setStore } = createDevtoolsContext() |
no test coverage detected