(el: Element | string, optionOverrides: OverrideFeedbackConfiguration = {})
| 279 | }; |
| 280 | |
| 281 | const _attachTo = (el: Element | string, optionOverrides: OverrideFeedbackConfiguration = {}): Unsubscribe => { |
| 282 | const mergedOptions = mergeOptions(_options, optionOverrides); |
| 283 | |
| 284 | const targetEl = |
| 285 | typeof el === 'string' ? DOCUMENT.querySelector(el) : typeof el.addEventListener === 'function' ? el : null; |
| 286 | |
| 287 | if (!targetEl) { |
| 288 | DEBUG_BUILD && debug.error('[Feedback] Unable to attach to target element'); |
| 289 | throw new Error('Unable to attach to target element'); |
| 290 | } |
| 291 | |
| 292 | let dialog: ReturnType<FeedbackModalIntegration['createDialog']> | null = null; |
| 293 | const handleClick = async (): Promise<void> => { |
| 294 | if (!dialog) { |
| 295 | dialog = await _loadAndRenderDialog({ |
| 296 | ...mergedOptions, |
| 297 | onFormSubmitted: () => { |
| 298 | dialog?.removeFromDom(); |
| 299 | mergedOptions.onFormSubmitted?.(); |
| 300 | }, |
| 301 | }); |
| 302 | } |
| 303 | dialog.appendToDom(); |
| 304 | dialog.open(); |
| 305 | }; |
| 306 | targetEl.addEventListener('click', handleClick); |
| 307 | const unsubscribe = (): void => { |
| 308 | _subscriptions = _subscriptions.filter(sub => sub !== unsubscribe); |
| 309 | dialog?.removeFromDom(); |
| 310 | dialog = null; |
| 311 | targetEl.removeEventListener('click', handleClick); |
| 312 | }; |
| 313 | _subscriptions.push(unsubscribe); |
| 314 | return unsubscribe; |
| 315 | }; |
| 316 | |
| 317 | const _createActor = (optionOverrides: OverrideFeedbackConfiguration = {}): ActorComponent => { |
| 318 | const mergedOptions = mergeOptions(_options, optionOverrides); |
no test coverage detected