Skip to content

Commit a956566

Browse files
stee-reca-d
authored andcommitted
docs: added editor (prop) to the plugin docs
1 parent 27f79c1 commit a956566

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

docs/plugin-api.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ OpenSCD core communicates the data necessary for editing SCL documents by settin
2020

2121
```typescript
2222
export default class MyPlugin extends HTMLElement {
23+
editor: Transactor<EditV2>;
2324
docs: Record<string, XMLDocument> = {}; // all loaded documents
2425
doc?: XMLDocument; // the document currently being edited
2526
docName?: string; // the current doc's name
@@ -28,19 +29,28 @@ export default class MyPlugin extends HTMLElement {
2829
}
2930
```
3031

32+
### `editor`
33+
34+
`editor` provides a reference to the central editor class used for modifying SCL documents. For
35+
more details on the Transactor<EditV2> (Defaults to XMLEditor). For more on the XMLEditor checkout the [documentation](https://github.com/OMICRONEnergyOSS/oscd-editor)
36+
3137
### `docs`
38+
3239
`docs` is set to an object mapping `string` keys (document names) to `XMLDocument` values.
3340

3441
### `docName`
42+
3543
The name of the `XMLDocument` currently being edited.
3644

3745
### `doc`
46+
3847
The `XMLDocument` currently being edited.
3948

4049
### `docVersion`
4150
A change in this property's value indicates a change to the `doc`.
4251

4352
### `locale`
53+
4454
Selected language (IETF language tag).
4555

4656
## Communicating user intent to OpenSCD core
@@ -56,20 +66,25 @@ export type EditDetailV2<E extends EditV2 = EditV2> = {
5666
edit: E;
5767
title?: string;
5868
squash?: boolean;
59-
}
69+
};
6070

61-
export type EditEventV2<E extends EditV2 = EditV2> = CustomEvent<EditDetailV2<E>>;
71+
export type EditEventV2<E extends EditV2 = EditV2> = CustomEvent<
72+
EditDetailV2<E>
73+
>;
6274

6375
export type EditEventOptions = {
6476
title?: string;
6577
squash?: boolean;
66-
}
78+
};
6779

68-
export function newEditEventV2<E extends EditV2>(edit: E, options: EditEventOptions): EditEventV2<E> {
80+
export function newEditEventV2<E extends EditV2>(
81+
edit: E,
82+
options: EditEventOptions,
83+
): EditEventV2<E> {
6984
return new CustomEvent<E>('oscd-edit-v2', {
7085
composed: true,
7186
bubbles: true,
72-
detail: {...options, edit},
87+
detail: { ...options, edit },
7388
});
7489
}
7590

@@ -85,15 +100,22 @@ Its `title` property is a human-readable description of the edit.
85100
The `squash` flag indicates whether the edit should be merged with the previous edit in the history.
86101

87102
#### `EditV2` type
103+
88104
The `EditDetailV2` defined above contains an `edit` of this type:
89105

90106
```typescript
91-
export type EditV2 = Insert | SetAttributes | SetTextContent | Remove | EditV2[];
107+
export type EditV2 =
108+
| Insert
109+
| SetAttributes
110+
| SetTextContent
111+
| Remove
112+
| EditV2[];
92113
```
93114

94115
This means that a single edit can either consist in a sequence of other edits or in one of the following atomic edit types:
95116

96117
> Intent to set or remove (if null) attributes on `element`.
118+
97119
```typescript
98120
export type SetAttributes = {
99121
element: Element;
@@ -103,6 +125,7 @@ export type SetAttributes = {
103125
```
104126

105127
> Intent to set the `textContent` of `element`.
128+
106129
```typescript
107130
export type SetTextContent = {
108131
element: Element;
@@ -111,6 +134,7 @@ export type SetTextContent = {
111134
```
112135

113136
> Intent to `parent.insertBefore(node, reference)`
137+
114138
```typescript
115139
export type Insert = {
116140
parent: Node;
@@ -120,6 +144,7 @@ export type Insert = {
120144
```
121145

122146
> Intent to remove a `node` from its `ownerDocument`.
147+
123148
```typescript
124149
export type Remove = {
125150
node: Node;

0 commit comments

Comments
 (0)