All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.delegate.ResizeHandler.js.map Maven / Gradle / Ivy

{"version":3,"file":"ResizeHandler.js","sourceRoot":"","sources":["../../src/delegate/ResizeHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAIxD,IAAI,cAA8B,CAAC;AACnC,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA8C,CAAC;AAE/E,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC9B,IAAI,CAAC,cAAc,EAAE;QACpB,cAAc,GAAG,IAAI,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE;YACpD,MAAM,CAAC,qBAAqB,CAAC,GAAG,EAAE;gBACjC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;oBACvB,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,MAAqB,CAAC,CAAC;oBACpE,yHAAyH;oBACzH,sIAAsI;oBACtI,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAgC,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;gBAC3F,CAAC,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;KACH;IACD,OAAO,cAAc,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAC,OAAoB,EAAE,QAAgC,EAAE,EAAE;IAC1E,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IAEtD,wEAAwE;IACxE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE;QACtB,iBAAiB,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;KACrC;IAED,iCAAiC;IACjC,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,SAAS,EAAE,QAAQ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,gBAAgB,CAAC,SAAS,EAAE,CAAC;SAChD;QAED,IAAI,gBAAgB,YAAY,WAAW,EAAE;YAC5C,SAAS,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;SACtC;aAAM;YACN,OAAO,CAAC,IAAI,CAAC,6CAA6C,EAAE,OAAO,CAAC,CAAC,CAAC,sBAAsB;SAC5F;IACF,CAAC;CACD;AAED,eAAe,aAAa,CAAC","sourcesContent":["import { instanceOfUI5Element } from \"../UI5Element.js\";\n\ntype ResizeObserverCallback = () => Promise | void;\n\nlet resizeObserver: ResizeObserver;\nconst observedElements = new Map>();\n\nconst getResizeObserver = () => {\n\tif (!resizeObserver) {\n\t\tresizeObserver = new window.ResizeObserver(entries => {\n\t\t\twindow.requestAnimationFrame(() => {\n\t\t\t\tentries.forEach(entry => {\n\t\t\t\t\tconst callbacks = observedElements.get(entry.target as HTMLElement);\n\t\t\t\t\t// Callbacks could be async and we need to handle returned promises to comply with the eslint \"no-misused-promises\" rule.\n\t\t\t\t\t// Although Promise.all awaits all, we don't await the additional task after calling the callbacks and should not make any difference.\n\t\t\t\t\tcallbacks && Promise.all(callbacks.map((callback: ResizeObserverCallback) => callback()));\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t}\n\treturn resizeObserver;\n};\n\nconst observe = (element: HTMLElement, callback: ResizeObserverCallback) => {\n\tconst callbacks = observedElements.get(element) || [];\n\n\t// if no callbacks have been added for this element - start observing it\n\tif (!callbacks.length) {\n\t\tgetResizeObserver().observe(element);\n\t}\n\n\t// save the callbacks in an array\n\tobservedElements.set(element, [...callbacks, callback]);\n};\n\nconst unobserve = (element: HTMLElement, callback: ResizeObserverCallback) => {\n\tconst callbacks = observedElements.get(element) || [];\n\tif (callbacks.length === 0) {\n\t\treturn;\n\t}\n\n\tconst filteredCallbacks = callbacks.filter((fn: ResizeObserverCallback) => fn !== callback);\n\tif (filteredCallbacks.length === 0) {\n\t\tgetResizeObserver().unobserve(element);\n\t\tobservedElements.delete(element);\n\t} else {\n\t\tobservedElements.set(element, filteredCallbacks);\n\t}\n};\n\n/**\n * Allows to register/deregister resize observers for a DOM element\n *\n * @public\n * @class\n  */\nclass ResizeHandler {\n\t/**\n\t * @public\n\t * @param element UI5 Web Component or DOM Element to be observed\n\t * @param callback Callback to be executed\n\t */\n\tstatic register(element: HTMLElement, callback: ResizeObserverCallback): void {\n\t\tlet effectiveElement: HTMLElement | undefined = element;\n\n\t\tif (instanceOfUI5Element(effectiveElement)) {\n\t\t\teffectiveElement = effectiveElement.getDomRef();\n\t\t}\n\n\t\tif (effectiveElement instanceof HTMLElement) {\n\t\t\tobserve(effectiveElement, callback);\n\t\t} else {\n\t\t\tconsole.warn(\"Cannot register ResizeHandler for element\", element); // eslint-disable-line\n\t\t}\n\t}\n\n\t/**\n\t * @public\n\t * @param element UI5 Web Component or DOM Element to be unobserved\n\t * @param callback Callback to be removed\n\t */\n\tstatic deregister(element: HTMLElement, callback: ResizeObserverCallback): void {\n\t\tlet effectiveElement: HTMLElement | undefined = element;\n\n\t\tif (instanceOfUI5Element(effectiveElement)) {\n\t\t\teffectiveElement = effectiveElement.getDomRef();\n\t\t}\n\n\t\tif (effectiveElement instanceof HTMLElement) {\n\t\t\tunobserve(effectiveElement, callback);\n\t\t} else {\n\t\t\tconsole.warn(\"Cannot deregister ResizeHandler for element\", element); // eslint-disable-line\n\t\t}\n\t}\n}\n\nexport default ResizeHandler;\nexport type {\n\tResizeObserverCallback,\n};\n"]}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy