Skip to content

Commit bd1a495

Browse files
committed
View scroll types
1 parent 8fe87e2 commit bd1a495

File tree

22 files changed

+117
-75
lines changed

22 files changed

+117
-75
lines changed

@types/core/controller/controller.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function identifierForController(controller: any, ident: any): any;
1+
export function identifierForController(controller: any, ident: any): string;
22
/**
33
* The {@link ng.$controller $controller service} is used by AngularTS to create new
44
* controllers.

@types/directive/include/include.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
22
*
33
* @param {ng.TemplateRequestService} $templateRequest
4-
* @param {import("../../services/anchor-scroll/anchor-scroll.js").AnchorScrollFunction} $anchorScroll
4+
* @param {ng.AnchorScrollService} $anchorScroll
55
* @param {ng.AnimateService} $animate
66
* @param {ng.ExceptionHandlerService} $exceptionHandler
77
* @returns {ng.Directive}
88
*/
99
export function ngIncludeDirective(
1010
$templateRequest: ng.TemplateRequestService,
11-
$anchorScroll: import("../../services/anchor-scroll/anchor-scroll.js").AnchorScrollFunction,
11+
$anchorScroll: ng.AnchorScrollService,
1212
$animate: ng.AnimateService,
1313
$exceptionHandler: ng.ExceptionHandlerService,
1414
): ng.Directive;

@types/namespace.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import {
88
} from "./core/scope/interface.ts";
99
import { NgModule as TNgModule } from "./core/di/ng-module/ng-module.js";
1010
import { InjectorService as TInjectorService } from "./core/di/internal-injector.js";
11+
import { AnchorScrollProvider as TAnchorScrollProvider } from "./services/anchor-scroll/anchor-scroll.js";
1112
import {
12-
AnchorScrollProvider as TAnchorScrollProvider,
13+
AnchorScrollFunction as TAnchorScrollFunction,
1314
AnchorScrollService as TAnchorScrollService,
14-
} from "./services/anchor-scroll/anchor-scroll.js";
15+
AnchorScrollObject as TAnchorScrollObject,
16+
} from "./services/anchor-scroll/interface.ts";
1517
import { ControllerService as TControllerService } from "./core/controller/interface.ts";
1618
import { ExceptionHandler as TExceptionHandler } from "./services/exception/interface.ts";
1719
import { ParseService as TParseService } from "./core/parse/interface.ts";
@@ -101,6 +103,7 @@ import {
101103
} from "./router/state/interface.ts";
102104
import { StateObject as TStateObject } from "./router/state/state-object.js";
103105
import { StateRegistryProvider as TStateRegistryProvider } from "./router/state/state-registry.js";
106+
import { IViewScrollService } from "./router/scroll/interface.ts";
104107
declare global {
105108
interface Function {
106109
$inject?: readonly string[] | undefined;
@@ -165,6 +168,7 @@ declare global {
165168
type TemplateRequestService = TTemplateRequestService;
166169
type UrlService = TUrlService;
167170
type ViewService = TViewService;
171+
type ViewScrollService = IViewScrollService;
168172
type ErrorHandlingConfig = TErrorHandlingConfig;
169173
type ListenerFn = TListenerFn;
170174
type Listener = TListener;
@@ -193,5 +197,7 @@ declare global {
193197
type StateDeclaration = TStateDeclaration;
194198
type BuiltStateDeclaration = TBuiltStateDeclaration;
195199
type StateObject = TStateObject;
200+
type AnchorScrollFunction = TAnchorScrollFunction;
201+
type AnchorScrollObject = TAnchorScrollObject;
196202
}
197203
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type IViewScrollService =
2+
| ng.AnchorScrollService
3+
| ((el: Element) => void | Promise<void>);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export class ViewScrollProvider {
2+
enabled: boolean;
3+
useAnchorScroll(): void;
4+
$get: (
5+
| string
6+
| (($anchorScroll: ng.AnchorScrollObject) => ng.ViewScrollService)
7+
)[];
8+
}

@types/router/view-scroll.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
/**
2-
* @typedef {Object} AnchorScrollObject
3-
* @property {number|function|Element} yOffset
4-
*/
5-
/**
6-
* @typedef {(string) => void} AnchorScrollFunction
7-
*/
8-
/**
9-
* @typedef {AnchorScrollFunction | AnchorScrollObject} AnchorScrollService
10-
*/
111
export class AnchorScrollProvider {
122
autoScrollingEnabled: boolean;
133
$get: (
144
| string
155
| ((
16-
$location: import("../../services/location/location.js").Location,
6+
$location: ng.LocationService,
177
$rootScope: ng.Scope,
18-
) => AnchorScrollFunction)
8+
) => import("./interface.ts").AnchorScrollFunction)
199
)[];
2010
}
21-
export type AnchorScrollObject = {
22-
yOffset: number | Function | Element;
23-
};
24-
export type AnchorScrollFunction = (string: any) => void;
25-
export type AnchorScrollService = AnchorScrollFunction | AnchorScrollObject;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export interface AnchorScrollObject {
2+
/**
3+
* Vertical scroll offset.
4+
* Can be a number, a function returning a number,
5+
* or an Element whose offsetTop will be used.
6+
*/
7+
yOffset?: number | (() => number) | Element;
8+
}
9+
export type AnchorScrollFunction = (hash?: string) => void;
10+
/**
11+
* AngularJS $anchorScroll service
12+
*
13+
* Callable as a function and also exposes properties.
14+
*/
15+
export type AnchorScrollService = AnchorScrollFunction | AnchorScrollObject;

@types/shared/utils.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ export function isBlankObject(value: any): boolean;
9191
/**
9292
* Determines if a reference is a `string`.
9393
*
94-
* @template T
95-
* @param {T} value - The value to check.
96-
* @returns {value is T & string} True if `value` is a string.
94+
* @param value - The value to check.
95+
* @returns {value is string} True if `value` is a string.
9796
*/
98-
export function isString<T>(value: T): value is T & string;
97+
export function isString(value: any): value is string;
9998
/**
10099
* Determines if a reference is a null.
101100
*

src/directive/include/include.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ngIncludeDirective.$inject = [
1111
/**
1212
*
1313
* @param {ng.TemplateRequestService} $templateRequest
14-
* @param {import("../../services/anchor-scroll/anchor-scroll.js").AnchorScrollFunction} $anchorScroll
14+
* @param {ng.AnchorScrollService} $anchorScroll
1515
* @param {ng.AnimateService} $animate
1616
* @param {ng.ExceptionHandlerService} $exceptionHandler
1717
* @returns {ng.Directive}
@@ -42,7 +42,7 @@ export function ngIncludeDirective(
4242
isDefined(autoScrollExp) &&
4343
(!autoScrollExp || scope.$eval(autoScrollExp))
4444
) {
45-
$anchorScroll();
45+
/** @type {ng.AnchorScrollFunction} */ ($anchorScroll)();
4646
}
4747
}
4848

0 commit comments

Comments
 (0)