@qalma/kit 0.1.0-beta.0 → 0.4.0

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,303 @@
1
+ import * as _angular_core from '@angular/core';
2
+ import { DestroyRef, ElementRef, Signal } from '@angular/core';
3
+ import { DragHandleMoveCommandValue, DragHandleCommandValue, QalmaEditorController } from '@qalma/editor';
4
+ import * as _qalma_kit_headless from '@qalma/kit/headless';
5
+
6
+ interface AnchorRect {
7
+ readonly top: number;
8
+ readonly bottom: number;
9
+ readonly left: number;
10
+ readonly right: number;
11
+ }
12
+ interface AnchorSize {
13
+ readonly width: number;
14
+ readonly height: number;
15
+ }
16
+ type AnchorPlacement = 'top' | 'bottom' | 'left' | 'right';
17
+ type AnchorAlign = 'start' | 'center' | 'end';
18
+ interface AnchorToRectOptions {
19
+ /** Which side of the anchor rect the floating element renders on. */
20
+ readonly placement: AnchorPlacement;
21
+ /** Rect (viewport or scroll surface) the result is clamped within. */
22
+ readonly boundary: AnchorRect;
23
+ /** Size of the floating element being positioned. */
24
+ readonly size: AnchorSize;
25
+ /** Distance between the anchor rect and the floating element. Default 8. */
26
+ readonly gap?: number;
27
+ /** Minimum distance kept from the boundary edges. Default 8. */
28
+ readonly edgeMargin?: number;
29
+ /**
30
+ * Cross-axis alignment relative to the anchor rect. `start` | `center` |
31
+ * `end` align to the anchor rect itself; a number instead pins the
32
+ * floating element's center to that viewport coordinate (clamped within
33
+ * the anchor rect), e.g. to follow a pointer's Y while hovering a tall
34
+ * block. Defaults to `start`.
35
+ */
36
+ readonly align?: AnchorAlign | number;
37
+ }
38
+ interface AnchorPosition {
39
+ readonly top: number;
40
+ readonly left: number;
41
+ }
42
+ declare function anchorToRect(anchor: AnchorRect, options: AnchorToRectOptions): AnchorPosition;
43
+
44
+ /**
45
+ * Fixed-position coordinates for a suggestion menu anchored to a caret/range
46
+ * rect. Exactly one of `top`/`bottom` is a number (the other is `null`): the
47
+ * menu is pinned below the anchor by `top`, or above it by `bottom`.
48
+ */
49
+ interface SuggestionMenuPlacement {
50
+ readonly left: number;
51
+ readonly top: number | null;
52
+ readonly bottom: number | null;
53
+ readonly maxHeight: number;
54
+ }
55
+ interface FlipAbovePlacementOptions {
56
+ /** Menu width, used to clamp `left` within the viewport. */
57
+ readonly width: number;
58
+ /** Ideal menu height for the current option count. */
59
+ readonly desiredHeight: number;
60
+ /** Floor for the computed `maxHeight` (e.g. one option / a loading row). */
61
+ readonly minHeight: number;
62
+ /** Viewport edge margin (default 12). */
63
+ readonly margin?: number;
64
+ /** Gap between the anchor and the menu (default 8). */
65
+ readonly gap?: number;
66
+ }
67
+ /**
68
+ * Positions a floating list under an anchor rect, flipping it above when there
69
+ * is not enough room below, and clamping its height and horizontal position to
70
+ * the viewport. Shared by the mention and slash-command menus, whose flip
71
+ * behavior `anchorToRect` does not cover (it has no flip / dynamic max-height).
72
+ */
73
+ declare function flipAbovePlacement(rect: {
74
+ readonly top: number;
75
+ readonly bottom: number;
76
+ readonly left: number;
77
+ }, options: FlipAbovePlacementOptions): SuggestionMenuPlacement;
78
+
79
+ interface DismissibleOverlayOptions {
80
+ /** Returns true when the event target is part of the overlay/trigger and should not dismiss it. */
81
+ isInside: (target: EventTarget | null) => boolean;
82
+ onDismiss: () => void;
83
+ }
84
+ /**
85
+ * Shared outside-click / Escape dismiss behavior for floating overlays
86
+ * (popovers, contextual menus, autocomplete lists). Generalizes the
87
+ * ad-hoc click-outside/Escape handling that used to be reimplemented
88
+ * separately per feature.
89
+ */
90
+ declare class DismissibleOverlay {
91
+ private readonly options;
92
+ private readonly pointerDown;
93
+ private readonly keydown;
94
+ constructor(options: DismissibleOverlayOptions);
95
+ connect(destroyRef: DestroyRef): void;
96
+ }
97
+
98
+ interface KeyboardNavigableListOptions<T> {
99
+ items: () => readonly T[];
100
+ activeIndex: () => number;
101
+ setActiveIndex: (index: number) => void;
102
+ onSelect: (item: T, index: number) => void;
103
+ }
104
+ /**
105
+ * Circular index step: move `index` by `delta` within `[0, length)`, wrapping
106
+ * around both ends; returns `index` unchanged for an empty list. This is the
107
+ * single source of truth for wrap-around list navigation — both
108
+ * `KeyboardNavigableList` (BYO-markup lists) and `QalmaSuggestionMenu` (the
109
+ * shipped mention/slash menus) delegate their arrow-key math to it.
110
+ */
111
+ declare function wrapIndex(index: number, delta: number, length: number): number;
112
+ /**
113
+ * Arrow-key navigation + Enter-to-select for autocomplete-style popovers
114
+ * (mention menu, slash command menu). Shared so both features stop
115
+ * reimplementing the same wrap-around index math.
116
+ *
117
+ * Takes a plain key string rather than a `KeyboardEvent` — some callers
118
+ * relay keys through a `CustomEvent` (no real `KeyboardEvent` to read),
119
+ * so preventing the default action is left to the caller.
120
+ */
121
+ declare class KeyboardNavigableList<T> {
122
+ private readonly options;
123
+ constructor(options: KeyboardNavigableListOptions<T>);
124
+ /** Returns true when the key was handled (caller should stop further propagation / preventDefault). */
125
+ handleKey(key: string): boolean;
126
+ }
127
+
128
+ /** Option buttons carry this attribute so the base can focus/scroll to one by index. */
129
+ declare const SUGGESTION_OPTION_INDEX_ATTR = "data-suggestion-index";
130
+ /** The scrollable options container carries this attribute (optional). */
131
+ declare const SUGGESTION_OPTIONS_SCROLLER_ATTR = "data-suggestion-options";
132
+ /**
133
+ * Shared behavior for caret-anchored suggestion menus (mention, slash command):
134
+ * flip-above placement input, active-option highlighting, and in-menu keyboard
135
+ * handling (Escape dismisses, Arrow moves + focuses, Enter/Space picks) with
136
+ * wrap-around and optional scroll-into-view. Concrete menus only supply their
137
+ * own item markup and expose their option list via `optionList`.
138
+ */
139
+ declare abstract class QalmaSuggestionMenu<TOption extends {
140
+ readonly id: string;
141
+ }> {
142
+ protected readonly elementRef: ElementRef<HTMLElement>;
143
+ readonly placement: _angular_core.InputSignal<SuggestionMenuPlacement | null>;
144
+ readonly activeIndex: _angular_core.InputSignal<number>;
145
+ readonly activate: _angular_core.OutputEmitterRef<number>;
146
+ readonly pick: _angular_core.OutputEmitterRef<TOption>;
147
+ readonly dismiss: _angular_core.OutputEmitterRef<void>;
148
+ /** The rendered options, bound by the concrete menu (`options`/`suggestions`). */
149
+ protected abstract readonly optionList: Signal<readonly TOption[]>;
150
+ protected preserveSelection(event: MouseEvent): void;
151
+ protected handleOptionKeydown(event: KeyboardEvent, option: TOption, index: number): void;
152
+ protected focusOption(index: number): void;
153
+ protected scrollOptionIntoView(index: number): void;
154
+ private getNextIndex;
155
+ private optionElement;
156
+ private optionsScroller;
157
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<QalmaSuggestionMenu<any>, never>;
158
+ static ɵdir: _angular_core.ɵɵDirectiveDeclaration<QalmaSuggestionMenu<any>, never, never, { "placement": { "alias": "placement"; "required": false; "isSignal": true; }; "activeIndex": { "alias": "activeIndex"; "required": false; "isSignal": true; }; }, { "activate": "activate"; "pick": "pick"; "dismiss": "dismiss"; }, never, never, true, never>;
159
+ }
160
+
161
+ interface QalmaDragHandleView {
162
+ target: DragHandleCommandValue;
163
+ transform: string;
164
+ blockType: string;
165
+ canMoveUp: boolean;
166
+ canMoveDown: boolean;
167
+ }
168
+ interface QalmaDragDropIndicator {
169
+ target: DragHandleMoveCommandValue;
170
+ transform: string;
171
+ width: number;
172
+ }
173
+ interface QalmaDragBlockHighlight {
174
+ transform: string;
175
+ width: number;
176
+ height: number;
177
+ }
178
+ declare class QalmaDragHandleController {
179
+ private readonly editor;
180
+ private readonly handleState;
181
+ private readonly dropIndicatorState;
182
+ private readonly draggedBlockHighlightState;
183
+ readonly handle: _angular_core.Signal<QalmaDragHandleView | null>;
184
+ readonly dropIndicator: _angular_core.Signal<QalmaDragDropIndicator | null>;
185
+ readonly draggedBlockHighlight: _angular_core.Signal<QalmaDragBlockHighlight | null>;
186
+ private surface;
187
+ private currentBlock;
188
+ private pendingBlock;
189
+ private lastPointerClientY;
190
+ private refreshFrame;
191
+ private handleKey;
192
+ private dragSession;
193
+ constructor(editor: () => QalmaEditorController);
194
+ connect(surface: HTMLElement, destroyRef: DestroyRef): void;
195
+ hide(): void;
196
+ startDrag(event: PointerEvent, handle: QalmaDragHandleView): void;
197
+ private handlePointerMove;
198
+ private handlePointerLeave;
199
+ private handleDragPointerMove;
200
+ private handleDragPointerUp;
201
+ private activateDragSession;
202
+ private updateDropIndicator;
203
+ private updateDraggedBlockHighlight;
204
+ private finishDrag;
205
+ private scheduleRefresh;
206
+ private refresh;
207
+ private updateFromBlock;
208
+ private cancelScheduledRefresh;
209
+ private setHandle;
210
+ private setDropIndicator;
211
+ }
212
+
213
+ declare class QalmaDragHandleDirective {
214
+ readonly editor: _angular_core.InputSignal<QalmaEditorController>;
215
+ private readonly destroyRef;
216
+ private readonly host;
217
+ private readonly controller;
218
+ readonly handle: _angular_core.Signal<QalmaDragHandleView | null>;
219
+ readonly dropIndicator: _angular_core.Signal<_qalma_kit_headless.QalmaDragDropIndicator | null>;
220
+ readonly draggedBlockHighlight: _angular_core.Signal<_qalma_kit_headless.QalmaDragBlockHighlight | null>;
221
+ constructor();
222
+ hide(): void;
223
+ startDrag(event: PointerEvent, handle: QalmaDragHandleView): void;
224
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<QalmaDragHandleDirective, never>;
225
+ static ɵdir: _angular_core.ɵɵDirectiveDeclaration<QalmaDragHandleDirective, "[qalmaDragHandle]", ["qalmaDragHandle"], { "editor": { "alias": "qalmaDragHandle"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
226
+ }
227
+
228
+ /**
229
+ * Fixed-position placement for a selection/contextual toolbar: a ready-to-apply
230
+ * CSS `transform` that pins the toolbar above the current selection rect.
231
+ * Produced by {@link QalmaSelectionToolbarController}; consumed by the styled
232
+ * `QalmaContextualToolbar` (or any custom bubble toolbar).
233
+ */
234
+ interface QalmaContextualToolbarPlacement {
235
+ transform: string;
236
+ }
237
+ declare class QalmaSelectionToolbarController {
238
+ private readonly editor;
239
+ private readonly placementState;
240
+ readonly placement: _angular_core.Signal<QalmaContextualToolbarPlacement | null>;
241
+ private surface;
242
+ private refreshFrame;
243
+ private placementKey;
244
+ constructor(editor: () => QalmaEditorController);
245
+ connect(surface: HTMLElement, destroyRef: DestroyRef): void;
246
+ refresh(): void;
247
+ hide(): void;
248
+ handleKeydown(event: Event): void;
249
+ private scheduleRefresh;
250
+ private cancelScheduledRefresh;
251
+ private setPlacement;
252
+ }
253
+
254
+ declare class QalmaSelectionToolbarDirective {
255
+ readonly editor: _angular_core.InputSignal<QalmaEditorController>;
256
+ private readonly destroyRef;
257
+ private readonly host;
258
+ private readonly controller;
259
+ readonly placement: _angular_core.Signal<_qalma_kit_headless.QalmaContextualToolbarPlacement | null>;
260
+ constructor();
261
+ refresh(): void;
262
+ hide(): void;
263
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<QalmaSelectionToolbarDirective, never>;
264
+ static ɵdir: _angular_core.ɵɵDirectiveDeclaration<QalmaSelectionToolbarDirective, "[qalmaSelectionToolbar]", ["qalmaSelectionToolbar"], { "editor": { "alias": "qalmaSelectionToolbar"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
265
+ }
266
+
267
+ interface LinkPopover extends LinkPopoverPlacement {
268
+ editing: boolean;
269
+ element: HTMLAnchorElement | null;
270
+ href: string;
271
+ rel: string | null;
272
+ target: '_blank' | null;
273
+ text: string;
274
+ }
275
+ interface LinkPopoverPlacement {
276
+ left: number;
277
+ top: number;
278
+ }
279
+ declare function createLinkPopoverPlacement(element: HTMLElement): LinkPopoverPlacement;
280
+ declare function findEditorLinkElement(target: EventTarget | null): HTMLAnchorElement | null;
281
+
282
+ declare class LinkPopoverController {
283
+ private readonly editor;
284
+ readonly popover: _angular_core.WritableSignal<LinkPopover | null>;
285
+ readonly href: _angular_core.WritableSignal<string>;
286
+ private hideTimeout;
287
+ constructor(editor: QalmaEditorController);
288
+ showToolbarEditor(event: MouseEvent): void;
289
+ showPreview(event: Event): void;
290
+ scheduleHideFromEvent(event: MouseEvent | FocusEvent): void;
291
+ edit(popover: LinkPopover): void;
292
+ save(popover: LinkPopover): void;
293
+ remove(popover: LinkPopover): void;
294
+ hide(): void;
295
+ keepOpen(): void;
296
+ scheduleHide(): void;
297
+ private selectLink;
298
+ private clearHideTimeout;
299
+ }
300
+
301
+ export { DismissibleOverlay, KeyboardNavigableList, LinkPopoverController, QalmaDragHandleController, QalmaDragHandleDirective, QalmaSelectionToolbarController, QalmaSelectionToolbarDirective, QalmaSuggestionMenu, SUGGESTION_OPTIONS_SCROLLER_ATTR, SUGGESTION_OPTION_INDEX_ATTR, anchorToRect, createLinkPopoverPlacement, findEditorLinkElement, flipAbovePlacement, wrapIndex };
302
+ export type { AnchorAlign, AnchorPlacement, AnchorPosition, AnchorRect, AnchorSize, AnchorToRectOptions, DismissibleOverlayOptions, FlipAbovePlacementOptions, KeyboardNavigableListOptions, LinkPopover, LinkPopoverPlacement, QalmaContextualToolbarPlacement, QalmaDragBlockHighlight, QalmaDragDropIndicator, QalmaDragHandleView, SuggestionMenuPlacement };
303
+ //# sourceMappingURL=qalma-kit-headless.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qalma-kit-headless.d.ts","sources":["../../../../libs/ui-kit/headless/src/lib/anchor-to-rect.ts","../../../../libs/ui-kit/headless/src/lib/flip-above-placement.ts","../../../../libs/ui-kit/headless/src/lib/dismissible-overlay.ts","../../../../libs/ui-kit/headless/src/lib/keyboard-navigable-list.ts","../../../../libs/ui-kit/headless/src/lib/suggestion-menu-base.ts","../../../../libs/ui-kit/headless/src/lib/drag-handle-controller.ts","../../../../libs/ui-kit/headless/src/lib/drag-handle-directive.ts","../../../../libs/ui-kit/headless/src/lib/selection-toolbar-controller.ts","../../../../libs/ui-kit/headless/src/lib/selection-toolbar-directive.ts","../../../../libs/ui-kit/headless/src/lib/link-popover.model.ts","../../../../libs/ui-kit/headless/src/lib/link-popover-controller.ts"],"mappings":";;;;;UAAiB,UAAU;AACzB;AACA;AACA;AACA;AACD;UAEgB,UAAU;AACzB;AACA;AACD;AAEK,KAAM,eAAe;AACrB,KAAM,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