Skip to content

Commit

Permalink
Update forked Angular files
Browse files Browse the repository at this point in the history
  • Loading branch information
m-akinc committed Jan 9, 2025
1 parent 2ffe308 commit 6813c26
Show file tree
Hide file tree
Showing 13 changed files with 1,178 additions and 790 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* [Nimble]
* Copied from https://github.com/angular/angular/blob/17.3.11/packages/forms/src/directives/checkbox_value_accessor.ts
* Copied from https://github.com/angular/angular/blob/18.2.13/packages/forms/src/directives/checkbox_value_accessor.ts
* with the following modifications:
* - Update imports
* - Remove all configuration from the CheckboxControlValueAccessor's `@Directive` decorator
Expand All @@ -11,13 +11,15 @@
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
* found in the LICENSE file at https://angular.dev/license
*/

import {Directive, forwardRef, Provider} from '@angular/core';

import {
BuiltInControlValueAccessor,
} from './control_value_accessor';
import type {ControlValueAccessor} from '@angular/forms';
import {BuiltInControlValueAccessor} from './control_value_accessor';

/* [Nimble] Do not register as a value accessor provider
const CHECKBOX_VALUE_ACCESSOR: Provider = {
Expand Down Expand Up @@ -53,14 +55,16 @@ const CHECKBOX_VALUE_ACCESSOR: Provider = {
/* [Nimble] Remove all configuration from @Directive decorator
@Directive({
selector:
'input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]',
'input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]',
host: {'(change)': 'onChange($event.target.checked)', '(blur)': 'onTouched()'},
providers: [CHECKBOX_VALUE_ACCESSOR]
providers: [CHECKBOX_VALUE_ACCESSOR],
})
*/
@Directive()
export class CheckboxControlValueAccessor extends BuiltInControlValueAccessor implements
ControlValueAccessor {
export class CheckboxControlValueAccessor
extends BuiltInControlValueAccessor
implements ControlValueAccessor
{
/**
* Sets the "checked" property on the input element.
* @nodoc
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* [Nimble]
* Copied from https://github.com/angular/angular/blob/17.3.11/packages/forms/src/directives/control_value_accessor.ts
* Copied from https://github.com/angular/angular/blob/18.2.13/packages/forms/src/directives/control_value_accessor.ts
* with the following modifications:
* - Update imports
* - Commented out ControlValueAccessor which is exported from @angular/forms
Expand All @@ -12,7 +12,7 @@
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
* found in the LICENSE file at https://angular.dev/license
*/

import {Directive, ElementRef, InjectionToken, Renderer2} from '@angular/core';
Expand Down Expand Up @@ -164,7 +164,10 @@ export class BaseControlValueAccessor {
*/
onTouched = () => {};

constructor(private _renderer: Renderer2, private _elementRef: ElementRef) {}
constructor(
private _renderer: Renderer2,
private _elementRef: ElementRef,
) {}

/**
* Helper method that sets a property on a target element using the current Renderer
Expand Down Expand Up @@ -210,8 +213,7 @@ export class BaseControlValueAccessor {
* applications code.
*/
@Directive()
export class BuiltInControlValueAccessor extends BaseControlValueAccessor {
}
export class BuiltInControlValueAccessor extends BaseControlValueAccessor {}

/**
* Used to provide a `ControlValueAccessor` for form controls.
Expand All @@ -221,6 +223,7 @@ export class BuiltInControlValueAccessor extends BaseControlValueAccessor {
* @publicApi
*/
/* [Nimble] Commenting out public injection token
export const NG_VALUE_ACCESSOR =
new InjectionToken<ReadonlyArray<ControlValueAccessor>>(ngDevMode ? 'NgValueAccessor' : '');
export const NG_VALUE_ACCESSOR = new InjectionToken<ReadonlyArray<ControlValueAccessor>>(
ngDevMode ? 'NgValueAccessor' : '',
);
*/
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* [Nimble]
* Copied from https://github.com/angular/angular/blob/17.3.11/packages/forms/src/directives/default_value_accessor.ts
* Copied from https://github.com/angular/angular/blob/18.2.13/packages/forms/src/directives/default_value_accessor.ts
* with the following modifications:
* - Update imports
* - Update implementation of `_isAndroid()` to not use private APIs
Expand All @@ -12,20 +12,32 @@
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
* found in the LICENSE file at https://angular.dev/license
*/

import {ɵgetDOM as getDOM} from '@angular/common';
import {Directive, ElementRef, forwardRef, Inject, InjectionToken, Optional, Provider, Renderer2} from '@angular/core';
import {
Directive,
ElementRef,
forwardRef,
Inject,
InjectionToken,
Optional,
Provider,
Renderer2,
} from '@angular/core';

import {
BaseControlValueAccessor,
// NG_VALUE_ACCESSOR,
} from './control_value_accessor';
import {ControlValueAccessor, COMPOSITION_BUFFER_MODE} from '@angular/forms';
import {BaseControlValueAccessor} from './control_value_accessor';

/* [Nimble] Do not register as a default value accessor provider
export const DEFAULT_VALUE_ACCESSOR: Provider = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => DefaultValueAccessor),
multi: true
multi: true,
};
*/

Expand All @@ -47,16 +59,16 @@ function _isAndroid(): boolean {
* the "compositionend" event occurs.
* @publicApi
*
export const COMPOSITION_BUFFER_MODE =
new InjectionToken<boolean>(ngDevMode ? 'CompositionEventMode' : '');
export const COMPOSITION_BUFFER_MODE = new InjectionToken<boolean>(
ngDevMode ? 'CompositionEventMode' : '',
);
*/

/**
* The default `ControlValueAccessor` for writing a value and listening to changes on input
* elements. The accessor is used by the `FormControlDirective`, `FormControlName`, and
* `NgModel` directives.
*
* {@searchKeywords ngDefaultControl}
*
* @usageNotes
*
Expand Down Expand Up @@ -89,17 +101,17 @@ export const COMPOSITION_BUFFER_MODE =
/* [Nimble] Remove all configuration from @Directive decorator
@Directive({
selector:
'input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]',
'input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]',
// TODO: vsavkin replace the above selector with the one below it once
// https://github.com/angular/angular/issues/3011 is implemented
// selector: '[ngModel],[formControl],[formControlName]',
host: {
'(input)': '$any(this)._handleInput($event.target.value)',
'(blur)': 'onTouched()',
'(compositionstart)': '$any(this)._compositionStart()',
'(compositionend)': '$any(this)._compositionEnd($event.target.value)'
'(compositionend)': '$any(this)._compositionEnd($event.target.value)',
},
providers: [DEFAULT_VALUE_ACCESSOR]
providers: [DEFAULT_VALUE_ACCESSOR],
})
*/
@Directive()
Expand All @@ -108,8 +120,10 @@ export class DefaultValueAccessor extends BaseControlValueAccessor implements Co
private _composing = false;

constructor(
renderer: Renderer2, elementRef: ElementRef,
@Optional() @Inject(COMPOSITION_BUFFER_MODE) private _compositionMode: boolean) {
renderer: Renderer2,
elementRef: ElementRef,
@Optional() @Inject(COMPOSITION_BUFFER_MODE) private _compositionMode: boolean,
) {
super(renderer, elementRef);
if (this._compositionMode == null) {
this._compositionMode = !_isAndroid();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* [Nimble]
* Copied from https://github.com/angular/angular/blob/17.3.11/packages/forms/src/directives/number_value_accessor.ts
* Copied from https://github.com/angular/angular/blob/18.2.13/packages/forms/src/directives/number_value_accessor.ts
* with the following modifications:
* - Update imports
* - Remove all configuration from NumberValueAccessor's `@Directive` decorator
Expand All @@ -12,19 +12,23 @@
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
* found in the LICENSE file at https://angular.dev/license
*/

import {Directive, ElementRef, forwardRef, Provider} from '@angular/core';

import type {ControlValueAccessor} from '@angular/forms';
import {BuiltInControlValueAccessor} from './control_value_accessor';
import {
BuiltInControlValueAccessor,
// ControlValueAccessor,
// NG_VALUE_ACCESSOR,
} from './control_value_accessor';

/* [Nimble] Do not register as a value accessor provider
const NUMBER_VALUE_ACCESSOR: Provider = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => NumberValueAccessor),
multi: true
multi: true,
};
*/

Expand Down Expand Up @@ -55,14 +59,16 @@ const NUMBER_VALUE_ACCESSOR: Provider = {
/* [Nimble] Remove all configuration from @Directive decorator
@Directive({
selector:
'input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]',
'input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]',
host: {'(input)': 'onChange($event.target.value)', '(blur)': 'onTouched()'},
providers: [NUMBER_VALUE_ACCESSOR]
providers: [NUMBER_VALUE_ACCESSOR],
})
*/
@Directive()
export class NumberValueAccessor extends BuiltInControlValueAccessor implements
ControlValueAccessor {
export class NumberValueAccessor
extends BuiltInControlValueAccessor
implements ControlValueAccessor
{
/**
* Sets the "value" property on the input element.
* @nodoc
Expand All @@ -77,7 +83,7 @@ export class NumberValueAccessor extends BuiltInControlValueAccessor implements
* Registers a function called when the control value changes.
* @nodoc
*/
override registerOnChange(fn: (_: number|null) => void): void {
override registerOnChange(fn: (_: number | null) => void): void {
this.onChange = (value) => {
fn(value == '' ? null : parseFloat(value));
};
Expand Down
Loading

0 comments on commit 6813c26

Please sign in to comment.