@hashrytech/quick-components-kit 0.19.14 → 0.19.15

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @hashrytech/quick-components-kit
2
2
 
3
+ ## 0.19.15
4
+
5
+ ### Patch Changes
6
+
7
+ - add: click outside function
8
+
3
9
  ## 0.19.14
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,22 @@
1
+ export type ClickOutsideEvent = MouseEvent | TouchEvent | PointerEvent;
2
+ export interface ClickOutsideOptions {
3
+ /**
4
+ * Function to call when clicking outside
5
+ */
6
+ callback: (event: ClickOutsideEvent) => void;
7
+ /**
8
+ * Array of element IDs to ignore
9
+ */
10
+ ignoreIds?: string[];
11
+ /**
12
+ * Whether the action is enabled
13
+ */
14
+ enabled?: boolean;
15
+ }
16
+ /**
17
+ * Triggers callback when clicking outside the element.
18
+ */
19
+ export declare function clickOutside(node: HTMLElement, options: ClickOutsideOptions): {
20
+ update(options: ClickOutsideOptions): void;
21
+ destroy(): void;
22
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Triggers callback when clicking outside the element.
3
+ */
4
+ export function clickOutside(node, options) {
5
+ let { callback, ignoreIds = [], enabled = true } = options;
6
+ const handleClick = (event) => {
7
+ if (!enabled)
8
+ return;
9
+ const target = event.target;
10
+ if (!target)
11
+ return;
12
+ // Click inside the node → ignore
13
+ if (node.contains(target))
14
+ return;
15
+ // Click is on an ignored element or one of its parents → ignore
16
+ if (ignoreIds.length > 0) {
17
+ let element = target;
18
+ while (element) {
19
+ if (element.id && ignoreIds.includes(element.id)) {
20
+ return;
21
+ }
22
+ element = element.parentElement;
23
+ }
24
+ }
25
+ // Click is outside and not on ignored element
26
+ callback(event);
27
+ };
28
+ // Attach listener
29
+ document.addEventListener('click', handleClick, true);
30
+ return {
31
+ update(newOptions) {
32
+ ({ callback, ignoreIds = [], enabled = true } = newOptions);
33
+ },
34
+ destroy() {
35
+ document.removeEventListener('click', handleClick, true);
36
+ }
37
+ };
38
+ }
package/dist/index.d.ts CHANGED
@@ -25,6 +25,7 @@ export * from './modules/crypto.js';
25
25
  export * from './modules/problem-details.js';
26
26
  export * from './functions/object-to-form-data.js';
27
27
  export * from './functions/compare-objects.js';
28
+ export * from './functions/click-outside.js';
28
29
  export * from './ui/headers/header-1/index.js';
29
30
  export * from './ui/footers/footer-1/index.js';
30
31
  export * from './ui/banners/banner-1/index.js';
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- // Reexport your entry components here
2
1
  // lib/index.js
3
2
  export * from './components/icon/index.js';
4
3
  export * from './components/text-input/index.js';
@@ -15,18 +14,23 @@ export * from './components/checkbox/index.js';
15
14
  export * from './components/tab-navigation/index.js';
16
15
  export * from './components/portal/index.js';
17
16
  export * from './components/table/index.js';
17
+ // Actions
18
18
  export * from './actions/disable-scroll.js';
19
19
  export * from './actions/on-keydown.js';
20
20
  export * from './actions/lock-scroll.js';
21
21
  export * from './actions/scroll-to.js';
22
22
  export * from './actions/stop-interaction.js';
23
23
  export * from './actions/portal.js';
24
+ // Modules
24
25
  export * from './modules/fetch-client.js';
25
26
  export * from './modules/api-proxy.js';
26
27
  export * from './modules/crypto.js';
27
28
  export * from './modules/problem-details.js';
29
+ // Functions
28
30
  export * from './functions/object-to-form-data.js';
29
31
  export * from './functions/compare-objects.js';
32
+ export * from './functions/click-outside.js';
33
+ // UI Components
30
34
  export * from './ui/headers/header-1/index.js';
31
35
  export * from './ui/footers/footer-1/index.js';
32
36
  export * from './ui/banners/banner-1/index.js';
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/hashrytech/quick-components-kit.git"
7
7
  },
8
- "version": "0.19.14",
8
+ "version": "0.19.15",
9
9
  "license": "MIT",
10
10
  "author": "Hashry Tech",
11
11
  "files": [