@veloceapps/sdk 5.0.9 → 5.0.10

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.
@@ -1083,16 +1083,10 @@ class ElementsResolver {
1083
1083
  this.uiDef = uiDef;
1084
1084
  this.renderableElements = [];
1085
1085
  this.sharedElements = [];
1086
- this.elements = this.transpileScripts(elements);
1087
- const flatElements = this.flattenElements(this.elements);
1088
- for (const el of flatElements) {
1089
- if (this.isSharedElement(el)) {
1090
- this.sharedElements.push(el);
1091
- }
1092
- else {
1093
- this.renderableElements.push(el);
1094
- }
1095
- }
1086
+ const transpiledElements = this.transpileScripts(elements);
1087
+ this.sharedElements = this.flattenElements(transpiledElements).filter(el => this.isSharedElement(el));
1088
+ this.elements = transpiledElements.map(el => this.processElementMetadata(el)).filter(Boolean);
1089
+ this.renderableElements = this.getRenderableElements(this.elements);
1096
1090
  }
1097
1091
  getNgComponents() {
1098
1092
  return this.renderableElements.map(el => this.resolveElement(el)).filter(Boolean);
@@ -1118,8 +1112,19 @@ class ElementsResolver {
1118
1112
  isSharedElement(el) {
1119
1113
  return Boolean(el.isShared) && el.type !== 'REFERENCE';
1120
1114
  }
1115
+ getRenderableElements(elements) {
1116
+ const renderable = [];
1117
+ for (const el of elements) {
1118
+ if (!this.isSharedElement(el)) {
1119
+ const children = el.children.filter(child => !this.isSharedElement(child));
1120
+ const renderableChildren = this.getRenderableElements(children);
1121
+ renderable.push(Object.assign(Object.assign({}, el), { children }), ...renderableChildren);
1122
+ }
1123
+ }
1124
+ return renderable;
1125
+ }
1121
1126
  getSharedElement(element) {
1122
- if (element.type !== 'REFERENCE') {
1127
+ if (!element.reference) {
1123
1128
  return;
1124
1129
  }
1125
1130
  return this.sharedElements.find(el => element.reference === el.name);
@@ -1136,28 +1141,37 @@ class ElementsResolver {
1136
1141
  }
1137
1142
  processElementMetadata(sourceElement) {
1138
1143
  var _a, _b;
1139
- const sharedElement = this.getSharedElement(sourceElement);
1140
1144
  let finalElement;
1141
1145
  if (sourceElement.type === 'REFERENCE') {
1146
+ const sharedElement = this.getSharedElement(sourceElement);
1142
1147
  if (!sharedElement) {
1143
1148
  console.warn(`Shared element "${sourceElement.reference}" not found`);
1144
1149
  return;
1145
1150
  }
1146
- finalElement = Object.assign(Object.assign({}, sourceElement), { type: sharedElement.type, template: sharedElement.template, styles: ((_a = sharedElement.styles) !== null && _a !== void 0 ? _a : '') + '\n' + ((_b = sourceElement.styles) !== null && _b !== void 0 ? _b : ''), inputs: Object.assign(Object.assign({}, sharedElement.inputs), sourceElement.inputs), outputs: Object.assign(Object.assign({}, sharedElement.outputs), sourceElement.outputs) });
1151
+ finalElement = Object.assign(Object.assign({}, sourceElement), { children: this.getSharedChildren(sharedElement.children, sourceElement.path), type: sharedElement.type, template: sharedElement.template, styles: ((_a = sharedElement.styles) !== null && _a !== void 0 ? _a : '') + '\n' + ((_b = sourceElement.styles) !== null && _b !== void 0 ? _b : ''), inputs: Object.assign(Object.assign({}, sharedElement.inputs), sourceElement.inputs), outputs: Object.assign(Object.assign({}, sharedElement.outputs), sourceElement.outputs) });
1147
1152
  }
1148
1153
  else {
1149
1154
  finalElement = sourceElement;
1155
+ delete sourceElement.reference;
1150
1156
  }
1151
1157
  finalElement.template = this.resolveElementTemplate(finalElement);
1152
1158
  finalElement.styles = this.resolveElementStyles(finalElement);
1153
- return finalElement;
1159
+ return Object.assign(Object.assign({}, finalElement), { children: finalElement.children
1160
+ .map(child => this.processElementMetadata(child))
1161
+ .filter(Boolean) });
1162
+ }
1163
+ getSharedChildren(children, parentPath) {
1164
+ return children.map(c => {
1165
+ if (!c.path) {
1166
+ return c;
1167
+ }
1168
+ const [elName] = c.path.split('/').reverse();
1169
+ const path = parentPath + '/' + elName;
1170
+ return Object.assign(Object.assign({}, c), { path, children: this.getSharedChildren(c.children, path) });
1171
+ });
1154
1172
  }
1155
- resolveElement(sourceElement) {
1173
+ resolveElement(element) {
1156
1174
  var _a;
1157
- const element = this.processElementMetadata(sourceElement);
1158
- if (!element) {
1159
- return;
1160
- }
1161
1175
  const config = CONFIG[element.type];
1162
1176
  const defaultPlugins = (_a = DEFAULT_PLUGINS[this.uiDef.type]) !== null && _a !== void 0 ? _a : [];
1163
1177
  if (!config) {
@@ -1173,7 +1187,7 @@ class ElementsResolver {
1173
1187
  { provide: DEFAULT_PLUGINS_TOKEN, useValue: defaultPlugins },
1174
1188
  { provide: UI_DEFINITION_METADATA, useValue: this.uiDef },
1175
1189
  { provide: ELEMENT_METADATA, useValue: element },
1176
- { provide: SHARED_ELEMENT_METADATA, useValue: this.getSharedElement(sourceElement) },
1190
+ { provide: SHARED_ELEMENT_METADATA, useValue: this.getSharedElement(element) },
1177
1191
  { provide: ELEMENT_CONFIG, useValue: config },
1178
1192
  { provide: VENDOR_MAP, useValue: vendorMap },
1179
1193
  ] });
@@ -1201,12 +1215,14 @@ class LauncherService {
1201
1215
  this.compiler = compiler;
1202
1216
  this.dynamicModuleService = dynamicModuleService;
1203
1217
  }
1204
- compileModule(elements, uiDefs) {
1205
- this.module = this.getModule(elements, uiDefs);
1218
+ compileModule(uiDef, elements) {
1219
+ const elementsResolver = new ElementsResolver(uiDef, elements);
1220
+ this.dynamicModuleService.elementsTree = elementsResolver.elements;
1221
+ this.module = this.getModule(elementsResolver.getNgComponents());
1206
1222
  return from(this.compiler.compileModuleAndAllComponentsAsync(this.module)).pipe(tap(m => {
1207
1223
  this.dynamicModuleService.componentFactories = m.componentFactories;
1208
1224
  this.moduleInstance = m;
1209
- }));
1225
+ }), map(m => ({ module: m, elements: elementsResolver.elements })));
1210
1226
  }
1211
1227
  destroy() {
1212
1228
  if (this.moduleInstance) {
@@ -1218,16 +1234,14 @@ class LauncherService {
1218
1234
  this.module = undefined;
1219
1235
  }
1220
1236
  }
1221
- getModule(elements, uiDef) {
1237
+ getModule(components) {
1222
1238
  const staticComponents = [ElementChildrenComponent, ElementRendererComponent, CustomTemplateDirective];
1223
- const elementsResolver = new ElementsResolver(uiDef, elements);
1224
- this.dynamicModuleService.elementsTree = elementsResolver.elements;
1225
1239
  let DynamicModule = class DynamicModule {
1226
1240
  };
1227
1241
  DynamicModule = __decorate([
1228
1242
  NgModule({
1229
1243
  imports: [CommonModule, FormsModule, ReactiveFormsModule, FederatedModule, DragDropModule],
1230
- declarations: [...staticComponents, ...elementsResolver.getNgComponents()],
1244
+ declarations: [...staticComponents, ...components],
1231
1245
  jit: true,
1232
1246
  })
1233
1247
  ], DynamicModule);
@@ -1295,10 +1309,13 @@ class PreviewComponent {
1295
1309
  return;
1296
1310
  }
1297
1311
  const _a = this.uiDefinition, { children } = _a, uiDefinitionMeta = __rest(_a, ["children"]);
1298
- this.elements = this.elementToMetadataSafe(children);
1299
- const compilation$ = this.launcherService.compileModule(this.elements, uiDefinitionMeta);
1312
+ const elements = this.elementToMetadataSafe(children);
1313
+ const compilation$ = this.launcherService.compileModule(uiDefinitionMeta, elements);
1300
1314
  forkJoin([compilation$, this.initializeConfiguration$()])
1301
- .pipe(tap(() => this.state$.next({ loading: false, failure: false })), catchError(error => {
1315
+ .pipe(tap(([result]) => {
1316
+ this.elements = result.elements;
1317
+ this.state$.next({ loading: false, failure: false });
1318
+ }), catchError(error => {
1302
1319
  var _a, _b;
1303
1320
  console.error(error);
1304
1321
  if (!((_b = (_a = this.uiDefinition) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.suppressToastMessages)) {