@htmlplus/element 0.6.7 → 0.6.8
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/client/utils/event.d.ts +8 -0
- package/client/utils/event.js +27 -0
- package/client/utils/index.d.ts +1 -2
- package/client/utils/index.js +1 -2
- package/client/utils/syncAttributes.js +1 -2
- package/package.json +1 -1
- package/client/utils/off.d.ts +0 -1
- package/client/utils/off.js +0 -3
- package/client/utils/on.d.ts +0 -1
- package/client/utils/on.js +0 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type EventTarget = Window | Document | Element;
|
|
2
|
+
type EventType = 'outside' | (string & {});
|
|
3
|
+
type EventHandler = EventListenerOrEventListenerObject;
|
|
4
|
+
type EventOptions = boolean | AddEventListenerOptions;
|
|
5
|
+
type EventListener = (target: EventTarget, type: EventType, handler: EventHandler, options?: EventOptions) => void;
|
|
6
|
+
export declare const off: EventListener;
|
|
7
|
+
export declare const on: EventListener;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const outsides = [];
|
|
2
|
+
export const off = (target, type, handler, options) => {
|
|
3
|
+
if (type != 'outside')
|
|
4
|
+
return target.removeEventListener(type, handler, options);
|
|
5
|
+
const index = outsides.findIndex((outside) => outside.target == target && outside.handler == handler && outside.options == options);
|
|
6
|
+
const outside = outsides[index];
|
|
7
|
+
if (!outside)
|
|
8
|
+
return;
|
|
9
|
+
off(document, outside.type, outside.callback, outside.options);
|
|
10
|
+
outsides.splice(index, 1);
|
|
11
|
+
};
|
|
12
|
+
export const on = (target, type, handler, options) => {
|
|
13
|
+
if (type != 'outside')
|
|
14
|
+
return target.addEventListener(type, handler, options);
|
|
15
|
+
const callback = (event) => {
|
|
16
|
+
!event.composedPath().some((item) => item == target) && handler(event);
|
|
17
|
+
};
|
|
18
|
+
type = 'ontouchstart' in window.document.documentElement ? 'touchstart' : 'click';
|
|
19
|
+
on(document, type, callback, options);
|
|
20
|
+
outsides.push({
|
|
21
|
+
target,
|
|
22
|
+
type,
|
|
23
|
+
handler,
|
|
24
|
+
options,
|
|
25
|
+
callback
|
|
26
|
+
});
|
|
27
|
+
};
|
package/client/utils/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './appendToMethod.js';
|
|
|
3
3
|
export * from './call.js';
|
|
4
4
|
export * from './config.js';
|
|
5
5
|
export * from './defineProperty.js';
|
|
6
|
+
export * from './event.js';
|
|
6
7
|
export * from './fromAttribute.js';
|
|
7
8
|
export * from './getFramework.js';
|
|
8
9
|
export * from './getMembers.js';
|
|
@@ -11,8 +12,6 @@ export * from './getTag.js';
|
|
|
11
12
|
export * from './host.js';
|
|
12
13
|
export * from './isEvent.js';
|
|
13
14
|
export * from './isServer.js';
|
|
14
|
-
export * from './off.js';
|
|
15
|
-
export * from './on.js';
|
|
16
15
|
export * from './request.js';
|
|
17
16
|
export * from './shadowRoot.js';
|
|
18
17
|
export * from './syncAttributes.js';
|
package/client/utils/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from './appendToMethod.js';
|
|
|
3
3
|
export * from './call.js';
|
|
4
4
|
export * from './config.js';
|
|
5
5
|
export * from './defineProperty.js';
|
|
6
|
+
export * from './event.js';
|
|
6
7
|
export * from './fromAttribute.js';
|
|
7
8
|
export * from './getFramework.js';
|
|
8
9
|
export * from './getMembers.js';
|
|
@@ -11,8 +12,6 @@ export * from './getTag.js';
|
|
|
11
12
|
export * from './host.js';
|
|
12
13
|
export * from './isEvent.js';
|
|
13
14
|
export * from './isServer.js';
|
|
14
|
-
export * from './off.js';
|
|
15
|
-
export * from './on.js';
|
|
16
15
|
export * from './request.js';
|
|
17
16
|
export * from './shadowRoot.js';
|
|
18
17
|
export * from './syncAttributes.js';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import { off, on } from './event.js';
|
|
1
2
|
import { isEvent } from './isEvent.js';
|
|
2
|
-
import { off } from './off.js';
|
|
3
|
-
import { on } from './on.js';
|
|
4
3
|
import { toEvent } from './toEvent.js';
|
|
5
4
|
import { updateAttribute } from './updateAttribute.js';
|
|
6
5
|
export const syncAttributes = (node) => {
|
package/package.json
CHANGED
package/client/utils/off.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const off: (target: Window | Document | Element, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => void;
|
package/client/utils/off.js
DELETED
package/client/utils/on.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const on: (target: Window | Document | Element, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void;
|
package/client/utils/on.js
DELETED