@angular/upgrade 20.0.0-next.0 → 20.0.0-next.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.
@@ -1,1252 +1,15 @@
1
1
  /**
2
- * @license Angular v20.0.0-next.0
3
- * (c) 2010-2024 Google LLC. https://angular.io/
2
+ * @license Angular v20.0.0-next.2
3
+ * (c) 2010-2025 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
6
6
 
7
+ import { m as module_, g as UPGRADE_APP_TYPE_KEY, I as INJECTOR_KEY, n as UPGRADE_MODULE_NAME, L as LAZY_MODULE_REF, a as $INJECTOR, l as destroyApp, p as $PROVIDE, q as DOWNGRADED_MODULE_COUNT_KEY, r as getDowngradedModuleCount, u as isNgModuleType, i as isFunction, U as UpgradeHelper, $ as $SCOPE, j as $$TESTABILITY, v as $DELEGATE, w as $INTERVAL, e as element, c as controllerKey, b as bootstrap } from './upgrade_helper-BOLCivYz.mjs';
8
+ export { V as VERSION, d as downgradeComponent, f as downgradeInjectable, x as getAngularJSGlobal, y as getAngularLib, z as setAngularJSGlobal, A as setAngularLib, B as ɵangular1, E as ɵconstants, F as ɵupgradeHelper, G as ɵutil } from './upgrade_helper-BOLCivYz.mjs';
7
9
  import * as i0 from '@angular/core';
8
- import { ɵNG_MOD_DEF, Injector, ChangeDetectorRef, Testability, TestabilityRegistry, ApplicationRef, SimpleChange, ɵSIGNAL, NgZone, ComponentFactoryResolver, Version, ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR, PlatformRef, EventEmitter, Directive, NgModule } from '@angular/core';
10
+ import { ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as _NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR, PlatformRef, EventEmitter, Directive, Testability, NgModule } from '@angular/core';
9
11
  import { platformBrowser } from '@angular/platform-browser';
10
12
 
11
- function noNg() {
12
- throw new Error('AngularJS v1.x is not loaded!');
13
- }
14
- const noNgElement = (() => noNg());
15
- noNgElement.cleanData = noNg;
16
- let angular = {
17
- bootstrap: noNg,
18
- module: noNg,
19
- element: noNgElement,
20
- injector: noNg,
21
- version: undefined,
22
- resumeBootstrap: noNg,
23
- getTestability: noNg,
24
- };
25
- try {
26
- if (window.hasOwnProperty('angular')) {
27
- angular = window.angular;
28
- }
29
- }
30
- catch {
31
- // ignore in CJS mode.
32
- }
33
- /**
34
- * @deprecated Use `setAngularJSGlobal` instead.
35
- *
36
- * @publicApi
37
- */
38
- function setAngularLib(ng) {
39
- setAngularJSGlobal(ng);
40
- }
41
- /**
42
- * @deprecated Use `getAngularJSGlobal` instead.
43
- *
44
- * @publicApi
45
- */
46
- function getAngularLib() {
47
- return getAngularJSGlobal();
48
- }
49
- /**
50
- * Resets the AngularJS global.
51
- *
52
- * Used when AngularJS is loaded lazily, and not available on `window`.
53
- *
54
- * @publicApi
55
- */
56
- function setAngularJSGlobal(ng) {
57
- angular = ng;
58
- }
59
- /**
60
- * Returns the current AngularJS global.
61
- *
62
- * @publicApi
63
- */
64
- function getAngularJSGlobal() {
65
- return angular;
66
- }
67
- const bootstrap = (e, modules, config) => angular.bootstrap(e, modules, config);
68
- // Do not declare as `module` to avoid webpack bug
69
- // (see https://github.com/angular/angular/issues/30050).
70
- const module_ = (prefix, dependencies) => angular.module(prefix, dependencies);
71
- const element = ((e) => angular.element(e));
72
- element.cleanData = (nodes) => angular.element.cleanData(nodes);
73
- const injector = (modules, strictDi) => angular.injector(modules, strictDi);
74
- const resumeBootstrap = () => angular.resumeBootstrap();
75
- const getTestability = (e) => angular.getTestability(e);
76
-
77
- var angular1 = /*#__PURE__*/Object.freeze({
78
- __proto__: null,
79
- setAngularLib: setAngularLib,
80
- getAngularLib: getAngularLib,
81
- setAngularJSGlobal: setAngularJSGlobal,
82
- getAngularJSGlobal: getAngularJSGlobal,
83
- bootstrap: bootstrap,
84
- module_: module_,
85
- element: element,
86
- injector: injector,
87
- resumeBootstrap: resumeBootstrap,
88
- getTestability: getTestability
89
- });
90
-
91
- const $COMPILE = '$compile';
92
- const $CONTROLLER = '$controller';
93
- const $DELEGATE = '$delegate';
94
- const $EXCEPTION_HANDLER = '$exceptionHandler';
95
- const $HTTP_BACKEND = '$httpBackend';
96
- const $INJECTOR = '$injector';
97
- const $INTERVAL = '$interval';
98
- const $PARSE = '$parse';
99
- const $PROVIDE = '$provide';
100
- const $ROOT_ELEMENT = '$rootElement';
101
- const $ROOT_SCOPE = '$rootScope';
102
- const $SCOPE = '$scope';
103
- const $TEMPLATE_CACHE = '$templateCache';
104
- const $TEMPLATE_REQUEST = '$templateRequest';
105
- const $$TESTABILITY = '$$testability';
106
- const COMPILER_KEY = '$$angularCompiler';
107
- const DOWNGRADED_MODULE_COUNT_KEY = '$$angularDowngradedModuleCount';
108
- const GROUP_PROJECTABLE_NODES_KEY = '$$angularGroupProjectableNodes';
109
- const INJECTOR_KEY = '$$angularInjector';
110
- const LAZY_MODULE_REF = '$$angularLazyModuleRef';
111
- const NG_ZONE_KEY = '$$angularNgZone';
112
- const UPGRADE_APP_TYPE_KEY = '$$angularUpgradeAppType';
113
- const REQUIRE_INJECTOR = '?^^' + INJECTOR_KEY;
114
- const REQUIRE_NG_MODEL = '?ngModel';
115
- const UPGRADE_MODULE_NAME = '$$UpgradeModule';
116
-
117
- var constants = /*#__PURE__*/Object.freeze({
118
- __proto__: null,
119
- $COMPILE: $COMPILE,
120
- $CONTROLLER: $CONTROLLER,
121
- $DELEGATE: $DELEGATE,
122
- $EXCEPTION_HANDLER: $EXCEPTION_HANDLER,
123
- $HTTP_BACKEND: $HTTP_BACKEND,
124
- $INJECTOR: $INJECTOR,
125
- $INTERVAL: $INTERVAL,
126
- $PARSE: $PARSE,
127
- $PROVIDE: $PROVIDE,
128
- $ROOT_ELEMENT: $ROOT_ELEMENT,
129
- $ROOT_SCOPE: $ROOT_SCOPE,
130
- $SCOPE: $SCOPE,
131
- $TEMPLATE_CACHE: $TEMPLATE_CACHE,
132
- $TEMPLATE_REQUEST: $TEMPLATE_REQUEST,
133
- $$TESTABILITY: $$TESTABILITY,
134
- COMPILER_KEY: COMPILER_KEY,
135
- DOWNGRADED_MODULE_COUNT_KEY: DOWNGRADED_MODULE_COUNT_KEY,
136
- GROUP_PROJECTABLE_NODES_KEY: GROUP_PROJECTABLE_NODES_KEY,
137
- INJECTOR_KEY: INJECTOR_KEY,
138
- LAZY_MODULE_REF: LAZY_MODULE_REF,
139
- NG_ZONE_KEY: NG_ZONE_KEY,
140
- UPGRADE_APP_TYPE_KEY: UPGRADE_APP_TYPE_KEY,
141
- REQUIRE_INJECTOR: REQUIRE_INJECTOR,
142
- REQUIRE_NG_MODEL: REQUIRE_NG_MODEL,
143
- UPGRADE_MODULE_NAME: UPGRADE_MODULE_NAME
144
- });
145
-
146
- /**
147
- * A `PropertyBinding` represents a mapping between a property name
148
- * and an attribute name. It is parsed from a string of the form
149
- * `"prop: attr"`; or simply `"propAndAttr" where the property
150
- * and attribute have the same identifier.
151
- */
152
- class PropertyBinding {
153
- prop;
154
- attr;
155
- bracketAttr;
156
- bracketParenAttr;
157
- parenAttr;
158
- onAttr;
159
- bindAttr;
160
- bindonAttr;
161
- constructor(prop, attr) {
162
- this.prop = prop;
163
- this.attr = attr;
164
- this.bracketAttr = `[${this.attr}]`;
165
- this.parenAttr = `(${this.attr})`;
166
- this.bracketParenAttr = `[(${this.attr})]`;
167
- const capitalAttr = this.attr.charAt(0).toUpperCase() + this.attr.slice(1);
168
- this.onAttr = `on${capitalAttr}`;
169
- this.bindAttr = `bind${capitalAttr}`;
170
- this.bindonAttr = `bindon${capitalAttr}`;
171
- }
172
- }
173
-
174
- const DIRECTIVE_PREFIX_REGEXP = /^(?:x|data)[:\-_]/i;
175
- const DIRECTIVE_SPECIAL_CHARS_REGEXP = /[:\-_]+(.)/g;
176
- function onError(e) {
177
- // TODO: (misko): We seem to not have a stack trace here!
178
- console.error(e, e.stack);
179
- throw e;
180
- }
181
- /**
182
- * Clean the jqLite/jQuery data on the element and all its descendants.
183
- * Equivalent to how jqLite/jQuery invoke `cleanData()` on an Element when removed:
184
- * https://github.com/angular/angular.js/blob/2e72ea13fa98bebf6ed4b5e3c45eaf5f990ed16f/src/jqLite.js#L349-L355
185
- * https://github.com/jquery/jquery/blob/6984d1747623dbc5e87fd6c261a5b6b1628c107c/src/manipulation.js#L182
186
- *
187
- * NOTE:
188
- * `cleanData()` will also invoke the AngularJS `$destroy` DOM event on the element:
189
- * https://github.com/angular/angular.js/blob/2e72ea13fa98bebf6ed4b5e3c45eaf5f990ed16f/src/Angular.js#L1932-L1945
190
- *
191
- * @param node The DOM node whose data needs to be cleaned.
192
- */
193
- function cleanData(node) {
194
- element.cleanData([node]);
195
- if (isParentNode(node)) {
196
- element.cleanData(node.querySelectorAll('*'));
197
- }
198
- }
199
- function controllerKey(name) {
200
- return '$' + name + 'Controller';
201
- }
202
- /**
203
- * Destroy an AngularJS app given the app `$injector`.
204
- *
205
- * NOTE: Destroying an app is not officially supported by AngularJS, but try to do our best by
206
- * destroying `$rootScope` and clean the jqLite/jQuery data on `$rootElement` and all
207
- * descendants.
208
- *
209
- * @param $injector The `$injector` of the AngularJS app to destroy.
210
- */
211
- function destroyApp($injector) {
212
- const $rootElement = $injector.get($ROOT_ELEMENT);
213
- const $rootScope = $injector.get($ROOT_SCOPE);
214
- $rootScope.$destroy();
215
- cleanData($rootElement[0]);
216
- }
217
- function directiveNormalize(name) {
218
- return name
219
- .replace(DIRECTIVE_PREFIX_REGEXP, '')
220
- .replace(DIRECTIVE_SPECIAL_CHARS_REGEXP, (_, letter) => letter.toUpperCase());
221
- }
222
- function getTypeName(type) {
223
- // Return the name of the type or the first line of its stringified version.
224
- return type.overriddenName || type.name || type.toString().split('\n')[0];
225
- }
226
- function getDowngradedModuleCount($injector) {
227
- return $injector.has(DOWNGRADED_MODULE_COUNT_KEY)
228
- ? $injector.get(DOWNGRADED_MODULE_COUNT_KEY)
229
- : 0;
230
- }
231
- function getUpgradeAppType($injector) {
232
- return $injector.has(UPGRADE_APP_TYPE_KEY)
233
- ? $injector.get(UPGRADE_APP_TYPE_KEY)
234
- : 0 /* UpgradeAppType.None */;
235
- }
236
- function isFunction(value) {
237
- return typeof value === 'function';
238
- }
239
- function isNgModuleType(value) {
240
- // NgModule class should have the `ɵmod` static property attached by AOT or JIT compiler.
241
- return isFunction(value) && !!value[ɵNG_MOD_DEF];
242
- }
243
- function isParentNode(node) {
244
- return isFunction(node.querySelectorAll);
245
- }
246
- function validateInjectionKey($injector, downgradedModule, injectionKey, attemptedAction) {
247
- const upgradeAppType = getUpgradeAppType($injector);
248
- const downgradedModuleCount = getDowngradedModuleCount($injector);
249
- // Check for common errors.
250
- switch (upgradeAppType) {
251
- case 1 /* UpgradeAppType.Dynamic */:
252
- case 2 /* UpgradeAppType.Static */:
253
- if (downgradedModule) {
254
- throw new Error(`Error while ${attemptedAction}: 'downgradedModule' unexpectedly specified.\n` +
255
- "You should not specify a value for 'downgradedModule', unless you are downgrading " +
256
- "more than one Angular module (via 'downgradeModule()').");
257
- }
258
- break;
259
- case 3 /* UpgradeAppType.Lite */:
260
- if (!downgradedModule && downgradedModuleCount >= 2) {
261
- throw new Error(`Error while ${attemptedAction}: 'downgradedModule' not specified.\n` +
262
- 'This application contains more than one downgraded Angular module, thus you need to ' +
263
- "always specify 'downgradedModule' when downgrading components and injectables.");
264
- }
265
- if (!$injector.has(injectionKey)) {
266
- throw new Error(`Error while ${attemptedAction}: Unable to find the specified downgraded module.\n` +
267
- 'Did you forget to downgrade an Angular module or include it in the AngularJS ' +
268
- 'application?');
269
- }
270
- break;
271
- default:
272
- throw new Error(`Error while ${attemptedAction}: Not a valid '@angular/upgrade' application.\n` +
273
- 'Did you forget to downgrade an Angular module or include it in the AngularJS ' +
274
- 'application?');
275
- }
276
- }
277
- class Deferred {
278
- promise;
279
- resolve;
280
- reject;
281
- constructor() {
282
- this.promise = new Promise((res, rej) => {
283
- this.resolve = res;
284
- this.reject = rej;
285
- });
286
- }
287
- }
288
- /**
289
- * @return Whether the passed-in component implements the subset of the
290
- * `ControlValueAccessor` interface needed for AngularJS `ng-model`
291
- * compatibility.
292
- */
293
- function supportsNgModel(component) {
294
- return (typeof component.writeValue === 'function' && typeof component.registerOnChange === 'function');
295
- }
296
- /**
297
- * Glue the AngularJS `NgModelController` (if it exists) to the component
298
- * (if it implements the needed subset of the `ControlValueAccessor` interface).
299
- */
300
- function hookupNgModel(ngModel, component) {
301
- if (ngModel && supportsNgModel(component)) {
302
- ngModel.$render = () => {
303
- component.writeValue(ngModel.$viewValue);
304
- };
305
- component.registerOnChange(ngModel.$setViewValue.bind(ngModel));
306
- if (typeof component.registerOnTouched === 'function') {
307
- component.registerOnTouched(ngModel.$setTouched.bind(ngModel));
308
- }
309
- }
310
- }
311
- /**
312
- * Test two values for strict equality, accounting for the fact that `NaN !== NaN`.
313
- */
314
- function strictEquals(val1, val2) {
315
- return val1 === val2 || (val1 !== val1 && val2 !== val2);
316
- }
317
-
318
- var util = /*#__PURE__*/Object.freeze({
319
- __proto__: null,
320
- onError: onError,
321
- cleanData: cleanData,
322
- controllerKey: controllerKey,
323
- destroyApp: destroyApp,
324
- directiveNormalize: directiveNormalize,
325
- getTypeName: getTypeName,
326
- getDowngradedModuleCount: getDowngradedModuleCount,
327
- getUpgradeAppType: getUpgradeAppType,
328
- isFunction: isFunction,
329
- isNgModuleType: isNgModuleType,
330
- validateInjectionKey: validateInjectionKey,
331
- Deferred: Deferred,
332
- hookupNgModel: hookupNgModel,
333
- strictEquals: strictEquals
334
- });
335
-
336
- const INITIAL_VALUE$1 = {
337
- __UNINITIALIZED__: true,
338
- };
339
- class DowngradeComponentAdapter {
340
- element;
341
- attrs;
342
- scope;
343
- ngModel;
344
- parentInjector;
345
- $compile;
346
- $parse;
347
- componentFactory;
348
- wrapCallback;
349
- unsafelyOverwriteSignalInputs;
350
- implementsOnChanges = false;
351
- inputChangeCount = 0;
352
- inputChanges = {};
353
- componentScope;
354
- constructor(element, attrs, scope, ngModel, parentInjector, $compile, $parse, componentFactory, wrapCallback, unsafelyOverwriteSignalInputs) {
355
- this.element = element;
356
- this.attrs = attrs;
357
- this.scope = scope;
358
- this.ngModel = ngModel;
359
- this.parentInjector = parentInjector;
360
- this.$compile = $compile;
361
- this.$parse = $parse;
362
- this.componentFactory = componentFactory;
363
- this.wrapCallback = wrapCallback;
364
- this.unsafelyOverwriteSignalInputs = unsafelyOverwriteSignalInputs;
365
- this.componentScope = scope.$new();
366
- }
367
- compileContents() {
368
- const compiledProjectableNodes = [];
369
- const projectableNodes = this.groupProjectableNodes();
370
- const linkFns = projectableNodes.map((nodes) => this.$compile(nodes));
371
- this.element.empty();
372
- linkFns.forEach((linkFn) => {
373
- linkFn(this.scope, (clone) => {
374
- compiledProjectableNodes.push(clone);
375
- this.element.append(clone);
376
- });
377
- });
378
- return compiledProjectableNodes;
379
- }
380
- createComponentAndSetup(projectableNodes, manuallyAttachView = false, propagateDigest = true) {
381
- const component = this.createComponent(projectableNodes);
382
- this.setupInputs(manuallyAttachView, propagateDigest, component);
383
- this.setupOutputs(component.componentRef);
384
- this.registerCleanup(component.componentRef);
385
- return component.componentRef;
386
- }
387
- createComponent(projectableNodes) {
388
- const providers = [{ provide: $SCOPE, useValue: this.componentScope }];
389
- const childInjector = Injector.create({
390
- providers: providers,
391
- parent: this.parentInjector,
392
- name: 'DowngradeComponentAdapter',
393
- });
394
- const componentRef = this.componentFactory.create(childInjector, projectableNodes, this.element[0]);
395
- const viewChangeDetector = componentRef.injector.get(ChangeDetectorRef);
396
- const changeDetector = componentRef.changeDetectorRef;
397
- // testability hook is commonly added during component bootstrap in
398
- // packages/core/src/application_ref.bootstrap()
399
- // in downgraded application, component creation will take place here as well as adding the
400
- // testability hook.
401
- const testability = componentRef.injector.get(Testability, null);
402
- if (testability) {
403
- componentRef.injector
404
- .get(TestabilityRegistry)
405
- .registerApplication(componentRef.location.nativeElement, testability);
406
- }
407
- hookupNgModel(this.ngModel, componentRef.instance);
408
- return { viewChangeDetector, componentRef, changeDetector };
409
- }
410
- setupInputs(manuallyAttachView, propagateDigest = true, { componentRef, changeDetector, viewChangeDetector }) {
411
- const attrs = this.attrs;
412
- const inputs = this.componentFactory.inputs || [];
413
- for (const input of inputs) {
414
- const inputBinding = new PropertyBinding(input.propName, input.templateName);
415
- let expr = null;
416
- if (attrs.hasOwnProperty(inputBinding.attr)) {
417
- const observeFn = ((prop, isSignal) => {
418
- let prevValue = INITIAL_VALUE$1;
419
- return (currValue) => {
420
- // Initially, both `$observe()` and `$watch()` will call this function.
421
- if (!strictEquals(prevValue, currValue)) {
422
- if (prevValue === INITIAL_VALUE$1) {
423
- prevValue = currValue;
424
- }
425
- this.updateInput(componentRef, prop, prevValue, currValue, isSignal);
426
- prevValue = currValue;
427
- }
428
- };
429
- })(inputBinding.prop, input.isSignal);
430
- attrs.$observe(inputBinding.attr, observeFn);
431
- // Use `$watch()` (in addition to `$observe()`) in order to initialize the input in time
432
- // for `ngOnChanges()`. This is necessary if we are already in a `$digest`, which means that
433
- // `ngOnChanges()` (which is called by a watcher) will run before the `$observe()` callback.
434
- let unwatch = this.componentScope.$watch(() => {
435
- unwatch();
436
- unwatch = null;
437
- observeFn(attrs[inputBinding.attr]);
438
- });
439
- }
440
- else if (attrs.hasOwnProperty(inputBinding.bindAttr)) {
441
- expr = attrs[inputBinding.bindAttr];
442
- }
443
- else if (attrs.hasOwnProperty(inputBinding.bracketAttr)) {
444
- expr = attrs[inputBinding.bracketAttr];
445
- }
446
- else if (attrs.hasOwnProperty(inputBinding.bindonAttr)) {
447
- expr = attrs[inputBinding.bindonAttr];
448
- }
449
- else if (attrs.hasOwnProperty(inputBinding.bracketParenAttr)) {
450
- expr = attrs[inputBinding.bracketParenAttr];
451
- }
452
- if (expr != null) {
453
- const watchFn = ((prop, isSignal) => (currValue, prevValue) => this.updateInput(componentRef, prop, prevValue, currValue, isSignal))(inputBinding.prop, input.isSignal);
454
- this.componentScope.$watch(expr, watchFn);
455
- }
456
- }
457
- // Invoke `ngOnChanges()` and Change Detection (when necessary)
458
- const detectChanges = () => changeDetector.detectChanges();
459
- const prototype = this.componentFactory.componentType.prototype;
460
- this.implementsOnChanges = !!(prototype && prototype.ngOnChanges);
461
- this.componentScope.$watch(() => this.inputChangeCount, this.wrapCallback(() => {
462
- // Invoke `ngOnChanges()`
463
- if (this.implementsOnChanges) {
464
- const inputChanges = this.inputChanges;
465
- this.inputChanges = {};
466
- componentRef.instance.ngOnChanges(inputChanges);
467
- }
468
- viewChangeDetector.markForCheck();
469
- // If opted out of propagating digests, invoke change detection when inputs change.
470
- if (!propagateDigest) {
471
- detectChanges();
472
- }
473
- }));
474
- // If not opted out of propagating digests, invoke change detection on every digest
475
- if (propagateDigest) {
476
- this.componentScope.$watch(this.wrapCallback(detectChanges));
477
- }
478
- // If necessary, attach the view so that it will be dirty-checked.
479
- // (Allow time for the initial input values to be set and `ngOnChanges()` to be called.)
480
- if (manuallyAttachView || !propagateDigest) {
481
- let unwatch = this.componentScope.$watch(() => {
482
- unwatch();
483
- unwatch = null;
484
- const appRef = this.parentInjector.get(ApplicationRef);
485
- appRef.attachView(componentRef.hostView);
486
- });
487
- }
488
- }
489
- setupOutputs(componentRef) {
490
- const attrs = this.attrs;
491
- const outputs = this.componentFactory.outputs || [];
492
- for (const output of outputs) {
493
- const outputBindings = new PropertyBinding(output.propName, output.templateName);
494
- const bindonAttr = outputBindings.bindonAttr.substring(0, outputBindings.bindonAttr.length - 6);
495
- const bracketParenAttr = `[(${outputBindings.bracketParenAttr.substring(2, outputBindings.bracketParenAttr.length - 8)})]`;
496
- // order below is important - first update bindings then evaluate expressions
497
- if (attrs.hasOwnProperty(bindonAttr)) {
498
- this.subscribeToOutput(componentRef, outputBindings, attrs[bindonAttr], true);
499
- }
500
- if (attrs.hasOwnProperty(bracketParenAttr)) {
501
- this.subscribeToOutput(componentRef, outputBindings, attrs[bracketParenAttr], true);
502
- }
503
- if (attrs.hasOwnProperty(outputBindings.onAttr)) {
504
- this.subscribeToOutput(componentRef, outputBindings, attrs[outputBindings.onAttr]);
505
- }
506
- if (attrs.hasOwnProperty(outputBindings.parenAttr)) {
507
- this.subscribeToOutput(componentRef, outputBindings, attrs[outputBindings.parenAttr]);
508
- }
509
- }
510
- }
511
- subscribeToOutput(componentRef, output, expr, isAssignment = false) {
512
- const getter = this.$parse(expr);
513
- const setter = getter.assign;
514
- if (isAssignment && !setter) {
515
- throw new Error(`Expression '${expr}' is not assignable!`);
516
- }
517
- const emitter = componentRef.instance[output.prop];
518
- if (emitter) {
519
- const subscription = emitter.subscribe({
520
- next: isAssignment
521
- ? (v) => setter(this.scope, v)
522
- : (v) => getter(this.scope, { '$event': v }),
523
- });
524
- componentRef.onDestroy(() => subscription.unsubscribe());
525
- }
526
- else {
527
- throw new Error(`Missing emitter '${output.prop}' on component '${getTypeName(this.componentFactory.componentType)}'!`);
528
- }
529
- }
530
- registerCleanup(componentRef) {
531
- const testabilityRegistry = componentRef.injector.get(TestabilityRegistry);
532
- const destroyComponentRef = this.wrapCallback(() => componentRef.destroy());
533
- let destroyed = false;
534
- this.element.on('$destroy', () => {
535
- // The `$destroy` event may have been triggered by the `cleanData()` call in the
536
- // `componentScope` `$destroy` handler below. In that case, we don't want to call
537
- // `componentScope.$destroy()` again.
538
- if (!destroyed)
539
- this.componentScope.$destroy();
540
- });
541
- this.componentScope.$on('$destroy', () => {
542
- if (!destroyed) {
543
- destroyed = true;
544
- testabilityRegistry.unregisterApplication(componentRef.location.nativeElement);
545
- // The `componentScope` might be getting destroyed, because an ancestor element is being
546
- // removed/destroyed. If that is the case, jqLite/jQuery would normally invoke `cleanData()`
547
- // on the removed element and all descendants.
548
- // https://github.com/angular/angular.js/blob/2e72ea13fa98bebf6ed4b5e3c45eaf5f990ed16f/src/jqLite.js#L349-L355
549
- // https://github.com/jquery/jquery/blob/6984d1747623dbc5e87fd6c261a5b6b1628c107c/src/manipulation.js#L182
550
- //
551
- // Here, however, `destroyComponentRef()` may under some circumstances remove the element
552
- // from the DOM and therefore it will no longer be a descendant of the removed element when
553
- // `cleanData()` is called. This would result in a memory leak, because the element's data
554
- // and event handlers (and all objects directly or indirectly referenced by them) would be
555
- // retained.
556
- //
557
- // To ensure the element is always properly cleaned up, we manually call `cleanData()` on
558
- // this element and its descendants before destroying the `ComponentRef`.
559
- cleanData(this.element[0]);
560
- destroyComponentRef();
561
- }
562
- });
563
- }
564
- updateInput(componentRef, prop, prevValue, currValue, isSignal) {
565
- if (this.implementsOnChanges) {
566
- this.inputChanges[prop] = new SimpleChange(prevValue, currValue, prevValue === currValue);
567
- }
568
- this.inputChangeCount++;
569
- if (isSignal && !this.unsafelyOverwriteSignalInputs) {
570
- const node = componentRef.instance[prop][ɵSIGNAL];
571
- node.applyValueToInputSignal(node, currValue);
572
- }
573
- else {
574
- componentRef.instance[prop] = currValue;
575
- }
576
- }
577
- groupProjectableNodes() {
578
- let ngContentSelectors = this.componentFactory.ngContentSelectors;
579
- return groupNodesBySelector(ngContentSelectors, this.element.contents());
580
- }
581
- }
582
- /**
583
- * Group a set of DOM nodes into `ngContent` groups, based on the given content selectors.
584
- */
585
- function groupNodesBySelector(ngContentSelectors, nodes) {
586
- const projectableNodes = [];
587
- for (let i = 0, ii = ngContentSelectors.length; i < ii; ++i) {
588
- projectableNodes[i] = [];
589
- }
590
- for (let j = 0, jj = nodes.length; j < jj; ++j) {
591
- const node = nodes[j];
592
- const ngContentIndex = findMatchingNgContentIndex(node, ngContentSelectors);
593
- if (ngContentIndex != null) {
594
- projectableNodes[ngContentIndex].push(node);
595
- }
596
- }
597
- return projectableNodes;
598
- }
599
- function findMatchingNgContentIndex(element, ngContentSelectors) {
600
- const ngContentIndices = [];
601
- let wildcardNgContentIndex = -1;
602
- for (let i = 0; i < ngContentSelectors.length; i++) {
603
- const selector = ngContentSelectors[i];
604
- if (selector === '*') {
605
- wildcardNgContentIndex = i;
606
- }
607
- else {
608
- if (matchesSelector(element, selector)) {
609
- ngContentIndices.push(i);
610
- }
611
- }
612
- }
613
- ngContentIndices.sort();
614
- if (wildcardNgContentIndex !== -1) {
615
- ngContentIndices.push(wildcardNgContentIndex);
616
- }
617
- return ngContentIndices.length ? ngContentIndices[0] : null;
618
- }
619
- function matchesSelector(el, selector) {
620
- const elProto = Element.prototype;
621
- return el.nodeType === Node.ELEMENT_NODE
622
- ? // matches is supported by all browsers from 2014 onwards except non-chromium edge
623
- (elProto.matches ?? elProto.msMatchesSelector).call(el, selector)
624
- : false;
625
- }
626
-
627
- function isThenable(obj) {
628
- return !!obj && isFunction(obj.then);
629
- }
630
- /**
631
- * Synchronous, promise-like object.
632
- */
633
- class SyncPromise {
634
- value;
635
- resolved = false;
636
- callbacks = [];
637
- static all(valuesOrPromises) {
638
- const aggrPromise = new SyncPromise();
639
- let resolvedCount = 0;
640
- const results = [];
641
- const resolve = (idx, value) => {
642
- results[idx] = value;
643
- if (++resolvedCount === valuesOrPromises.length)
644
- aggrPromise.resolve(results);
645
- };
646
- valuesOrPromises.forEach((p, idx) => {
647
- if (isThenable(p)) {
648
- p.then((v) => resolve(idx, v));
649
- }
650
- else {
651
- resolve(idx, p);
652
- }
653
- });
654
- return aggrPromise;
655
- }
656
- resolve(value) {
657
- // Do nothing, if already resolved.
658
- if (this.resolved)
659
- return;
660
- this.value = value;
661
- this.resolved = true;
662
- // Run the queued callbacks.
663
- this.callbacks.forEach((callback) => callback(value));
664
- this.callbacks.length = 0;
665
- }
666
- then(callback) {
667
- if (this.resolved) {
668
- callback(this.value);
669
- }
670
- else {
671
- this.callbacks.push(callback);
672
- }
673
- }
674
- }
675
-
676
- /**
677
- * @description
678
- *
679
- * A helper function that allows an Angular component to be used from AngularJS.
680
- *
681
- * *Part of the [upgrade/static](api?query=upgrade%2Fstatic)
682
- * library for hybrid upgrade apps that support AOT compilation*
683
- *
684
- * This helper function returns a factory function to be used for registering
685
- * an AngularJS wrapper directive for "downgrading" an Angular component.
686
- *
687
- * @usageNotes
688
- * ### Examples
689
- *
690
- * Let's assume that you have an Angular component called `ng2Heroes` that needs
691
- * to be made available in AngularJS templates.
692
- *
693
- * {@example upgrade/static/ts/full/module.ts region="ng2-heroes"}
694
- *
695
- * We must create an AngularJS [directive](https://docs.angularjs.org/guide/directive)
696
- * that will make this Angular component available inside AngularJS templates.
697
- * The `downgradeComponent()` function returns a factory function that we
698
- * can use to define the AngularJS directive that wraps the "downgraded" component.
699
- *
700
- * {@example upgrade/static/ts/full/module.ts region="ng2-heroes-wrapper"}
701
- *
702
- * For more details and examples on downgrading Angular components to AngularJS components please
703
- * visit the [Upgrade guide](https://angular.io/guide/upgrade#using-angular-components-from-angularjs-code).
704
- *
705
- * @param info contains information about the Component that is being downgraded:
706
- *
707
- * - `component: Type<any>`: The type of the Component that will be downgraded
708
- * - `downgradedModule?: string`: The name of the downgraded module (if any) that the component
709
- * "belongs to", as returned by a call to `downgradeModule()`. It is the module, whose
710
- * corresponding Angular module will be bootstrapped, when the component needs to be instantiated.
711
- * <br />
712
- * (This option is only necessary when using `downgradeModule()` to downgrade more than one
713
- * Angular module.)
714
- * - `propagateDigest?: boolean`: Whether to perform {@link ChangeDetectorRef#detectChanges} on the
715
- * component on every
716
- * [$digest](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$digest). If set to `false`,
717
- * change detection will still be performed when any of the component's inputs changes.
718
- * (Default: true)
719
- *
720
- * @returns a factory function that can be used to register the component in an
721
- * AngularJS module.
722
- *
723
- * @publicApi
724
- */
725
- function downgradeComponent(info) {
726
- const directiveFactory = function ($compile, $injector, $parse) {
727
- const unsafelyOverwriteSignalInputs = info.unsafelyOverwriteSignalInputs ?? false;
728
- // When using `downgradeModule()`, we need to handle certain things specially. For example:
729
- // - We always need to attach the component view to the `ApplicationRef` for it to be
730
- // dirty-checked.
731
- // - We need to ensure callbacks to Angular APIs (e.g. change detection) are run inside the
732
- // Angular zone.
733
- // NOTE: This is not needed, when using `UpgradeModule`, because `$digest()` will be run
734
- // inside the Angular zone (except if explicitly escaped, in which case we shouldn't
735
- // force it back in).
736
- const isNgUpgradeLite = getUpgradeAppType($injector) === 3 /* UpgradeAppType.Lite */;
737
- const wrapCallback = !isNgUpgradeLite
738
- ? (cb) => cb
739
- : (cb) => () => (NgZone.isInAngularZone() ? cb() : ngZone.run(cb));
740
- let ngZone;
741
- // When downgrading multiple modules, special handling is needed wrt injectors.
742
- const hasMultipleDowngradedModules = isNgUpgradeLite && getDowngradedModuleCount($injector) > 1;
743
- return {
744
- restrict: 'E',
745
- terminal: true,
746
- require: [REQUIRE_INJECTOR, REQUIRE_NG_MODEL],
747
- // Controller needs to be set so that `angular-component-router.js` (from beta Angular 2)
748
- // configuration properties can be made available. See:
749
- // See G3: javascript/angular2/angular1_router_lib.js
750
- // https://github.com/angular/angular.js/blob/47bf11ee94664367a26ed8c91b9b586d3dd420f5/src/ng/compile.js#L1670-L1691.
751
- controller: function () { },
752
- link: (scope, element, attrs, required) => {
753
- // We might have to compile the contents asynchronously, because this might have been
754
- // triggered by `UpgradeNg1ComponentAdapterBuilder`, before the Angular templates have
755
- // been compiled.
756
- const ngModel = required[1];
757
- const parentInjector = required[0];
758
- let moduleInjector = undefined;
759
- let ranAsync = false;
760
- if (!parentInjector || hasMultipleDowngradedModules) {
761
- const downgradedModule = info.downgradedModule || '';
762
- const lazyModuleRefKey = `${LAZY_MODULE_REF}${downgradedModule}`;
763
- const attemptedAction = `instantiating component '${getTypeName(info.component)}'`;
764
- validateInjectionKey($injector, downgradedModule, lazyModuleRefKey, attemptedAction);
765
- const lazyModuleRef = $injector.get(lazyModuleRefKey);
766
- moduleInjector = lazyModuleRef.injector ?? lazyModuleRef.promise;
767
- }
768
- // Notes:
769
- //
770
- // There are two injectors: `finalModuleInjector` and `finalParentInjector` (they might be
771
- // the same instance, but that is irrelevant):
772
- // - `finalModuleInjector` is used to retrieve `ComponentFactoryResolver`, thus it must be
773
- // on the same tree as the `NgModule` that declares this downgraded component.
774
- // - `finalParentInjector` is used for all other injection purposes.
775
- // (Note that Angular knows to only traverse the component-tree part of that injector,
776
- // when looking for an injectable and then switch to the module injector.)
777
- //
778
- // There are basically three cases:
779
- // - If there is no parent component (thus no `parentInjector`), we bootstrap the downgraded
780
- // `NgModule` and use its injector as both `finalModuleInjector` and
781
- // `finalParentInjector`.
782
- // - If there is a parent component (and thus a `parentInjector`) and we are sure that it
783
- // belongs to the same `NgModule` as this downgraded component (e.g. because there is only
784
- // one downgraded module, we use that `parentInjector` as both `finalModuleInjector` and
785
- // `finalParentInjector`.
786
- // - If there is a parent component, but it may belong to a different `NgModule`, then we
787
- // use the `parentInjector` as `finalParentInjector` and this downgraded component's
788
- // declaring `NgModule`'s injector as `finalModuleInjector`.
789
- // Note 1: If the `NgModule` is already bootstrapped, we just get its injector (we don't
790
- // bootstrap again).
791
- // Note 2: It is possible that (while there are multiple downgraded modules) this
792
- // downgraded component and its parent component both belong to the same NgModule.
793
- // In that case, we could have used the `parentInjector` as both
794
- // `finalModuleInjector` and `finalParentInjector`, but (for simplicity) we are
795
- // treating this case as if they belong to different `NgModule`s. That doesn't
796
- // really affect anything, since `parentInjector` has `moduleInjector` as ancestor
797
- // and trying to resolve `ComponentFactoryResolver` from either one will return
798
- // the same instance.
799
- // If there is a parent component, use its injector as parent injector.
800
- // If this is a "top-level" Angular component, use the module injector.
801
- const finalParentInjector = parentInjector || moduleInjector;
802
- // If this is a "top-level" Angular component or the parent component may belong to a
803
- // different `NgModule`, use the module injector for module-specific dependencies.
804
- // If there is a parent component that belongs to the same `NgModule`, use its injector.
805
- const finalModuleInjector = moduleInjector || parentInjector;
806
- const doDowngrade = (injector, moduleInjector) => {
807
- // Retrieve `ComponentFactoryResolver` from the injector tied to the `NgModule` this
808
- // component belongs to.
809
- const componentFactoryResolver = moduleInjector.get(ComponentFactoryResolver);
810
- const componentFactory = componentFactoryResolver.resolveComponentFactory(info.component);
811
- if (!componentFactory) {
812
- throw new Error(`Expecting ComponentFactory for: ${getTypeName(info.component)}`);
813
- }
814
- const injectorPromise = new ParentInjectorPromise(element);
815
- const facade = new DowngradeComponentAdapter(element, attrs, scope, ngModel, injector, $compile, $parse, componentFactory, wrapCallback, unsafelyOverwriteSignalInputs);
816
- const projectableNodes = facade.compileContents();
817
- const componentRef = facade.createComponentAndSetup(projectableNodes, isNgUpgradeLite, info.propagateDigest);
818
- injectorPromise.resolve(componentRef.injector);
819
- if (ranAsync) {
820
- // If this is run async, it is possible that it is not run inside a
821
- // digest and initial input values will not be detected.
822
- scope.$evalAsync(() => { });
823
- }
824
- };
825
- const downgradeFn = !isNgUpgradeLite
826
- ? doDowngrade
827
- : (pInjector, mInjector) => {
828
- if (!ngZone) {
829
- ngZone = pInjector.get(NgZone);
830
- }
831
- wrapCallback(() => doDowngrade(pInjector, mInjector))();
832
- };
833
- // NOTE:
834
- // Not using `ParentInjectorPromise.all()` (which is inherited from `SyncPromise`), because
835
- // Closure Compiler (or some related tool) complains:
836
- // `TypeError: ...$src$downgrade_component_ParentInjectorPromise.all is not a function`
837
- SyncPromise.all([finalParentInjector, finalModuleInjector]).then(([pInjector, mInjector]) => downgradeFn(pInjector, mInjector));
838
- ranAsync = true;
839
- },
840
- };
841
- };
842
- // bracket-notation because of closure - see #14441
843
- directiveFactory['$inject'] = [$COMPILE, $INJECTOR, $PARSE];
844
- return directiveFactory;
845
- }
846
- /**
847
- * Synchronous promise-like object to wrap parent injectors,
848
- * to preserve the synchronous nature of AngularJS's `$compile`.
849
- */
850
- class ParentInjectorPromise extends SyncPromise {
851
- element;
852
- injectorKey = controllerKey(INJECTOR_KEY);
853
- constructor(element) {
854
- super();
855
- this.element = element;
856
- // Store the promise on the element.
857
- element.data(this.injectorKey, this);
858
- }
859
- resolve(injector) {
860
- // Store the real injector on the element.
861
- this.element.data(this.injectorKey, injector);
862
- // Release the element to prevent memory leaks.
863
- this.element = null;
864
- // Resolve the promise.
865
- super.resolve(injector);
866
- }
867
- }
868
-
869
- /**
870
- * @description
871
- *
872
- * A helper function to allow an Angular service to be accessible from AngularJS.
873
- *
874
- * *Part of the [upgrade/static](api?query=upgrade%2Fstatic)
875
- * library for hybrid upgrade apps that support AOT compilation*
876
- *
877
- * This helper function returns a factory function that provides access to the Angular
878
- * service identified by the `token` parameter.
879
- *
880
- * @usageNotes
881
- * ### Examples
882
- *
883
- * First ensure that the service to be downgraded is provided in an `NgModule`
884
- * that will be part of the upgrade application. For example, let's assume we have
885
- * defined `HeroesService`
886
- *
887
- * {@example upgrade/static/ts/full/module.ts region="ng2-heroes-service"}
888
- *
889
- * and that we have included this in our upgrade app `NgModule`
890
- *
891
- * {@example upgrade/static/ts/full/module.ts region="ng2-module"}
892
- *
893
- * Now we can register the `downgradeInjectable` factory function for the service
894
- * on an AngularJS module.
895
- *
896
- * {@example upgrade/static/ts/full/module.ts region="downgrade-ng2-heroes-service"}
897
- *
898
- * Inside an AngularJS component's controller we can get hold of the
899
- * downgraded service via the name we gave when downgrading.
900
- *
901
- * {@example upgrade/static/ts/full/module.ts region="example-app"}
902
- *
903
- * <div class="docs-alert docs-alert-important">
904
- *
905
- * When using `downgradeModule()`, downgraded injectables will not be available until the Angular
906
- * module that provides them is instantiated. In order to be safe, you need to ensure that the
907
- * downgraded injectables are not used anywhere _outside_ the part of the app where it is
908
- * guaranteed that their module has been instantiated.
909
- *
910
- * For example, it is _OK_ to use a downgraded service in an upgraded component that is only used
911
- * from a downgraded Angular component provided by the same Angular module as the injectable, but
912
- * it is _not OK_ to use it in an AngularJS component that may be used independently of Angular or
913
- * use it in a downgraded Angular component from a different module.
914
- *
915
- * </div>
916
- *
917
- * @param token an `InjectionToken` that identifies a service provided from Angular.
918
- * @param downgradedModule the name of the downgraded module (if any) that the injectable
919
- * "belongs to", as returned by a call to `downgradeModule()`. It is the module, whose injector will
920
- * be used for instantiating the injectable.<br />
921
- * (This option is only necessary when using `downgradeModule()` to downgrade more than one Angular
922
- * module.)
923
- *
924
- * @returns a [factory function](https://docs.angularjs.org/guide/di) that can be
925
- * used to register the service on an AngularJS module.
926
- *
927
- * @publicApi
928
- */
929
- function downgradeInjectable(token, downgradedModule = '') {
930
- const factory = function ($injector) {
931
- const injectorKey = `${INJECTOR_KEY}${downgradedModule}`;
932
- const injectableName = isFunction(token) ? getTypeName(token) : String(token);
933
- const attemptedAction = `instantiating injectable '${injectableName}'`;
934
- validateInjectionKey($injector, downgradedModule, injectorKey, attemptedAction);
935
- try {
936
- const injector = $injector.get(injectorKey);
937
- return injector.get(token);
938
- }
939
- catch (err) {
940
- throw new Error(`Error while ${attemptedAction}: ${err.message || err}`);
941
- }
942
- };
943
- factory['$inject'] = [$INJECTOR];
944
- return factory;
945
- }
946
-
947
- /**
948
- * @module
949
- * @description
950
- * Entry point for all public APIs of the upgrade package.
951
- */
952
- /**
953
- * @publicApi
954
- */
955
- const VERSION = new Version('20.0.0-next.0');
956
-
957
- /**
958
- * The Trusted Types policy, or null if Trusted Types are not
959
- * enabled/supported, or undefined if the policy has not been created yet.
960
- */
961
- let policy;
962
- /**
963
- * Returns the Trusted Types policy, or null if Trusted Types are not
964
- * enabled/supported. The first call to this function will create the policy.
965
- */
966
- function getPolicy() {
967
- if (policy === undefined) {
968
- policy = null;
969
- const windowWithTrustedTypes = window;
970
- if (windowWithTrustedTypes.trustedTypes) {
971
- try {
972
- policy = windowWithTrustedTypes.trustedTypes.createPolicy('angular#unsafe-upgrade', {
973
- createHTML: (s) => s,
974
- });
975
- }
976
- catch {
977
- // trustedTypes.createPolicy throws if called with a name that is
978
- // already registered, even in report-only mode. Until the API changes,
979
- // catch the error not to break the applications functionally. In such
980
- // cases, the code will fall back to using strings.
981
- }
982
- }
983
- }
984
- return policy;
985
- }
986
- /**
987
- * Unsafely promote a legacy AngularJS template to a TrustedHTML, falling back
988
- * to strings when Trusted Types are not available.
989
- * @security This is a security-sensitive function; any use of this function
990
- * must go through security review. In particular, the template string should
991
- * always be under full control of the application author, as untrusted input
992
- * can cause an XSS vulnerability.
993
- */
994
- function trustedHTMLFromLegacyTemplate(html) {
995
- return getPolicy()?.createHTML(html) || html;
996
- }
997
-
998
- // Constants
999
- const REQUIRE_PREFIX_RE = /^(\^\^?)?(\?)?(\^\^?)?/;
1000
- // Classes
1001
- class UpgradeHelper {
1002
- name;
1003
- $injector;
1004
- element;
1005
- $element;
1006
- directive;
1007
- $compile;
1008
- $controller;
1009
- constructor(injector, name, elementRef, directive) {
1010
- this.name = name;
1011
- this.$injector = injector.get($INJECTOR);
1012
- this.$compile = this.$injector.get($COMPILE);
1013
- this.$controller = this.$injector.get($CONTROLLER);
1014
- this.element = elementRef.nativeElement;
1015
- this.$element = element(this.element);
1016
- this.directive = directive ?? UpgradeHelper.getDirective(this.$injector, name);
1017
- }
1018
- static getDirective($injector, name) {
1019
- const directives = $injector.get(name + 'Directive');
1020
- if (directives.length > 1) {
1021
- throw new Error(`Only support single directive definition for: ${name}`);
1022
- }
1023
- const directive = directives[0];
1024
- // AngularJS will transform `link: xyz` to `compile: () => xyz`. So we can only tell there was a
1025
- // user-defined `compile` if there is no `link`. In other cases, we will just ignore `compile`.
1026
- if (directive.compile && !directive.link)
1027
- notSupported(name, 'compile');
1028
- if (directive.replace)
1029
- notSupported(name, 'replace');
1030
- if (directive.terminal)
1031
- notSupported(name, 'terminal');
1032
- return directive;
1033
- }
1034
- static getTemplate($injector, directive, fetchRemoteTemplate = false, $element) {
1035
- if (directive.template !== undefined) {
1036
- return trustedHTMLFromLegacyTemplate(getOrCall(directive.template, $element));
1037
- }
1038
- else if (directive.templateUrl) {
1039
- const $templateCache = $injector.get($TEMPLATE_CACHE);
1040
- const url = getOrCall(directive.templateUrl, $element);
1041
- const template = $templateCache.get(url);
1042
- if (template !== undefined) {
1043
- return trustedHTMLFromLegacyTemplate(template);
1044
- }
1045
- else if (!fetchRemoteTemplate) {
1046
- throw new Error('loading directive templates asynchronously is not supported');
1047
- }
1048
- return new Promise((resolve, reject) => {
1049
- const $httpBackend = $injector.get($HTTP_BACKEND);
1050
- $httpBackend('GET', url, null, (status, response) => {
1051
- if (status === 200) {
1052
- resolve(trustedHTMLFromLegacyTemplate($templateCache.put(url, response)));
1053
- }
1054
- else {
1055
- reject(`GET component template from '${url}' returned '${status}: ${response}'`);
1056
- }
1057
- });
1058
- });
1059
- }
1060
- else {
1061
- throw new Error(`Directive '${directive.name}' is not a component, it is missing template.`);
1062
- }
1063
- }
1064
- buildController(controllerType, $scope) {
1065
- // TODO: Document that we do not pre-assign bindings on the controller instance.
1066
- // Quoted properties below so that this code can be optimized with Closure Compiler.
1067
- const locals = { '$scope': $scope, '$element': this.$element };
1068
- const controller = this.$controller(controllerType, locals, null, this.directive.controllerAs);
1069
- this.$element.data?.(controllerKey(this.directive.name), controller);
1070
- return controller;
1071
- }
1072
- compileTemplate(template) {
1073
- if (template === undefined) {
1074
- template = UpgradeHelper.getTemplate(this.$injector, this.directive, false, this.$element);
1075
- }
1076
- return this.compileHtml(template);
1077
- }
1078
- onDestroy($scope, controllerInstance) {
1079
- if (controllerInstance && isFunction(controllerInstance.$onDestroy)) {
1080
- controllerInstance.$onDestroy();
1081
- }
1082
- $scope.$destroy();
1083
- cleanData(this.element);
1084
- }
1085
- prepareTransclusion() {
1086
- const transclude = this.directive.transclude;
1087
- const contentChildNodes = this.extractChildNodes();
1088
- const attachChildrenFn = (scope, cloneAttachFn) => {
1089
- // Since AngularJS v1.5.8, `cloneAttachFn` will try to destroy the transclusion scope if
1090
- // `$template` is empty. Since the transcluded content comes from Angular, not AngularJS,
1091
- // there will be no transclusion scope here.
1092
- // Provide a dummy `scope.$destroy()` method to prevent `cloneAttachFn` from throwing.
1093
- scope = scope || { $destroy: () => undefined };
1094
- return cloneAttachFn($template, scope);
1095
- };
1096
- let $template = contentChildNodes;
1097
- if (transclude) {
1098
- const slots = Object.create(null);
1099
- if (typeof transclude === 'object') {
1100
- $template = [];
1101
- const slotMap = Object.create(null);
1102
- const filledSlots = Object.create(null);
1103
- // Parse the element selectors.
1104
- Object.keys(transclude).forEach((slotName) => {
1105
- let selector = transclude[slotName];
1106
- const optional = selector.charAt(0) === '?';
1107
- selector = optional ? selector.substring(1) : selector;
1108
- slotMap[selector] = slotName;
1109
- slots[slotName] = null; // `null`: Defined but not yet filled.
1110
- filledSlots[slotName] = optional; // Consider optional slots as filled.
1111
- });
1112
- // Add the matching elements into their slot.
1113
- contentChildNodes.forEach((node) => {
1114
- const slotName = slotMap[directiveNormalize(node.nodeName.toLowerCase())];
1115
- if (slotName) {
1116
- filledSlots[slotName] = true;
1117
- slots[slotName] = slots[slotName] || [];
1118
- slots[slotName].push(node);
1119
- }
1120
- else {
1121
- $template.push(node);
1122
- }
1123
- });
1124
- // Check for required slots that were not filled.
1125
- Object.keys(filledSlots).forEach((slotName) => {
1126
- if (!filledSlots[slotName]) {
1127
- throw new Error(`Required transclusion slot '${slotName}' on directive: ${this.name}`);
1128
- }
1129
- });
1130
- Object.keys(slots)
1131
- .filter((slotName) => slots[slotName])
1132
- .forEach((slotName) => {
1133
- const nodes = slots[slotName];
1134
- slots[slotName] = (scope, cloneAttach) => {
1135
- return cloneAttach(nodes, scope);
1136
- };
1137
- });
1138
- }
1139
- // Attach `$$slots` to default slot transclude fn.
1140
- attachChildrenFn.$$slots = slots;
1141
- // AngularJS v1.6+ ignores empty or whitespace-only transcluded text nodes. But Angular
1142
- // removes all text content after the first interpolation and updates it later, after
1143
- // evaluating the expressions. This would result in AngularJS failing to recognize text
1144
- // nodes that start with an interpolation as transcluded content and use the fallback
1145
- // content instead.
1146
- // To avoid this issue, we add a
1147
- // [zero-width non-joiner character](https://en.wikipedia.org/wiki/Zero-width_non-joiner)
1148
- // to empty text nodes (which can only be a result of Angular removing their initial content).
1149
- // NOTE: Transcluded text content that starts with whitespace followed by an interpolation
1150
- // will still fail to be detected by AngularJS v1.6+
1151
- $template.forEach((node) => {
1152
- if (node.nodeType === Node.TEXT_NODE && !node.nodeValue) {
1153
- node.nodeValue = '\u200C';
1154
- }
1155
- });
1156
- }
1157
- return attachChildrenFn;
1158
- }
1159
- resolveAndBindRequiredControllers(controllerInstance) {
1160
- const directiveRequire = this.getDirectiveRequire();
1161
- const requiredControllers = this.resolveRequire(directiveRequire);
1162
- if (controllerInstance && this.directive.bindToController && isMap(directiveRequire)) {
1163
- const requiredControllersMap = requiredControllers;
1164
- Object.keys(requiredControllersMap).forEach((key) => {
1165
- controllerInstance[key] = requiredControllersMap[key];
1166
- });
1167
- }
1168
- return requiredControllers;
1169
- }
1170
- compileHtml(html) {
1171
- this.element.innerHTML = html;
1172
- return this.$compile(this.element.childNodes);
1173
- }
1174
- extractChildNodes() {
1175
- const childNodes = [];
1176
- let childNode;
1177
- while ((childNode = this.element.firstChild)) {
1178
- childNode.remove();
1179
- childNodes.push(childNode);
1180
- }
1181
- return childNodes;
1182
- }
1183
- getDirectiveRequire() {
1184
- const require = this.directive.require || (this.directive.controller && this.directive.name);
1185
- if (isMap(require)) {
1186
- Object.entries(require).forEach(([key, value]) => {
1187
- const match = value.match(REQUIRE_PREFIX_RE);
1188
- const name = value.substring(match[0].length);
1189
- if (!name) {
1190
- require[key] = match[0] + key;
1191
- }
1192
- });
1193
- }
1194
- return require;
1195
- }
1196
- resolveRequire(require) {
1197
- if (!require) {
1198
- return null;
1199
- }
1200
- else if (Array.isArray(require)) {
1201
- return require.map((req) => this.resolveRequire(req));
1202
- }
1203
- else if (typeof require === 'object') {
1204
- const value = {};
1205
- Object.keys(require).forEach((key) => (value[key] = this.resolveRequire(require[key])));
1206
- return value;
1207
- }
1208
- else if (typeof require === 'string') {
1209
- const match = require.match(REQUIRE_PREFIX_RE);
1210
- const inheritType = match[1] || match[3];
1211
- const name = require.substring(match[0].length);
1212
- const isOptional = !!match[2];
1213
- const searchParents = !!inheritType;
1214
- const startOnParent = inheritType === '^^';
1215
- const ctrlKey = controllerKey(name);
1216
- const elem = startOnParent ? this.$element.parent() : this.$element;
1217
- const value = searchParents ? elem.inheritedData(ctrlKey) : elem.data(ctrlKey);
1218
- if (!value && !isOptional) {
1219
- throw new Error(`Unable to find required '${require}' in upgraded directive '${this.name}'.`);
1220
- }
1221
- return value;
1222
- }
1223
- else {
1224
- throw new Error(`Unrecognized 'require' syntax on upgraded directive '${this.name}': ${require}`);
1225
- }
1226
- }
1227
- }
1228
- function getOrCall(property, ...args) {
1229
- return isFunction(property) ? property(...args) : property;
1230
- }
1231
- // NOTE: Only works for `typeof T !== 'object'`.
1232
- function isMap(value) {
1233
- return value && !Array.isArray(value) && typeof value === 'object';
1234
- }
1235
- function notSupported(name, feature) {
1236
- throw new Error(`Upgraded directive '${name}' contains unsupported feature: '${feature}'.`);
1237
- }
1238
-
1239
- var upgrade_helper = /*#__PURE__*/Object.freeze({
1240
- __proto__: null,
1241
- UpgradeHelper: UpgradeHelper
1242
- });
1243
-
1244
- /**
1245
- * Note: We intentionally use cross entry-point relative paths here. This
1246
- * is because the primary entry-point is deprecated and we also don't have
1247
- * it available in G3.
1248
- */
1249
-
1250
13
  // We have to do a little dance to get the ng1 injector into the module injector.
1251
14
  // We store the ng1 injector so that the provider in the module injector can access it
1252
15
  // Then we "get" the ng1 injector from the module injector, which triggers the provider to read
@@ -1293,7 +56,7 @@ class NgAdapterInjector {
1293
56
  // injector.
1294
57
  // AngularJS only supports a single tree and should always check the module injector.
1295
58
  get(token, notFoundValue) {
1296
- if (notFoundValue === ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) {
59
+ if (notFoundValue === _NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) {
1297
60
  return notFoundValue;
1298
61
  }
1299
62
  return this.modInjector.get(token, notFoundValue);
@@ -1406,7 +169,7 @@ let moduleUid = 0;
1406
169
  * {@link PlatformRef#bootstrapmodulefactory `bootstrapModuleFactory()`} to bootstrap the
1407
170
  * downgraded modules, each one is considered a "root" module. As a consequence, a new instance
1408
171
  * will be created for every injectable provided in `"root"` (via
1409
- * {@link Injectable#providedIn `providedIn`}).
172
+ * {@link /api/core/Injectable#providedIn providedIn}
1410
173
  * If this is not your intention, you can have a shared module (that will act as act as the "root"
1411
174
  * module) and create all downgraded modules using that module's injector:
1412
175
  *
@@ -1716,10 +479,10 @@ class UpgradeComponent {
1716
479
  bindingDestination.$onChanges(changes);
1717
480
  }
1718
481
  }
1719
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0-next.0", ngImport: i0, type: UpgradeComponent, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive });
1720
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.0.0-next.0", type: UpgradeComponent, isStandalone: true, usesOnChanges: true, ngImport: i0 });
482
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0-next.2", ngImport: i0, type: UpgradeComponent, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive });
483
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.0.0-next.2", type: UpgradeComponent, isStandalone: true, usesOnChanges: true, ngImport: i0 });
1721
484
  }
1722
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0-next.0", ngImport: i0, type: UpgradeComponent, decorators: [{
485
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0-next.2", ngImport: i0, type: UpgradeComponent, decorators: [{
1723
486
  type: Directive
1724
487
  }], ctorParameters: () => [{ type: undefined }, { type: i0.ElementRef }, { type: i0.Injector }] });
1725
488
 
@@ -1746,7 +509,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0-next.0",
1746
509
  * {@link UpgradeModule#upgrading-an-angular-1-service Upgrading an AngularJS service} below.
1747
510
  * 4. Creation of an AngularJS service that wraps and exposes an Angular injectable
1748
511
  * so that it can be injected into an AngularJS context. See `downgradeInjectable`.
1749
- * 3. Bootstrapping of a hybrid Angular application which contains both of the frameworks
512
+ * 5. Bootstrapping of a hybrid Angular application which contains both of the frameworks
1750
513
  * coexisting in a single application.
1751
514
  *
1752
515
  * @usageNotes
@@ -1812,7 +575,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0-next.0",
1812
575
  *
1813
576
  * ### Examples
1814
577
  *
1815
- * Import the `UpgradeModule` into your top level {@link NgModule Angular `NgModule`}.
578
+ * Import the `UpgradeModule` into your top level Angular {@link NgModule NgModule}.
1816
579
  *
1817
580
  * {@example upgrade/static/ts/full/module.ts region='ng2-module'}
1818
581
  *
@@ -1826,7 +589,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0-next.0",
1826
589
  *
1827
590
  * {@example upgrade/static/ts/full/module.ts region='bootstrap-ng2'}
1828
591
  *
1829
- * {@a upgrading-an-angular-1-service}
1830
592
  * ### Upgrading an AngularJS service
1831
593
  *
1832
594
  * There is no specific API for upgrading an AngularJS service. Instead you should just follow the
@@ -2003,22 +765,14 @@ class UpgradeModule {
2003
765
  }
2004
766
  return returnValue;
2005
767
  }
2006
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0-next.0", ngImport: i0, type: UpgradeModule, deps: [{ token: i0.Injector }, { token: i0.NgZone }, { token: i0.PlatformRef }], target: i0.ɵɵFactoryTarget.NgModule });
2007
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.0-next.0", ngImport: i0, type: UpgradeModule });
2008
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.0-next.0", ngImport: i0, type: UpgradeModule, providers: [angular1Providers] });
768
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0-next.2", ngImport: i0, type: UpgradeModule, deps: [{ token: i0.Injector }, { token: i0.NgZone }, { token: i0.PlatformRef }], target: i0.ɵɵFactoryTarget.NgModule });
769
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.0-next.2", ngImport: i0, type: UpgradeModule });
770
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.0-next.2", ngImport: i0, type: UpgradeModule, providers: [angular1Providers] });
2009
771
  }
2010
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0-next.0", ngImport: i0, type: UpgradeModule, decorators: [{
772
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0-next.2", ngImport: i0, type: UpgradeModule, decorators: [{
2011
773
  type: NgModule,
2012
774
  args: [{ providers: [angular1Providers] }]
2013
775
  }], ctorParameters: () => [{ type: i0.Injector }, { type: i0.NgZone }, { type: i0.PlatformRef }] });
2014
776
 
2015
- // This file only re-exports items to appear in the public api. Keep it that way.
2016
-
2017
- // This file is not used to build this module. It is only used during editing
2018
-
2019
- /**
2020
- * Generated bundle index. Do not edit.
2021
- */
2022
-
2023
- export { UpgradeComponent, UpgradeModule, VERSION, downgradeComponent, downgradeInjectable, downgradeModule, getAngularJSGlobal, getAngularLib, setAngularJSGlobal, setAngularLib, angular1 as ɵangular1, constants as ɵconstants, upgrade_helper as ɵupgradeHelper, util as ɵutil };
777
+ export { UpgradeComponent, UpgradeModule, downgradeModule };
2024
778
  //# sourceMappingURL=static.mjs.map