@dvirus-js/angular 0.0.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.
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { inject, ElementRef, input, output, effect, Directive } from '@angular/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Directive that emits an event when a click occurs outside the host element or a group of elements.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```html
|
|
9
|
+
* <div [clickOutside]="handler"></div>
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* - Emits `clickOutside` when a click is detected outside the host and any elements in the `group` input.
|
|
13
|
+
* - Useful for closing popups, dropdowns, or dialogs when clicking outside.
|
|
14
|
+
*/
|
|
15
|
+
class ClickOutsideDirective {
|
|
16
|
+
/**
|
|
17
|
+
* Reference to the host element.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
el = inject(ElementRef);
|
|
21
|
+
/**
|
|
22
|
+
* Optional group of elements to consider as 'inside'.
|
|
23
|
+
* If the click is inside any of these, the event will not fire.
|
|
24
|
+
*/
|
|
25
|
+
group = input([], ...(ngDevMode ? [{ debugName: "group" }] : []));
|
|
26
|
+
/**
|
|
27
|
+
* Event emitted when a click occurs outside the host and group elements.
|
|
28
|
+
*/
|
|
29
|
+
clickOutside = output();
|
|
30
|
+
/**
|
|
31
|
+
* Handles document click events and emits if the click is outside.
|
|
32
|
+
* @param event MouseEvent from the document
|
|
33
|
+
*/
|
|
34
|
+
handleClick = (event) => {
|
|
35
|
+
const allElements = [this.el.nativeElement, ...this.group()];
|
|
36
|
+
const clickedInside = allElements.some((el) => el.contains(event.target));
|
|
37
|
+
if (!clickedInside) {
|
|
38
|
+
this.clickOutside.emit(event);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Sets up the document click listener and cleans up on destroy.
|
|
43
|
+
*/
|
|
44
|
+
constructor() {
|
|
45
|
+
effect((cleanFn) => {
|
|
46
|
+
document.addEventListener('click', this.handleClick, true);
|
|
47
|
+
cleanFn(() => {
|
|
48
|
+
document.removeEventListener('click', this.handleClick, true);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.4", ngImport: i0, type: ClickOutsideDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
53
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.4", type: ClickOutsideDirective, isStandalone: true, selector: "[djsClickOutside]", inputs: { group: { classPropertyName: "group", publicName: "group", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { clickOutside: "clickOutside" }, ngImport: i0 });
|
|
54
|
+
}
|
|
55
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.4", ngImport: i0, type: ClickOutsideDirective, decorators: [{
|
|
56
|
+
type: Directive,
|
|
57
|
+
args: [{
|
|
58
|
+
selector: '[djsClickOutside]',
|
|
59
|
+
}]
|
|
60
|
+
}], ctorParameters: () => [], propDecorators: { group: [{ type: i0.Input, args: [{ isSignal: true, alias: "group", required: false }] }], clickOutside: [{ type: i0.Output, args: ["clickOutside"] }] } });
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Generated bundle index. Do not edit.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
export { ClickOutsideDirective };
|
|
67
|
+
//# sourceMappingURL=dvirus-js-angular.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dvirus-js-angular.mjs","sources":["../../../../../packages/angular/angular-utils/src/lib/directives/click-outside.directive.ts","../../../../../packages/angular/angular-utils/src/dvirus-js-angular.ts"],"sourcesContent":["import { Directive, effect, ElementRef, inject, input, output } from '@angular/core';\n\n/**\n * Directive that emits an event when a click occurs outside the host element or a group of elements.\n *\n * Usage:\n * ```html\n * <div [clickOutside]=\"handler\"></div>\n * ```\n *\n * - Emits `clickOutside` when a click is detected outside the host and any elements in the `group` input.\n * - Useful for closing popups, dropdowns, or dialogs when clicking outside.\n */\n@Directive({\n selector: '[djsClickOutside]',\n})\nexport class ClickOutsideDirective {\n /**\n * Reference to the host element.\n * @internal\n */\n private el = inject<ElementRef<HTMLElement>>(ElementRef);\n\n /**\n * Optional group of elements to consider as 'inside'.\n * If the click is inside any of these, the event will not fire.\n */\n group = input<HTMLElement[]>([]);\n\n /**\n * Event emitted when a click occurs outside the host and group elements.\n */\n clickOutside = output<MouseEvent>();\n\n /**\n * Handles document click events and emits if the click is outside.\n * @param event MouseEvent from the document\n */\n private handleClick = (event: MouseEvent) => {\n const allElements = [this.el.nativeElement, ...this.group()];\n const clickedInside = allElements.some((el) => el.contains(event.target as Node));\n\n if (!clickedInside) {\n this.clickOutside.emit(event);\n }\n };\n\n /**\n * Sets up the document click listener and cleans up on destroy.\n */\n constructor() {\n effect((cleanFn) => {\n document.addEventListener('click', this.handleClick, true);\n\n cleanFn(() => {\n document.removeEventListener('click', this.handleClick, true);\n });\n });\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAEA;;;;;;;;;;AAUG;MAIU,qBAAqB,CAAA;AAChC;;;AAGG;AACK,IAAA,EAAE,GAAG,MAAM,CAA0B,UAAU,CAAC;AAExD;;;AAGG;AACH,IAAA,KAAK,GAAG,KAAK,CAAgB,EAAE,iDAAC;AAEhC;;AAEG;IACH,YAAY,GAAG,MAAM,EAAc;AAEnC;;;AAGG;AACK,IAAA,WAAW,GAAG,CAAC,KAAiB,KAAI;AAC1C,QAAA,MAAM,WAAW,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC5D,MAAM,aAAa,GAAG,WAAW,CAAC,IAAI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
5
|
+
"@angular/core": "^21.1.0",
|
|
6
|
+
"@angular/forms": "^21.1.0"
|
|
7
|
+
},
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"module": "fesm2022/dvirus-js-angular.mjs",
|
|
13
|
+
"typings": "types/dvirus-js-angular.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": {
|
|
16
|
+
"default": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./types/dvirus-js-angular.d.ts",
|
|
20
|
+
"default": "./fesm2022/dvirus-js-angular.mjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"tslib": "^2.3.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as _angular_core from '@angular/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Directive that emits an event when a click occurs outside the host element or a group of elements.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* ```html
|
|
8
|
+
* <div [clickOutside]="handler"></div>
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* - Emits `clickOutside` when a click is detected outside the host and any elements in the `group` input.
|
|
12
|
+
* - Useful for closing popups, dropdowns, or dialogs when clicking outside.
|
|
13
|
+
*/
|
|
14
|
+
declare class ClickOutsideDirective {
|
|
15
|
+
/**
|
|
16
|
+
* Reference to the host element.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
private el;
|
|
20
|
+
/**
|
|
21
|
+
* Optional group of elements to consider as 'inside'.
|
|
22
|
+
* If the click is inside any of these, the event will not fire.
|
|
23
|
+
*/
|
|
24
|
+
group: _angular_core.InputSignal<HTMLElement[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Event emitted when a click occurs outside the host and group elements.
|
|
27
|
+
*/
|
|
28
|
+
clickOutside: _angular_core.OutputEmitterRef<MouseEvent>;
|
|
29
|
+
/**
|
|
30
|
+
* Handles document click events and emits if the click is outside.
|
|
31
|
+
* @param event MouseEvent from the document
|
|
32
|
+
*/
|
|
33
|
+
private handleClick;
|
|
34
|
+
/**
|
|
35
|
+
* Sets up the document click listener and cleans up on destroy.
|
|
36
|
+
*/
|
|
37
|
+
constructor();
|
|
38
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<ClickOutsideDirective, never>;
|
|
39
|
+
static ɵdir: _angular_core.ɵɵDirectiveDeclaration<ClickOutsideDirective, "[djsClickOutside]", never, { "group": { "alias": "group"; "required": false; "isSignal": true; }; }, { "clickOutside": "clickOutside"; }, never, never, true, never>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { ClickOutsideDirective };
|