@neovici/cosmoz-utils 5.33.0 → 5.35.0
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.
|
@@ -51,11 +51,15 @@ export declare const hauntedPolymer: (outputPath: string | Hook, hook?: Hook) =>
|
|
|
51
51
|
readonly offsetTop: number;
|
|
52
52
|
readonly offsetWidth: number;
|
|
53
53
|
outerText: string;
|
|
54
|
+
popover: string | null;
|
|
54
55
|
spellcheck: boolean;
|
|
55
56
|
title: string;
|
|
56
57
|
translate: boolean;
|
|
57
58
|
attachInternals(): ElementInternals;
|
|
58
59
|
click(): void;
|
|
60
|
+
hidePopover(): void;
|
|
61
|
+
showPopover(): void;
|
|
62
|
+
togglePopover(force?: boolean | undefined): void;
|
|
59
63
|
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined): void;
|
|
60
64
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined): void;
|
|
61
65
|
removeEventListener<K_1 extends keyof HTMLElementEventMap>(type: K_1, listener: (this: HTMLElement, ev: HTMLElementEventMap[K_1]) => any, options?: boolean | EventListenerOptions | undefined): void;
|
|
@@ -89,6 +93,7 @@ export declare const hauntedPolymer: (outputPath: string | Hook, hook?: Hook) =>
|
|
|
89
93
|
closest<K_3 extends keyof SVGElementTagNameMap>(selector: K_3): SVGElementTagNameMap[K_3] | null;
|
|
90
94
|
closest<K_4 extends keyof MathMLElementTagNameMap>(selector: K_4): MathMLElementTagNameMap[K_4] | null;
|
|
91
95
|
closest<E extends Element = Element>(selectors: string): E | null;
|
|
96
|
+
computedStyleMap(): StylePropertyMapReadOnly;
|
|
92
97
|
getAttribute(qualifiedName: string): string | null;
|
|
93
98
|
getAttributeNS(namespace: string | null, localName: string): string | null;
|
|
94
99
|
getAttributeNames(): string[];
|
|
@@ -246,6 +251,7 @@ export declare const hauntedPolymer: (outputPath: string | Hook, hook?: Hook) =>
|
|
|
246
251
|
querySelectorAll<E_2 extends Element = Element>(selectors: string): NodeListOf<E_2>;
|
|
247
252
|
replaceChildren(...nodes: (string | Node)[]): void;
|
|
248
253
|
readonly assignedSlot: HTMLSlotElement | null;
|
|
254
|
+
readonly attributeStyleMap: StylePropertyMap;
|
|
249
255
|
readonly style: CSSStyleDeclaration;
|
|
250
256
|
contentEditable: string;
|
|
251
257
|
enterKeyHint: string;
|
|
@@ -318,6 +324,7 @@ export declare const hauntedPolymer: (outputPath: string | Hook, hook?: Hook) =>
|
|
|
318
324
|
onreset: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
319
325
|
onresize: ((this: GlobalEventHandlers, ev: UIEvent) => any) | null;
|
|
320
326
|
onscroll: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
327
|
+
onscrollend: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
321
328
|
onsecuritypolicyviolation: ((this: GlobalEventHandlers, ev: SecurityPolicyViolationEvent) => any) | null;
|
|
322
329
|
onseeked: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
323
330
|
onseeking: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export declare const applyMove: <T>(list: T[], from: number, to: number) => T[];
|
|
2
|
-
|
|
2
|
+
interface Opts {
|
|
3
|
+
prefix?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const useDragItems: (onMove?: ((from: number, to: number) => void) | undefined, { prefix }?: Opts) => {
|
|
3
6
|
onDown: (e: MouseEvent) => void;
|
|
4
7
|
onDragStart: (e: DragEvent) => void;
|
|
5
8
|
onDragEnter: (e: DragEvent) => void;
|
|
@@ -7,3 +10,4 @@ export declare const useDragItems: (onMove?: ((from: number, to: number) => void
|
|
|
7
10
|
onDragLeave: (e: DragEvent) => void;
|
|
8
11
|
onDrop: (e: DragEvent) => void;
|
|
9
12
|
};
|
|
13
|
+
export {};
|
|
@@ -6,10 +6,27 @@ export const applyMove = (list, from, to) => {
|
|
|
6
6
|
newList.splice(to + (from >= to ? 0 : -1), 0, newList.splice(from, 1)[0]);
|
|
7
7
|
return newList;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
const getIndexer = (prefix) => {
|
|
10
|
+
const key = ['move-index', prefix].filter(Boolean).join('-');
|
|
11
|
+
return {
|
|
12
|
+
set(dt, index) {
|
|
13
|
+
const idx = index.toString();
|
|
14
|
+
dt.setData(key, idx);
|
|
15
|
+
dt.setData('text/plain', idx);
|
|
16
|
+
},
|
|
17
|
+
get(dt) {
|
|
18
|
+
return parse(dt.getData(key));
|
|
19
|
+
},
|
|
20
|
+
has(dt) {
|
|
21
|
+
return dt.types.includes(key);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export const useDragItems = (onMove, { prefix } = {}) => {
|
|
10
26
|
const meta = useMeta({
|
|
11
27
|
onMove,
|
|
12
28
|
});
|
|
29
|
+
const indexer = getIndexer(prefix);
|
|
13
30
|
return {
|
|
14
31
|
onDown: useCallback((e) => {
|
|
15
32
|
if (!e.target.closest('[data-pull]')) {
|
|
@@ -24,23 +41,23 @@ export const useDragItems = (onMove) => {
|
|
|
24
41
|
}
|
|
25
42
|
meta.handle = undefined;
|
|
26
43
|
const dt = e.dataTransfer;
|
|
27
|
-
const idx = index.toString();
|
|
28
44
|
dt.effectAllowed = 'move';
|
|
29
|
-
|
|
30
|
-
dt.setData('text/plain', idx);
|
|
45
|
+
indexer.set(dt, index);
|
|
31
46
|
setTimeout(() => (target.dataset.drag = ''), 0);
|
|
32
47
|
target.addEventListener('dragend', (e) => delete e.target.dataset.drag, { once: true });
|
|
33
48
|
}, [meta]),
|
|
34
49
|
onDragEnter: useCallback((e) => {
|
|
35
50
|
const ctg = e.currentTarget;
|
|
36
|
-
|
|
51
|
+
const dt = e.dataTransfer;
|
|
52
|
+
if (ctg !== e.target || !indexer.has(dt))
|
|
37
53
|
return;
|
|
38
|
-
}
|
|
39
54
|
e.preventDefault();
|
|
40
|
-
|
|
55
|
+
dt.dropEffect = 'move';
|
|
41
56
|
ctg.dataset.dragover = '';
|
|
42
57
|
}, []),
|
|
43
58
|
onDragOver: useCallback((e) => {
|
|
59
|
+
if (!indexer.has(e.dataTransfer))
|
|
60
|
+
return;
|
|
44
61
|
e.preventDefault();
|
|
45
62
|
e.currentTarget.dataset.dragover = '';
|
|
46
63
|
}, []),
|
|
@@ -52,9 +69,13 @@ export const useDragItems = (onMove) => {
|
|
|
52
69
|
delete ctg.dataset.dragover;
|
|
53
70
|
}, []),
|
|
54
71
|
onDrop: useCallback((e) => {
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
delete
|
|
72
|
+
const ctg = e.currentTarget;
|
|
73
|
+
const dt = e.dataTransfer;
|
|
74
|
+
delete ctg.dataset.dragover;
|
|
75
|
+
if (!indexer.has(dt))
|
|
76
|
+
return;
|
|
77
|
+
const from = indexer.get(dt) || 0;
|
|
78
|
+
const to = parse(ctg.dataset.index) || 0;
|
|
58
79
|
e.preventDefault();
|
|
59
80
|
meta.onMove?.(from, to);
|
|
60
81
|
}, [meta]),
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const notifyProperty: <K extends string, T extends HTMLElement & { [key in K]?: unknown; }>(host: T, name: K, value: T[K]) => void
|
|
2
|
-
export
|
|
1
|
+
export declare const notifyProperty: <K extends string, T extends HTMLElement & { [key in K]?: unknown; }>(host: T, name: K, value: T[K]) => void;
|
|
2
|
+
export declare const useNotifyProperty: <K extends string, V>(name: K, value: V, deps?: unknown[]) => void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useEffect } from 'haunted';
|
|
2
2
|
import { useHost } from './use-host';
|
|
3
|
-
const UPPER = /([A-Z])/gu
|
|
3
|
+
const UPPER = /([A-Z])/gu;
|
|
4
4
|
/* Emulate polymer notify props */
|
|
5
|
-
notifyProperty = (host, name, value) => {
|
|
5
|
+
export const notifyProperty = (host, name, value) => {
|
|
6
6
|
// this is required to make polymer double-binding recognize the change
|
|
7
7
|
// @see https://github.com/Polymer/polymer/blob/76c71e186ecc605294c3575dd31ac7983a8b3ae3/lib/mixins/property-effects.js#L382
|
|
8
8
|
host[name] = value;
|
|
@@ -10,10 +10,10 @@ notifyProperty = (host, name, value) => {
|
|
|
10
10
|
host.dispatchEvent(new CustomEvent(name.replace(UPPER, '-$1').toLowerCase() + '-changed', {
|
|
11
11
|
detail: { value },
|
|
12
12
|
}));
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
|
+
export const useNotifyProperty = (name, value, deps = [value]) => {
|
|
14
15
|
const host = useHost();
|
|
15
16
|
useEffect(() => {
|
|
16
17
|
notifyProperty(host, name, value);
|
|
17
18
|
}, deps);
|
|
18
19
|
};
|
|
19
|
-
export { notifyProperty, useNotifyProperty };
|
package/dist/promise.js
CHANGED
|
@@ -5,7 +5,7 @@ export class ManagedPromise extends Promise {
|
|
|
5
5
|
Object.assign(this, handles);
|
|
6
6
|
callback?.(handles.resolve, handles.reject);
|
|
7
7
|
}
|
|
8
|
-
// eslint-disable-next-line
|
|
8
|
+
// eslint-disable-next-line no-empty-function
|
|
9
9
|
resolve = () => { };
|
|
10
10
|
}
|
|
11
11
|
export const timeout$ = (ms) => new Promise((res) => setTimeout(res, ms));
|