@angular/upgrade 19.2.1 → 19.2.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,1251 +1,15 @@
1
1
  /**
2
- * @license Angular v19.2.1
2
+ * @license Angular v19.2.2
3
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 /api/core/ChangeDetectorRef#detectChanges detectChanges} on the
715
- * component on every {@link https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$digest $digest}.
716
- * If set to `false`, change detection will still be performed when any of the component's inputs changes.
717
- * (Default: true)
718
- *
719
- * @returns a factory function that can be used to register the component in an
720
- * AngularJS module.
721
- *
722
- * @publicApi
723
- */
724
- function downgradeComponent(info) {
725
- const directiveFactory = function ($compile, $injector, $parse) {
726
- const unsafelyOverwriteSignalInputs = info.unsafelyOverwriteSignalInputs ?? false;
727
- // When using `downgradeModule()`, we need to handle certain things specially. For example:
728
- // - We always need to attach the component view to the `ApplicationRef` for it to be
729
- // dirty-checked.
730
- // - We need to ensure callbacks to Angular APIs (e.g. change detection) are run inside the
731
- // Angular zone.
732
- // NOTE: This is not needed, when using `UpgradeModule`, because `$digest()` will be run
733
- // inside the Angular zone (except if explicitly escaped, in which case we shouldn't
734
- // force it back in).
735
- const isNgUpgradeLite = getUpgradeAppType($injector) === 3 /* UpgradeAppType.Lite */;
736
- const wrapCallback = !isNgUpgradeLite
737
- ? (cb) => cb
738
- : (cb) => () => (NgZone.isInAngularZone() ? cb() : ngZone.run(cb));
739
- let ngZone;
740
- // When downgrading multiple modules, special handling is needed wrt injectors.
741
- const hasMultipleDowngradedModules = isNgUpgradeLite && getDowngradedModuleCount($injector) > 1;
742
- return {
743
- restrict: 'E',
744
- terminal: true,
745
- require: [REQUIRE_INJECTOR, REQUIRE_NG_MODEL],
746
- // Controller needs to be set so that `angular-component-router.js` (from beta Angular 2)
747
- // configuration properties can be made available. See:
748
- // See G3: javascript/angular2/angular1_router_lib.js
749
- // https://github.com/angular/angular.js/blob/47bf11ee94664367a26ed8c91b9b586d3dd420f5/src/ng/compile.js#L1670-L1691.
750
- controller: function () { },
751
- link: (scope, element, attrs, required) => {
752
- // We might have to compile the contents asynchronously, because this might have been
753
- // triggered by `UpgradeNg1ComponentAdapterBuilder`, before the Angular templates have
754
- // been compiled.
755
- const ngModel = required[1];
756
- const parentInjector = required[0];
757
- let moduleInjector = undefined;
758
- let ranAsync = false;
759
- if (!parentInjector || hasMultipleDowngradedModules) {
760
- const downgradedModule = info.downgradedModule || '';
761
- const lazyModuleRefKey = `${LAZY_MODULE_REF}${downgradedModule}`;
762
- const attemptedAction = `instantiating component '${getTypeName(info.component)}'`;
763
- validateInjectionKey($injector, downgradedModule, lazyModuleRefKey, attemptedAction);
764
- const lazyModuleRef = $injector.get(lazyModuleRefKey);
765
- moduleInjector = lazyModuleRef.injector ?? lazyModuleRef.promise;
766
- }
767
- // Notes:
768
- //
769
- // There are two injectors: `finalModuleInjector` and `finalParentInjector` (they might be
770
- // the same instance, but that is irrelevant):
771
- // - `finalModuleInjector` is used to retrieve `ComponentFactoryResolver`, thus it must be
772
- // on the same tree as the `NgModule` that declares this downgraded component.
773
- // - `finalParentInjector` is used for all other injection purposes.
774
- // (Note that Angular knows to only traverse the component-tree part of that injector,
775
- // when looking for an injectable and then switch to the module injector.)
776
- //
777
- // There are basically three cases:
778
- // - If there is no parent component (thus no `parentInjector`), we bootstrap the downgraded
779
- // `NgModule` and use its injector as both `finalModuleInjector` and
780
- // `finalParentInjector`.
781
- // - If there is a parent component (and thus a `parentInjector`) and we are sure that it
782
- // belongs to the same `NgModule` as this downgraded component (e.g. because there is only
783
- // one downgraded module, we use that `parentInjector` as both `finalModuleInjector` and
784
- // `finalParentInjector`.
785
- // - If there is a parent component, but it may belong to a different `NgModule`, then we
786
- // use the `parentInjector` as `finalParentInjector` and this downgraded component's
787
- // declaring `NgModule`'s injector as `finalModuleInjector`.
788
- // Note 1: If the `NgModule` is already bootstrapped, we just get its injector (we don't
789
- // bootstrap again).
790
- // Note 2: It is possible that (while there are multiple downgraded modules) this
791
- // downgraded component and its parent component both belong to the same NgModule.
792
- // In that case, we could have used the `parentInjector` as both
793
- // `finalModuleInjector` and `finalParentInjector`, but (for simplicity) we are
794
- // treating this case as if they belong to different `NgModule`s. That doesn't
795
- // really affect anything, since `parentInjector` has `moduleInjector` as ancestor
796
- // and trying to resolve `ComponentFactoryResolver` from either one will return
797
- // the same instance.
798
- // If there is a parent component, use its injector as parent injector.
799
- // If this is a "top-level" Angular component, use the module injector.
800
- const finalParentInjector = parentInjector || moduleInjector;
801
- // If this is a "top-level" Angular component or the parent component may belong to a
802
- // different `NgModule`, use the module injector for module-specific dependencies.
803
- // If there is a parent component that belongs to the same `NgModule`, use its injector.
804
- const finalModuleInjector = moduleInjector || parentInjector;
805
- const doDowngrade = (injector, moduleInjector) => {
806
- // Retrieve `ComponentFactoryResolver` from the injector tied to the `NgModule` this
807
- // component belongs to.
808
- const componentFactoryResolver = moduleInjector.get(ComponentFactoryResolver);
809
- const componentFactory = componentFactoryResolver.resolveComponentFactory(info.component);
810
- if (!componentFactory) {
811
- throw new Error(`Expecting ComponentFactory for: ${getTypeName(info.component)}`);
812
- }
813
- const injectorPromise = new ParentInjectorPromise(element);
814
- const facade = new DowngradeComponentAdapter(element, attrs, scope, ngModel, injector, $compile, $parse, componentFactory, wrapCallback, unsafelyOverwriteSignalInputs);
815
- const projectableNodes = facade.compileContents();
816
- const componentRef = facade.createComponentAndSetup(projectableNodes, isNgUpgradeLite, info.propagateDigest);
817
- injectorPromise.resolve(componentRef.injector);
818
- if (ranAsync) {
819
- // If this is run async, it is possible that it is not run inside a
820
- // digest and initial input values will not be detected.
821
- scope.$evalAsync(() => { });
822
- }
823
- };
824
- const downgradeFn = !isNgUpgradeLite
825
- ? doDowngrade
826
- : (pInjector, mInjector) => {
827
- if (!ngZone) {
828
- ngZone = pInjector.get(NgZone);
829
- }
830
- wrapCallback(() => doDowngrade(pInjector, mInjector))();
831
- };
832
- // NOTE:
833
- // Not using `ParentInjectorPromise.all()` (which is inherited from `SyncPromise`), because
834
- // Closure Compiler (or some related tool) complains:
835
- // `TypeError: ...$src$downgrade_component_ParentInjectorPromise.all is not a function`
836
- SyncPromise.all([finalParentInjector, finalModuleInjector]).then(([pInjector, mInjector]) => downgradeFn(pInjector, mInjector));
837
- ranAsync = true;
838
- },
839
- };
840
- };
841
- // bracket-notation because of closure - see #14441
842
- directiveFactory['$inject'] = [$COMPILE, $INJECTOR, $PARSE];
843
- return directiveFactory;
844
- }
845
- /**
846
- * Synchronous promise-like object to wrap parent injectors,
847
- * to preserve the synchronous nature of AngularJS's `$compile`.
848
- */
849
- class ParentInjectorPromise extends SyncPromise {
850
- element;
851
- injectorKey = controllerKey(INJECTOR_KEY);
852
- constructor(element) {
853
- super();
854
- this.element = element;
855
- // Store the promise on the element.
856
- element.data(this.injectorKey, this);
857
- }
858
- resolve(injector) {
859
- // Store the real injector on the element.
860
- this.element.data(this.injectorKey, injector);
861
- // Release the element to prevent memory leaks.
862
- this.element = null;
863
- // Resolve the promise.
864
- super.resolve(injector);
865
- }
866
- }
867
-
868
- /**
869
- * @description
870
- *
871
- * A helper function to allow an Angular service to be accessible from AngularJS.
872
- *
873
- * *Part of the [upgrade/static](api?query=upgrade%2Fstatic)
874
- * library for hybrid upgrade apps that support AOT compilation*
875
- *
876
- * This helper function returns a factory function that provides access to the Angular
877
- * service identified by the `token` parameter.
878
- *
879
- * @usageNotes
880
- * ### Examples
881
- *
882
- * First ensure that the service to be downgraded is provided in an `NgModule`
883
- * that will be part of the upgrade application. For example, let's assume we have
884
- * defined `HeroesService`
885
- *
886
- * {@example upgrade/static/ts/full/module.ts region="ng2-heroes-service"}
887
- *
888
- * and that we have included this in our upgrade app `NgModule`
889
- *
890
- * {@example upgrade/static/ts/full/module.ts region="ng2-module"}
891
- *
892
- * Now we can register the `downgradeInjectable` factory function for the service
893
- * on an AngularJS module.
894
- *
895
- * {@example upgrade/static/ts/full/module.ts region="downgrade-ng2-heroes-service"}
896
- *
897
- * Inside an AngularJS component's controller we can get hold of the
898
- * downgraded service via the name we gave when downgrading.
899
- *
900
- * {@example upgrade/static/ts/full/module.ts region="example-app"}
901
- *
902
- * <div class="docs-alert docs-alert-important">
903
- *
904
- * When using `downgradeModule()`, downgraded injectables will not be available until the Angular
905
- * module that provides them is instantiated. In order to be safe, you need to ensure that the
906
- * downgraded injectables are not used anywhere _outside_ the part of the app where it is
907
- * guaranteed that their module has been instantiated.
908
- *
909
- * For example, it is _OK_ to use a downgraded service in an upgraded component that is only used
910
- * from a downgraded Angular component provided by the same Angular module as the injectable, but
911
- * it is _not OK_ to use it in an AngularJS component that may be used independently of Angular or
912
- * use it in a downgraded Angular component from a different module.
913
- *
914
- * </div>
915
- *
916
- * @param token an `InjectionToken` that identifies a service provided from Angular.
917
- * @param downgradedModule the name of the downgraded module (if any) that the injectable
918
- * "belongs to", as returned by a call to `downgradeModule()`. It is the module, whose injector will
919
- * be used for instantiating the injectable.<br />
920
- * (This option is only necessary when using `downgradeModule()` to downgrade more than one Angular
921
- * module.)
922
- *
923
- * @returns a [factory function](https://docs.angularjs.org/guide/di) that can be
924
- * used to register the service on an AngularJS module.
925
- *
926
- * @publicApi
927
- */
928
- function downgradeInjectable(token, downgradedModule = '') {
929
- const factory = function ($injector) {
930
- const injectorKey = `${INJECTOR_KEY}${downgradedModule}`;
931
- const injectableName = isFunction(token) ? getTypeName(token) : String(token);
932
- const attemptedAction = `instantiating injectable '${injectableName}'`;
933
- validateInjectionKey($injector, downgradedModule, injectorKey, attemptedAction);
934
- try {
935
- const injector = $injector.get(injectorKey);
936
- return injector.get(token);
937
- }
938
- catch (err) {
939
- throw new Error(`Error while ${attemptedAction}: ${err.message || err}`);
940
- }
941
- };
942
- factory['$inject'] = [$INJECTOR];
943
- return factory;
944
- }
945
-
946
- /**
947
- * @module
948
- * @description
949
- * Entry point for all public APIs of the upgrade package.
950
- */
951
- /**
952
- * @publicApi
953
- */
954
- const VERSION = new Version('19.2.1');
955
-
956
- /**
957
- * The Trusted Types policy, or null if Trusted Types are not
958
- * enabled/supported, or undefined if the policy has not been created yet.
959
- */
960
- let policy;
961
- /**
962
- * Returns the Trusted Types policy, or null if Trusted Types are not
963
- * enabled/supported. The first call to this function will create the policy.
964
- */
965
- function getPolicy() {
966
- if (policy === undefined) {
967
- policy = null;
968
- const windowWithTrustedTypes = window;
969
- if (windowWithTrustedTypes.trustedTypes) {
970
- try {
971
- policy = windowWithTrustedTypes.trustedTypes.createPolicy('angular#unsafe-upgrade', {
972
- createHTML: (s) => s,
973
- });
974
- }
975
- catch {
976
- // trustedTypes.createPolicy throws if called with a name that is
977
- // already registered, even in report-only mode. Until the API changes,
978
- // catch the error not to break the applications functionally. In such
979
- // cases, the code will fall back to using strings.
980
- }
981
- }
982
- }
983
- return policy;
984
- }
985
- /**
986
- * Unsafely promote a legacy AngularJS template to a TrustedHTML, falling back
987
- * to strings when Trusted Types are not available.
988
- * @security This is a security-sensitive function; any use of this function
989
- * must go through security review. In particular, the template string should
990
- * always be under full control of the application author, as untrusted input
991
- * can cause an XSS vulnerability.
992
- */
993
- function trustedHTMLFromLegacyTemplate(html) {
994
- return getPolicy()?.createHTML(html) || html;
995
- }
996
-
997
- // Constants
998
- const REQUIRE_PREFIX_RE = /^(\^\^?)?(\?)?(\^\^?)?/;
999
- // Classes
1000
- class UpgradeHelper {
1001
- name;
1002
- $injector;
1003
- element;
1004
- $element;
1005
- directive;
1006
- $compile;
1007
- $controller;
1008
- constructor(injector, name, elementRef, directive) {
1009
- this.name = name;
1010
- this.$injector = injector.get($INJECTOR);
1011
- this.$compile = this.$injector.get($COMPILE);
1012
- this.$controller = this.$injector.get($CONTROLLER);
1013
- this.element = elementRef.nativeElement;
1014
- this.$element = element(this.element);
1015
- this.directive = directive ?? UpgradeHelper.getDirective(this.$injector, name);
1016
- }
1017
- static getDirective($injector, name) {
1018
- const directives = $injector.get(name + 'Directive');
1019
- if (directives.length > 1) {
1020
- throw new Error(`Only support single directive definition for: ${name}`);
1021
- }
1022
- const directive = directives[0];
1023
- // AngularJS will transform `link: xyz` to `compile: () => xyz`. So we can only tell there was a
1024
- // user-defined `compile` if there is no `link`. In other cases, we will just ignore `compile`.
1025
- if (directive.compile && !directive.link)
1026
- notSupported(name, 'compile');
1027
- if (directive.replace)
1028
- notSupported(name, 'replace');
1029
- if (directive.terminal)
1030
- notSupported(name, 'terminal');
1031
- return directive;
1032
- }
1033
- static getTemplate($injector, directive, fetchRemoteTemplate = false, $element) {
1034
- if (directive.template !== undefined) {
1035
- return trustedHTMLFromLegacyTemplate(getOrCall(directive.template, $element));
1036
- }
1037
- else if (directive.templateUrl) {
1038
- const $templateCache = $injector.get($TEMPLATE_CACHE);
1039
- const url = getOrCall(directive.templateUrl, $element);
1040
- const template = $templateCache.get(url);
1041
- if (template !== undefined) {
1042
- return trustedHTMLFromLegacyTemplate(template);
1043
- }
1044
- else if (!fetchRemoteTemplate) {
1045
- throw new Error('loading directive templates asynchronously is not supported');
1046
- }
1047
- return new Promise((resolve, reject) => {
1048
- const $httpBackend = $injector.get($HTTP_BACKEND);
1049
- $httpBackend('GET', url, null, (status, response) => {
1050
- if (status === 200) {
1051
- resolve(trustedHTMLFromLegacyTemplate($templateCache.put(url, response)));
1052
- }
1053
- else {
1054
- reject(`GET component template from '${url}' returned '${status}: ${response}'`);
1055
- }
1056
- });
1057
- });
1058
- }
1059
- else {
1060
- throw new Error(`Directive '${directive.name}' is not a component, it is missing template.`);
1061
- }
1062
- }
1063
- buildController(controllerType, $scope) {
1064
- // TODO: Document that we do not pre-assign bindings on the controller instance.
1065
- // Quoted properties below so that this code can be optimized with Closure Compiler.
1066
- const locals = { '$scope': $scope, '$element': this.$element };
1067
- const controller = this.$controller(controllerType, locals, null, this.directive.controllerAs);
1068
- this.$element.data?.(controllerKey(this.directive.name), controller);
1069
- return controller;
1070
- }
1071
- compileTemplate(template) {
1072
- if (template === undefined) {
1073
- template = UpgradeHelper.getTemplate(this.$injector, this.directive, false, this.$element);
1074
- }
1075
- return this.compileHtml(template);
1076
- }
1077
- onDestroy($scope, controllerInstance) {
1078
- if (controllerInstance && isFunction(controllerInstance.$onDestroy)) {
1079
- controllerInstance.$onDestroy();
1080
- }
1081
- $scope.$destroy();
1082
- cleanData(this.element);
1083
- }
1084
- prepareTransclusion() {
1085
- const transclude = this.directive.transclude;
1086
- const contentChildNodes = this.extractChildNodes();
1087
- const attachChildrenFn = (scope, cloneAttachFn) => {
1088
- // Since AngularJS v1.5.8, `cloneAttachFn` will try to destroy the transclusion scope if
1089
- // `$template` is empty. Since the transcluded content comes from Angular, not AngularJS,
1090
- // there will be no transclusion scope here.
1091
- // Provide a dummy `scope.$destroy()` method to prevent `cloneAttachFn` from throwing.
1092
- scope = scope || { $destroy: () => undefined };
1093
- return cloneAttachFn($template, scope);
1094
- };
1095
- let $template = contentChildNodes;
1096
- if (transclude) {
1097
- const slots = Object.create(null);
1098
- if (typeof transclude === 'object') {
1099
- $template = [];
1100
- const slotMap = Object.create(null);
1101
- const filledSlots = Object.create(null);
1102
- // Parse the element selectors.
1103
- Object.keys(transclude).forEach((slotName) => {
1104
- let selector = transclude[slotName];
1105
- const optional = selector.charAt(0) === '?';
1106
- selector = optional ? selector.substring(1) : selector;
1107
- slotMap[selector] = slotName;
1108
- slots[slotName] = null; // `null`: Defined but not yet filled.
1109
- filledSlots[slotName] = optional; // Consider optional slots as filled.
1110
- });
1111
- // Add the matching elements into their slot.
1112
- contentChildNodes.forEach((node) => {
1113
- const slotName = slotMap[directiveNormalize(node.nodeName.toLowerCase())];
1114
- if (slotName) {
1115
- filledSlots[slotName] = true;
1116
- slots[slotName] = slots[slotName] || [];
1117
- slots[slotName].push(node);
1118
- }
1119
- else {
1120
- $template.push(node);
1121
- }
1122
- });
1123
- // Check for required slots that were not filled.
1124
- Object.keys(filledSlots).forEach((slotName) => {
1125
- if (!filledSlots[slotName]) {
1126
- throw new Error(`Required transclusion slot '${slotName}' on directive: ${this.name}`);
1127
- }
1128
- });
1129
- Object.keys(slots)
1130
- .filter((slotName) => slots[slotName])
1131
- .forEach((slotName) => {
1132
- const nodes = slots[slotName];
1133
- slots[slotName] = (scope, cloneAttach) => {
1134
- return cloneAttach(nodes, scope);
1135
- };
1136
- });
1137
- }
1138
- // Attach `$$slots` to default slot transclude fn.
1139
- attachChildrenFn.$$slots = slots;
1140
- // AngularJS v1.6+ ignores empty or whitespace-only transcluded text nodes. But Angular
1141
- // removes all text content after the first interpolation and updates it later, after
1142
- // evaluating the expressions. This would result in AngularJS failing to recognize text
1143
- // nodes that start with an interpolation as transcluded content and use the fallback
1144
- // content instead.
1145
- // To avoid this issue, we add a
1146
- // [zero-width non-joiner character](https://en.wikipedia.org/wiki/Zero-width_non-joiner)
1147
- // to empty text nodes (which can only be a result of Angular removing their initial content).
1148
- // NOTE: Transcluded text content that starts with whitespace followed by an interpolation
1149
- // will still fail to be detected by AngularJS v1.6+
1150
- $template.forEach((node) => {
1151
- if (node.nodeType === Node.TEXT_NODE && !node.nodeValue) {
1152
- node.nodeValue = '\u200C';
1153
- }
1154
- });
1155
- }
1156
- return attachChildrenFn;
1157
- }
1158
- resolveAndBindRequiredControllers(controllerInstance) {
1159
- const directiveRequire = this.getDirectiveRequire();
1160
- const requiredControllers = this.resolveRequire(directiveRequire);
1161
- if (controllerInstance && this.directive.bindToController && isMap(directiveRequire)) {
1162
- const requiredControllersMap = requiredControllers;
1163
- Object.keys(requiredControllersMap).forEach((key) => {
1164
- controllerInstance[key] = requiredControllersMap[key];
1165
- });
1166
- }
1167
- return requiredControllers;
1168
- }
1169
- compileHtml(html) {
1170
- this.element.innerHTML = html;
1171
- return this.$compile(this.element.childNodes);
1172
- }
1173
- extractChildNodes() {
1174
- const childNodes = [];
1175
- let childNode;
1176
- while ((childNode = this.element.firstChild)) {
1177
- childNode.remove();
1178
- childNodes.push(childNode);
1179
- }
1180
- return childNodes;
1181
- }
1182
- getDirectiveRequire() {
1183
- const require = this.directive.require || (this.directive.controller && this.directive.name);
1184
- if (isMap(require)) {
1185
- Object.entries(require).forEach(([key, value]) => {
1186
- const match = value.match(REQUIRE_PREFIX_RE);
1187
- const name = value.substring(match[0].length);
1188
- if (!name) {
1189
- require[key] = match[0] + key;
1190
- }
1191
- });
1192
- }
1193
- return require;
1194
- }
1195
- resolveRequire(require) {
1196
- if (!require) {
1197
- return null;
1198
- }
1199
- else if (Array.isArray(require)) {
1200
- return require.map((req) => this.resolveRequire(req));
1201
- }
1202
- else if (typeof require === 'object') {
1203
- const value = {};
1204
- Object.keys(require).forEach((key) => (value[key] = this.resolveRequire(require[key])));
1205
- return value;
1206
- }
1207
- else if (typeof require === 'string') {
1208
- const match = require.match(REQUIRE_PREFIX_RE);
1209
- const inheritType = match[1] || match[3];
1210
- const name = require.substring(match[0].length);
1211
- const isOptional = !!match[2];
1212
- const searchParents = !!inheritType;
1213
- const startOnParent = inheritType === '^^';
1214
- const ctrlKey = controllerKey(name);
1215
- const elem = startOnParent ? this.$element.parent() : this.$element;
1216
- const value = searchParents ? elem.inheritedData(ctrlKey) : elem.data(ctrlKey);
1217
- if (!value && !isOptional) {
1218
- throw new Error(`Unable to find required '${require}' in upgraded directive '${this.name}'.`);
1219
- }
1220
- return value;
1221
- }
1222
- else {
1223
- throw new Error(`Unrecognized 'require' syntax on upgraded directive '${this.name}': ${require}`);
1224
- }
1225
- }
1226
- }
1227
- function getOrCall(property, ...args) {
1228
- return isFunction(property) ? property(...args) : property;
1229
- }
1230
- // NOTE: Only works for `typeof T !== 'object'`.
1231
- function isMap(value) {
1232
- return value && !Array.isArray(value) && typeof value === 'object';
1233
- }
1234
- function notSupported(name, feature) {
1235
- throw new Error(`Upgraded directive '${name}' contains unsupported feature: '${feature}'.`);
1236
- }
1237
-
1238
- var upgrade_helper = /*#__PURE__*/Object.freeze({
1239
- __proto__: null,
1240
- UpgradeHelper: UpgradeHelper
1241
- });
1242
-
1243
- /**
1244
- * Note: We intentionally use cross entry-point relative paths here. This
1245
- * is because the primary entry-point is deprecated and we also don't have
1246
- * it available in G3.
1247
- */
1248
-
1249
13
  // We have to do a little dance to get the ng1 injector into the module injector.
1250
14
  // We store the ng1 injector so that the provider in the module injector can access it
1251
15
  // Then we "get" the ng1 injector from the module injector, which triggers the provider to read
@@ -1292,7 +56,7 @@ class NgAdapterInjector {
1292
56
  // injector.
1293
57
  // AngularJS only supports a single tree and should always check the module injector.
1294
58
  get(token, notFoundValue) {
1295
- if (notFoundValue === ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) {
59
+ if (notFoundValue === _NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) {
1296
60
  return notFoundValue;
1297
61
  }
1298
62
  return this.modInjector.get(token, notFoundValue);
@@ -1715,10 +479,10 @@ class UpgradeComponent {
1715
479
  bindingDestination.$onChanges(changes);
1716
480
  }
1717
481
  }
1718
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: UpgradeComponent, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive });
1719
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.1", type: UpgradeComponent, isStandalone: true, usesOnChanges: true, ngImport: i0 });
482
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: UpgradeComponent, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive });
483
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: UpgradeComponent, isStandalone: true, usesOnChanges: true, ngImport: i0 });
1720
484
  }
1721
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: UpgradeComponent, decorators: [{
485
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: UpgradeComponent, decorators: [{
1722
486
  type: Directive
1723
487
  }], ctorParameters: () => [{ type: undefined }, { type: i0.ElementRef }, { type: i0.Injector }] });
1724
488
 
@@ -2001,22 +765,14 @@ class UpgradeModule {
2001
765
  }
2002
766
  return returnValue;
2003
767
  }
2004
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: UpgradeModule, deps: [{ token: i0.Injector }, { token: i0.NgZone }, { token: i0.PlatformRef }], target: i0.ɵɵFactoryTarget.NgModule });
2005
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: UpgradeModule });
2006
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: UpgradeModule, providers: [angular1Providers] });
768
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.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: "19.2.2", ngImport: i0, type: UpgradeModule });
770
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: UpgradeModule, providers: [angular1Providers] });
2007
771
  }
2008
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: UpgradeModule, decorators: [{
772
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: UpgradeModule, decorators: [{
2009
773
  type: NgModule,
2010
774
  args: [{ providers: [angular1Providers] }]
2011
775
  }], ctorParameters: () => [{ type: i0.Injector }, { type: i0.NgZone }, { type: i0.PlatformRef }] });
2012
776
 
2013
- // This file only re-exports items to appear in the public api. Keep it that way.
2014
-
2015
- // This file is not used to build this module. It is only used during editing
2016
-
2017
- /**
2018
- * Generated bundle index. Do not edit.
2019
- */
2020
-
2021
- 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 };
2022
778
  //# sourceMappingURL=static.mjs.map