@ngneat/helipopper 13.1.1 → 13.1.2
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.
package/README.md
CHANGED
|
@@ -144,6 +144,73 @@ class MyComponent {
|
|
|
144
144
|
<button [tp]="MyComponent">Click Me</button>
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
+
### Use a Lazy Factory to Resolve a Component
|
|
148
|
+
|
|
149
|
+
Pass a factory function that returns a `Promise<Type<any>>` to defer loading the component until the tooltip is first shown. This is ideal for code-splitting — the component's chunk is only fetched on demand:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
@Component({})
|
|
153
|
+
class HostComponent {
|
|
154
|
+
lazyComponent = () => import('./heavy-popover.component').then(m => m.HeavyPopoverComponent);
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
```html
|
|
159
|
+
<button [tp]="lazyComponent" tpVariation="popper">Click Me</button>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The factory is called once; after the component resolves, subsequent shows reuse the already-loaded class.
|
|
163
|
+
|
|
164
|
+
`provideTippyLoader` accepts optional feature functions as additional arguments to control what happens while the lazy component is being fetched:
|
|
165
|
+
|
|
166
|
+
#### `withTippyLoaderComponent`
|
|
167
|
+
|
|
168
|
+
Renders a placeholder component inside the tooltip while the import is in flight:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
import { provideTippyLoader, withTippyLoaderComponent } from '@ngneat/helipopper/config';
|
|
172
|
+
|
|
173
|
+
bootstrapApplication(AppComponent, {
|
|
174
|
+
providers: [
|
|
175
|
+
provideTippyLoader(
|
|
176
|
+
() => import('tippy.js'),
|
|
177
|
+
withTippyLoaderComponent(SpinnerComponent),
|
|
178
|
+
),
|
|
179
|
+
],
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
`SpinnerComponent` is mounted as the tooltip content the moment the tooltip opens, then replaced by the resolved component once the import completes.
|
|
184
|
+
|
|
185
|
+
#### `withTippyLoaderTiming`
|
|
186
|
+
|
|
187
|
+
Controls the minimum time the loader is visible. The default is a synchronous observable (`of(undefined)`) that lets the swap happen as soon as the import resolves. Pass a factory — with full DI support — to impose a minimum display duration:
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
import { provideTippyLoader, withTippyLoaderTiming } from '@ngneat/helipopper/config';
|
|
191
|
+
import { inject } from '@angular/core';
|
|
192
|
+
|
|
193
|
+
bootstrapApplication(AppComponent, {
|
|
194
|
+
providers: [
|
|
195
|
+
provideTippyLoader(
|
|
196
|
+
() => import('tippy.js'),
|
|
197
|
+
withTippyLoaderComponent(SpinnerComponent),
|
|
198
|
+
withTippyLoaderTiming(() => {
|
|
199
|
+
const scheduler = inject(Scheduler);
|
|
200
|
+
return new Observable(subscriber => {
|
|
201
|
+
scheduler.schedule(() => {
|
|
202
|
+
subscriber.next();
|
|
203
|
+
subscriber.complete();
|
|
204
|
+
}, 300);
|
|
205
|
+
});
|
|
206
|
+
}),
|
|
207
|
+
),
|
|
208
|
+
],
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
The tooltip swaps the loader for the real component only when **both** the import has resolved and the timing observable has emitted — so the spinner is guaranteed to be visible for at least the configured duration regardless of how fast the import finishes.
|
|
213
|
+
|
|
147
214
|
### Component Bindings
|
|
148
215
|
|
|
149
216
|
Pass reactive Angular bindings (`inputBinding`, `outputBinding`, `twoWayBinding`) to a dynamically created component using the `tpBindings` input:
|
|
@@ -306,7 +373,7 @@ live [here](https://ngneat.github.io/helipopper/).
|
|
|
306
373
|
### Inputs
|
|
307
374
|
|
|
308
375
|
```ts
|
|
309
|
-
tp: string | TemplateRef<any> | Type<any> | undefined | null;
|
|
376
|
+
tp: string | TemplateRef<any> | Type<any> | (() => Promise<Type<any>>) | undefined | null;
|
|
310
377
|
tpAppendTo: TippyProps['appendTo'];
|
|
311
378
|
tpDelay: TippyProps['delay'];
|
|
312
379
|
tpDuration: TippyProps['duration'];
|
|
@@ -32,19 +32,14 @@ const TIPPY_CONFIG = new InjectionToken(ngDevMode ? 'TIPPY_CONFIG' : '');
|
|
|
32
32
|
const TIPPY_LOADER_COMPONENT = new InjectionToken(ngDevMode ? 'TIPPY_LOADER_COMPONENT' : '');
|
|
33
33
|
const TIPPY_LOADER_TIMING = new InjectionToken(ngDevMode ? 'TIPPY_LOADER_TIMING' : '', { factory: () => of(undefined) });
|
|
34
34
|
|
|
35
|
-
function provideTippyLoader(loader) {
|
|
36
|
-
return makeEnvironmentProviders([
|
|
35
|
+
function provideTippyLoader(loader, ...features) {
|
|
36
|
+
return makeEnvironmentProviders([
|
|
37
|
+
{ provide: TIPPY_LOADER, useValue: loader },
|
|
38
|
+
...features,
|
|
39
|
+
]);
|
|
37
40
|
}
|
|
38
|
-
function provideTippyConfig(config
|
|
39
|
-
|
|
40
|
-
return makeEnvironmentProviders([
|
|
41
|
-
{ provide: TIPPY_CONFIG, useValue: config },
|
|
42
|
-
...features,
|
|
43
|
-
]);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
return { provide: TIPPY_CONFIG, useValue: config };
|
|
47
|
-
}
|
|
41
|
+
function provideTippyConfig(config) {
|
|
42
|
+
return { provide: TIPPY_CONFIG, useValue: config };
|
|
48
43
|
}
|
|
49
44
|
function withTippyLoaderComponent(component) {
|
|
50
45
|
return makeEnvironmentProviders([
|
|
@@ -52,7 +47,7 @@ function withTippyLoaderComponent(component) {
|
|
|
52
47
|
]);
|
|
53
48
|
}
|
|
54
49
|
function withTippyLoaderTiming(timing) {
|
|
55
|
-
return makeEnvironmentProviders([{ provide: TIPPY_LOADER_TIMING,
|
|
50
|
+
return makeEnvironmentProviders([{ provide: TIPPY_LOADER_TIMING, useFactory: timing }]);
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngneat-helipopper-config.mjs","sources":["../../../../projects/ngneat/helipopper/config/src/defaults.ts","../../../../projects/ngneat/helipopper/config/src/tippy.types.ts","../../../../projects/ngneat/helipopper/config/src/providers.ts","../../../../projects/ngneat/helipopper/config/src/ngneat-helipopper-config.ts"],"sourcesContent":["import type { TippyProps, VariationConfig } from './tippy.types';\n\n// A variation is a set of predefined tippy properties.\ntype Variation = Partial<TippyProps>;\n\nexport const tooltipVariation: Variation = {\n theme: undefined,\n arrow: false,\n animation: 'scale',\n trigger: 'mouseenter focus',\n offset: [0, 5],\n};\n\nexport const popperVariation: Variation = {\n theme: 'light',\n arrow: true,\n offset: [0, 10],\n animation: undefined,\n trigger: 'click',\n interactive: true,\n};\n\nexport function withContextMenuVariation(baseVariation: Variation): VariationConfig {\n return {\n ...baseVariation,\n placement: 'right-start',\n trigger: 'manual',\n arrow: false,\n offset: [0, 0],\n isContextMenu: true, // signals the directive to attach the right-click listener\n };\n}\n","import type tippy from 'tippy.js';\nimport type { Instance, Props } from 'tippy.js';\nimport { ElementRef, InjectionToken, Type } from '@angular/core';\nimport { Observable, of } from 'rxjs';\nimport type { Content, ResolveViewRef, ViewOptions } from '@ngneat/overview';\n\nexport interface CreateOptions extends Partial<TippyProps>, ViewOptions {\n variation: string;\n preserveView: boolean;\n className: string | string[];\n data: any;\n}\n\nexport interface TippyInstance extends Instance {\n data?: any;\n}\n\nexport type TippyProps = Props;\n\n// Extends tippy props with isContextMenu so any named variation (not just one\n// called 'contextMenu') can opt into right-click listener behaviour.\nexport type VariationConfig = Partial<TippyProps> & { isContextMenu?: boolean };\n\nexport interface ExtendedTippyProps extends TippyProps {\n variations: Record<string, VariationConfig>;\n defaultVariation: keyof ExtendedTippyProps['variations'];\n beforeRender?: (text: string) => string;\n zIndexGetter?(): number;\n}\n\nexport type TippyElement = ElementRef | Element;\n\nexport interface ExtendedTippyInstance<T> extends TippyInstance {\n view: ResolveViewRef<T> | null;\n $viewOptions: ViewOptions;\n context?: ViewOptions['context'];\n}\n\nexport type TippyConfig = Partial<ExtendedTippyProps>;\n\nexport type TippyContent = Content | (() => Promise<Type<any>>);\n\nexport type TippyLoader = () => typeof tippy | Promise<{ default: typeof tippy }>;\n\nexport const TIPPY_LOADER = new InjectionToken<TippyLoader>(\n ngDevMode ? 'TIPPY_LOADER' : '',\n);\n\nexport const TIPPY_CONFIG = new InjectionToken<TippyConfig>(\n ngDevMode ? 'TIPPY_CONFIG' : '',\n);\n\nexport const TIPPY_LOADER_COMPONENT = new InjectionToken<Type<unknown>>(\n ngDevMode ? 'TIPPY_LOADER_COMPONENT' : '',\n);\n\nexport type TippyLoaderTiming = Observable<void>;\n\nexport const TIPPY_LOADER_TIMING = new InjectionToken<TippyLoaderTiming>(\n ngDevMode ? 'TIPPY_LOADER_TIMING' : '',\n { factory: () => of(undefined) },\n);\n","import {\n EnvironmentProviders,\n makeEnvironmentProviders,\n Provider,\n Type,\n} from '@angular/core';\n\nimport {\n TIPPY_CONFIG,\n TIPPY_LOADER,\n TIPPY_LOADER_COMPONENT,\n TIPPY_LOADER_TIMING,\n type TippyLoader,\n type TippyConfig,\n type TippyLoaderTiming,\n} from './tippy.types';\n\nexport function provideTippyLoader(
|
|
1
|
+
{"version":3,"file":"ngneat-helipopper-config.mjs","sources":["../../../../projects/ngneat/helipopper/config/src/defaults.ts","../../../../projects/ngneat/helipopper/config/src/tippy.types.ts","../../../../projects/ngneat/helipopper/config/src/providers.ts","../../../../projects/ngneat/helipopper/config/src/ngneat-helipopper-config.ts"],"sourcesContent":["import type { TippyProps, VariationConfig } from './tippy.types';\n\n// A variation is a set of predefined tippy properties.\ntype Variation = Partial<TippyProps>;\n\nexport const tooltipVariation: Variation = {\n theme: undefined,\n arrow: false,\n animation: 'scale',\n trigger: 'mouseenter focus',\n offset: [0, 5],\n};\n\nexport const popperVariation: Variation = {\n theme: 'light',\n arrow: true,\n offset: [0, 10],\n animation: undefined,\n trigger: 'click',\n interactive: true,\n};\n\nexport function withContextMenuVariation(baseVariation: Variation): VariationConfig {\n return {\n ...baseVariation,\n placement: 'right-start',\n trigger: 'manual',\n arrow: false,\n offset: [0, 0],\n isContextMenu: true, // signals the directive to attach the right-click listener\n };\n}\n","import type tippy from 'tippy.js';\nimport type { Instance, Props } from 'tippy.js';\nimport { ElementRef, InjectionToken, Type } from '@angular/core';\nimport { Observable, of } from 'rxjs';\nimport type { Content, ResolveViewRef, ViewOptions } from '@ngneat/overview';\n\nexport interface CreateOptions extends Partial<TippyProps>, ViewOptions {\n variation: string;\n preserveView: boolean;\n className: string | string[];\n data: any;\n}\n\nexport interface TippyInstance extends Instance {\n data?: any;\n}\n\nexport type TippyProps = Props;\n\n// Extends tippy props with isContextMenu so any named variation (not just one\n// called 'contextMenu') can opt into right-click listener behaviour.\nexport type VariationConfig = Partial<TippyProps> & { isContextMenu?: boolean };\n\nexport interface ExtendedTippyProps extends TippyProps {\n variations: Record<string, VariationConfig>;\n defaultVariation: keyof ExtendedTippyProps['variations'];\n beforeRender?: (text: string) => string;\n zIndexGetter?(): number;\n}\n\nexport type TippyElement = ElementRef | Element;\n\nexport interface ExtendedTippyInstance<T> extends TippyInstance {\n view: ResolveViewRef<T> | null;\n $viewOptions: ViewOptions;\n context?: ViewOptions['context'];\n}\n\nexport type TippyConfig = Partial<ExtendedTippyProps>;\n\nexport type TippyContent = Content | (() => Promise<Type<any>>);\n\nexport type TippyLoader = () => typeof tippy | Promise<{ default: typeof tippy }>;\n\nexport const TIPPY_LOADER = new InjectionToken<TippyLoader>(\n ngDevMode ? 'TIPPY_LOADER' : '',\n);\n\nexport const TIPPY_CONFIG = new InjectionToken<TippyConfig>(\n ngDevMode ? 'TIPPY_CONFIG' : '',\n);\n\nexport const TIPPY_LOADER_COMPONENT = new InjectionToken<Type<unknown>>(\n ngDevMode ? 'TIPPY_LOADER_COMPONENT' : '',\n);\n\nexport type TippyLoaderTiming = Observable<void>;\n\nexport const TIPPY_LOADER_TIMING = new InjectionToken<TippyLoaderTiming>(\n ngDevMode ? 'TIPPY_LOADER_TIMING' : '',\n { factory: () => of(undefined) },\n);\n","import {\n EnvironmentProviders,\n makeEnvironmentProviders,\n Provider,\n Type,\n} from '@angular/core';\n\nimport {\n TIPPY_CONFIG,\n TIPPY_LOADER,\n TIPPY_LOADER_COMPONENT,\n TIPPY_LOADER_TIMING,\n type TippyLoader,\n type TippyConfig,\n type TippyLoaderTiming,\n} from './tippy.types';\n\nexport function provideTippyLoader(\n loader: TippyLoader,\n ...features: EnvironmentProviders[]\n) {\n return makeEnvironmentProviders([\n { provide: TIPPY_LOADER, useValue: loader },\n ...features,\n ]);\n}\n\nexport function provideTippyConfig(config: TippyConfig): Provider {\n return { provide: TIPPY_CONFIG, useValue: config };\n}\n\nexport function withTippyLoaderComponent(component: Type<unknown>): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: TIPPY_LOADER_COMPONENT, useValue: component },\n ]);\n}\n\nexport function withTippyLoaderTiming(\n timing: () => TippyLoaderTiming,\n): EnvironmentProviders {\n return makeEnvironmentProviders([{ provide: TIPPY_LOADER_TIMING, useFactory: timing }]);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAKO,MAAM,gBAAgB,GAAc;AACzC,IAAA,KAAK,EAAE,SAAS;AAChB,IAAA,KAAK,EAAE,KAAK;AACZ,IAAA,SAAS,EAAE,OAAO;AAClB,IAAA,OAAO,EAAE,kBAAkB;AAC3B,IAAA,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;;AAGT,MAAM,eAAe,GAAc;AACxC,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,KAAK,EAAE,IAAI;AACX,IAAA,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;AACf,IAAA,SAAS,EAAE,SAAS;AACpB,IAAA,OAAO,EAAE,OAAO;AAChB,IAAA,WAAW,EAAE,IAAI;;AAGb,SAAU,wBAAwB,CAAC,aAAwB,EAAA;IAC/D,OAAO;AACL,QAAA,GAAG,aAAa;AAChB,QAAA,SAAS,EAAE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tooltipVariation: Variation;
|
|
|
44
44
|
declare const popperVariation: Variation;
|
|
45
45
|
declare function withContextMenuVariation(baseVariation: Variation): VariationConfig;
|
|
46
46
|
|
|
47
|
-
declare function provideTippyLoader(loader: TippyLoader): EnvironmentProviders;
|
|
47
|
+
declare function provideTippyLoader(loader: TippyLoader, ...features: EnvironmentProviders[]): EnvironmentProviders;
|
|
48
48
|
declare function provideTippyConfig(config: TippyConfig): Provider;
|
|
49
|
-
declare function provideTippyConfig(config: TippyConfig, ...features: EnvironmentProviders[]): EnvironmentProviders;
|
|
50
49
|
declare function withTippyLoaderComponent(component: Type<unknown>): EnvironmentProviders;
|
|
51
|
-
declare function withTippyLoaderTiming(timing: TippyLoaderTiming): EnvironmentProviders;
|
|
50
|
+
declare function withTippyLoaderTiming(timing: () => TippyLoaderTiming): EnvironmentProviders;
|
|
52
51
|
|
|
53
52
|
export { TIPPY_CONFIG, TIPPY_LOADER, TIPPY_LOADER_COMPONENT, TIPPY_LOADER_TIMING, popperVariation, provideTippyConfig, provideTippyLoader, tooltipVariation, withContextMenuVariation, withTippyLoaderComponent, withTippyLoaderTiming };
|
|
54
53
|
export type { CreateOptions, ExtendedTippyInstance, ExtendedTippyProps, TippyConfig, TippyContent, TippyElement, TippyInstance, TippyLoader, TippyLoaderTiming, TippyProps, VariationConfig };
|