|
1 | | -import { Directive, ElementRef, inject, TemplateRef } from '@angular/core' |
2 | | -import type { SplitAreaComponent } from '../split-area/split-area.component' |
| 1 | +import { Directive, inject, TemplateRef } from '@angular/core' |
| 2 | +import type { SplitGutterContext } from './split-gutter-context' |
3 | 3 |
|
4 | | -export interface SplitGutterTemplateContext { |
5 | | - /** |
6 | | - * The area before the gutter. |
7 | | - * In RTL the right area and in LTR the left area |
8 | | - */ |
9 | | - areaBefore: SplitAreaComponent |
10 | | - /** |
11 | | - * The area after the gutter. |
12 | | - * In RTL the left area and in LTR the right area |
13 | | - */ |
14 | | - areaAfter: SplitAreaComponent |
15 | | - /** |
16 | | - * The absolute number of the gutter based on direction (RTL and LTR). |
17 | | - * First gutter is 1, second is 2, etc... |
18 | | - */ |
19 | | - gutterNum: number |
20 | | - /** |
21 | | - * Whether this is the first gutter. |
22 | | - * In RTL the most right area and in LTR the most left area |
23 | | - */ |
24 | | - first: boolean |
25 | | - /** |
26 | | - * Whether this is the last gutter. |
27 | | - * In RTL the most left area and in LTR the most right area |
28 | | - */ |
29 | | - last: boolean |
30 | | - /** |
31 | | - * Whether the gutter is being dragged now |
32 | | - */ |
33 | | - isDragged: boolean |
34 | | -} |
| 4 | +export type SplitGutterTemplateContext = SplitGutterContext |
35 | 5 |
|
36 | 6 | @Directive({ |
37 | 7 | selector: '[asSplitGutter]', |
38 | 8 | }) |
39 | 9 | export class SplitGutterDirective { |
40 | 10 | readonly template = inject<TemplateRef<SplitGutterTemplateContext>>(TemplateRef) |
41 | 11 |
|
42 | | - /** |
43 | | - * The map holds reference to the drag handle elements inside instances |
44 | | - * of the provided template. |
45 | | - * |
46 | | - * @internal |
47 | | - */ |
48 | | - readonly _gutterToHandleElementMap = new Map<number, ElementRef<HTMLElement>[]>() |
49 | | - /** |
50 | | - * The map holds reference to the excluded drag elements inside instances |
51 | | - * of the provided template. |
52 | | - * |
53 | | - * @internal |
54 | | - */ |
55 | | - readonly _gutterToExcludeDragElementMap = new Map<number, ElementRef<HTMLElement>[]>() |
56 | | - |
57 | | - /** |
58 | | - * @internal |
59 | | - */ |
60 | | - _canStartDragging(originElement: HTMLElement, gutterNum: number) { |
61 | | - if (this._gutterToExcludeDragElementMap.has(gutterNum)) { |
62 | | - const isInsideExclude = this._gutterToExcludeDragElementMap |
63 | | - .get(gutterNum) |
64 | | - .some((gutterExcludeElement) => gutterExcludeElement.nativeElement.contains(originElement)) |
65 | | - |
66 | | - if (isInsideExclude) { |
67 | | - return false |
68 | | - } |
69 | | - } |
70 | | - |
71 | | - if (this._gutterToHandleElementMap.has(gutterNum)) { |
72 | | - return this._gutterToHandleElementMap |
73 | | - .get(gutterNum) |
74 | | - .some((gutterHandleElement) => gutterHandleElement.nativeElement.contains(originElement)) |
75 | | - } |
76 | | - |
77 | | - return true |
78 | | - } |
79 | | - |
80 | | - /** |
81 | | - * @internal |
82 | | - */ |
83 | | - _addToMap(map: Map<number, ElementRef<HTMLElement>[]>, gutterNum: number, elementRef: ElementRef<HTMLElement>) { |
84 | | - if (map.has(gutterNum)) { |
85 | | - map.get(gutterNum).push(elementRef) |
86 | | - } else { |
87 | | - map.set(gutterNum, [elementRef]) |
88 | | - } |
89 | | - } |
90 | | - |
91 | | - /** |
92 | | - * @internal |
93 | | - */ |
94 | | - _removedFromMap(map: Map<number, ElementRef<HTMLElement>[]>, gutterNum: number, elementRef: ElementRef<HTMLElement>) { |
95 | | - const elements = map.get(gutterNum) |
96 | | - elements.splice(elements.indexOf(elementRef), 1) |
97 | | - |
98 | | - if (elements.length === 0) { |
99 | | - map.delete(gutterNum) |
100 | | - } |
101 | | - } |
102 | | - |
103 | 12 | static ngTemplateContextGuard(_dir: SplitGutterDirective, ctx: unknown): ctx is SplitGutterTemplateContext { |
104 | 13 | return true |
105 | 14 | } |
|
0 commit comments