core
zard/coreFreeComponent
@zard publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by @zard on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.zardui.com/r/core.jsonSource
1import {2 Directive,3 type EmbeddedViewRef,4 inject,5 input,6 type OnDestroy,7 TemplateRef,8 ViewContainerRef,9 effect,10 type EffectRef,11} from '@angular/core';1213export function isTemplateRef<C = unknown>(value: unknown): value is TemplateRef<C> {14 return value instanceof TemplateRef;15}1617export interface ZardStringTemplateOutletContext {18 $implicit: unknown;19 [key: string]: unknown;20}2122@Directive({23 selector: '[zStringTemplateOutlet]',24 exportAs: 'zStringTemplateOutlet',25})26export class ZardStringTemplateOutletDirective<T = unknown> implements OnDestroy {27 private readonly viewContainer = inject(ViewContainerRef);28 private readonly templateRef = inject(TemplateRef<void>);2930 private embeddedViewRef: EmbeddedViewRef<ZardStringTemplateOutletContext> | null = null;31 private readonly context = {} as ZardStringTemplateOutletContext;3233 #isFirstChange = true;34 #lastOutletWasTemplate = false;35 #lastTemplateRef: TemplateRef<void> | null = null;36 #lastContext?: ZardStringTemplateOutletContext;3738 readonly zStringTemplateOutletContext = input<ZardStringTemplateOutletContext | undefined>(undefined);39 readonly zStringTemplateOutlet = input.required<T | TemplateRef<void>>();4041 #hasContextShapeChanged(context: ZardStringTemplateOutletContext | undefined): boolean {42 if (!context) {43 return false;44 }45 const prevCtxKeys = Object.keys(this.#lastContext || {});46 const currCtxKeys = Object.keys(context || {});4748 if (prevCtxKeys.length === currCtxKeys.length) {49 for (const propName of currCtxKeys) {50 if (!prevCtxKeys.includes(propName)) {51 return true;52 }53 }54 return false;55 } else {56 return true;57 }58 }5960 #shouldViewBeRecreated(61 stringTemplateOutlet: TemplateRef<void> | T,62 stringTemplateOutletContext: ZardStringTemplateOutletContext | undefined,63 ): boolean {64 const isTemplate = isTemplateRef(stringTemplateOutlet);6566 const shouldOutletRecreate =67 this.#isFirstChange ||68 isTemplate !== this.#lastOutletWasTemplate ||69 (isTemplate && stringTemplateOutlet !== this.#lastTemplateRef);7071 const shouldContextRecreate = this.#hasContextShapeChanged(stringTemplateOutletContext);72 return shouldContextRecreate || shouldOutletRecreate;73 }7475 #updateTrackingState(76 stringTemplateOutlet: TemplateRef<void> | T,77 stringTemplateOutletContext: ZardStringTemplateOutletContext | undefined,78 ): void {79 const isTemplate = isTemplateRef(stringTemplateOutlet);80// … truncated
Files it writes
More from @zard
All 49 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | @zard | Components | Free | no deps · 5 files | |
| alertalert | @zard | Components | Free | no deps · 3 files | |
| alert-dialogalert-dialog | @zard | Components | Free | no deps · 5 files | |
| avataravatar | @zard | Components | Free | no deps · 4 files | |
| badgebadge | @zard | Components | Free | no deps · 3 files | |
| breadcrumbbreadcrumb | @zard | Components | Free | no deps · 4 files | |
| buttonbutton | @zard | Components | Free | no deps · 3 files | |
| button-groupbutton-group | @zard | Components | Free | no deps · 3 files |
