package.dist.popup-utils.PopoverRegistry.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webcomponents Show documentation
Show all versions of webcomponents Show documentation
UI5 Web Components: webcomponents.main
The newest version!
{"version":3,"file":"PopoverRegistry.js","sourceRoot":"","sources":["../../src/popup-utils/PopoverRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF,OAAO,gBAAgB,MAAM,uDAAuD,CAAC;AAErF,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAO/F,IAAI,cAAwB,CAAC;AAC7B,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,cAAc,GAA6B,EAAE,CAAC;AAEpD,MAAM,kBAAkB,GAAG,GAAG,EAAE;IAC/B,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,wBAAwB,GAAG,GAAG,EAAE;IACrC,IAAI,gBAAgB,EAAG,CAAC,OAAO,KAAK,QAAQ,EAAE;QAC7C,WAAW,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;KACxF;AACF,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC9B,cAAc,GAAG,WAAW,CAAC,GAAG,EAAE;QACjC,kBAAkB,EAAE,CAAC;QAErB,wBAAwB,EAAE,CAAC;IAC5B,CAAC,EAAE,eAAe,CAAC,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,GAAG,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ACvB,CAAC,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAAC,QAAiB,EAAE,EAAE;IACvD,IAAI,cAAc,GAAG,QAAQ,CAAC,UAAU,CAAC;IACzC,MAAM,cAAc,GAAmB,EAAE,CAAC;IAE1C,OAAO,cAAc,IAAI,cAAc,CAAC,UAAU,EAAE;QACnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC/C,IAAI,cAAc,KAAK,cAAc,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;gBAClD,cAAc,CAAC,IAAI,CAAC,cAAyB,CAAC,CAAC;aAC/C;SACD;QAED,cAAc,GAAG,cAAc,CAAC,UAAU,CAAC;KAC3C;IAED,OAAO,cAAc,CAAC;AACvB,CAAC,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { isClickInRect } from \"@ui5/webcomponents-base/dist/util/PopupUtils.js\";\nimport type { Interval } from \"@ui5/webcomponents-base/dist/types.js\";\nimport getActiveElement from \"@ui5/webcomponents-base/dist/util/getActiveElement.js\";\nimport type Popover from \"../Popover.js\";\nimport { instanceOfPopover } from \"../Popover.js\";\nimport { getOpenedPopups, addOpenedPopup, removeOpenedPopup } from \"./OpenedPopupsRegistry.js\";\n\ntype RegisteredPopover = {\n\tinstance: Popover;\n\tparentPopovers: Array;\n}\n\nlet updateInterval: Interval;\nconst intervalTimeout = 300;\nconst openedRegistry: Array = [];\n\nconst repositionPopovers = () => {\n\topenedRegistry.forEach(popover => {\n\t\tpopover.instance.reposition();\n\t});\n};\n\nconst closePopoversIfLostFocus = () => {\n\tif (getActiveElement()!.tagName === \"IFRAME\") {\n\t\tgetRegistry().reverse().forEach(popup => popup.instance.closePopup(false, false, true));\n\t}\n};\n\nconst runUpdateInterval = () => {\n\tupdateInterval = setInterval(() => {\n\t\trepositionPopovers();\n\n\t\tclosePopoversIfLostFocus();\n\t}, intervalTimeout);\n};\n\nconst stopUpdateInterval = () => {\n\tclearInterval(updateInterval);\n};\n\nconst attachGlobalScrollHandler = () => {\n\tdocument.addEventListener(\"scroll\", repositionPopovers, { capture: true });\n};\n\nconst detachGlobalScrollHandler = () => {\n\tdocument.removeEventListener(\"scroll\", repositionPopovers, { capture: true });\n};\n\nconst attachScrollHandler = (popover: Popover) => {\n\tpopover && popover.shadowRoot!.addEventListener(\"scroll\", repositionPopovers, { capture: true });\n};\n\nconst detachScrollHandler = (popover: Popover) => {\n\tpopover && popover.shadowRoot!.removeEventListener(\"scroll\", repositionPopovers, { capture: true });\n};\n\nconst attachGlobalClickHandler = () => {\n\tdocument.addEventListener(\"mousedown\", clickHandler);\n};\n\nconst detachGlobalClickHandler = () => {\n\tdocument.removeEventListener(\"mousedown\", clickHandler);\n};\n\nconst clickHandler = (event: MouseEvent) => {\n\tconst openedPopups = getOpenedPopups();\n\n\tif (openedPopups.length === 0) {\n\t\treturn;\n\t}\n\n\tconst isTopPopupPopover = instanceOfPopover(openedPopups[openedPopups.length - 1].instance);\n\n\tif (!isTopPopupPopover) {\n\t\treturn;\n\t}\n\n\t// loop all open popovers\n\tfor (let i = (openedPopups.length - 1); i !== -1; i--) {\n\t\tconst popup = openedPopups[i].instance;\n\n\t\t// if popup is modal, opener is clicked, popup is dialog skip closing\n\t\tif (popup.isModal || (popup as Popover).isOpenerClicked(event)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (isClickInRect(event, popup.getBoundingClientRect())) {\n\t\t\tbreak;\n\t\t}\n\n\t\tpopup.closePopup();\n\t}\n};\n\nconst addOpenedPopover = (instance: Popover) => {\n\tconst parentPopovers = getParentPopoversIfNested(instance);\n\n\taddOpenedPopup(instance, parentPopovers);\n\topenedRegistry.push({\n\t\tinstance,\n\t\tparentPopovers,\n\t});\n\n\tattachScrollHandler(instance);\n\n\tif (openedRegistry.length === 1) {\n\t\tattachGlobalScrollHandler();\n\t\tattachGlobalClickHandler();\n\t\trunUpdateInterval();\n\t}\n};\n\nconst removeOpenedPopover = (instance: Popover) => {\n\tconst popoversToClose = [instance];\n\n\tfor (let i = 0; i < openedRegistry.length; i++) {\n\t\tconst indexOfCurrentInstance = openedRegistry[i].parentPopovers.indexOf(instance);\n\t\tif (openedRegistry[i].parentPopovers.length > 0 && indexOfCurrentInstance > -1) {\n\t\t\tpopoversToClose.push(openedRegistry[i].instance);\n\t\t}\n\t}\n\n\tfor (let i = popoversToClose.length - 1; i >= 0; i--) {\n\t\tfor (let j = 0; j < openedRegistry.length; j++) {\n\t\t\tlet indexOfItemToRemove = -1;\n\t\t\tif (popoversToClose[i] === openedRegistry[j].instance) {\n\t\t\t\tindexOfItemToRemove = j;\n\t\t\t}\n\n\t\t\tif (indexOfItemToRemove >= 0) {\n\t\t\t\tremoveOpenedPopup(openedRegistry[indexOfItemToRemove].instance);\n\t\t\t\tdetachScrollHandler(openedRegistry[indexOfItemToRemove].instance);\n\t\t\t\tconst itemToClose = openedRegistry.splice(indexOfItemToRemove, 1);\n\t\t\t\titemToClose[0].instance.closePopup(false, true);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!openedRegistry.length) {\n\t\tdetachGlobalScrollHandler();\n\t\tdetachGlobalClickHandler();\n\t\tstopUpdateInterval();\n\t}\n};\n\nconst getRegistry = () => {\n\treturn openedRegistry;\n};\n\nconst getParentPopoversIfNested = (instance: Popover) => {\n\tlet currentElement = instance.parentNode;\n\tconst parentPopovers: Array = [];\n\n\twhile (currentElement && currentElement.parentNode) {\n\t\tfor (let i = 0; i < openedRegistry.length; i++) {\n\t\t\tif (currentElement === openedRegistry[i].instance) {\n\t\t\t\tparentPopovers.push(currentElement as Popover);\n\t\t\t}\n\t\t}\n\n\t\tcurrentElement = currentElement.parentNode;\n\t}\n\n\treturn parentPopovers;\n};\n\nexport { addOpenedPopover, removeOpenedPopover, getRegistry };\n"]}