import { KbqInlineEditModule } from '@koobiq/components/inline-edit';

KbqInlineEdit

componentСкопировать ссылку на KbqInlineEdit

Customizable component that enables edit-in-place logic for specified control and it's view. This component is projecting edit/view mode templates and adds keyboard/pointer handlers. Edit mode opens in a positioned overlay that matches the view mode width or can be customized.

@Component({ selector: 'kbq-inline-edit', exportAs: 'kbqInlineEdit' })
class KbqInlineEdit implements KbqConnectedOverlayOriginProvider, KbqInlineEditSaveRecovery {
    readonly showActions = input<boolean>(false);
    readonly showTooltipOnError = input<boolean>(true);
    readonly validationTooltip = input<string | TemplateRef<unknown>>();
    readonly disabled = input<boolean>(false);
    readonly editModeWidth = input<number | undefined>();
    readonly tooltipPlacement = input<PopUpPlacements>();
    readonly overlayPanelClass = input<string | string[]>('');
    readonly getValueHandler = input<() => unknown>();
    readonly setValueHandler = input<(value: unknown) => void>();
    readonly ariaLabel = input<string | null>(null, {
        alias: 'aria-label'
    });
    readonly compareWith = input<((a: any, b: any) => boolean) | null>(
        (a, b) => a === b
    );
    readonly saveHandler = input<KbqInlineEditSaveHandler>();
    readonly saveErrorHandler = input<KbqInlineEditSaveErrorHandler | null>(
        inject(KBQ_INLINE_EDIT_SAVE_ERROR_HANDLER, { optional: true })
    );
    readonly canSaveOnEnter = input<(event: KeyboardEvent) => boolean>(
        (event: KeyboardEvent): boolean => {
            // A control that runs its own action on Enter would otherwise fire it and save at the same time.
            if (isElement(event.target) && event.target.closest(ENTER_ACTIVATED_SELECTORS)) return false;

            return hasModifierKey(event, 'ctrlKey', 'metaKey') || !(event.target instanceof HTMLTextAreaElement);
        }
    );
    readonly interactiveSelectors = input<string[]>(['a', 'kbq-tag']);
    readonly mode = model<KbqInlineEditMode>('view');
    readonly saved = output<void>();
    readonly canceled = output<void>();
    readonly saveError = output<KbqInlineEditSaveErrorContext>();
    readonly saveStatus: Signal<KbqInlineEditSaveStatus>;
    toggleMode(): void;
    commit(): void;
    retrySave(): void;
    rollback(): void;
}
showActionsinputСкопировать ссылку на showActionsboolean

Whether to show save/cancel action buttons in edit mode. Defaults to false.

showTooltipOnErrorinputСкопировать ссылку на showTooltipOnErrorboolean

Whether to automatically show validation error tooltips on save attempts. Has no effect unless validationTooltip is set. Defaults to true.

validationTooltipinputСкопировать ссылку на validationTooltipstring | TemplateRef<unknown>

Custom validation tooltip message.

disabledinputСкопировать ссылку на disabledboolean

Disables the component, preventing interaction and mode switching. Only allows menu dropdown. Defaults to false.

editModeWidthinputСкопировать ссылку на editModeWidthnumber | undefined

Custom width in pixels for the edit mode overlay. Auto-calculated if not set.

tooltipPlacementinputСкопировать ссылку на tooltipPlacementPopUpPlacements

User-defined tooltip placement

overlayPanelClassinputСкопировать ссылку на overlayPanelClassstring | string[]

Classes to be passed to the inline edit panel.

getValueHandlerinputСкопировать ссылку на getValueHandler() => unknown

Handler function to retrieve the current value

setValueHandlerinputСкопировать ссылку на setValueHandler(value: unknown) => void

Handler function to update the value

aria-labelinputСкопировать ссылку на aria-labelstring | null

Accessible name of the control that opens the editor. Defaults to the localized "Edit"; set a field-specific name where the projected value alone doesn't say what is being edited.

compareWithinputСкопировать ссылку на compareWith((a: any, b: any) => boolean) | null

Whether the value still equals the one the editor opened with, in which case saveHandler is not called. The default suits text and numbers; bind your own for arrays and objects, or null to send every time. A failed save is always retried, however the values compare.

saveHandlerinputСкопировать ссылку на saveHandlerKbqInlineEditSaveHandler

Saves a valid value in the background: edit mode closes right away and view mode reports how the request went. Without it, a valid value is saved immediately.

saveErrorHandlerinputСкопировать ссылку на saveErrorHandlerKbqInlineEditSaveErrorHandler | null

Reaction to a failed save for this inline edit alone. Defaults to KBQ_INLINE_EDIT_SAVE_ERROR_HANDLER; bind null to leave it without one.

canSaveOnEnterinputСкопировать ссылку на canSaveOnEnter(event: KeyboardEvent) => boolean

Customizable function that checks if saving on enter available.

interactiveSelectorsinputСкопировать ссылку на interactiveSelectorsstring[]

CSS selectors for elements in view mode that should handle clicks instead of opening edit mode. Override to replace or extend the default list.

Example
<kbq-inline-edit [interactiveSelectors]="['a', 'kbq-tag', 'button']">
modemodelСкопировать ссылку на modeKbqInlineEditMode

Current mode. Two-way bindable: [(mode)] opens and closes the editor programmatically, and (modeChange) alone reports every transition.

localeOverridesinputСкопировать ссылку на localeOverridesKbqPartialLocaleData | undefined

Localized strings for this element and its subtree, keyed by locale section. Every key is optional at every depth.

savedoutputСкопировать ссылку на savedvoid

Emitted when the inline edit is saved successfully.

canceledoutputСкопировать ссылку на canceledvoid

Emitted when the inline edit is canceled and changes are discarded.

saveErroroutputСкопировать ссылку на saveErrorKbqInlineEditSaveErrorContext

Emitted when a saveHandler request fails. Silent once the row is destroyed; saveErrorHandler is not.

saveStatusСкопировать ссылку на saveStatusSignal<KbqInlineEditSaveStatus>

State of the background save started by saveHandler.

toggleMode()Скопировать ссылку на toggleMode()void

Manually switch mode. Does nothing while a saveHandler request is in flight.

commit()Скопировать ссылку на commit()void

Saves the current value, running the same validation as a normal save.

retrySave()Скопировать ссылку на retrySave()void

Repeats the request for a value the server rejected. Does nothing unless the last save failed.

rollback()Скопировать ссылку на rollback()void

Discards the value the server rejected, restoring the last saved one and closing the editor.

KbqInlineEditMenu

directiveСкопировать ссылку на KbqInlineEditMenu

This directive enhances element acting as dropdown trigger, visually indicating the active state with the kbq-active class. Also, it prevents click/keydown events from being propagated to disable mode toggling of parent component.

@Directive({ selector: '[kbqInlineEditMenu]', exportAs: 'kbqInlineEditMenu' })
class KbqInlineEditMenu {}

KbqInlineEditPlaceholder

directiveСкопировать ссылку на KbqInlineEditPlaceholder

Directive for easy using styles of inline edit placeholder publicly.

@Directive({
    selector: '[kbqInlineEditPlaceholder]',
    exportAs: 'kbqInlineEditPlaceholder'
})
class KbqInlineEditPlaceholder {}

KbqInlineEditMode

typeСкопировать ссылку на KbqInlineEditMode
type KbqInlineEditMode = 'view' | 'edit';

KbqInlineEditSaveErrorContext

interfaceСкопировать ссылку на KbqInlineEditSaveErrorContext

Failed save, reported through saveError and KBQ_INLINE_EDIT_SAVE_ERROR_HANDLER.

interface KbqInlineEditSaveErrorContext<E = any> {
    readonly error: E;
    readonly inlineEdit: KbqInlineEditSaveRecovery;
}
errorСкопировать ссылку на errorE

Parameterise the interface to type this.

KbqInlineEditSaveErrorHandler

typeСкопировать ссылку на KbqInlineEditSaveErrorHandler

Reaction to a failed save, e.g. opening a toast.

type KbqInlineEditSaveErrorHandler = (context: KbqInlineEditSaveErrorContext) => void;

KbqInlineEditSaveHandler

typeСкопировать ссылку на KbqInlineEditSaveHandler

Saves the edited value, e.g. sends it to a server. Only the first emission counts, and the observable must emit or complete: destroying the row does not cancel it, so one that never settles keeps the row in memory.

Called without a receiver, so bind an arrow function rather than a method that relies on this.

type KbqInlineEditSaveHandler = () => Observable<unknown>;

KbqInlineEditSaveRecovery

interfaceСкопировать ссылку на KbqInlineEditSaveRecovery

Recovery a failed-save notification can offer: retry, edit again, discard the unsaved value.

interface KbqInlineEditSaveRecovery {
    retrySave(): void;
    toggleMode(): void;
    rollback(): void;
}

KbqInlineEditSaveStatus

typeСкопировать ссылку на KbqInlineEditSaveStatus

State of the save request started by saveHandler. progress is pending past the indicator delay.

type KbqInlineEditSaveStatus = 'idle' | 'pending' | 'progress' | 'error';

KBQ_INLINE_EDIT_SAVE_ERROR_HANDLER

constСкопировать ссылку на KBQ_INLINE_EDIT_SAVE_ERROR_HANDLER

Reports every failed save the same way across the application. Declare it in the root injector.

const KBQ_INLINE_EDIT_SAVE_ERROR_HANDLER: InjectionToken<KbqInlineEditSaveErrorHandler>;

kbqInlineEditSaveProgressDelay

constСкопировать ссылку на kbqInlineEditSaveProgressDelay

Delay before the save progress state appears, so a fast response causes no flicker.

const kbqInlineEditSaveProgressDelay: number;

kbqInlineEditSaveProgressMinimumDuration

constСкопировать ссылку на kbqInlineEditSaveProgressMinimumDuration

Minimum time the save progress state stays once it has appeared.

const kbqInlineEditSaveProgressMinimumDuration: number;
Предложения по улучшению
Если вы нашли ошибку или хотите доработать статью, создайте запрос на GitHub.