Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions projects/ngneat/helipopper/config/src/tippy.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type tippy from 'tippy.js';
import type { Instance, Props } from 'tippy.js';
import { ElementRef, InjectionToken } from '@angular/core';
import { ElementRef, InjectionToken, isDevMode } from '@angular/core';
import type { ResolveViewRef, ViewOptions } from '@ngneat/overview';

export interface CreateOptions extends Partial<TippyProps>, ViewOptions {
Expand Down Expand Up @@ -36,17 +36,9 @@ export type TippyConfig = Partial<ExtendedTippyProps>;
export type TippyLoader = () => typeof tippy | Promise<{ default: typeof tippy }>;

export const TIPPY_LOADER = new InjectionToken<TippyLoader>(
typeof ngDevMode !== 'undefined' && ngDevMode ? 'TIPPY_LOADER' : ''
isDevMode() ? 'TIPPY_LOADER' : ''
);

export const TIPPY_CONFIG = new InjectionToken<TippyConfig>(
typeof ngDevMode !== 'undefined' && ngDevMode ? 'TIPPY_CONFIG' : ''
isDevMode() ? 'TIPPY_CONFIG' : ''
);

/** @internal */
declare global {
// Indicates whether the application is operating in development mode.
// `ngDevMode` is a global flag set by Angular CLI.
// https://github.com/angular/angular-cli/blob/9b883fe28862c96720c7899b431174e9b47ad7e4/packages/angular/build/src/tools/esbuild/application-code-bundle.ts#L604
const ngDevMode: boolean;
}
6 changes: 3 additions & 3 deletions projects/ngneat/helipopper/src/lib/inject-tippy.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { inject, InjectionToken } from '@angular/core';
import { inject, InjectionToken, isDevMode } from '@angular/core';
import type { TippyInstance } from '@ngneat/helipopper/config';

import { TippyErrorCode } from './utils';

export const TIPPY_REF = /* @__PURE__ */ new InjectionToken<TippyInstance>(
typeof ngDevMode !== 'undefined' && ngDevMode ? 'TIPPY_REF' : ''
isDevMode() ? 'TIPPY_REF' : ''
);

export function injectTippyRef(): TippyInstance {
const instance = inject(TIPPY_REF, { optional: true });

if (!instance) {
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
if (isDevMode()) {
throw new Error(
'tp is not provided in the current context or on one of its ancestors'
);
Expand Down