* get components map of all the nodes in this document * @param extraComps - extra components that will be added to the components map, use for custom components
(extraComps?: string[])
| 357 | * @param extraComps - extra components that will be added to the components map, use for custom components |
| 358 | */ |
| 359 | getComponentsMap(extraComps?: string[]) { |
| 360 | const componentsMap: ComponentsMap = [] |
| 361 | // use map to avoid duplicate |
| 362 | const existedMap: Record<string, boolean> = {} |
| 363 | |
| 364 | for (const node of this._nodesMap.values()) { |
| 365 | const { componentName } = node || {} |
| 366 | if (!existedMap[node.materialUsageKey]) { |
| 367 | existedMap[node.materialUsageKey] = true |
| 368 | if (node.componentMeta?.npm?.package) { |
| 369 | componentsMap.push({ |
| 370 | ...node.componentMeta.npm, |
| 371 | componentName, |
| 372 | }) |
| 373 | } else { |
| 374 | componentsMap.push({ |
| 375 | devMode: 'lowCode', |
| 376 | componentName, |
| 377 | }) |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | // combine extra components |
| 383 | if (Array.isArray(extraComps)) { |
| 384 | extraComps.forEach(componentName => { |
| 385 | if (componentName && !existedMap[componentName]) { |
| 386 | const meta = this.getComponentMeta(componentName) |
| 387 | if (meta?.npm?.package) { |
| 388 | componentsMap.push({ |
| 389 | ...meta?.npm, |
| 390 | componentName, |
| 391 | }) |
| 392 | } else { |
| 393 | componentsMap.push({ |
| 394 | devMode: 'lowCode', |
| 395 | componentName, |
| 396 | }) |
| 397 | } |
| 398 | } |
| 399 | }) |
| 400 | } |
| 401 | |
| 402 | return componentsMap |
| 403 | } |
| 404 | |
| 405 | getComponentMeta(componentName: string) { |
| 406 | return this.designer.materials.getComponentMeta(componentName) |
no test coverage detected