Skip to content

Commit fa750ab

Browse files
committed
Type fixes on transclude
1 parent a3e5f79 commit fa750ab

File tree

14 files changed

+140
-37
lines changed

14 files changed

+140
-37
lines changed

@types/core/compile/inteface.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { Scope } from "../scope/scope.js";
22
import type { NodeRef } from "../../shared/noderef.js";
3+
type TranscludedNodes = Node | Node[] | NodeList | null;
4+
type TranscludeFnCb = (clone?: TranscludedNodes, scope?: Scope | null) => void;
35
/**
46
* A function passed as the fifth argument to a `PublicLinkFn` link function.
57
* It behaves like a linking function, with the `scope` argument automatically created
@@ -8,7 +10,8 @@ import type { NodeRef } from "../../shared/noderef.js";
810
* The function returns the DOM content to be injected (transcluded) into the directive.
911
*/
1012
export type TranscludeFn = {
11-
(clone?: Element | Node | ChildNode | NodeList | Node[], scope?: Scope): void;
13+
(cb: TranscludeFnCb): void;
14+
(scope: Scope, cb?: TranscludeFnCb): void;
1215
$$slots?: any;
1316
};
1417
/**
@@ -84,3 +87,4 @@ export type CompositeLinkFn = (
8487
$linkNode: NodeRef,
8588
parentBoundTranscludeFn?: Function,
8689
) => void;
90+
export {};

@types/directive/form/form.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ export function setupValidity(instance: any): void;
44
* $nonscope: boolean,
55
* $addControl: Function,
66
* $getControls: () => any[],
7-
* $$renameControl: Function,
7+
* _renameControl: Function,
88
* $removeControl: Function,
99
* $setValidity: Function | ((key: any, isValid: boolean, control: any) => any),
1010
* $setDirty: Function,
1111
* $setPristine: Function,
1212
* $setSubmitted: Function,
13-
* $$setSubmitted: Function
13+
* _setSubmitted: Function
1414
* }}
1515
*/
1616
export const nullFormCtrl: {
1717
$nonscope: boolean;
1818
$addControl: Function;
1919
$getControls: () => any[];
20-
$$renameControl: Function;
20+
_renameControl: Function;
2121
$removeControl: Function;
2222
$setValidity: Function | ((key: any, isValid: boolean, control: any) => any);
2323
$setDirty: Function;
2424
$setPristine: Function;
2525
$setSubmitted: Function;
26-
$$setSubmitted: Function;
26+
_setSubmitted: Function;
2727
};
2828
export const PENDING_CLASS: "ng-pending";
2929
/**
@@ -158,7 +158,7 @@ export class FormController {
158158
* @returns {ReadonlyArray<FormController>}
159159
*/
160160
$getControls(): ReadonlyArray<FormController>;
161-
$$renameControl(control: any, newName: any): void;
161+
_renameControl(control: any, newName: any): void;
162162
/**
163163
* Deregister a control from the form.
164164
*
@@ -206,7 +206,7 @@ export class FormController {
206206
* parent forms of the form.
207207
*/
208208
$setSubmitted(): void;
209-
$$setSubmitted(): void;
209+
_setSubmitted(): void;
210210
set(object: any, property: any, controller: any): void;
211211
unset(object: any, property: any, controller: any): void;
212212
/**

@types/directive/model/model.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ export class NgModelController {
102102
$nonscope: boolean;
103103
$addControl: Function;
104104
$getControls: () => any[];
105-
$$renameControl: Function;
105+
_renameControl: Function;
106106
$removeControl: Function;
107107
$setValidity:
108108
| Function
109109
| ((key: any, isValid: boolean, control: any) => any);
110110
$setDirty: Function;
111111
$setPristine: Function;
112112
$setSubmitted: Function;
113-
$$setSubmitted: Function;
113+
_setSubmitted: Function;
114114
};
115115
$options: {
116116
$$options: import("../model-options/model-options.js").ModelOptionsConfig;

@types/shared/common.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ export function applyPairs(memo: any, keyValTuple: any): any;
113113
/**
114114
* Returns the last element of an array, or undefined if the array is empty.
115115
* @template T
116-
* @param {string} arr - The input array.
116+
* @param {any[]|string} arr - The input array.
117117
* @returns {T | undefined} The last element or undefined.
118118
*/
119-
export function tail<T>(arr: string): T | undefined;
119+
export function tail<T>(arr: any[] | string): T | undefined;
120120
/**
121121
* shallow copy from src to dest
122122
*/

@types/shared/dom.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export function emptyElement(element: Element): void;
202202
* @param {HTMLElement | Element} parentElement
203203
* The parent element that will receive the inserted element.
204204
*
205-
* @param {HTMLElement | Element | null} [afterElement]
205+
* @param {ChildNode | Element | null} [afterElement]
206206
* An optional sibling element — if present and valid, `element`
207207
* will be inserted after it. If omitted or invalid, `element`
208208
* is prepended to `parentElement`.
@@ -212,17 +212,17 @@ export function emptyElement(element: Element): void;
212212
export function domInsert(
213213
element: HTMLElement | Element,
214214
parentElement: HTMLElement | Element,
215-
afterElement?: HTMLElement | Element | null,
215+
afterElement?: ChildNode | Element | null,
216216
): void;
217217
/**
218218
* @param {HTMLElement} element
219219
* @param {HTMLElement} parent
220-
* @param {HTMLElement | null | undefined} after
220+
* @param {ChildNode | null | undefined} after
221221
*/
222222
export function animatedomInsert(
223223
element: HTMLElement,
224224
parent: HTMLElement,
225-
after: HTMLElement | null | undefined,
225+
after: ChildNode | null | undefined,
226226
): void;
227227
/**
228228
* Returns the base href of the document.

src/animations/animate.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import {
22
extend,
33
hasAnimate,
44
isFunction,
5+
isIntanceOf,
56
isObject,
67
mergeClasses,
78
minErr,
89
} from "../shared/utils.js";
9-
import { animatedomInsert, removeElement } from "../shared/dom.js";
10+
import { animatedomInsert, domInsert, removeElement } from "../shared/dom.js";
1011
import { NG_ANIMATE_CLASSNAME } from "./shared.js";
1112
import { $injectTokens } from "../injection-tokens.js";
1213

@@ -334,13 +335,21 @@ export function AnimateProvider($provide) {
334335
*
335336
* @param {Element} element - the element which will be inserted into the DOM
336337
* @param {Element} parent - the parent element which will append the element as a child (so long as the after element is not present)
337-
* @param {Element} [after] - after the sibling element after which the element will be appended
338+
* @param {ChildNode | null | undefined} [after] - after the sibling element after which the element will be appended
338339
* @param {import("./interface.ts").AnimationOptions} [options] - an optional collection of options/styles that will be applied to the element.
339340
* @returns {import('./runner/animate-runner.js').AnimateRunner} the animation runner
340341
*/
341342
enter(element, parent, after, options) {
342343
parent = parent || after.parentElement;
343-
animatedomInsert(element, parent, after);
344+
345+
if (
346+
isIntanceOf(element, HTMLElement) &&
347+
isIntanceOf(parent, HTMLElement)
348+
) {
349+
animatedomInsert(element, parent, after);
350+
} else {
351+
domInsert(element, parent, after);
352+
}
344353

345354
return $$animateQueue.push(
346355
element,
@@ -363,7 +372,15 @@ export function AnimateProvider($provide) {
363372
*/
364373
move(element, parent, after, options) {
365374
parent = parent || after.parentElement;
366-
animatedomInsert(element, parent, after);
375+
376+
if (
377+
isIntanceOf(element, HTMLElement) &&
378+
isIntanceOf(parent, HTMLElement)
379+
) {
380+
animatedomInsert(element, parent, after);
381+
} else {
382+
domInsert(element, parent, after);
383+
}
367384

368385
return $$animateQueue.push(
369386
element,

src/core/compile/inteface.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { Scope } from "../scope/scope.js";
22
import type { NodeRef } from "../../shared/noderef.js";
33

4+
type TranscludedNodes = Node | Node[] | NodeList | null;
5+
type TranscludeFnCb = (clone?: TranscludedNodes, scope?: Scope | null) => void;
6+
47
/**
58
* A function passed as the fifth argument to a `PublicLinkFn` link function.
69
* It behaves like a linking function, with the `scope` argument automatically created
@@ -9,7 +12,8 @@ import type { NodeRef } from "../../shared/noderef.js";
912
* The function returns the DOM content to be injected (transcluded) into the directive.
1013
*/
1114
export type TranscludeFn = {
12-
(clone?: Element | Node | ChildNode | NodeList | Node[], scope?: Scope): void;
15+
(cb: TranscludeFnCb): void;
16+
(scope: Scope, cb?: TranscludeFnCb): void;
1317
$$slots?: any;
1418
};
1519

src/directive/form/form.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import {
2222
* $nonscope: boolean,
2323
* $addControl: Function,
2424
* $getControls: () => any[],
25-
* $$renameControl: Function,
25+
* _renameControl: Function,
2626
* $removeControl: Function,
2727
* $setValidity: Function | ((key: any, isValid: boolean, control: any) => any),
2828
* $setDirty: Function,
2929
* $setPristine: Function,
3030
* $setSubmitted: Function,
31-
* $$setSubmitted: Function
31+
* _setSubmitted: Function
3232
* }}
3333
*/
3434
export const nullFormCtrl = {
@@ -37,7 +37,7 @@ export const nullFormCtrl = {
3737
/* empty */
3838
},
3939
$getControls: () => [],
40-
$$renameControl: (control, name) => {
40+
_renameControl: (control, name) => {
4141
control.$name = name;
4242
},
4343
$removeControl: () => {
@@ -55,7 +55,7 @@ export const nullFormCtrl = {
5555
$setSubmitted: () => {
5656
/* empty */
5757
},
58-
$$setSubmitted: () => {
58+
_setSubmitted: () => {
5959
/* empty */
6060
},
6161
};
@@ -233,7 +233,7 @@ export class FormController {
233233
}
234234

235235
// Private API: rename a form control
236-
$$renameControl(control, newName) {
236+
_renameControl(control, newName) {
237237
const oldName = control.$name;
238238

239239
if (this[oldName] === control) {
@@ -355,19 +355,19 @@ export class FormController {
355355
while (rootForm.$$parentForm && rootForm.$$parentForm !== nullFormCtrl) {
356356
rootForm = rootForm.$$parentForm;
357357
}
358-
rootForm.$$setSubmitted();
358+
rootForm._setSubmitted();
359359
}
360360

361-
$$setSubmitted() {
361+
_setSubmitted() {
362362
if (hasAnimate(this.$$element)) {
363363
this.$$animate.addClass(this.$$element, SUBMITTED_CLASS);
364364
} else {
365365
this.$$element.classList.add(SUBMITTED_CLASS);
366366
}
367367
this.$submitted = true;
368368
this._controls.forEach((control) => {
369-
if (control.$$setSubmitted) {
370-
control.$$setSubmitted();
369+
if (control._setSubmitted) {
370+
control._setSubmitted();
371371
}
372372
});
373373
}
@@ -685,7 +685,7 @@ const formDirectiveFactory = function (isNgForm) {
685685
attrParam.$observe(nameAttr, (newValue) => {
686686
if (controller.$name === newValue) return;
687687
scope.$target[controller.$name] = undefined;
688-
controller.$$parentForm.$$renameControl(controller, newValue);
688+
controller.$$parentForm._renameControl(controller, newValue);
689689

690690
if (
691691
scope.$target !== controller.$$parentForm &&

src/directive/if/if.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export function ngIfDirective($animate) {
3636
if (!childScope) {
3737
$transclude(
3838
(
39-
/** @type {Element | null | undefined} */ clone,
40-
/** @type {ng.Scope | null} */ newScope,
39+
/** @type {Element} */ clone,
40+
/** @type {ng.Scope} */ newScope,
4141
) => {
4242
childScope = newScope;
4343
// Note: We only need the first/last node of the cloned nodes.

src/directive/model/model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ export function ngModelDirective() {
12091209

12101210
attr.$observe("name", (newValue) => {
12111211
if (modelCtrl.$name !== newValue) {
1212-
modelCtrl.$$parentForm.$$renameControl(modelCtrl, newValue);
1212+
modelCtrl.$$parentForm._renameControl(modelCtrl, newValue);
12131213
}
12141214
});
12151215
const deregisterWatch = scope.$watch(attr.ngModel, (val) => {

0 commit comments

Comments
 (0)