forked from ca-d/open-scd-core
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathedit-event-v1.ts
51 lines (43 loc) · 1.28 KB
/
edit-event-v1.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/** Intent to `parent.insertBefore(node, reference)` */
import { Insert, Remove } from '@openenergytools/xml-lib';
/** @deprecated */
export type NamespacedAttributeValue = {
value: string | null;
namespaceURI: string | null;
};
/** @deprecated */
export type AttributeValue = string | null | NamespacedAttributeValue;
/** Intent to set or remove (if null) attributes on element @deprecated */
export type Update = {
element: Element;
attributes: Partial<Record<string, AttributeValue>>;
};
/** Represents the user's intent to change an XMLDocument @deprecated */
export type Edit = Insert | Update | Remove | Edit[];
export function isNamespaced(
value: AttributeValue
): value is NamespacedAttributeValue {
return value !== null && typeof value !== 'string';
}
export function isUpdate(edit: Edit): edit is Update {
return (edit as Update).element !== undefined;
}
/** @deprecated */
export type EditEvent<E extends Edit = Edit> = CustomEvent<E>;
/**
* @deprecated
* @param edit
* @returns a custom event `oscd-edit`
*/
export function newEditEventV1<E extends Edit>(edit: E): EditEvent<E> {
return new CustomEvent<E>('oscd-edit', {
composed: true,
bubbles: true,
detail: edit,
});
}
declare global {
interface ElementEventMap {
['oscd-edit']: EditEvent;
}
}