The simple solution would be to just discard and recalculate the power distribution in the whole grid whenever you make a change. Considering that your grid is only 18x18, it shouldn't be too computationally intensive to do so.
Inverters might be problematic, though. What do you want to happen when the player connects the output of an inverter to its input? This would lead to a paradoxical situation. In a real-life circuit, the inverter might either oscillate (switch between on- and off as fast as it can) or just short-circuit and break.
When you want to go for the oscillating solution, you should go for a tick-based simulation where a fixed number of updates is calculated each second. In such a simulation, an inverter would not directly forward the state of its input. It would instead be modeled as an object which blocks power-flow, but which is also an independent power-source, just with the difference that the player can not switch it off- and on directly. The update-function which is executed in regular intervals would then look like this in pseudo-code:
for each source if source is inverter if input wire is in "on" set source to "off" else set source to "on" for each wire set wire to "off" for each source if source is "on" flood-fill wires starting from output-wire and set all found wires to "on"
note that evaluation of the inverter-state and evaluation of the wire-state are two separate steps. That way you will not run into any infinite loops during the update.
When you instead want to go for a "breaking" solution, you would recursively flood-fill from all sources. The status of each wire would start out as "undefined". When you start flood-filling from a souce, you fill with the value "on". When you pass through an inverter, you toggle from "on" to "off" or vice versa and continue flood-filling with the new value. When you ever encounter an "off" wire while flooding with "on" or an "on" wire while flooding with "off", you found a paradoxon in the players circuit, revert the last move and tell the player they can't do that.