{"version":3,"file":"sdcorejs-angular-components-org-chart.mjs","sources":["../../../projects/sdcorejs-angular/components/org-chart/src/org-chart-item-def.directive.ts","../../../projects/sdcorejs-angular/components/org-chart/src/org-chart.component.ts","../../../projects/sdcorejs-angular/components/org-chart/src/org-chart.component.html","../../../projects/sdcorejs-angular/components/org-chart/sdcorejs-angular-components-org-chart.ts"],"sourcesContent":["import { Directive, TemplateRef, inject } from '@angular/core';\nimport { SdOrgChartItem, SdOrgChartItemContext } from './org-chart.model';\n\n@Directive({\n  selector: '[sdOrgChartItemDef]',\n})\nexport class SdOrgChartItemDefDirective<T extends SdOrgChartItem = SdOrgChartItem> {\n  static ngTemplateContextGuard<T extends SdOrgChartItem>(\n    _dir: SdOrgChartItemDefDirective<T>,\n    _ctx: unknown\n  ): _ctx is SdOrgChartItemContext<T> {\n    return true;\n  }\n\n  readonly templateRef: TemplateRef<SdOrgChartItemContext<T>> = inject(TemplateRef);\n}\n","import { CommonModule } from '@angular/common';\nimport { ChangeDetectionStrategy, Component, TemplateRef, booleanAttribute, computed, contentChild, input, signal } from '@angular/core';\nimport { SdOrgChartItemDefDirective } from './org-chart-item-def.directive';\nimport { SdOrgChartItem, SdOrgChartItemContext, SdOrgChartOption } from './org-chart.model';\nimport { SdIcon } from '@sdcorejs/angular/modules/icon';\n\n@Component({\n  selector: 'sd-org-chart',\n  standalone: true,\n  imports: [SdIcon, CommonModule],\n  templateUrl: './org-chart.component.html',\n  styleUrl: './org-chart.component.scss',\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  host: {\n    '[attr.data-autoid]': 'autoId()',\n  },\n})\nexport class SdOrgChart {\n  readonly autoIdInput = input<string | undefined | null>(undefined, { alias: 'autoId' });\n  readonly option = input<SdOrgChartOption | undefined>(undefined);\n  readonly autoId = computed(() => {\n    const scope = this.option()?.autoId ?? this.autoIdInput();\n    return scope ? `components-org-chart-${scope}` : undefined;\n  });\n\n  readonly items = input<SdOrgChartItem[] | undefined>(undefined);\n  readonly itemTemplate = input<TemplateRef<SdOrgChartItemContext> | undefined | null>(undefined);\n  readonly collapsible = input(true, { transform: booleanAttribute });\n\n  readonly itemDef = contentChild(SdOrgChartItemDefDirective);\n  readonly resolvedItems = computed(() => this.option()?.items ?? this.items() ?? []);\n  readonly resolvedCollapsible = computed(() => this.option()?.collapsible ?? this.collapsible());\n\n  readonly resolvedItemTemplate = computed<TemplateRef<SdOrgChartItemContext> | undefined>(() => {\n    return this.itemDef()?.templateRef || this.option()?.itemTemplate || this.itemTemplate() || undefined;\n  });\n\n  readonly #expandedState = signal<Record<string, boolean>>({});\n\n  readonly trackByItem = (_index: number, item: SdOrgChartItem) => item.id;\n\n  hasChildren = (item: SdOrgChartItem): boolean => {\n    return this.childrenOf(item).length > 0;\n  };\n\n  childrenOf = (item: SdOrgChartItem): SdOrgChartItem[] => {\n    return item.children || [];\n  };\n\n  isExpanded = (item: SdOrgChartItem): boolean => {\n    if (!this.resolvedCollapsible()) {\n      return true;\n    }\n\n    const key = this.#itemKey(item);\n    const state = this.#expandedState();\n    return state[key] ?? item.expanded ?? true;\n  };\n\n  toggle = (item: SdOrgChartItem, event?: Event): void => {\n    event?.stopPropagation();\n\n    if (!this.resolvedCollapsible() || !this.hasChildren(item)) {\n      return;\n    }\n\n    const key = this.#itemKey(item);\n    const expanded = !(this.#expandedState()[key] ?? item.expanded ?? true);\n    this.#expandedState.update(state => ({\n      ...state,\n      [key]: expanded,\n    }));\n    this.option()?.onToggle?.({ item, expanded });\n  };\n\n  createContext = (item: SdOrgChartItem, depth: number, parent: SdOrgChartItem | null): SdOrgChartItemContext => {\n    const hasChildren = this.hasChildren(item);\n    const expanded = this.isExpanded(item);\n\n    return {\n      $implicit: item,\n      item,\n      depth,\n      parent,\n      expanded,\n      hasChildren,\n      isLeaf: !hasChildren,\n      toggle: () => this.toggle(item),\n    };\n  };\n\n  nodeAutoId = (item: SdOrgChartItem, part: 'node' | 'image' | 'title' | 'description' | 'toggle'): string | undefined => {\n    const base = this.autoId();\n    if (!base) {\n      return undefined;\n    }\n\n    return `${base}-${part}-${this.#autoIdKey(item)}`;\n  };\n\n  #itemKey = (item: SdOrgChartItem): string => {\n    return String(item.id);\n  };\n\n  #autoIdKey = (item: SdOrgChartItem): string => {\n    return this.#itemKey(item).replace(/[^a-zA-Z0-9_-]/g, '-');\n  };\n}\n","@let _resolvedItems = resolvedItems();\n@let _resolvedItemTemplate = resolvedItemTemplate();\n\n<div class=\"sd-org-chart\" role=\"tree\">\n  <ul class=\"sd-org-chart__tree\">\n    @for (item of _resolvedItems; track trackByItem($index, item)) {\n      <ng-container\n        *ngTemplateOutlet=\"nodeTemplate; context: { $implicit: item, item: item, depth: 0, parent: null, templateRef: _resolvedItemTemplate }\" />\n    }\n  </ul>\n</div>\n\n<ng-template #nodeTemplate let-item let-depth=\"depth\" let-parent=\"parent\" let-templateRef=\"templateRef\">\n  @let _children = childrenOf(item);\n  @let _hasChildren = _children.length > 0;\n  @let _expanded = isExpanded(item);\n  @let _context = createContext(item, depth, parent);\n\n  <li\n    class=\"sd-org-chart__node\"\n    [class.sd-org-chart__node--expanded]=\"_hasChildren && _expanded\"\n    [class.sd-org-chart__node--collapsed]=\"_hasChildren && !_expanded\"\n    role=\"treeitem\"\n    [attr.aria-expanded]=\"_hasChildren ? _expanded : null\">\n    <div class=\"sd-org-chart__node-shell\">\n      <div\n        class=\"sd-org-chart__card\"\n        [class.sd-org-chart__card--no-image]=\"!item.image\"\n        [class.sd-org-chart__card--compact]=\"!item.image && !item.description\"\n        [attr.data-node-id]=\"item.id\"\n        [attr.data-autoid]=\"nodeAutoId(item, 'node')\"\n        [attr.data-depth]=\"depth\"\n        [style.--sd-org-node-color]=\"item.color || null\">\n        @if (templateRef) {\n          <ng-container *ngTemplateOutlet=\"templateRef; context: _context\" />\n        } @else {\n          @if (item.image) {\n            <img class=\"sd-org-chart__image\" [src]=\"item.image\" [alt]=\"item.title\" [attr.data-autoid]=\"nodeAutoId(item, 'image')\" />\n          }\n          <div class=\"sd-org-chart__title\" [attr.data-autoid]=\"nodeAutoId(item, 'title')\">{{ item.title }}</div>\n          @if (item.description) {\n            <div class=\"sd-org-chart__description\" [attr.data-autoid]=\"nodeAutoId(item, 'description')\">{{ item.description }}</div>\n          }\n        }\n      </div>\n\n      @if (_hasChildren && collapsible()) {\n        <button\n          type=\"button\"\n          class=\"sd-org-chart__toggle\"\n          [attr.aria-label]=\"_expanded ? 'Collapse children' : 'Expand children'\"\n          [attr.aria-expanded]=\"_expanded\"\n          [attr.data-autoid]=\"nodeAutoId(item, 'toggle')\"\n          (click)=\"toggle(item, $event)\">\n          <sd-icon [name]=\"_expanded ? 'expand_more' : 'chevron_right'\"></sd-icon>\n        </button>\n      }\n    </div>\n\n    @if (_hasChildren && _expanded) {\n      <ul class=\"sd-org-chart__children\" role=\"group\">\n        @for (child of _children; track trackByItem($index, child)) {\n          <ng-container\n            *ngTemplateOutlet=\"\n              nodeTemplate;\n              context: { $implicit: child, item: child, depth: depth + 1, parent: item, templateRef: templateRef }\n            \" />\n        }\n      </ul>\n    }\n  </li>\n</ng-template>\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;MAMa,0BAA0B,CAAA;AACrC,IAAA,OAAO,sBAAsB,CAC3B,IAAmC,EACnC,IAAa,EAAA;AAEb,QAAA,OAAO,IAAI;IACb;AAES,IAAA,WAAW,GAA0C,MAAM,CAAC,WAAW,CAAC;wGARtE,0BAA0B,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;4FAA1B,0BAA0B,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,qBAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA;;4FAA1B,0BAA0B,EAAA,UAAA,EAAA,CAAA;kBAHtC,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACT,oBAAA,QAAQ,EAAE,qBAAqB;AAChC,iBAAA;;;MCYY,UA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