@veloceapps/sdk 10.0.0-6 → 10.0.0-7

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.
@@ -602,6 +602,18 @@ const findElementByModule = (elements, module, elementName) => {
602
602
  }
603
603
  return;
604
604
  };
605
+ const findElement = (source, comparatorFn) => {
606
+ for (const el of source) {
607
+ if (comparatorFn(el)) {
608
+ return el;
609
+ }
610
+ const found = findElement(el.children, comparatorFn);
611
+ if (found) {
612
+ return found;
613
+ }
614
+ }
615
+ return;
616
+ };
605
617
 
606
618
  const CMS_COMPILATION_SERVICE = new InjectionToken('VENDOR_MAP');
607
619
 
@@ -610,6 +622,7 @@ class RuntimeService {
610
622
  this.injector = injector;
611
623
  this.integrationState = integrationState;
612
624
  this.moduleRefs = [];
625
+ this.componentRefs = {};
613
626
  this.componentTypes = {};
614
627
  this.applicationTree = [];
615
628
  this.isInitialized$ = new BehaviorSubject(false);
@@ -686,6 +699,7 @@ class RuntimeService {
686
699
  this.compilationService.clear();
687
700
  this.moduleRefs.forEach(m => m.destroy());
688
701
  this.moduleRefs = [];
702
+ this.componentRefs = {};
689
703
  this.applicationTree = [];
690
704
  this.componentTypes = {};
691
705
  this.isInitialized$.next(false);
@@ -963,6 +977,7 @@ class ElementRendererComponent {
963
977
  return;
964
978
  }
965
979
  const componentRef = this.el?.createComponent(this.type, { index });
980
+ this.runtimeService.componentRefs[this.meta.path] = componentRef;
966
981
  if (componentRef) {
967
982
  componentRef.location.nativeElement.setAttribute('name', this.meta.name);
968
983
  componentRef.location.nativeElement.setAttribute('path', this.meta.path);
@@ -1609,6 +1624,29 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1609
1624
  args: [{ providedIn: 'root' }]
1610
1625
  }] });
1611
1626
 
1627
+ const cmsInject = (token) => {
1628
+ const self = inject(ELEMENT_METADATA);
1629
+ const runtimeService = inject(RuntimeService);
1630
+ const el = findElement(runtimeService.applicationTree, el => el.name === token);
1631
+ if (!el) {
1632
+ throw getError(token, self, 'element not found');
1633
+ }
1634
+ if (el.type !== 'SERVICE') {
1635
+ throw getError(token, self, 'only SERVICE elements can be injected');
1636
+ }
1637
+ if (el.model) {
1638
+ throw getError(token, self, 'injecting a service with a "model" defined is not supported yet');
1639
+ }
1640
+ const componentRef = runtimeService.componentRefs[el.path];
1641
+ if (!componentRef) {
1642
+ throw getError(token, self, 'no instance created yet.');
1643
+ }
1644
+ return componentRef.instance;
1645
+ };
1646
+ function getError(token, self, reason) {
1647
+ return new Error(`Injecting "${token}" in "/${self.path}": ${reason}`);
1648
+ }
1649
+
1612
1650
  const VELOCE_LIBS = {
1613
1651
  '@veloceapps/core': {
1614
1652
  isDefined,
@@ -1660,6 +1698,7 @@ const VELOCE_LIBS = {
1660
1698
  TemplatesService,
1661
1699
  IntegrationState,
1662
1700
  ResourcesService,
1701
+ cmsInject,
1663
1702
  },
1664
1703
  };
1665
1704
  const VELOCE_LIBS_BACKWARDS_COMPATIBLE = Object.entries(VELOCE_LIBS).reduce((trunk, [key, value]) => ({ ...trunk, [key.replace('@veloceapps/', '@veloce/')]: value }), {});
@@ -2772,5 +2811,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
2772
2811
  * Generated bundle index. Do not edit.
2773
2812
  */
2774
2813
 
2775
- export { ApplyProductConfigurationAction, CloseDocGenAction, CmsAction, ConfigureProductAction, DEFAULT_ELEMENT, DEFAULT_PLUGINS_TOKEN, ELEMENT_CONFIG, ELEMENT_METADATA, ElementComponent, ElementDefinition, ElementMetadataWorker, ElementsResolver, FlowAction, LAYOUT, LauncherModule, MigrationsModule, MigrationsService, NavigateBackAction, NavigateToCatalogAction, OpenDocGenAction, PreviewComponent, PreviewModule, RemoteApplyAction, RemoteCancelAction, ResourcesService, RuntimeEditorService, RuntimeModule, RuntimeService, SHARED_ELEMENT_METADATA, STARTING_PAGE_LAYOUT, STARTING_PAGE_NAME, STARTING_PAGE_STYLES, STARTING_PAGE_TYPE, SwitchObjectAction, TemplatesService, TranspilationWorker, UI_DEFINITION_METADATA, UiBuildError, atobSafe, btoaSafe, constructPage, constructPageChildren, constructRegion, doesElementSupportIO, elementToMetadata, extendElementMetadata, extractElementMetadata, findElementByModule, findElementByPath, flattenElements, getAbsolutePath, getElementAngularIOs, getElementConfig, insertElement, isElementAngularIO, isSharedElement, isValidScript, metadataToElement, normalizeElementMetadata, parseBoundPath, parsePath, removeElement, stringifyElementMetadata, toElementAngularIO };
2814
+ export { ApplyProductConfigurationAction, CloseDocGenAction, CmsAction, ConfigureProductAction, DEFAULT_ELEMENT, DEFAULT_PLUGINS_TOKEN, ELEMENT_CONFIG, ELEMENT_METADATA, ElementComponent, ElementDefinition, ElementMetadataWorker, ElementsResolver, FlowAction, LAYOUT, LauncherModule, MigrationsModule, MigrationsService, NavigateBackAction, NavigateToCatalogAction, OpenDocGenAction, PreviewComponent, PreviewModule, RemoteApplyAction, RemoteCancelAction, ResourcesService, RuntimeEditorService, RuntimeModule, RuntimeService, SHARED_ELEMENT_METADATA, STARTING_PAGE_LAYOUT, STARTING_PAGE_NAME, STARTING_PAGE_STYLES, STARTING_PAGE_TYPE, SwitchObjectAction, TemplatesService, TranspilationWorker, UI_DEFINITION_METADATA, UiBuildError, atobSafe, btoaSafe, cmsInject, constructPage, constructPageChildren, constructRegion, doesElementSupportIO, elementToMetadata, extendElementMetadata, extractElementMetadata, findElement, findElementByModule, findElementByPath, flattenElements, getAbsolutePath, getElementAngularIOs, getElementConfig, insertElement, isElementAngularIO, isSharedElement, isValidScript, metadataToElement, normalizeElementMetadata, parseBoundPath, parsePath, removeElement, stringifyElementMetadata, toElementAngularIO };
2776
2815
  //# sourceMappingURL=veloceapps-sdk-cms.mjs.map