var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _OutletManagerController_instances, _OutletManagerController_outlets_get; import { Controller } from '@hotwired/stimulus'; class OutletManagerController extends Controller { constructor() { super(...arguments); _OutletManagerController_instances.add(this); this.outletEventsLookup = null; this.eventRecords = new Map(); } getOutlets() { return null; } outletUpdate(event, data) { } // eslint-disable-line no-unused-vars getState() { return null; } connect() { this.syncOutlets(); } syncOutlets() { const event = new Event('init'); this.sendToOutlets(event, { data: this.getState(), eventKey: this.getEventKey(event), }); } sendToOutlets(event, updateTo = {}) { var _a; const eventKey = (_a = updateTo.eventKey) !== null && _a !== void 0 ? _a : this.getEventKey(event); const outlets = __classPrivateFieldGet(this, _OutletManagerController_instances, "a", _OutletManagerController_outlets_get); if (outlets === null || outlets === void 0 ? void 0 : outlets.length) { for (const index in outlets) { const outlet = outlets[index]; if (outlet.isListeningForOutletEvent(eventKey) && !this.hasHeardEvent(event)) { const isSameControllerType = this.identifier === outlet.identifier; outlet.outletUpdate(event, { eventKey, data: isSameControllerType ? updateTo.data : undefined }); } } } } isListeningForOutletEvent(eventTypes) { const eventTypeNames = eventTypes.split('-'); if (!eventTypeNames.length) { return false; } let lookup = this.outletEvents; for (let i = 0; i < eventTypeNames.length; i++) { const name = eventTypeNames[i]; if (typeof lookup === 'boolean') { return lookup; } const hasWildCard = lookup['*'] !== undefined; let nextKey = name; if (hasWildCard) { nextKey = '*'; } else { const isListeningForDOMEvent = lookup.domEvent !== undefined; if (isListeningForDOMEvent && !this.isDOMEventName(name)) { return false; } else if (isListeningForDOMEvent) { nextKey = 'domEvent'; } } if (!lookup[nextKey]) { return false; } lookup = lookup[nextKey]; } return true; } isDOMEventName(eventName) { return OutletManagerController.domEvents[eventName]; } getEventKey(event) { const pre = this.event_key_prefix; const post = this.event_key_postfix; const maybePreHyphen = pre ? '-' : ''; const maybePrefix = pre !== null && pre !== void 0 ? pre : ''; const maybePostHyphen = post ? '-' : ''; const maybePostfix = post !== null && post !== void 0 ? post : ''; return `${this.identifier}-${maybePrefix}${maybePreHyphen}${event.type}${maybePostHyphen}${maybePostfix}`; } hasHeardEvent(event) { if (this.eventRecords.has(event)) { return true; } this.eventRecords.set(event, true); setTimeout(() => this.eventRecords.delete(event)); return false; } get event_key_prefix() { return ''; } get event_key_postfix() { return ''; } get outletEvents() { if (!this.outletEventsLookup && this.hasOutletEventsValue) { this.outletEventsLookup = this.outletEventsValue.reduce((acc, eventType) => { let step = acc; eventType.split('-').forEach((eventTypeName, i, splitArr) => { if (typeof step === 'boolean') { return; } if (i === splitArr.length - 1) { step[eventTypeName] = true; } else if (step[eventTypeName] === undefined) { step[eventTypeName] = {}; } step = step[eventTypeName]; }); return acc; }, {}); } else if (!this.outletEventsLookup) { this.outletEventsLookup = { '*': true }; } return this.outletEventsLookup; } } _OutletManagerController_instances = new WeakSet(), _OutletManagerController_outlets_get = function _OutletManagerController_outlets_get() { const outlets = this.getOutlets(); if (outlets) { return outlets; } const defaultOutlets = []; if (this.hasToggleableOutlet) { defaultOutlets.push(...this.toggleableOutlets); } if (this.hasOptionsOutlet) { defaultOutlets.push(...this.optionsOutlets); } if (this.hasStringMatchOutlet) { defaultOutlets.push(...this.stringMatchOutlets); } return defaultOutlets; }; OutletManagerController.values = { outletEvents: Array, }; OutletManagerController.outlets = ['toggleable', 'options', 'string-match']; OutletManagerController.domEvents = { abort: true, afterprint: true, animationend: true, animationiteration: true, animationstart: true, beforeprint: true, beforeunload: true, blur: true, canplay: true, canplaythrough: true, change: true, click: true, contextmenu: true, copy: true, cut: true, dblclick: true, drag: true, dragend: true, dragenter: true, dragleave: true, dragover: true, dragstart: true, drop: true, durationchange: true, ended: true, error: true, focus: true, focusin: true, focusout: true, fullscreenchange: true, fullscreenerror: true, hashchange: true, input: true, invalid: true, keydown: true, keypress: true, keyup: true, load: true, loadeddata: true, loadedmetadata: true, loadstart: true, message: true, mousedown: true, mouseenter: true, mouseleave: true, mousemove: true, mouseover: true, mouseout: true, mouseup: true, mousewheel: true, offline: true, online: true, open: true, pagehide: true, pageshow: true, paste: true, pause: true, play: true, playing: true, popstate: true, progress: true, ratechange: true, resize: true, reset: true, scroll: true, search: true, seeked: true, seeking: true, select: true, show: true, stalled: true, storage: true, submit: true, suspend: true, timeupdate: true, toggle: true, touchcancel: true, touchend: true, touchmove: true, touchstart: true, transitionend: true, unload: true, volumechange: true, waiting: true, wheel: true, }; export default OutletManagerController;