@praxisui/crud
Version:
CRUD building blocks for Praxis UI: integrates dynamic forms and tables with unified configuration and services.
228 lines (216 loc) • 9.63 kB
TypeScript
import * as i0 from '@angular/core';
import { NgZone, OnChanges, EventEmitter, SimpleChanges, OnInit, Provider, InjectionToken } from '@angular/core';
import { MatDialogConfig, MatDialogRef, MatDialog } from '@angular/material/dialog';
export { MAT_DIALOG_DATA as DIALOG_DATA } from '@angular/material/dialog';
import { ComponentType } from '@angular/cdk/portal';
import { ApiEndpoint, TableConfig, FormConfig, BackConfig, RowAction, ToolbarAction, GenericCrudService, ConfigStorage, ComponentDocMeta } from '@praxisui/core';
export { BackConfig } from '@praxisui/core';
import { PraxisDynamicForm } from '@praxisui/dynamic-form';
type DialogRef<T = any, R = any> = MatDialogRef<T, R>;
interface DialogConfig<D = any> extends MatDialogConfig<D> {
/** Disable closing when user clicks on backdrop */
disableCloseOnBackdrop?: boolean;
/** Disable closing when user presses escape */
disableCloseOnEsc?: boolean;
/** Enable maximize button */
canMaximize?: boolean;
/** Start dialog maximized */
startMaximized?: boolean;
/** Screen width in px where dialog starts fullscreen */
fullscreenBreakpoint?: number;
}
declare class DialogService {
private matDialog;
private zone;
constructor(matDialog: MatDialog, zone: NgZone);
open<T, D = unknown, R = unknown>(component: ComponentType<T>, config?: DialogConfig<D>): DialogRef<T, R>;
openAsync<T, D = unknown, R = unknown>(loader: () => Promise<ComponentType<T>>, config?: DialogConfig<D>): Promise<DialogRef<T, R>>;
static ɵfac: i0.ɵɵFactoryDeclaration<DialogService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<DialogService>;
}
type FormOpenMode = 'route' | 'modal' | 'drawer';
interface CrudParamMapping {
from: string;
to: 'routeParam' | 'query' | 'input';
name: string;
}
type CrudAction = (RowAction | ToolbarAction) & {
openMode?: FormOpenMode;
route?: string;
formId?: string;
params?: CrudParamMapping[];
back?: BackConfig;
};
interface CrudDefaults {
openMode?: FormOpenMode;
modal?: DialogConfig;
back?: BackConfig;
header?: CrudHeaderConfig;
}
interface CrudResource {
path: string;
idField?: string | number;
endpointKey?: ApiEndpoint;
}
interface CrudMetadata {
component: 'praxis-crud';
resource?: CrudResource;
table: TableConfig;
form?: FormConfig;
defaults?: CrudDefaults;
actions?: CrudAction[];
i18n?: {
crudDialog?: Record<string, string>;
};
}
interface CrudHeaderConfig {
showBack?: boolean;
backLabel?: string;
variant?: 'ghost' | 'tonal' | 'outlined';
sticky?: boolean;
breadcrumbs?: boolean;
divider?: boolean;
}
declare function assertCrudMetadata(meta: CrudMetadata): void;
declare class PraxisCrudComponent implements OnChanges {
/** Habilita visual de debug para alinhamento/layouot */
debugLayout: boolean;
/** JSON inline ou chave/URL resolvida pelo MetadataResolver */
metadata: CrudMetadata | string;
context?: Record<string, unknown>;
/** Encaminha o modo de edição de layout para a tabela interna */
editModeEnabled: boolean;
/** CTA: usado pelo Builder para abrir configuração de metadados quando vazio */
configureRequested: EventEmitter<void>;
afterOpen: EventEmitter<{
mode: FormOpenMode;
action: string;
}>;
afterClose: EventEmitter<void>;
afterSave: EventEmitter<{
id: string | number;
data: unknown;
}>;
afterDelete: EventEmitter<{
id: string | number;
}>;
error: EventEmitter<unknown>;
resolvedMetadata: CrudMetadata;
/** Configuração efetiva da tabela com melhorias automáticas (ex.: botão Adicionar). */
effectiveTableConfig?: TableConfig;
/** Config passado ao PraxisTable — sempre definido (fallback seguro). */
tableConfigForBinding: TableConfig;
private readonly launcher;
private table;
private readonly storage;
private readonly snack;
private readonly global;
/**
* Stable CRUD context passed to PraxisTable.
* Previously this was created via a getter, producing a new object each CD tick
* and causing excessive re-renders. Now we compute it only when metadata changes.
*/
tableCrudContext?: {
tableId: string;
resourcePath?: string;
defaults?: any;
actions?: Array<{
action: string;
label?: string;
formId?: string;
route?: string;
openMode?: 'modal' | 'route';
}>;
};
onResetPreferences(): void;
ngOnChanges(changes: SimpleChanges): void;
onAction(action: string, row?: Record<string, unknown>): Promise<void>;
private refreshTable;
private getIdField;
onConfigureRequested(): void;
/**
* Constrói uma configuração de tabela efetiva a partir dos metadados,
* adicionando automaticamente a ação de "Adicionar" na toolbar quando aplicável.
* - Evita duplicidade se a toolbar já tiver ação equivalente.
* - Garante visibilidade da toolbar quando a ação é injetada.
*/
private buildEffectiveTableConfig;
/** Heurística leve para identificar ações do tipo "adicionar/criar" */
private isAddLike;
/** Builds a stable CRUD context object for PraxisTable based on metadata. */
private buildTableCrudContext;
static ɵfac: i0.ɵɵFactoryDeclaration<PraxisCrudComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<PraxisCrudComponent, "praxis-crud", never, { "debugLayout": { "alias": "debugLayout"; "required": false; }; "metadata": { "alias": "metadata"; "required": true; }; "context": { "alias": "context"; "required": false; }; "editModeEnabled": { "alias": "editModeEnabled"; "required": false; }; }, { "configureRequested": "configureRequested"; "afterOpen": "afterOpen"; "afterClose": "afterClose"; "afterSave": "afterSave"; "afterDelete": "afterDelete"; "error": "error"; }, never, never, true, never>;
}
declare class CrudLauncherService {
private readonly router;
private readonly dialog;
private readonly storage;
private readonly global;
private readonly drawerAdapter;
launch(action: CrudAction, row: Record<string, unknown> | undefined, metadata: CrudMetadata): Promise<{
mode: FormOpenMode;
ref?: DialogRef<any>;
}>;
resolveOpenMode(action: CrudAction, metadata: CrudMetadata): FormOpenMode;
private buildRoute;
private mapInputs;
private mergeCrudOverrides;
static ɵfac: i0.ɵɵFactoryDeclaration<CrudLauncherService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<CrudLauncherService>;
}
declare class DynamicFormDialogHostComponent implements OnInit {
dialogRef: DialogRef<DynamicFormDialogHostComponent>;
data: any;
private dialogService;
private crud;
private configStorage;
formComp?: PraxisDynamicForm;
modal: any;
maximized: boolean;
private initialSize;
private rememberState;
private stateKey?;
private destroyRef;
resourcePath?: string;
resourceId?: string | number;
mode: 'create' | 'edit' | 'view';
backConfig?: BackConfig;
private idField;
texts: Record<string, string>;
constructor(dialogRef: DialogRef<DynamicFormDialogHostComponent>, data: any, dialogService: DialogService, crud: GenericCrudService<any>, configStorage: ConfigStorage);
ngOnInit(): void;
onSave(result: unknown): void;
onCancel(): void;
toggleMaximize(initial?: boolean): void;
private saveState;
static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormDialogHostComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<DynamicFormDialogHostComponent, "praxis-dynamic-form-dialog-host", never, {}, {}, never, never, true, never>;
}
/** Metadata for PraxisCrudComponent */
declare const PRAXIS_CRUD_COMPONENT_METADATA: ComponentDocMeta;
/** Provider para auto-registrar metadados do componente CRUD. */
declare function providePraxisCrudMetadata(): Provider;
type CrudHeaderVariant = 'ghost' | 'tonal' | 'outlined';
declare class CrudPageHeaderComponent {
title: string;
backLabel?: string;
showBack: boolean;
variant: CrudHeaderVariant;
sticky: boolean;
divider: boolean;
returnTo?: string | null;
static ɵfac: i0.ɵɵFactoryDeclaration<CrudPageHeaderComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<CrudPageHeaderComponent, "praxis-crud-page-header", never, { "title": { "alias": "title"; "required": false; }; "backLabel": { "alias": "backLabel"; "required": false; }; "showBack": { "alias": "showBack"; "required": false; }; "variant": { "alias": "variant"; "required": false; }; "sticky": { "alias": "sticky"; "required": false; }; "divider": { "alias": "divider"; "required": false; }; "returnTo": { "alias": "returnTo"; "required": false; }; }, {}, never, ["*"], true, never>;
}
interface CrudDrawerOpenConfig {
action: CrudAction;
metadata: CrudMetadata;
inputs: Record<string, unknown>;
}
interface CrudDrawerAdapter {
open(config: CrudDrawerOpenConfig): Promise<void> | void;
}
declare const CRUD_DRAWER_ADAPTER: InjectionToken<CrudDrawerAdapter>;
export { CRUD_DRAWER_ADAPTER, CrudLauncherService, CrudPageHeaderComponent, DialogService, DynamicFormDialogHostComponent, PRAXIS_CRUD_COMPONENT_METADATA, PraxisCrudComponent, assertCrudMetadata, providePraxisCrudMetadata };
export type { CrudAction, CrudDefaults, CrudDrawerAdapter, CrudDrawerOpenConfig, CrudHeaderConfig, CrudHeaderVariant, CrudMetadata, CrudParamMapping, CrudResource, DialogConfig, DialogRef, FormOpenMode };