@libs-ui/services-dynamic-component 0.2.158 → 0.2.160

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"libs-ui-services-dynamic-component.mjs","sources":["../../../../../libs-ui/services/dynamic-component/src/dynamic-component.service.ts","../../../../../libs-ui/services/dynamic-component/src/libs-ui-services-dynamic-component.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { ApplicationRef, ComponentRef, EmbeddedViewRef, Injectable, createComponent, inject } from '@angular/core';\nimport { uuid } from '@libs-ui/utils';\n@Injectable({\n providedIn: 'root'\n})\n\nexport class LibsUiDynamicComponentService {\n private elementLayoutContent!: HTMLElement | null;\n private elementBody!: HTMLElement | null;\n private mapStylesToParentDocument: Map<string, Array<Node>> = new Map();\n private appRef = inject(ApplicationRef);\n\n public resolveComponentFactory(component: any): ComponentRef<any> {\n return createComponent(component, { environmentInjector: this.appRef.injector });\n }\n\n public addToBody(componentRef: any, isAddParentDocument?: boolean): string {\n if (!componentRef || !componentRef.hostView) {\n return '';\n }\n\n this.appRef.attachView(componentRef.hostView);\n const domElem = (componentRef.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement;\n\n if (isAddParentDocument) {\n window.parent.document.body.appendChild(domElem);\n\n return this.updateStyleToParentDocument();\n }\n if (!this.elementBody) {\n this.elementBody = document.body;\n }\n this.elementBody.appendChild(domElem);\n\n return '';\n }\n\n public addToElement(componentRef: any, elementAdd: any) {\n if (!componentRef || !componentRef.hostView || !elementAdd) {\n return;\n }\n this.appRef.attachView(componentRef.hostView);\n const domElem = (componentRef.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement;\n\n return elementAdd.appendChild(domElem);\n }\n\n public addToIdAttributeElement(componentRef: any, id: string) {\n if (!this.elementLayoutContent) {\n this.elementLayoutContent = document.getElementById(id);\n }\n if (!componentRef || !componentRef.hostView) {\n return;\n }\n this.appRef.attachView(componentRef.hostView);\n const domElem = (componentRef.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement;\n\n return this.elementLayoutContent?.appendChild(domElem);\n }\n\n public remove(componentRef: any, frameId = '', ignoreDestroyComponent?: boolean) {\n if (!componentRef) {\n return;\n }\n this.removeStyleToParentDocument(frameId);\n if (componentRef.hostView) {\n this.appRef.detachView(componentRef.hostView);\n }\n if (!ignoreDestroyComponent && componentRef.destroy) {\n componentRef.destroy();\n }\n }\n\n private updateStyleToParentDocument(): string {\n const frameId = uuid();\n const documentParent = window.parent.document;\n\n if (documentParent && !this.mapStylesToParentDocument.has(frameId)) {\n const styleTags = new Array<Node>();\n\n Array.from(document.head.querySelectorAll(\"style\")).forEach(styleTag => {\n const cloneStyleTag = styleTag.cloneNode(true);\n\n styleTags.push(cloneStyleTag);\n documentParent?.head.appendChild(cloneStyleTag);\n });\n this.mapStylesToParentDocument.set(frameId, styleTags);\n }\n\n return frameId;\n }\n\n private removeStyleToParentDocument(frameId: string) {\n if (!frameId) {\n return;\n }\n const styleTagsPopup = this.mapStylesToParentDocument.get(frameId);\n const documentParent = window.parent.document;\n\n if (!styleTagsPopup || !styleTagsPopup.length || !documentParent) {\n return;\n }\n styleTagsPopup.forEach(styleTag => {\n documentParent?.head.removeChild(styleTag);\n });\n this.mapStylesToParentDocument.delete(frameId);\n }\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAAA;MAOa,6BAA6B,CAAA;AAChC,IAAA,oBAAoB,CAAsB;AAC1C,IAAA,WAAW,CAAsB;AACjC,IAAA,yBAAyB,GAA6B,IAAI,GAAG,EAAE,CAAC;AAChE,IAAA,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAEjC,IAAA,uBAAuB,CAAC,SAAc,EAAA;AAC3C,QAAA,OAAO,eAAe,CAAC,SAAS,EAAE,EAAE,mBAAmB,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,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;;;"}
1
+ {"version":3,"file":"libs-ui-services-dynamic-component.mjs","sources":["../../../../../libs-ui/services/dynamic-component/src/dynamic-component.service.ts","../../../../../libs-ui/services/dynamic-component/src/libs-ui-services-dynamic-component.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { ApplicationRef, ComponentRef, EmbeddedViewRef, Injectable, createComponent, inject } from '@angular/core';\nimport { uuid } from '@libs-ui/utils';\n@Injectable({\n providedIn: 'root'\n})\n\nexport class LibsUiDynamicComponentService {\n private elementLayoutContent!: HTMLElement | null;\n private elementBody!: HTMLElement | null;\n private mapStylesToParentDocument: Map<string, Array<Node>> = new Map();\n private appRef = inject(ApplicationRef);\n\n public resolveComponentFactory(component: any): ComponentRef<any> {\n return createComponent(component, { environmentInjector: this.appRef.injector });\n }\n\n public addToBody(componentRef: any, isAddParentDocument?: boolean): string {\n if (!componentRef || !componentRef.hostView) {\n return '';\n }\n\n this.appRef.attachView(componentRef.hostView);\n const domElem = (componentRef.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement;\n\n if (isAddParentDocument) {\n window.parent.document.body.appendChild(domElem);\n\n return this.updateStyleToParentDocument();\n }\n if (!this.elementBody) {\n this.elementBody = document.body;\n }\n this.elementBody.appendChild(domElem);\n\n return '';\n }\n\n public addToElement(componentRef: any, elementAdd: any) {\n if (!componentRef || !componentRef.hostView || !elementAdd) {\n return;\n }\n this.appRef.attachView(componentRef.hostView);\n const domElem = (componentRef.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement;\n\n return elementAdd.appendChild(domElem);\n }\n\n public addToIdAttributeElement(componentRef: any, id: string) {\n if (!this.elementLayoutContent) {\n this.elementLayoutContent = document.getElementById(id);\n }\n if (!componentRef || !componentRef.hostView) {\n return;\n }\n this.appRef.attachView(componentRef.hostView);\n const domElem = (componentRef.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement;\n\n return this.elementLayoutContent?.appendChild(domElem);\n }\n\n public remove(componentRef: any, frameId = '', ignoreDestroyComponent?: boolean) {\n if (!componentRef) {\n return;\n }\n this.removeStyleToParentDocument(frameId);\n if (componentRef.hostView) {\n this.appRef.detachView(componentRef.hostView);\n }\n if (!ignoreDestroyComponent && componentRef.destroy) {\n componentRef.destroy();\n }\n }\n\n private updateStyleToParentDocument(): string {\n const frameId = uuid();\n const documentParent = window.parent.document;\n\n if (documentParent && !this.mapStylesToParentDocument.has(frameId)) {\n const styleTags = new Array<Node>();\n\n Array.from(document.head.querySelectorAll(\"style\")).forEach(styleTag => {\n const cloneStyleTag = styleTag.cloneNode(true);\n\n styleTags.push(cloneStyleTag);\n documentParent?.head.appendChild(cloneStyleTag);\n });\n this.mapStylesToParentDocument.set(frameId, styleTags);\n }\n\n return frameId;\n }\n\n private removeStyleToParentDocument(frameId: string) {\n if (!frameId) {\n return;\n }\n const styleTagsPopup = this.mapStylesToParentDocument.get(frameId);\n const documentParent = window.parent.document;\n\n if (!styleTagsPopup || !styleTagsPopup.length || !documentParent) {\n return;\n }\n styleTagsPopup.forEach(styleTag => {\n documentParent?.head.removeChild(styleTag);\n });\n this.mapStylesToParentDocument.delete(frameId);\n }\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAAA;MAOa,6BAA6B,CAAA;AAChC,IAAA,oBAAoB;AACpB,IAAA,WAAW;AACX,IAAA,yBAAyB,GAA6B,IAAI,GAAG,EAAE;AAC/D,IAAA,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC;AAEhC,IAAA,uBAAuB,CAAC,SAAc,EAAA;AAC3C,QAAA,OAAO,eAAe,CAAC,SAAS,EAAE,EAAE,mBAAmB,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;;IAG3E,SAAS,CAAC,YAAiB,EAAE,mBAA6B,EAAA;QAC/D,IAAI,CAAC,YAAY,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE;AAC3C,YAAA,OAAO,EAAE;;QAGX,IAA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AAC;AAClE,QAAA,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ;QAE7C,IAAI,CAAC,cAAc,IAAI,CAAC,cAAc,CAAC,MAAM,IAAI,CAAC,cAAc,EAAE;YAChE;;AAEF,QAAA,cAAc,CAAC,OAAO,CAAC,QAAQ,IAAG;AAChC,YAAA,cAAc,EAAE,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;AAC5C,SAAC,CAAC;AACF,QAAA,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,OAAO,CAAC;;wGAnGrC,6BAA6B,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAA7B,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,6BAA6B,cAH5B,MAAM,EAAA,CAAA;;4FAGP,6BAA6B,EAAA,UAAA,EAAA,CAAA;kBAJzC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;;ACLD;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libs-ui/services-dynamic-component",
3
- "version": "0.2.158",
3
+ "version": "0.2.160",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^18.2.0",
6
6
  "@angular/core": "^18.2.0"