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