diff --git a/projects/ngneat/helipopper/config/src/inject-tippy.ts b/projects/ngneat/helipopper/config/src/inject-tippy.ts index 0d52140..5c4354b 100644 --- a/projects/ngneat/helipopper/config/src/inject-tippy.ts +++ b/projects/ngneat/helipopper/config/src/inject-tippy.ts @@ -1,13 +1,19 @@ import { inject } from '@angular/core'; -import { TIPPY_REF, type TippyInstance } from './tippy.types'; +import { TIPPY_REF, TippyErrorCode, type TippyInstance } from './tippy.types'; export function injectTippyRef(): TippyInstance { const instance = inject(TIPPY_REF, { optional: true }); - if (instance) { - return instance; + if (!instance) { + if (typeof ngDevMode !== 'undefined' && ngDevMode) { + throw new Error( + 'tp is not provided in the current context or on one of its ancestors' + ); + } else { + throw new Error(`[tp]: ${TippyErrorCode.TippyNotProvided}`); + } } - throw new Error('tp is not provided in the current context or on one of its ancestors'); + return instance; } diff --git a/projects/ngneat/helipopper/config/src/tippy.types.ts b/projects/ngneat/helipopper/config/src/tippy.types.ts index 7e9df03..d32da24 100644 --- a/projects/ngneat/helipopper/config/src/tippy.types.ts +++ b/projects/ngneat/helipopper/config/src/tippy.types.ts @@ -3,6 +3,10 @@ import type { Instance, Props } from 'tippy.js'; import { ElementRef, InjectionToken } from '@angular/core'; import type { ResolveViewRef, ViewOptions } from '@ngneat/overview'; +export const enum TippyErrorCode { + TippyNotProvided = 1, +} + export interface CreateOptions extends Partial, ViewOptions { variation: string; preserveView: boolean; @@ -35,8 +39,22 @@ export type TippyConfig = Partial; export type TippyLoader = () => typeof tippy | Promise<{ default: typeof tippy }>; -export const TIPPY_LOADER = new InjectionToken('TIPPY_LOADER'); +export const TIPPY_LOADER = new InjectionToken( + typeof ngDevMode !== 'undefined' && ngDevMode ? 'TIPPY_LOADER' : '' +); -export const TIPPY_REF = /* @__PURE__ */ new InjectionToken('TIPPY_REF'); +export const TIPPY_REF = /* @__PURE__ */ new InjectionToken( + typeof ngDevMode !== 'undefined' && ngDevMode ? 'TIPPY_REF' : '' +); -export const TIPPY_CONFIG = new InjectionToken('Tippy config'); +export const TIPPY_CONFIG = new InjectionToken( + typeof ngDevMode !== 'undefined' && ngDevMode ? '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; +}