@flxgde/gigamenu 0.2.0 → 0.5.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.
@@ -1,8 +1,23 @@
1
1
  import * as _angular_core from '@angular/core';
2
2
  import { TemplateRef } from '@angular/core';
3
3
  import { Router, Routes } from '@angular/router';
4
+ import * as _flxgde_gigamenu from '@flxgde/gigamenu';
4
5
 
5
6
  type GigamenuItemCategory = 'page' | 'command';
7
+ /**
8
+ * Autocomplete option for parameter suggestions.
9
+ * label: Display text shown in the autocomplete dropdown
10
+ * value: Actual value that gets passed to the action
11
+ */
12
+ interface AutocompleteOption {
13
+ label: string;
14
+ value: string;
15
+ }
16
+ /**
17
+ * Provider for autocomplete suggestions.
18
+ * Can be either a static array of options or an async function that returns options.
19
+ */
20
+ type ParamProvider = AutocompleteOption[] | ((query: string) => Promise<AutocompleteOption[]> | AutocompleteOption[]);
6
21
  interface GigamenuItem {
7
22
  id: string;
8
23
  label: string;
@@ -17,6 +32,39 @@ interface GigamenuItem {
17
32
  action: (args?: string) => void;
18
33
  /** Required parameter names for this item (e.g., ['id', 'commentId']) */
19
34
  params?: string[];
35
+ /**
36
+ * Autocomplete providers for parameters.
37
+ * Key: parameter name (must match a name in params array)
38
+ * Value: ParamProvider (static array or async function)
39
+ */
40
+ paramProviders?: Record<string, ParamProvider>;
41
+ /**
42
+ * Optional section/group label. Items supplied by dynamic providers typically
43
+ * set this so the UI can render them under a heading (e.g. "Recipes").
44
+ */
45
+ group?: string;
46
+ /** Provider id when produced by a dynamic provider. Set automatically. */
47
+ providerId?: string;
48
+ }
49
+ /**
50
+ * A dynamic provider returns items that depend on the current query, e.g. results
51
+ * fetched from a server. Returned items skip the built-in fuzzy filter.
52
+ */
53
+ type GigamenuProvider = (query: string) => Promise<GigamenuProviderItem[]> | GigamenuProviderItem[];
54
+ /**
55
+ * Items returned from a provider. Same shape as GigamenuItem but `category` is
56
+ * optional — it defaults to 'command'. Providers typically omit it.
57
+ */
58
+ type GigamenuProviderItem = Omit<GigamenuItem, 'category'> & {
59
+ category?: GigamenuItemCategory;
60
+ };
61
+ interface GigamenuProviderOptions {
62
+ /** Minimum query length before the provider is invoked. Default: 2. */
63
+ minQueryLength?: number;
64
+ /** Debounce window in ms before invoking the provider. Default: 200. */
65
+ debounceMs?: number;
66
+ /** Optional group label applied to all items from this provider. */
67
+ group?: string;
20
68
  }
21
69
  /** Colors for parameter highlighting */
22
70
  declare const PARAM_COLORS: readonly ["text-blue-500 dark:text-blue-400", "text-green-500 dark:text-green-400", "text-orange-500 dark:text-orange-400", "text-pink-500 dark:text-pink-400", "text-cyan-500 dark:text-cyan-400"];
@@ -32,6 +80,12 @@ interface GigamenuConfig {
32
80
  autoDiscoverRoutes?: boolean;
33
81
  /** Separator between search query and arguments (default: ' ') */
34
82
  argSeparator?: string;
83
+ /** CSS class name for dark mode (default: 'dark') */
84
+ darkModeClass?: string;
85
+ /** Tab behavior for autocomplete: 'cycle' always cycles, 'accept-first' accepts on first tab (default: 'cycle') */
86
+ autocompleteTabBehavior?: 'cycle' | 'accept-first';
87
+ /** When to dismiss autocomplete overlay: 'on-type' hides on any keystroke, 'manual' only on Escape/selection (default: 'on-type') */
88
+ autocompleteDismiss?: 'on-type' | 'manual';
35
89
  }
36
90
  declare const DEFAULT_CONFIG: GigamenuConfig;
37
91
  /**
@@ -89,12 +143,18 @@ interface DiscoverRoutesOptions {
89
143
  map?: RouteMapper;
90
144
  }
91
145
 
146
+ interface RegisteredProvider {
147
+ provider: GigamenuProvider;
148
+ options: Required<GigamenuProviderOptions>;
149
+ }
92
150
  declare class GigamenuService {
93
151
  private _router?;
94
152
  private readonly _items;
153
+ private readonly _providers;
95
154
  private readonly _isOpen;
96
155
  private readonly _config;
97
156
  readonly items: _angular_core.Signal<GigamenuItem[]>;
157
+ readonly providers: _angular_core.Signal<Map<string, RegisteredProvider>>;
98
158
  readonly isOpen: _angular_core.Signal<boolean>;
99
159
  readonly config: _angular_core.Signal<GigamenuConfig>;
100
160
  /**
@@ -106,8 +166,16 @@ declare class GigamenuService {
106
166
  open(): void;
107
167
  close(): void;
108
168
  toggle(): void;
169
+ toggleDarkMode(): void;
109
170
  registerItem(item: GigamenuItem): void;
110
171
  unregisterItem(id: string): void;
172
+ /**
173
+ * Register a dynamic item provider. The provider is invoked when the user
174
+ * types in the menu (in action-selection mode) and its results are merged
175
+ * into the displayed items alongside statically registered items.
176
+ */
177
+ registerProvider(id: string, provider: GigamenuProvider, options?: GigamenuProviderOptions): void;
178
+ unregisterProvider(id: string): void;
111
179
  registerCommand(command: GigamenuCommand): void;
112
180
  registerPage(page: GigamenuPage): void;
113
181
  private extractParamNames;
@@ -168,20 +236,26 @@ interface GigamenuEmptyContext {
168
236
  * Context provided to the header template.
169
237
  */
170
238
  interface GigamenuHeaderContext {
171
- /** The current full query */
239
+ /** The current query value */
172
240
  $implicit: string;
173
- /** The search term (before separator) */
174
- searchTerm: string;
175
- /** The arguments (after separator) */
176
- args: string;
177
- /** Whether the query contains a separator */
178
- hasSeparator: boolean;
241
+ /** The current query value */
242
+ query: string;
243
+ /** The locked action (if in parameter mode) */
244
+ lockedAction: GigamenuItem | null;
245
+ /** Array of filled parameter values */
246
+ paramValues: string[];
247
+ /** Name of the current parameter being edited */
248
+ currentParamName: string | null;
249
+ /** Placeholder text */
250
+ placeholder: string;
179
251
  /** Callback to update the query */
180
252
  onQueryChange: (value: string) => void;
181
253
  /** Callback for keydown events */
182
254
  onKeydown: (event: KeyboardEvent) => void;
183
- /** Placeholder text */
184
- placeholder: string;
255
+ /** Callback to unlock the action (go back to action selection) */
256
+ onUnlockAction: () => void;
257
+ /** Callback to go back to a specific parameter */
258
+ onGoToParam: (index: number) => void;
185
259
  }
186
260
  /**
187
261
  * Context provided to the footer template.
@@ -278,28 +352,28 @@ declare class GigamenuFooterTemplate {
278
352
  * ```
279
353
  */
280
354
  interface GigamenuPanelContext {
281
- /** Filtered items to display */
355
+ /** Items to display (actions or autocomplete suggestions) */
282
356
  $implicit: GigamenuItem[];
283
- /** Current full query */
357
+ /** Items to display (actions or autocomplete suggestions) */
358
+ items: GigamenuItem[];
359
+ /** Current query value */
284
360
  query: string;
285
- /** The search term (before separator) */
286
- searchTerm: string;
287
- /** The arguments (after separator) */
288
- args: string;
289
- /** Whether the query contains a separator */
290
- hasSeparator: boolean;
361
+ /** The locked action (if in parameter mode) */
362
+ lockedAction: GigamenuItem | null;
363
+ /** Array of filled parameter values */
364
+ paramValues: string[];
291
365
  /** Currently selected index */
292
366
  selectedIndex: number;
293
- /** Callback to execute an item */
294
- executeItem: (item: GigamenuItem) => void;
367
+ /** Placeholder text from config */
368
+ placeholder: string;
369
+ /** Callback when item is clicked */
370
+ onItemClick: (item: GigamenuItem, index: number) => void;
295
371
  /** Callback to update selection */
296
- setSelectedIndex: (index: number) => void;
372
+ onSelectIndex: (index: number) => void;
297
373
  /** Callback to update query */
298
- setQuery: (query: string) => void;
374
+ onQueryChange: (query: string) => void;
299
375
  /** Callback to close the menu */
300
- close: () => void;
301
- /** Placeholder text from config */
302
- placeholder: string;
376
+ onClose: () => void;
303
377
  }
304
378
  declare class GigamenuPanelTemplate {
305
379
  readonly template: TemplateRef<GigamenuPanelContext>;
@@ -307,6 +381,24 @@ declare class GigamenuPanelTemplate {
307
381
  static ɵdir: _angular_core.ɵɵDirectiveDeclaration<GigamenuPanelTemplate, "[gmPanel]", never, {}, {}, never, never, true, never>;
308
382
  }
309
383
 
384
+ /**
385
+ * Represents the different states of the gigamenu input.
386
+ * New paradigm: input handles ONE thing at a time.
387
+ */
388
+ declare enum InputState {
389
+ /** Menu is closed */
390
+ Closed = "closed",
391
+ /** User is searching/selecting an action (page or command) */
392
+ ActionSelection = "actionSelection",
393
+ /** User is inputting a parameter value */
394
+ ParameterInput = "parameterInput"
395
+ }
396
+
397
+ /**
398
+ * Get color class for a parameter index.
399
+ */
400
+ declare function getParamColor(index: number): string;
401
+
310
402
  declare class GigamenuComponent {
311
403
  protected readonly service: GigamenuService;
312
404
  private readonly frecency;
@@ -320,40 +412,75 @@ declare class GigamenuComponent {
320
412
  protected readonly panelTemplate: _angular_core.Signal<GigamenuPanelTemplate>;
321
413
  protected readonly query: _angular_core.WritableSignal<string>;
322
414
  protected readonly selectedIndex: _angular_core.WritableSignal<number>;
323
- /** Parsed search term (before first separator) */
324
- protected readonly searchTerm: _angular_core.Signal<string>;
325
- /** Parsed arguments (after first separator) */
326
- protected readonly args: _angular_core.Signal<string>;
327
- /** Whether the query contains a separator (for display purposes) */
328
- protected readonly hasSeparator: _angular_core.Signal<boolean>;
329
- /** Parsed arguments as array */
330
- protected readonly argsArray: _angular_core.Signal<string[]>;
331
- /** Currently selected item */
415
+ protected readonly lockedAction: _angular_core.WritableSignal<GigamenuItem>;
416
+ protected readonly paramValues: _angular_core.WritableSignal<string[]>;
417
+ protected readonly autocompleteSuggestions: _angular_core.WritableSignal<AutocompleteOption[]>;
418
+ private autocompleteCache;
419
+ private readonly selectedParamOptions;
420
+ private readonly providerResults;
421
+ private providerTimers;
422
+ private providerGeneration;
423
+ private readonly queryParser;
332
424
  protected readonly selectedItem: _angular_core.Signal<GigamenuItem>;
333
- /** Whether the selected item can be executed (has all required params) */
334
- protected readonly canExecute: _angular_core.Signal<boolean>;
335
- /** Get color class for a parameter index */
336
- protected getParamColor(index: number): string;
425
+ protected readonly currentParamIndex: _angular_core.Signal<number>;
426
+ protected readonly currentParamName: _angular_core.Signal<string>;
427
+ protected readonly hasAutocomplete: _angular_core.Signal<boolean>;
428
+ protected readonly currentState: _angular_core.Signal<InputState>;
337
429
  protected readonly filteredItems: _angular_core.Signal<GigamenuItem[]>;
430
+ protected readonly displayItems: _angular_core.Signal<GigamenuItem[]>;
431
+ protected getParamColor: typeof getParamColor;
338
432
  constructor(service: GigamenuService, frecency: FrecencyService, platformId: object);
339
433
  onGlobalKeydown(event: KeyboardEvent): void;
340
434
  protected onInputKeydown(event: KeyboardEvent): void;
341
- private scrollSelectedIntoView;
435
+ private getActionsForState;
436
+ private dispatchAction;
342
437
  protected onQueryChange(event: Event): void;
343
438
  protected onBackdropClick(event: MouseEvent): void;
344
- protected executeItem(item: GigamenuItem): void;
345
- protected getItemContext(item: GigamenuItem, index: number): GigamenuItemContext;
346
- protected getEmptyContext(): GigamenuEmptyContext;
347
- protected getHeaderContext(): GigamenuHeaderContext;
348
- protected getFooterContext(): GigamenuFooterContext;
349
- protected getPanelContext(): GigamenuPanelContext;
439
+ protected onItemClick(item: GigamenuItem, index: number): void;
440
+ private executeItemWithArgs;
441
+ private selectSuggestion;
442
+ /**
443
+ * Build args array using values from selectedParamOptions when available.
444
+ * For each param, if a suggestion was selected, use its value; otherwise use the typed text.
445
+ */
446
+ private buildArgsWithValues;
447
+ protected getItemContext(item: GigamenuItem, index: number): _flxgde_gigamenu.GigamenuItemContext;
448
+ protected getEmptyContext(): _flxgde_gigamenu.GigamenuEmptyContext;
449
+ protected getFooterContext(): _flxgde_gigamenu.GigamenuFooterContext;
450
+ protected getHeaderContext(): {
451
+ $implicit: string;
452
+ query: string;
453
+ lockedAction: GigamenuItem;
454
+ paramValues: string[];
455
+ currentParamName: string;
456
+ placeholder: string;
457
+ onQueryChange: (value: string) => void;
458
+ onKeydown: (event: KeyboardEvent) => void;
459
+ onUnlockAction: () => void;
460
+ onGoToParam: (index: number) => void;
461
+ };
462
+ protected getPanelContext(): {
463
+ $implicit: GigamenuItem[];
464
+ items: GigamenuItem[];
465
+ query: string;
466
+ lockedAction: GigamenuItem;
467
+ paramValues: string[];
468
+ selectedIndex: number;
469
+ placeholder: string;
470
+ onItemClick: (item: GigamenuItem, index: number) => void;
471
+ onSelectIndex: (index: number) => void;
472
+ onQueryChange: (query: string) => void;
473
+ onClose: () => void;
474
+ };
475
+ private fetchSuggestions;
350
476
  private close;
351
- private sortByFrecency;
352
- private matchesQuery;
353
- private isInputFocused;
477
+ private clearProviderResults;
478
+ private normalizeProviderItems;
479
+ protected unlockActionFromUI(): void;
480
+ protected goToParam(index: number): void;
354
481
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<GigamenuComponent, never>;
355
482
  static ɵcmp: _angular_core.ɵɵComponentDeclaration<GigamenuComponent, "gm-gigamenu", never, {}, {}, ["itemTemplate", "emptyTemplate", "headerTemplate", "footerTemplate", "panelTemplate"], never, true, never>;
356
483
  }
357
484
 
358
485
  export { DEFAULT_CONFIG, FrecencyService, GigamenuComponent, GigamenuEmptyTemplate, GigamenuFooterTemplate, GigamenuHeaderTemplate, GigamenuItemTemplate, GigamenuPanelTemplate, GigamenuService, PARAM_COLORS, defineCommand };
359
- export type { CommandDefinition, DiscoverRoutesOptions, GigamenuCommand, GigamenuConfig, GigamenuEmptyContext, GigamenuFooterContext, GigamenuHeaderContext, GigamenuItem, GigamenuItemCategory, GigamenuItemContext, GigamenuPage, GigamenuPanelContext, MappedPage, RouteFilter, RouteInfo, RouteMapper };
486
+ export type { AutocompleteOption, CommandDefinition, DiscoverRoutesOptions, GigamenuCommand, GigamenuConfig, GigamenuEmptyContext, GigamenuFooterContext, GigamenuHeaderContext, GigamenuItem, GigamenuItemCategory, GigamenuItemContext, GigamenuPage, GigamenuPanelContext, GigamenuProvider, GigamenuProviderItem, GigamenuProviderOptions, MappedPage, ParamProvider, RouteFilter, RouteInfo, RouteMapper };