@cocoar/ui-overlay 0.1.0-beta.79 → 0.1.0-beta.82

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.
@@ -137,50 +137,6 @@ declare const COAR_OVERLAY_DEFAULTS: {
137
137
  readonly strategy: "body";
138
138
  };
139
139
  };
140
- type ResolvedOverlaySpec<TInputs> = Required<Omit<OverlaySpec<TInputs>, 'content'>> & Pick<Required<OverlaySpec<TInputs>>, 'content'>;
141
-
142
- declare class ContentBuilder {
143
- fromComponent<C>(component: Type<C>): ContentSpec<Partial<C>>;
144
- fromTemplate<TCtx>(template: TemplateRef<TCtx>): ContentSpec<TCtx>;
145
- fromText(): ContentSpec<{
146
- text: string;
147
- }>;
148
- }
149
-
150
- declare class OverlayBuilder {
151
- private readonly draft;
152
- constructor(seed?: OverlaySpec<unknown>);
153
- backdrop(cfg?: BackdropSpec | 'none' | 'modal'): this;
154
- anchor(cfg: AnchorSpec): this;
155
- position(cfg: PositionSpec): this;
156
- size(cfg: SizeSpec): this;
157
- scroll(cfg: ScrollSpec): this;
158
- dismiss(cfg: DismissSpec): this;
159
- focus(cfg: FocusSpec): this;
160
- a11y(cfg: A11ySpec): this;
161
- attachment(cfg: AttachmentSpec): this;
162
- content(fn: (c: ContentBuilder) => ContentSpec<unknown>): this;
163
- freeze<TInputs = void>(): OverlaySpec<TInputs>;
164
- }
165
-
166
- type OverlayPreset = (b: OverlayBuilder) => void;
167
- declare const coarTooltipPreset: OverlayPreset;
168
- declare const coarModalPreset: OverlayPreset;
169
- declare const coarMenuPreset: OverlayPreset;
170
- /**
171
- * Menu preset for hover-driven menus (context menus, cascading flyouts).
172
- *
173
- * Enables hoverTree dismissal so a parent overlay stays open while the pointer
174
- * is inside any child overlay opened via openChild().
175
- */
176
- declare const coarHoverMenuPreset: OverlayPreset;
177
-
178
- declare class CoarOverlay {
179
- static define<TInputs = void>(fn: (b: OverlayBuilder) => void, ...presets: readonly OverlayPreset[]): OverlaySpec<TInputs>;
180
- static fork<TInputs>(base: OverlaySpec<TInputs>, fn: (b: OverlayBuilder) => void): OverlaySpec<TInputs>;
181
- }
182
- /** Alias kept for spec parity (`Overlay.define(...)`). */
183
- declare const Overlay: typeof CoarOverlay;
184
140
 
185
141
  interface OverlayRef {
186
142
  close(result?: unknown): void;
@@ -201,17 +157,13 @@ interface OverlayRef {
201
157
  }
202
158
 
203
159
  interface OverlayOpenOptions {
204
- /**
205
- * Optional parent overlay. Used for menus/submenus so the service can keep trees consistent
206
- * (e.g. closing a parent closes its children).
207
- */
208
- parent?: OverlayRef;
209
- /**
210
- * If true, closes all sibling overlays (other children of the same parent) when this overlay opens.
211
- * Useful for menus where only one submenu should be visible at a time.
212
- */
213
160
  closeSiblings?: boolean;
214
161
  }
162
+ type OverlaySettings<TInputs> = Omit<OverlaySpec<TInputs>, 'content'>;
163
+ type UnwrapInputSignal<T> = T extends i0.InputSignal<infer V> ? V : T;
164
+ type ComponentInputs<C> = {
165
+ [K in keyof C]?: UnwrapInputSignal<C[K]>;
166
+ };
215
167
  declare class CoarOverlayService {
216
168
  private readonly appRef;
217
169
  private readonly environmentInjector;
@@ -220,10 +172,20 @@ declare class CoarOverlayService {
220
172
  private globalListenersInstalled;
221
173
  private readonly onDocumentPointerDown;
222
174
  private readonly onDocumentKeyDown;
223
- open<TInputs>(spec: OverlaySpec<TInputs>, inputs: TInputs, options?: OverlayOpenOptions): OverlayRef;
224
- openChild<TInputs>(parent: OverlayRef, spec: OverlaySpec<TInputs>, inputs: TInputs, options?: {
225
- closeSiblings?: boolean;
175
+ openTemplate<TCtx>(template: TemplateRef<TCtx>, settings: OverlaySettings<TCtx>, inputs: TCtx): OverlayRef;
176
+ openComponent<C>(component: Type<C>, settings: OverlaySettings<ComponentInputs<C>>, inputs: ComponentInputs<C>): OverlayRef;
177
+ openText(settings: OverlaySettings<{
178
+ text: string;
179
+ }>, inputs: {
180
+ text: string;
226
181
  }): OverlayRef;
182
+ openTemplateAsChild<TCtx>(parent: OverlayRef, template: TemplateRef<TCtx>, settings: OverlaySettings<TCtx>, inputs: TCtx, options?: OverlayOpenOptions): OverlayRef;
183
+ openComponentAsChild<C>(parent: OverlayRef, component: Type<C>, settings: OverlaySettings<ComponentInputs<C>>, inputs: ComponentInputs<C>, options?: OverlayOpenOptions): OverlayRef;
184
+ openTextAsChild(parent: OverlayRef, settings: OverlaySettings<{
185
+ text: string;
186
+ }>, inputs: {
187
+ text: string;
188
+ }, options?: OverlayOpenOptions): OverlayRef;
227
189
  closeAll(): void;
228
190
  private resolveSpec;
229
191
  private applySpecResolvers;
@@ -237,46 +199,79 @@ declare class CoarOverlayService {
237
199
  private getTopmostDismissableOverlay;
238
200
  private getTopmostFocusTrappingOverlay;
239
201
  private mergeInputs;
240
- private renderContent;
241
202
  static ɵfac: i0.ɵɵFactoryDeclaration<CoarOverlayService, never>;
242
203
  static ɵprov: i0.ɵɵInjectableDeclaration<CoarOverlayService>;
243
204
  }
244
205
 
245
- interface ViewportRect {
246
- readonly width: number;
247
- readonly height: number;
206
+ interface OverlayChildOpenOptions {
207
+ closeSiblings?: boolean;
248
208
  }
249
- interface Rect {
250
- readonly left: number;
251
- readonly top: number;
252
- readonly right: number;
253
- readonly bottom: number;
254
- readonly width: number;
255
- readonly height: number;
209
+ interface TemplateOverlayOpener<TCtx> {
210
+ open(inputs: TCtx): OverlayRef;
211
+ openAsChild(parent: OverlayRef, inputs: TCtx, options?: OverlayChildOpenOptions): OverlayRef;
256
212
  }
257
- interface Point {
258
- readonly x: number;
259
- readonly y: number;
213
+ interface ComponentOverlayOpener<C> {
214
+ open(inputs: ComponentInputs<C>): OverlayRef;
215
+ openAsChild(parent: OverlayRef, inputs: ComponentInputs<C>, options?: OverlayChildOpenOptions): OverlayRef;
260
216
  }
261
- interface OverlaySize {
262
- readonly width: number;
263
- readonly height: number;
217
+ interface TextOverlayOpener {
218
+ open(inputs: {
219
+ text: string;
220
+ }): OverlayRef;
221
+ openAsChild(parent: OverlayRef, inputs: {
222
+ text: string;
223
+ }, options?: OverlayChildOpenOptions): OverlayRef;
264
224
  }
265
- interface OverlayCoordinates {
266
- readonly left: number;
267
- readonly top: number;
268
- readonly placement: Placement;
225
+ declare class CoarOverlayOpenBuilder {
226
+ private readonly service;
227
+ private readonly settings;
228
+ constructor(service: CoarOverlayService, settings?: OverlaySettings<unknown>);
229
+ fork(): CoarOverlayOpenBuilder;
230
+ backdrop(value: OverlaySettings<unknown>['backdrop']): CoarOverlayOpenBuilder;
231
+ anchor(value: OverlaySettings<unknown>['anchor']): CoarOverlayOpenBuilder;
232
+ position(value: OverlaySettings<unknown>['position']): CoarOverlayOpenBuilder;
233
+ size(value: OverlaySettings<unknown>['size']): CoarOverlayOpenBuilder;
234
+ scroll(value: OverlaySettings<unknown>['scroll']): CoarOverlayOpenBuilder;
235
+ dismiss(value: OverlaySettings<unknown>['dismiss']): CoarOverlayOpenBuilder;
236
+ focus(value: OverlaySettings<unknown>['focus']): CoarOverlayOpenBuilder;
237
+ a11y(value: OverlaySettings<unknown>['a11y']): CoarOverlayOpenBuilder;
238
+ attachment(value: OverlaySettings<unknown>['attachment']): CoarOverlayOpenBuilder;
239
+ /**
240
+ * Applies baseline settings, without overriding fields already set on this builder.
241
+ * Useful for applying a preset after you've already configured part of the builder.
242
+ */
243
+ withPreset(value: OverlaySettings<unknown>): CoarOverlayOpenBuilder;
244
+ fromTemplate<TCtx>(template: TemplateRef<TCtx>): TemplateOverlayOpener<TCtx>;
245
+ fromComponent<C>(component: Type<C>): ComponentOverlayOpener<C>;
246
+ fromText(): TextOverlayOpener;
269
247
  }
270
- declare function getViewportRect(): ViewportRect;
271
- declare function getContainerRect(container: HTMLElement): Rect;
272
- declare function rectFromDom(domRect: DOMRect): Rect;
273
- declare function getAnchorRect(anchor: AnchorSpec, viewport: ViewportRect): Rect;
274
- declare function rectFromPoint(point: Point, width: number, height: number): Rect;
275
- declare function rectFromVirtual(spec: Extract<AnchorSpec, {
276
- kind: 'virtual';
277
- }>, viewport: ViewportRect): Rect;
278
- declare function getScrollParents(element: Element): Array<Element | Window>;
279
- declare function computeOverlayCoordinates(anchorRect: Rect, overlaySize: OverlaySize, position: PositionSpec, viewport: ViewportRect, boundaryRect?: Rect): OverlayCoordinates;
248
+ /**
249
+ * Content-last overlay builder (configure shared overlay settings once).
250
+ *
251
+ * Intended usage:
252
+ *
253
+ * ```ts
254
+ * const overlay = createOverlayBuilder()
255
+ * .anchor({ kind: 'element', element })
256
+ * .position({ placement: 'bottom-start', offset: 4, flip: true, shift: true });
257
+ *
258
+ * overlay.fromTemplate(tpl).open({ $implicit: data });
259
+ * overlay.fromComponent(MyCmp).open({ text: 'Hello' });
260
+ * ```
261
+ *
262
+ * You can also provide initial settings:
263
+ *
264
+ * ```ts
265
+ * const overlay = createOverlayBuilder(coarMenuPreset);
266
+ * ```
267
+ */
268
+ declare function createOverlayBuilder(): CoarOverlayOpenBuilder;
269
+ declare function createOverlayBuilder(initial: OverlaySettings<unknown>): CoarOverlayOpenBuilder;
270
+
271
+ declare const coarTooltipPreset: OverlaySettings<unknown>;
272
+ declare const coarModalPreset: OverlaySettings<unknown>;
273
+ declare const coarMenuPreset: OverlaySettings<unknown>;
274
+ declare const coarHoverMenuPreset: OverlaySettings<unknown>;
280
275
 
281
276
  /**
282
277
  * The OverlayRef for the overlay currently rendering this content.
@@ -292,5 +287,5 @@ declare const COAR_OVERLAY_REF: InjectionToken<OverlayRef>;
292
287
  */
293
288
  declare const COAR_MENU_PARENT: InjectionToken<OverlayRef | null>;
294
289
 
295
- export { COAR_MENU_PARENT, COAR_OVERLAY_DEFAULTS, COAR_OVERLAY_REF, COAR_OVERLAY_SPEC_RESOLVERS, CoarOverlay, CoarOverlayService, ContentBuilder, Overlay, OverlayBuilder, CoarOverlayService as OverlayService, coarHoverMenuPreset, coarMenuPreset, coarModalPreset, coarTooltipPreset, computeOverlayCoordinates, getAnchorRect, getContainerRect, getScrollParents, getViewportRect, coarHoverMenuPreset as hoverMenuPreset, coarMenuPreset as menuPreset, coarModalPreset as modalPreset, rectFromDom, rectFromPoint, rectFromVirtual, coarTooltipPreset as tooltipPreset };
296
- export type { A11ySpec, AnchorSpec, AttachmentSpec, BackdropSpec, ContentSpec, DismissSpec, FocusSpec, OverlayCoordinates, OverlayOpenOptions, OverlayPreset, OverlayRef, OverlaySize, OverlaySpec, OverlaySpecResolver, Placement, Point, PositionSpec, Rect, ResolvedOverlaySpec, ScrollSpec, SizeSpec, ViewportRect };
290
+ export { COAR_MENU_PARENT, COAR_OVERLAY_DEFAULTS, COAR_OVERLAY_REF, COAR_OVERLAY_SPEC_RESOLVERS, CoarOverlayOpenBuilder, coarHoverMenuPreset, coarMenuPreset, coarModalPreset, coarTooltipPreset, createOverlayBuilder };
291
+ export type { A11ySpec, AnchorSpec, AttachmentSpec, BackdropSpec, ComponentOverlayOpener, DismissSpec, FocusSpec, OverlayChildOpenOptions, OverlayRef, OverlaySettings, OverlaySpec, OverlaySpecResolver, Placement, PositionSpec, ScrollSpec, SizeSpec, TemplateOverlayOpener, TextOverlayOpener };