i-tech-shared-components 1.4.100 → 1.4.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ import { ChangeDetectorRef, ElementRef, EventEmitter, OnChanges, OnDestroy, SimpleChanges } from '@angular/core';
2
+ import { AbstractControl } from '@angular/forms';
3
+ import { InlineDisplayDirective, InlineEditorDirective } from './inline-edit.directives';
4
+ import { InlineEditEndEvent, InlineEditorContext } from '../../interfaces/inline-edit.interface';
5
+ import * as i0 from "@angular/core";
6
+ /**
7
+ * Click-to-edit wrapper. Three states:
8
+ * 1. read - plain text (`displayValue`)
9
+ * 2. hover - highlighted box + pencil icon, signals that the value is editable
10
+ * 3. edit - renders the projected `iTechInlineEditor` template (any form control)
11
+ *
12
+ * Commits on: click or focus moving outside (overlay panels such as autocomplete/datepicker count as inside),
13
+ * Enter in an input (Ctrl/Cmd+Enter in a textarea), or a value change when `closeOnChange` is set.
14
+ * Cancels on Escape: `control` is reverted to the value it had when editing started.
15
+ * With `blockInvalidCommit`, an invalid control keeps the editor open and flips the editor
16
+ * context's `showErrors` so the projected input displays its validation message.
17
+ *
18
+ * Works for both page-level save (read the form later) and per-field save
19
+ * (handle `editEnd`, save when `changed`, toggle `loading`, revert to `previousValue` on error).
20
+ *
21
+ * ```html
22
+ * <i-tech-inline-edit [displayValue]="weightLabel" [control]="form.controls.weight" placeholder="weight">
23
+ * <ng-template iTechInlineEditor let-showErrors="showErrors">
24
+ * <i-tech-text-input formControlName="weight" [inputData]="{ hideLabel: true, submit: showErrors }"></i-tech-text-input>
25
+ * </ng-template>
26
+ * </i-tech-inline-edit>
27
+ * ```
28
+ */
29
+ export declare class InlineEditComponent<T = unknown> implements OnChanges, OnDestroy {
30
+ private host;
31
+ private cdr;
32
+ private document;
33
+ /** Text shown in read mode. The parent is responsible for mapping ids to labels. */
34
+ displayValue: string | number | null | undefined;
35
+ /** Translation key shown (muted) when there is no value. Falls back to `---`. */
36
+ placeholder: string;
37
+ disabled: boolean;
38
+ /** Shows a spinner and blocks editing, e.g. while a per-field save is in flight. */
39
+ loading: boolean;
40
+ /**
41
+ * Control behind the editor. Enables Escape-revert, `closeOnChange`, `blockInvalidCommit`,
42
+ * the `editEnd` values, invalid styling in read mode and disabled sync.
43
+ */
44
+ control: AbstractControl<T> | null;
45
+ /** Commit as soon as the value changes. For single selects / date pickers - not for multi-selects. */
46
+ closeOnChange: boolean;
47
+ /**
48
+ * Keep the editor open while `control` is invalid: commits are refused, the control is marked touched
49
+ * and `showErrors` becomes true in the editor template context. Escape still cancels.
50
+ */
51
+ blockInvalidCommit: boolean;
52
+ /**
53
+ * Focus the editor when edit mode starts: `[cdkFocusInitial]` element if present,
54
+ * otherwise the first input/textarea, otherwise opens a mat-select.
55
+ */
56
+ autoFocus: boolean;
57
+ /** Field name for screen readers (translation key), read together with the value. */
58
+ ariaLabel: string;
59
+ testId: string;
60
+ editStart: EventEmitter<void>;
61
+ editEnd: EventEmitter<InlineEditEndEvent<T>>;
62
+ editor?: InlineEditorDirective;
63
+ display?: InlineDisplayDirective;
64
+ editorHost?: ElementRef<HTMLElement>;
65
+ displayEl?: ElementRef<HTMLElement>;
66
+ editing: boolean;
67
+ isEmpty: boolean;
68
+ isDisabled: boolean;
69
+ isInvalid: boolean;
70
+ editorContext: InlineEditorContext;
71
+ private valueOnEditStart;
72
+ private controlSub?;
73
+ private valueSub?;
74
+ private readonly onDocumentMouseDown;
75
+ constructor(host: ElementRef<HTMLElement>, cdr: ChangeDetectorRef, document: Document);
76
+ ngOnChanges(changes: SimpleChanges): void;
77
+ ngOnDestroy(): void;
78
+ startEdit(): void;
79
+ /** Returns false when the commit was refused by `blockInvalidCommit`. */
80
+ commit(restoreFocus?: boolean): boolean;
81
+ cancel(restoreFocus?: boolean): void;
82
+ onFocusOut(event: FocusEvent): void;
83
+ onEditorKeydown(event: KeyboardEvent): void;
84
+ private stopEdit;
85
+ /** Inside the host, or inside an overlay (select panel, datepicker) that isn't the dialog hosting us. */
86
+ private isInside;
87
+ private focusEditor;
88
+ private subscribeToControl;
89
+ private updateControlState;
90
+ private isSameValue;
91
+ static ɵfac: i0.ɵɵFactoryDeclaration<InlineEditComponent<any>, never>;
92
+ static ɵcmp: i0.ɵɵComponentDeclaration<InlineEditComponent<any>, "i-tech-inline-edit", never, { "displayValue": { "alias": "displayValue"; "required": false; }; "placeholder": { "alias": "placeholder"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "loading": { "alias": "loading"; "required": false; }; "control": { "alias": "control"; "required": false; }; "closeOnChange": { "alias": "closeOnChange"; "required": false; }; "blockInvalidCommit": { "alias": "blockInvalidCommit"; "required": false; }; "autoFocus": { "alias": "autoFocus"; "required": false; }; "ariaLabel": { "alias": "ariaLabel"; "required": false; }; "testId": { "alias": "testId"; "required": false; }; }, { "editStart": "editStart"; "editEnd": "editEnd"; }, ["editor", "display"], never, true, never>;
93
+ }
@@ -0,0 +1,34 @@
1
+ import { TemplateRef } from '@angular/core';
2
+ import { InlineDisplayContext, InlineEditorContext } from '../../interfaces/inline-edit.interface';
3
+ import * as i0 from "@angular/core";
4
+ /**
5
+ * Marks the template rendered while an `<i-tech-inline-edit>` is in edit mode.
6
+ * Any form control works inside it (text input, autocomplete, date picker, ...).
7
+ *
8
+ * ```html
9
+ * <ng-template iTechInlineEditor let-showErrors="showErrors">
10
+ * <i-tech-text-input formControlName="weight" [inputData]="{ ..., submit: showErrors }"></i-tech-text-input>
11
+ * </ng-template>
12
+ * ```
13
+ */
14
+ export declare class InlineEditorDirective {
15
+ templateRef: TemplateRef<InlineEditorContext>;
16
+ constructor(templateRef: TemplateRef<InlineEditorContext>);
17
+ static ngTemplateContextGuard(dir: InlineEditorDirective, ctx: unknown): ctx is InlineEditorContext;
18
+ static ɵfac: i0.ɵɵFactoryDeclaration<InlineEditorDirective, never>;
19
+ static ɵdir: i0.ɵɵDirectiveDeclaration<InlineEditorDirective, "ng-template[iTechInlineEditor]", never, {}, {}, never, never, true, never>;
20
+ }
21
+ /**
22
+ * Optional custom read-mode template. Receives the display value as implicit context.
23
+ *
24
+ * ```html
25
+ * <ng-template iTechInlineDisplay let-value>{{ value }} lbs</ng-template>
26
+ * ```
27
+ */
28
+ export declare class InlineDisplayDirective {
29
+ templateRef: TemplateRef<InlineDisplayContext>;
30
+ constructor(templateRef: TemplateRef<InlineDisplayContext>);
31
+ static ngTemplateContextGuard(dir: InlineDisplayDirective, ctx: unknown): ctx is InlineDisplayContext;
32
+ static ɵfac: i0.ɵɵFactoryDeclaration<InlineDisplayDirective, never>;
33
+ static ɵdir: i0.ɵɵDirectiveDeclaration<InlineDisplayDirective, "ng-template[iTechInlineDisplay]", never, {}, {}, never, never, true, never>;
34
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Payload of `InlineEditComponent.editEnd`.
3
+ */
4
+ export interface InlineEditEndEvent<T = unknown> {
5
+ /** Closed with Escape - the control was reverted to `previousValue`. */
6
+ cancelled: boolean;
7
+ /** Value differs from the one edit mode started with. Use it to skip no-op saves. */
8
+ changed: boolean;
9
+ /** Control value after editing (`undefined` when no `control` is bound). */
10
+ value: T;
11
+ /** Control value when edit mode started. Use it to roll back after a failed save. */
12
+ previousValue: T;
13
+ }
14
+ /**
15
+ * Context of the `iTechInlineEditor` template.
16
+ *
17
+ * `<ng-template iTechInlineEditor let-showErrors="showErrors">`
18
+ */
19
+ export interface InlineEditorContext {
20
+ /** True after a commit was refused by `blockInvalidCommit` - bind it to the editor's error display. */
21
+ showErrors: boolean;
22
+ }
23
+ /**
24
+ * Context of the `iTechInlineDisplay` template.
25
+ *
26
+ * `<ng-template iTechInlineDisplay let-value>`
27
+ */
28
+ export interface InlineDisplayContext<T = unknown> {
29
+ /** The component's `displayValue`. */
30
+ $implicit: T;
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i-tech-shared-components",
3
- "version": "1.4.100",
3
+ "version": "1.4.101",
4
4
  "peerDependencies": {
5
5
  "@angular/animations": "^19.0.0",
6
6
  "@angular/cdk": "^19.0.0",
package/public-api.d.ts CHANGED
@@ -41,3 +41,6 @@ export * from './lib/components/segmented-button/segmented-button.component';
41
41
  export * from './lib/components/time-input/time-input.component';
42
42
  export * from './lib/interfaces/announcement.interface';
43
43
  export * from './lib/components/announcement-modal/announcement-modal.component';
44
+ export * from './lib/interfaces/inline-edit.interface';
45
+ export * from './lib/components/inline-edit/inline-edit.directives';
46
+ export * from './lib/components/inline-edit/inline-edit.component';