This is a difficult situation as I can understand you don't want to tell your gran never to visit again!
To manage such a dog around children you would need a qualified behaviourist to assess the dog and come up with a training programme that would need to be implemented by all members of the family. Do you think your gran is up to this?
Either way the interactions between your DCs and the dog must be more managed. Is the dog crate trained? Do you have baby gates/room dividers to ensure the dog is kept away from the DCs unless very closely supervised (as long as you trust yourself to read the dog's signs of stress - if you don't feel confident about this it's best for the DCs not to have any contact with the dog at all).
Apologies if it seems like I'm picking it all apart but understanding the dog's behaviour may help you;
"usually when dd goes to stroke her. This time dd was just reaching for a toy beside where the dog was lying." I'd say, management wise, from now on DD should not be interacting with the dog except for the purpose of training. Interactions should be led by the dog. As DD is quite young, it may not be possible to be able to explain this sufficiently to her so may just be a case of strong management.
"She's also very nervy and timid but I have no idea why, my gran has had her from being a pup and nobody has ever hurt her although she was attacked by a larger dog once (no major injuries)." t may be that although your gran has had the dog since a puppy she never properly socialised her. Experiencing lots of different things as a puppy is important. Just as important is giving these things associations. Exposure to children is no good unless a positive association is made. Perhaps your gran's dog experienced its exposure to children as either neutral to negative. This doesn't seem farfetched considering young children move strangely, make weird noses, run around a lot and can be quite grabby. All scary things that need to be counteracted by introducing something positive such as play or lots of food. Even then interaction needs to be relatively well controlled as to not overwhelm the dog (especially what would have been a teeny puppy). If your gran never bothered with any training it seems likely she didn't do the above quite thoroughly enough
"I'm struggling to know what to do. My gran won't go anywhere without the dog so I can't ban her from the house but at the same time dd comes first." Will she be willing to work with a behaviourist (as she sounds devoted) and for the dog to be behind a stair gate or similiar during your visits? The dog may even feel safer this way- not having to be too close to DD.
"I think it's linked to her feeling nervous and sometimes she will growl to warn us off which is fine but other times she strikes with no warning." If she regularly growls at people I think it's quite possible that when she's not growling she is in fact not comfortable, but whatever signs she is showing of this are much less noticable than a growl. If she is giving few signals preceding her bites then even more important to get a behaviourist in. Google 'ladder of aggression' to give you some idea of the other signals she may be giving in the build up to a bite.
Really my main "idea" as it were would be for your gran to contact a behaviourist, or leave the dog at home. Or both. The dog sounds like maybe it leads a rather stressy life. For its own welfare a behaviorist might be good regardless. The dog needs to build a new positive association between the children and any interaction they have with her (however limited that is). They may also be able to take more details about the particular 'incidents' where the dog has bitten and consider if there are other common factors to suggest more than general anxiety around the children (guarding of some sort, handling issues). Also encourage your gran to get the dog checked over by a vet. I don't know how old it is or how long it's been exhibiting these behaviours but pain and disease can alter a dog's behaviour dramatically.
My gran is elderly and spends a lot of time with us, she has a 3 year old Yorkshire terrier who she adores but this dog is seriously nuts. She's nipped my toddler dd on 3/4 occasions. Never breaking the skin but usually when dd goes to stroke her. This time dd was just reaching for a toy beside where the dog was lying. The dog is treated like a princess at home and we all treat her kindly, would never hurt her but she's yappy and totally untrained. She's also very nervy and timid but I have no idea why, my gran has had her from being a pup and nobody has ever hurt her although she was attacked by a larger dog once (no major injuries). I'm struggling to know what to do. My gran won't go anywhere without the dog so I can't ban her from the house but at the same time dd comes first. I try to keep the dc away from her but they're toddlers and tbf mostly the dog quite likes them to stroke her! I don't understand why she would snap at dd. I think it's linked to her feeling nervous and sometimes she will growl to warn us off which is fine but other times she strikes with no warning. She's grown up around the children so it's not like she's not used to them. Any ideas?