( eventString: DomEventNameWithModifier | string, options?: TriggerOptions )
| 145 | } |
| 146 | |
| 147 | function createDOMEvent( |
| 148 | eventString: DomEventNameWithModifier | string, |
| 149 | options?: TriggerOptions |
| 150 | ) { |
| 151 | // split eventString like `keydown.ctrl.shift` into `keydown` and array of modifiers |
| 152 | const [eventType, ...modifiers] = eventString.split('.') |
| 153 | |
| 154 | const eventParams: EventParams = { |
| 155 | eventType: eventType as DomEventName, |
| 156 | modifiers: modifiers as KeyName[], |
| 157 | options |
| 158 | } |
| 159 | const event: Event & TriggerOptions = createEvent(eventParams) |
| 160 | const eventPrototype = Object.getPrototypeOf(event) |
| 161 | |
| 162 | // attach custom options to the event, like `relatedTarget` and so on. |
| 163 | if (options) { |
| 164 | Object.keys(options).forEach(key => { |
| 165 | const propertyDescriptor = Object.getOwnPropertyDescriptor( |
| 166 | eventPrototype, |
| 167 | key |
| 168 | ) |
| 169 | const canSetProperty = !( |
| 170 | propertyDescriptor && propertyDescriptor.set === undefined |
| 171 | ) |
| 172 | if (canSetProperty) { |
| 173 | event[key] = options[key] |
| 174 | } |
| 175 | }) |
| 176 | } |
| 177 | return event |
| 178 | } |
| 179 | |
| 180 | export { |
| 181 | TriggerOptions, |
no test coverage detected
searching dependent graphs…