UNPKG

primeng

Version:

PrimeNG is a premium UI library for Angular featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock,

242 lines (237 loc) 12 kB
export * from 'primeng/types/blockui'; import { isPlatformBrowser, NgTemplateOutlet } from '@angular/common'; import * as i0 from '@angular/core'; import { Injectable, InjectionToken, inject, input, booleanAttribute, numberAttribute, contentChild, signal, effect, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule } from '@angular/core'; import { blockBodyScroll, unblockBodyScroll } from '@primeuix/utils'; import { SharedModule } from 'primeng/api'; import { BaseComponent, PARENT_INSTANCE } from 'primeng/basecomponent'; import * as i1 from 'primeng/bind'; import { Bind } from 'primeng/bind'; import { ZIndexUtils } from 'primeng/utils'; import { style } from '@primeuix/styles/blockui'; import { BaseStyle } from 'primeng/base'; const classes = { root: ({ instance }) => [ 'p-blockui p-blockui-mask', { 'p-blockui-mask-document': !instance.target() } ] }; class BlockUiStyle extends BaseStyle { name = 'blockui'; style = style; classes = classes; static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: BlockUiStyle, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: BlockUiStyle }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: BlockUiStyle, decorators: [{ type: Injectable }] }); /** * * BlockUI represents people using icons, labels and images. * * [Live Demo](https://www.primeng.org/blockui) * * @module blockuistyle * */ var BlockUIClasses; (function (BlockUIClasses) { /** * Class name of the root element */ BlockUIClasses["root"] = "p-blockui"; })(BlockUIClasses || (BlockUIClasses = {})); const BLOCKUI_INSTANCE = new InjectionToken('BLOCKUI_INSTANCE'); /** * BlockUI can either block other components or the whole page. * @group Components */ class BlockUI extends BaseComponent { componentName = 'BlockUI'; $pcBlockUI = inject(BLOCKUI_INSTANCE, { optional: true, skipSelf: true }) ?? undefined; bindDirectiveInstance = inject(Bind, { self: true }); /** * Name of the local ng-template variable referring to another component. * @group Props */ target = input(/* @ts-ignore */ ...(ngDevMode ? [undefined, { debugName: "target" }] : /* istanbul ignore next */ [])); /** * Whether to automatically manage layering. * @group Props */ autoZIndex = input(true, { ...(ngDevMode ? { debugName: "autoZIndex" } : /* istanbul ignore next */ {}), transform: booleanAttribute }); /** * Base zIndex value to use in layering. * @group Props */ baseZIndex = input(0, { ...(ngDevMode ? { debugName: "baseZIndex" } : /* istanbul ignore next */ {}), transform: numberAttribute }); /** * Current blocked state as a boolean. * @group Props */ blocked = input(false, { ...(ngDevMode ? { debugName: "blocked" } : /* istanbul ignore next */ {}), transform: booleanAttribute }); /** * Template of the content. * @group Templates */ contentTemplate = contentChild('content', { ...(ngDevMode ? { debugName: "contentTemplate" } : /* istanbul ignore next */ {}), descendants: false }); _blocked = signal(false, /* @ts-ignore */ ...(ngDevMode ? [{ debugName: "_blocked" }] : /* istanbul ignore next */ [])); animationEndListener; _componentStyle = inject(BlockUiStyle); constructor() { super(); effect(() => { const blocked = this.blocked(); if (this.el?.nativeElement) { if (blocked) { this.block(); } else if (this._blocked()) { this.unblock(); } } else { this._blocked.set(blocked); } }); } onAfterViewChecked() { this.bindDirectiveInstance.setAttrs(this.ptms(['host', 'root'])); } onAfterViewInit() { if (this._blocked()) this.block(); const target = this.target(); if (target && !target.getBlockableElement) { throw 'Target of BlockUI must implement BlockableUI interface'; } } block() { if (isPlatformBrowser(this.platformId)) { this.unbindAnimationEndListener(); if (!this.$unstyled()) { this.renderer.removeClass(this.el.nativeElement, 'p-overlay-mask-leave-active'); } this._blocked.set(true); this.el.nativeElement.style.display = 'flex'; const target = this.target(); if (target) { target.getBlockableElement().appendChild(this.el.nativeElement); target.getBlockableElement().style.position = 'relative'; } else { this.renderer.appendChild(this.document.body, this.el.nativeElement); //@ts-ignore blockBodyScroll(); } if (this.autoZIndex() && !this.target()) { ZIndexUtils.set('modal', this.el.nativeElement, this.baseZIndex() + this.config.zIndex.modal); } if (!this.$unstyled()) { this.renderer.addClass(this.el.nativeElement, 'p-overlay-mask'); this.renderer.addClass(this.el.nativeElement, 'p-overlay-mask-enter-active'); } } } unblock() { if (isPlatformBrowser(this.platformId) && this.el && this._blocked()) { this._blocked.set(false); if (!this.animationEndListener) { this.animationEndListener = this.renderer.listen(this.el.nativeElement, 'animationend', this.destroyModal.bind(this)); } if (!this.$unstyled()) { this.renderer.removeClass(this.el.nativeElement, 'p-overlay-mask-enter-active'); this.renderer.addClass(this.el.nativeElement, 'p-overlay-mask-leave-active'); } } } destroyModal() { this._blocked.set(false); if (this.el && isPlatformBrowser(this.platformId)) { this.el.nativeElement.style.display = 'none'; if (!this.$unstyled()) { this.renderer.removeClass(this.el.nativeElement, 'p-overlay-mask'); this.renderer.removeClass(this.el.nativeElement, 'p-overlay-mask-leave-active'); } ZIndexUtils.clear(this.el.nativeElement); if (!this.target()) { this.document.body.removeChild(this.el.nativeElement); //@ts-ignore unblockBodyScroll(); } } this.unbindAnimationEndListener(); } unbindAnimationEndListener() { if (this.animationEndListener && this.el) { this.animationEndListener(); this.animationEndListener = null; } } onDestroy() { if (this._blocked()) { // Skip animation on destroy, just cleanup this._blocked.set(false); if (this.el && isPlatformBrowser(this.platformId)) { ZIndexUtils.clear(this.el.nativeElement); if (!this.target()) { //@ts-ignore unblockBodyScroll(); } } this.unbindAnimationEndListener(); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: BlockUI, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: BlockUI, isStandalone: true, selector: "p-blockui, p-block-ui", inputs: { target: { classPropertyName: "target", publicName: "target", isSignal: true, isRequired: false, transformFunction: null }, autoZIndex: { classPropertyName: "autoZIndex", publicName: "autoZIndex", isSignal: true, isRequired: false, transformFunction: null }, baseZIndex: { classPropertyName: "baseZIndex", publicName: "baseZIndex", isSignal: true, isRequired: false, transformFunction: null }, blocked: { classPropertyName: "blocked", publicName: "blocked", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.aria-busy": "_blocked()", "class": "cx('root')" }, styleAttribute: "display: none" }, providers: [BlockUiStyle, { provide: BLOCKUI_INSTANCE, useExisting: BlockUI }, { provide: PARENT_INSTANCE, useExisting: BlockUI }], queries: [{ propertyName: "contentTemplate", first: true, predicate: ["content"], isSignal: true }], usesInheritance: true, hostDirectives: [{ directive: i1.Bind }], ngImport: i0, template: ` <ng-content></ng-content> @if (contentTemplate()) { <ng-container [ngTemplateOutlet]="contentTemplate()"></ng-container> } `, isInline: true, dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "ngmodule", type: SharedModule }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: BlockUI, decorators: [{ type: Component, args: [{ selector: 'p-blockui, p-block-ui', standalone: true, imports: [NgTemplateOutlet, SharedModule], template: ` <ng-content></ng-content> @if (contentTemplate()) { <ng-container [ngTemplateOutlet]="contentTemplate()"></ng-container> } `, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [BlockUiStyle, { provide: BLOCKUI_INSTANCE, useExisting: BlockUI }, { provide: PARENT_INSTANCE, useExisting: BlockUI }], host: { '[attr.aria-busy]': '_blocked()', '[class]': "cx('root')", style: 'display: none' }, hostDirectives: [Bind] }] }], ctorParameters: () => [], propDecorators: { target: [{ type: i0.Input, args: [{ isSignal: true, alias: "target", required: false }] }], autoZIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoZIndex", required: false }] }], baseZIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "baseZIndex", required: false }] }], blocked: [{ type: i0.Input, args: [{ isSignal: true, alias: "blocked", required: false }] }], contentTemplate: [{ type: i0.ContentChild, args: ['content', { ...{ descendants: false }, isSignal: true }] }] } }); class BlockUIModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: BlockUIModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.0.6", ngImport: i0, type: BlockUIModule, imports: [BlockUI, SharedModule], exports: [BlockUI, SharedModule] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: BlockUIModule, imports: [BlockUI, SharedModule, SharedModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: BlockUIModule, decorators: [{ type: NgModule, args: [{ imports: [BlockUI, SharedModule], exports: [BlockUI, SharedModule] }] }] }); /** * Generated bundle index. Do not edit. */ export { BlockUI, BlockUIClasses, BlockUIModule, BlockUiStyle }; //# sourceMappingURL=primeng-blockui.mjs.map