| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,23 +1,21 @@ | |||
| 1 | - import { Directive, OnInit, OnDestroy, Inject, ElementRef } from '@angular/core' | ||
| 1 | + import { Directive, OnDestroy, ElementRef, inject } from '@angular/core' | ||
| 2 | 2 | import { SplitGutterDirective } from './split-gutter.directive' | |
| 3 | 3 | import { GUTTER_NUM_TOKEN } from './gutter-num-token' | |
| 4 | 4 | ||
| 5 | 5 | @Directive({ | |
| 6 | 6 | selector: '[asSplitGutterDragHandle]', | |
| 7 | 7 | standalone: true, | |
| 8 | 8 | }) | |
| 9 | - export class SplitGutterDragHandleDirective implements OnInit, OnDestroy { | ||
| 10 | - constructor( | ||
| 11 | - @Inject(GUTTER_NUM_TOKEN) private gutterNum: number, | ||
| 12 | - private elementRef: ElementRef<HTMLElement>, | ||
| 13 | - private gutterDir: SplitGutterDirective, | ||
| 14 | - ) {} | ||
| 9 | + export class SplitGutterDragHandleDirective implements OnDestroy { | ||
| 10 | + private readonly gutterNum = inject(GUTTER_NUM_TOKEN) | ||
| 11 | + private readonly elementRef = inject<ElementRef<HTMLElement>>(ElementRef) | ||
| 12 | + private readonly gutterDir = inject(SplitGutterDirective) | ||
| 15 | 13 | ||
| 16 | - ngOnInit(): void { | ||
| 17 | - this.gutterDir.addToMap(this.gutterDir.gutterToHandleElementMap, this.gutterNum, this.elementRef) | ||
| 14 | + constructor() { | ||
| 15 | + this.gutterDir._addToMap(this.gutterDir._gutterToHandleElementMap, this.gutterNum, this.elementRef) | ||
| 18 | 16 | } | |
| 19 | 17 | ||
| 20 | 18 | ngOnDestroy(): void { | |
| 21 | - this.gutterDir.removedFromMap(this.gutterDir.gutterToHandleElementMap, this.gutterNum, this.elementRef) | ||
| 19 | + this.gutterDir._removedFromMap(this.gutterDir._gutterToHandleElementMap, this.gutterNum, this.elementRef) | ||
| 22 | 20 | } | |
| 23 | 21 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - import { Injector, Directive, Input, ViewContainerRef, TemplateRef } from '@angular/core' | ||
| 1 | + import { Injector, Directive, ViewContainerRef, TemplateRef, input, effect, inject } from '@angular/core' | ||
| 2 | 2 | import { GUTTER_NUM_TOKEN } from './gutter-num-token' | |
| 3 | 3 | ||
| 4 | 4 | interface SplitGutterDynamicInjectorTemplateContext { | |
@@ -14,30 +14,31 @@ interface SplitGutterDynamicInjectorTemplateContext { | |||
| 14 | 14 | standalone: true, | |
| 15 | 15 | }) | |
| 16 | 16 | export class SplitGutterDynamicInjectorDirective { | |
| 17 | - @Input('asSplitGutterDynamicInjector') | ||
| 18 | - set gutterNum(value: number) { | ||
| 19 | - this.vcr.clear() | ||
| 17 | + private readonly vcr = inject(ViewContainerRef) | ||
| 18 | + private readonly templateRef = inject<TemplateRef<SplitGutterDynamicInjectorTemplateContext>>(TemplateRef) | ||
| 20 | 19 | ||
| 21 | - const injector = Injector.create({ | ||
| 22 | - providers: [ | ||
| 23 | - { | ||
| 24 | - provide: GUTTER_NUM_TOKEN, | ||
| 25 | - useValue: value, | ||
| 26 | - }, | ||
| 27 | - ], | ||
| 28 | - parent: this.vcr.injector, | ||
| 29 | - }) | ||
| 20 | + protected readonly gutterNum = input.required<number>({ alias: 'asSplitGutterDynamicInjector' }) | ||
| 30 | 21 | ||
| 31 | - this.vcr.createEmbeddedView(this.templateRef, { $implicit: injector }) | ||
| 32 | - } | ||
| 22 | + constructor() { | ||
| 23 | + effect(() => { | ||
| 24 | + this.vcr.clear() | ||
| 25 | + | ||
| 26 | + const injector = Injector.create({ | ||
| 27 | + providers: [ | ||
| 28 | + { | ||
| 29 | + provide: GUTTER_NUM_TOKEN, | ||
| 30 | + useValue: this.gutterNum(), | ||
| 31 | + }, | ||
| 32 | + ], | ||
| 33 | + parent: this.vcr.injector, | ||
| 34 | + }) | ||
| 33 | 35 | ||
| 34 | - constructor( | ||
| 35 | - private vcr: ViewContainerRef, | ||
| 36 | - private templateRef: TemplateRef<SplitGutterDynamicInjectorTemplateContext>, | ||
| 37 | - ) {} | ||
| 36 | + this.vcr.createEmbeddedView(this.templateRef, { $implicit: injector }) | ||
| 37 | + }) | ||
| 38 | + } | ||
| 38 | 39 | ||
| 39 | 40 | static ngTemplateContextGuard( | |
| 40 | - dir: SplitGutterDynamicInjectorDirective, | ||
| 41 | + _dir: SplitGutterDynamicInjectorDirective, | ||
| 41 | 42 | ctx: unknown, | |
| 42 | 43 | ): ctx is SplitGutterDynamicInjectorTemplateContext { | |
| 43 | 44 | return true | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,23 +1,21 @@ | |||
| 1 | - import { Directive, OnInit, OnDestroy, Inject, ElementRef } from '@angular/core' | ||
| 1 | + import { Directive, OnDestroy, ElementRef, inject } from '@angular/core' | ||
| 2 | 2 | import { SplitGutterDirective } from './split-gutter.directive' | |
| 3 | 3 | import { GUTTER_NUM_TOKEN } from './gutter-num-token' | |
| 4 | 4 | ||
| 5 | 5 | @Directive({ | |
| 6 | 6 | selector: '[asSplitGutterExcludeFromDrag]', | |
| 7 | 7 | standalone: true, | |
| 8 | 8 | }) | |
| 9 | - export class SplitGutterExcludeFromDragDirective implements OnInit, OnDestroy { | ||
| 10 | - constructor( | ||
| 11 | - @Inject(GUTTER_NUM_TOKEN) private gutterNum: number, | ||
| 12 | - private elementRef: ElementRef<HTMLElement>, | ||
| 13 | - private gutterDir: SplitGutterDirective, | ||
| 14 | - ) {} | ||
| 9 | + export class SplitGutterExcludeFromDragDirective implements OnDestroy { | ||
| 10 | + private readonly gutterNum = inject(GUTTER_NUM_TOKEN) | ||
| 11 | + private readonly elementRef = inject<ElementRef<HTMLElement>>(ElementRef) | ||
| 12 | + private readonly gutterDir = inject(SplitGutterDirective) | ||
| 15 | 13 | ||
| 16 | - ngOnInit(): void { | ||
| 17 | - this.gutterDir.addToMap(this.gutterDir.gutterToExcludeDragElementMap, this.gutterNum, this.elementRef) | ||
| 14 | + constructor() { | ||
| 15 | + this.gutterDir._addToMap(this.gutterDir._gutterToExcludeDragElementMap, this.gutterNum, this.elementRef) | ||
| 18 | 16 | } | |
| 19 | 17 | ||
| 20 | 18 | ngOnDestroy(): void { | |
| 21 | - this.gutterDir.removedFromMap(this.gutterDir.gutterToExcludeDragElementMap, this.gutterNum, this.elementRef) | ||
| 19 | + this.gutterDir._removedFromMap(this.gutterDir._gutterToExcludeDragElementMap, this.gutterNum, this.elementRef) | ||
| 22 | 20 | } | |
| 23 | 21 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - import { Directive, ElementRef, TemplateRef } from '@angular/core' | ||
| 1 | + import { Directive, ElementRef, inject, TemplateRef } from '@angular/core' | ||
| 2 | 2 | import { SplitAreaComponent } from '../split-area/split-area.component' | |
| 3 | 3 | ||
| 4 | 4 | export interface SplitGutterTemplateContext { | |
@@ -38,22 +38,29 @@ export interface SplitGutterTemplateContext { | |||
| 38 | 38 | standalone: true, | |
| 39 | 39 | }) | |
| 40 | 40 | export class SplitGutterDirective { | |
| 41 | + readonly template = inject<TemplateRef<SplitGutterTemplateContext>>(TemplateRef) | ||
| 42 | + | ||
| 41 | 43 | /** | |
| 42 | 44 | * The map holds reference to the drag handle elements inside instances | |
| 43 | 45 | * of the provided template. | |
| 46 | + * | ||
| 47 | + * @internal | ||
| 44 | 48 | */ | |
| 45 | - gutterToHandleElementMap = new Map<number, ElementRef<HTMLElement>[]>() | ||
| 49 | + readonly _gutterToHandleElementMap = new Map<number, ElementRef<HTMLElement>[]>() | ||
| 46 | 50 | /** | |
| 47 | 51 | * The map holds reference to the excluded drag elements inside instances | |
| 48 | 52 | * of the provided template. | |
| 53 | + * | ||
| 54 | + * @internal | ||
| 49 | 55 | */ | |
| 50 | - gutterToExcludeDragElementMap = new Map<number, ElementRef<HTMLElement>[]>() | ||
| 51 | - | ||
| 52 | - constructor(public template: TemplateRef<SplitGutterTemplateContext>) {} | ||
| 56 | + readonly _gutterToExcludeDragElementMap = new Map<number, ElementRef<HTMLElement>[]>() | ||
| 53 | 57 | ||
| 54 | - canStartDragging(originElement: HTMLElement, gutterNum: number) { | ||
| 55 | - if (this.gutterToExcludeDragElementMap.has(gutterNum)) { | ||
| 56 | - const isInsideExclude = this.gutterToExcludeDragElementMap | ||
| 58 | + /** | ||
| 59 | + * @internal | ||
| 60 | + */ | ||
| 61 | + _canStartDragging(originElement: HTMLElement, gutterNum: number) { | ||
| 62 | + if (this._gutterToExcludeDragElementMap.has(gutterNum)) { | ||
| 63 | + const isInsideExclude = this._gutterToExcludeDragElementMap | ||
| 57 | 64 | .get(gutterNum) | |
| 58 | 65 | .some((gutterExcludeElement) => gutterExcludeElement.nativeElement.contains(originElement)) | |
| 59 | 66 | ||
@@ -62,24 +69,30 @@ export class SplitGutterDirective { | |||
| 62 | 69 | } | |
| 63 | 70 | } | |
| 64 | 71 | ||
| 65 | - if (this.gutterToHandleElementMap.has(gutterNum)) { | ||
| 66 | - return this.gutterToHandleElementMap | ||
| 72 | + if (this._gutterToHandleElementMap.has(gutterNum)) { | ||
| 73 | + return this._gutterToHandleElementMap | ||
| 67 | 74 | .get(gutterNum) | |
| 68 | 75 | .some((gutterHandleElement) => gutterHandleElement.nativeElement.contains(originElement)) | |
| 69 | 76 | } | |
| 70 | 77 | ||
| 71 | 78 | return true | |
| 72 | 79 | } | |
| 73 | 80 | ||
| 74 | - addToMap(map: Map<number, ElementRef<HTMLElement>[]>, gutterNum: number, elementRef: ElementRef<HTMLElement>) { | ||
| 81 | + /** | ||
| 82 | + * @internal | ||
| 83 | + */ | ||
| 84 | + _addToMap(map: Map<number, ElementRef<HTMLElement>[]>, gutterNum: number, elementRef: ElementRef<HTMLElement>) { | ||
| 75 | 85 | if (map.has(gutterNum)) { | |
| 76 | 86 | map.get(gutterNum).push(elementRef) | |
| 77 | 87 | } else { | |
| 78 | 88 | map.set(gutterNum, [elementRef]) | |
| 79 | 89 | } | |
| 80 | 90 | } | |
| 81 | 91 | ||
| 82 | - removedFromMap(map: Map<number, ElementRef<HTMLElement>[]>, gutterNum: number, elementRef: ElementRef<HTMLElement>) { | ||
| 92 | + /** | ||
| 93 | + * @internal | ||
| 94 | + */ | ||
| 95 | + _removedFromMap(map: Map<number, ElementRef<HTMLElement>[]>, gutterNum: number, elementRef: ElementRef<HTMLElement>) { | ||
| 83 | 96 | const elements = map.get(gutterNum) | |
| 84 | 97 | elements.splice(elements.indexOf(elementRef), 1) | |
| 85 | 98 | ||
@@ -88,7 +101,7 @@ export class SplitGutterDirective { | |||
| 88 | 101 | } | |
| 89 | 102 | } | |
| 90 | 103 | ||
| 91 | - static ngTemplateContextGuard(dir: SplitGutterDirective, ctx: unknown): ctx is SplitGutterTemplateContext { | ||
| 104 | + static ngTemplateContextGuard(_dir: SplitGutterDirective, ctx: unknown): ctx is SplitGutterTemplateContext { | ||
| 92 | 105 | return true | |
| 93 | 106 | } | |
| 94 | 107 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -242,7 +242,10 @@ export class SplitComponent { | |||
| 242 | 242 | filter( | |
| 243 | 243 | (context) => | |
| 244 | 244 | !this.customGutter() || | |
| 245 | - this.customGutter().canStartDragging(context.mouseDownEvent.target as HTMLElement, context.gutterIndex + 1), | ||
| 245 | + this.customGutter()._canStartDragging( | ||
| 246 | + context.mouseDownEvent.target as HTMLElement, | ||
| 247 | + context.gutterIndex + 1, | ||
| 248 | + ), | ||
| 246 | 249 | ), | |
| 247 | 250 | switchMap((mouseDownContext) => | |
| 248 | 251 | // As we have gutterClickDeltaPx we can't just start the drag but need to make sure | |
| Back | FazBrowse Home | New Git URL |
0 commit comments