@compas-oscd/open-scd 0.34.21 → 0.34.23
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/dist/WizardDivider.d.ts +1 -0
- package/dist/WizardDivider.d.ts.map +1 -0
- package/dist/Wizarding.d.ts +20 -0
- package/dist/Wizarding.d.ts.map +1 -0
- package/dist/Wizarding.js +4 -1
- package/dist/Wizarding.js.map +1 -1
- package/dist/action-icon.d.ts +1 -0
- package/dist/action-icon.d.ts.map +1 -0
- package/dist/action-pane.d.ts +1 -0
- package/dist/action-pane.d.ts.map +1 -0
- package/dist/addons/Editor.d.ts +1 -0
- package/dist/addons/Editor.d.ts.map +1 -0
- package/dist/addons/History.d.ts +11 -0
- package/dist/addons/History.d.ts.map +1 -0
- package/dist/addons/History.js +10 -0
- package/dist/addons/History.js.map +1 -1
- package/dist/addons/Layout.d.ts +1 -0
- package/dist/addons/Layout.d.ts.map +1 -0
- package/dist/addons/Settings.d.ts +1 -0
- package/dist/addons/Settings.d.ts.map +1 -0
- package/dist/addons/Waiter.d.ts +1 -0
- package/dist/addons/Waiter.d.ts.map +1 -0
- package/dist/addons/Wizards.d.ts +1 -0
- package/dist/addons/Wizards.d.ts.map +1 -0
- package/dist/addons/editor/edit-action-to-v1-converter.d.ts +1 -0
- package/dist/addons/editor/edit-action-to-v1-converter.d.ts.map +1 -0
- package/dist/addons/editor/edit-v1-to-v2-converter.d.ts +1 -0
- package/dist/addons/editor/edit-v1-to-v2-converter.d.ts.map +1 -0
- package/dist/addons/history/get-log-text.d.ts +1 -0
- package/dist/addons/history/get-log-text.d.ts.map +1 -0
- package/dist/addons/menu-tabs/menu-tabs.d.ts +1 -0
- package/dist/addons/menu-tabs/menu-tabs.d.ts.map +1 -0
- package/dist/addons/plugin-manager/custom-plugin-dialog.d.ts +1 -0
- package/dist/addons/plugin-manager/custom-plugin-dialog.d.ts.map +1 -0
- package/dist/addons/plugin-manager/plugin-manager.d.ts +1 -0
- package/dist/addons/plugin-manager/plugin-manager.d.ts.map +1 -0
- package/dist/filtered-list.d.ts +1 -0
- package/dist/filtered-list.d.ts.map +1 -0
- package/dist/finder-list.d.ts +1 -0
- package/dist/finder-list.d.ts.map +1 -0
- package/dist/foundation/compare.d.ts +1 -0
- package/dist/foundation/compare.d.ts.map +1 -0
- package/dist/foundation/dai.d.ts +1 -0
- package/dist/foundation/dai.d.ts.map +1 -0
- package/dist/foundation/generators.d.ts +1 -0
- package/dist/foundation/generators.d.ts.map +1 -0
- package/dist/foundation/ied.d.ts +1 -0
- package/dist/foundation/ied.d.ts.map +1 -0
- package/dist/foundation/nsd.d.ts +1 -0
- package/dist/foundation/nsd.d.ts.map +1 -0
- package/dist/foundation/nsdoc.d.ts +1 -0
- package/dist/foundation/nsdoc.d.ts.map +1 -0
- package/dist/foundation/scl.d.ts +1 -0
- package/dist/foundation/scl.d.ts.map +1 -0
- package/dist/foundation.d.ts +1 -0
- package/dist/foundation.d.ts.map +1 -0
- package/dist/icons/compare.d.ts +1 -0
- package/dist/icons/compare.d.ts.map +1 -0
- package/dist/icons/icons.d.ts +1 -0
- package/dist/icons/icons.d.ts.map +1 -0
- package/dist/icons/ied-icons.d.ts +1 -0
- package/dist/icons/ied-icons.d.ts.map +1 -0
- package/dist/icons/lnode.d.ts +1 -0
- package/dist/icons/lnode.d.ts.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/open-scd.d.ts +1 -0
- package/dist/open-scd.d.ts.map +1 -0
- package/dist/oscd-filter-button.d.ts +1 -0
- package/dist/oscd-filter-button.d.ts.map +1 -0
- package/dist/plain-compare-list.d.ts +1 -0
- package/dist/plain-compare-list.d.ts.map +1 -0
- package/dist/plugin-tag.d.ts +1 -0
- package/dist/plugin-tag.d.ts.map +1 -0
- package/dist/plugin.d.ts +1 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.events.d.ts +1 -0
- package/dist/plugin.events.d.ts.map +1 -0
- package/dist/plugins.d.ts +1 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/schemas.d.ts +1 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/themes.d.ts +1 -0
- package/dist/themes.d.ts.map +1 -0
- package/dist/translations/de.d.ts +1 -0
- package/dist/translations/de.d.ts.map +1 -0
- package/dist/translations/en.d.ts +1 -0
- package/dist/translations/en.d.ts.map +1 -0
- package/dist/translations/loader.d.ts +1 -0
- package/dist/translations/loader.d.ts.map +1 -0
- package/dist/wizard-checkbox.d.ts +1 -0
- package/dist/wizard-checkbox.d.ts.map +1 -0
- package/dist/wizard-dialog.d.ts +1 -0
- package/dist/wizard-dialog.d.ts.map +1 -0
- package/dist/wizard-select.d.ts +1 -0
- package/dist/wizard-select.d.ts.map +1 -0
- package/dist/wizard-textfield.d.ts +2 -1
- package/dist/wizard-textfield.d.ts.map +1 -0
- package/dist/wizards.d.ts +1 -0
- package/dist/wizards.d.ts.map +1 -0
- package/package.json +317 -47
- package/dist/core/api/api.js +0 -7
- package/dist/core/api/api.js.map +0 -1
- package/dist/core/api/editor/subject.js +0 -22
- package/dist/core/api/editor/subject.js.map +0 -1
- package/dist/core/api/editor/xml-editor.js +0 -82
- package/dist/core/api/editor/xml-editor.js.map +0 -1
- package/dist/core/api/plugin-state-api.js +0 -27
- package/dist/core/api/plugin-state-api.js.map +0 -1
- package/dist/core/foundation/cyrb64.js +0 -26
- package/dist/core/foundation/cyrb64.js.map +0 -1
- package/dist/core/foundation/deprecated/edit-event.js +0 -44
- package/dist/core/foundation/deprecated/edit-event.js.map +0 -1
- package/dist/core/foundation/deprecated/editor.js +0 -94
- package/dist/core/foundation/deprecated/editor.js.map +0 -1
- package/dist/core/foundation/deprecated/history.js +0 -17
- package/dist/core/foundation/deprecated/history.js.map +0 -1
- package/dist/core/foundation/deprecated/open-event.js +0 -9
- package/dist/core/foundation/deprecated/open-event.js.map +0 -1
- package/dist/core/foundation/deprecated/settings.js +0 -19
- package/dist/core/foundation/deprecated/settings.js.map +0 -1
- package/dist/core/foundation/deprecated/validation.js +0 -8
- package/dist/core/foundation/deprecated/validation.js.map +0 -1
- package/dist/core/foundation/deprecated/waiter.js +0 -12
- package/dist/core/foundation/deprecated/waiter.js.map +0 -1
- package/dist/core/foundation/edit-completed-event.js +0 -11
- package/dist/core/foundation/edit-completed-event.js.map +0 -1
- package/dist/core/foundation/edit-event.js +0 -8
- package/dist/core/foundation/edit-event.js.map +0 -1
- package/dist/core/foundation/edit.js +0 -31
- package/dist/core/foundation/edit.js.map +0 -1
- package/dist/core/foundation/handle-edit.js +0 -151
- package/dist/core/foundation/handle-edit.js.map +0 -1
- package/dist/core/foundation/open-event.js +0 -8
- package/dist/core/foundation/open-event.js.map +0 -1
- package/dist/core/foundation/plugin.js +0 -2
- package/dist/core/foundation/plugin.js.map +0 -1
- package/dist/core/foundation.js +0 -14
- package/dist/core/foundation.js.map +0 -1
- package/dist/core/locales.js +0 -21
- package/dist/core/locales.js.map +0 -1
- package/dist/openscd/src/WizardDivider.js +0 -37
- package/dist/openscd/src/WizardDivider.js.map +0 -1
- package/dist/openscd/src/Wizarding.js +0 -38
- package/dist/openscd/src/Wizarding.js.map +0 -1
- package/dist/openscd/src/action-icon.js +0 -220
- package/dist/openscd/src/action-icon.js.map +0 -1
- package/dist/openscd/src/action-pane.js +0 -176
- package/dist/openscd/src/action-pane.js.map +0 -1
- package/dist/openscd/src/addons/Editor.js +0 -106
- package/dist/openscd/src/addons/Editor.js.map +0 -1
- package/dist/openscd/src/addons/History.js +0 -490
- package/dist/openscd/src/addons/History.js.map +0 -1
- package/dist/openscd/src/addons/Layout.js +0 -619
- package/dist/openscd/src/addons/Layout.js.map +0 -1
- package/dist/openscd/src/addons/Settings.js +0 -465
- package/dist/openscd/src/addons/Settings.js.map +0 -1
- package/dist/openscd/src/addons/Waiter.js +0 -45
- package/dist/openscd/src/addons/Waiter.js.map +0 -1
- package/dist/openscd/src/addons/Wizards.js +0 -48
- package/dist/openscd/src/addons/Wizards.js.map +0 -1
- package/dist/openscd/src/addons/editor/edit-action-to-v1-converter.js +0 -96
- package/dist/openscd/src/addons/editor/edit-action-to-v1-converter.js.map +0 -1
- package/dist/openscd/src/addons/editor/edit-v1-to-v2-converter.js +0 -37
- package/dist/openscd/src/addons/editor/edit-v1-to-v2-converter.js.map +0 -1
- package/dist/openscd/src/addons/history/get-log-text.js +0 -26
- package/dist/openscd/src/addons/history/get-log-text.js.map +0 -1
- package/dist/openscd/src/addons/menu-tabs/menu-tabs.js +0 -74
- package/dist/openscd/src/addons/menu-tabs/menu-tabs.js.map +0 -1
- package/dist/openscd/src/addons/plugin-manager/custom-plugin-dialog.js +0 -177
- package/dist/openscd/src/addons/plugin-manager/custom-plugin-dialog.js.map +0 -1
- package/dist/openscd/src/addons/plugin-manager/plugin-manager.js +0 -165
- package/dist/openscd/src/addons/plugin-manager/plugin-manager.js.map +0 -1
- package/dist/openscd/src/filtered-list.js +0 -168
- package/dist/openscd/src/filtered-list.js.map +0 -1
- package/dist/openscd/src/finder-list.js +0 -207
- package/dist/openscd/src/finder-list.js.map +0 -1
- package/dist/openscd/src/foundation/compare.js +0 -273
- package/dist/openscd/src/foundation/compare.js.map +0 -1
- package/dist/openscd/src/foundation/dai.js +0 -127
- package/dist/openscd/src/foundation/dai.js.map +0 -1
- package/dist/openscd/src/foundation/generators.js +0 -67
- package/dist/openscd/src/foundation/generators.js.map +0 -1
- package/dist/openscd/src/foundation/ied.js +0 -84
- package/dist/openscd/src/foundation/ied.js.map +0 -1
- package/dist/openscd/src/foundation/nsd.js +0 -13
- package/dist/openscd/src/foundation/nsd.js.map +0 -1
- package/dist/openscd/src/foundation/nsdoc.js +0 -180
- package/dist/openscd/src/foundation/nsdoc.js.map +0 -1
- package/dist/openscd/src/foundation/scl.js +0 -64
- package/dist/openscd/src/foundation/scl.js.map +0 -1
- package/dist/openscd/src/foundation.js +0 -1922
- package/dist/openscd/src/foundation.js.map +0 -1
- package/dist/openscd/src/icons/compare.js +0 -11
- package/dist/openscd/src/icons/compare.js.map +0 -1
- package/dist/openscd/src/icons/icons.js +0 -611
- package/dist/openscd/src/icons/icons.js.map +0 -1
- package/dist/openscd/src/icons/ied-icons.js +0 -11
- package/dist/openscd/src/icons/ied-icons.js.map +0 -1
- package/dist/openscd/src/icons/lnode.js +0 -50
- package/dist/openscd/src/icons/lnode.js.map +0 -1
- package/dist/openscd/src/open-scd.js +0 -483
- package/dist/openscd/src/open-scd.js.map +0 -1
- package/dist/openscd/src/oscd-filter-button.js +0 -89
- package/dist/openscd/src/oscd-filter-button.js.map +0 -1
- package/dist/openscd/src/plain-compare-list.js +0 -132
- package/dist/openscd/src/plain-compare-list.js.map +0 -1
- package/dist/openscd/src/plugin-tag.js +0 -23
- package/dist/openscd/src/plugin-tag.js.map +0 -1
- package/dist/openscd/src/plugin.events.js +0 -12
- package/dist/openscd/src/plugin.events.js.map +0 -1
- package/dist/openscd/src/plugin.js +0 -2
- package/dist/openscd/src/plugin.js.map +0 -1
- package/dist/openscd/src/plugins.js +0 -256
- package/dist/openscd/src/plugins.js.map +0 -1
- package/dist/openscd/src/schemas.js +0 -9325
- package/dist/openscd/src/schemas.js.map +0 -1
- package/dist/openscd/src/themes.js +0 -122
- package/dist/openscd/src/themes.js.map +0 -1
- package/dist/openscd/src/translations/de.js +0 -954
- package/dist/openscd/src/translations/de.js.map +0 -1
- package/dist/openscd/src/translations/en.js +0 -950
- package/dist/openscd/src/translations/en.js.map +0 -1
- package/dist/openscd/src/translations/loader.js +0 -10
- package/dist/openscd/src/translations/loader.js.map +0 -1
- package/dist/openscd/src/wizard-checkbox.js +0 -152
- package/dist/openscd/src/wizard-checkbox.js.map +0 -1
- package/dist/openscd/src/wizard-dialog.js +0 -374
- package/dist/openscd/src/wizard-dialog.js.map +0 -1
- package/dist/openscd/src/wizard-select.js +0 -115
- package/dist/openscd/src/wizard-select.js.map +0 -1
- package/dist/openscd/src/wizard-textfield.js +0 -191
- package/dist/openscd/src/wizard-textfield.js.map +0 -1
- package/dist/openscd/src/wizards.js +0 -196
- package/dist/openscd/src/wizards.js.map +0 -1
- package/dist/xml/src/foundation.js +0 -67
- package/dist/xml/src/foundation.js.map +0 -1
- package/dist/xml/src/index.js +0 -2
- package/dist/xml/src/index.js.map +0 -1
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
import { html } from 'lit-element';
|
|
2
|
-
import { repeat } from 'lit-html/directives/repeat';
|
|
3
|
-
import { get } from 'lit-translate';
|
|
4
|
-
import '@material/mwc-list';
|
|
5
|
-
import '@material/mwc-list/mwc-list-item';
|
|
6
|
-
import '@material/mwc-icon';
|
|
7
|
-
import { identity } from '../foundation.js';
|
|
8
|
-
import { attributeIcon, contentIcon, elementIcon } from '../icons/compare.js';
|
|
9
|
-
const diffTypeToIcon = new Map();
|
|
10
|
-
diffTypeToIcon.set('Attribute', attributeIcon);
|
|
11
|
-
diffTypeToIcon.set('Content', contentIcon);
|
|
12
|
-
diffTypeToIcon.set('Element', elementIcon);
|
|
13
|
-
function getDiffFilterSelector(elementToBeCompared, rootElementToBeCompared, filters) {
|
|
14
|
-
const querySelector = rootElementToBeCompared === elementToBeCompared
|
|
15
|
-
? ':scope'
|
|
16
|
-
: Object.keys(filters).find(selector => Array.from(rootElementToBeCompared.querySelectorAll(selector)).includes(elementToBeCompared));
|
|
17
|
-
return querySelector ? filters[querySelector] : undefined;
|
|
18
|
-
}
|
|
19
|
-
function shouldFilterElement(element, filter) {
|
|
20
|
-
if (!filter || !filter.full) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
const consumer = filter.full;
|
|
24
|
-
return typeof consumer === 'boolean' ? consumer : consumer(element);
|
|
25
|
-
}
|
|
26
|
-
function shouldFilterAttribute(element, attribute, filter) {
|
|
27
|
-
if (!filter || !filter.attributes || !filter.attributes[attribute]) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
const consumer = filter.attributes[attribute];
|
|
31
|
-
return typeof consumer === 'boolean' ? consumer : consumer(element);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Returns the description of the Element that differs.
|
|
35
|
-
*
|
|
36
|
-
* @param element - The Element to retrieve the identifier from.
|
|
37
|
-
*/
|
|
38
|
-
function describe(element) {
|
|
39
|
-
const id = identity(element);
|
|
40
|
-
return typeof id === 'string' ? id : get('unidentifiable');
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Check if there are any attribute values changed between the two elements.
|
|
44
|
-
*
|
|
45
|
-
* @param elementToBeCompared - The element to check for differences.
|
|
46
|
-
* @param elementToCompareAgainst - The element used to check against.
|
|
47
|
-
*/
|
|
48
|
-
export function diffSclAttributes(elementToBeCompared, elementToCompareAgainst, filterToIgnore, searchElementToBeCompared) {
|
|
49
|
-
const attrDiffs = [];
|
|
50
|
-
// First check if there is any text inside the element and there should be no child elements.
|
|
51
|
-
const newText = elementToBeCompared.textContent?.trim() ?? '';
|
|
52
|
-
const oldText = elementToCompareAgainst.textContent?.trim() ?? '';
|
|
53
|
-
if (elementToBeCompared.childElementCount === 0 &&
|
|
54
|
-
elementToCompareAgainst.childElementCount === 0 &&
|
|
55
|
-
newText !== oldText) {
|
|
56
|
-
const shouldFilter = shouldFilterElement(elementToBeCompared, getDiffFilterSelector(elementToBeCompared, searchElementToBeCompared, filterToIgnore));
|
|
57
|
-
if (!shouldFilter) {
|
|
58
|
-
attrDiffs.push([
|
|
59
|
-
'value',
|
|
60
|
-
{ type: 'Content', newValue: newText, oldValue: oldText },
|
|
61
|
-
]);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// Next check if there are any difference between attributes.
|
|
65
|
-
const attributeNames = new Set(elementToCompareAgainst
|
|
66
|
-
.getAttributeNames()
|
|
67
|
-
.concat(elementToBeCompared.getAttributeNames()));
|
|
68
|
-
for (const name of attributeNames) {
|
|
69
|
-
const shouldFilter = shouldFilterAttribute(elementToBeCompared, name, getDiffFilterSelector(elementToBeCompared, searchElementToBeCompared, filterToIgnore));
|
|
70
|
-
if (!shouldFilter &&
|
|
71
|
-
elementToCompareAgainst.getAttribute(name) !==
|
|
72
|
-
elementToBeCompared.getAttribute(name)) {
|
|
73
|
-
attrDiffs.push([
|
|
74
|
-
name,
|
|
75
|
-
{
|
|
76
|
-
type: 'Attribute',
|
|
77
|
-
newValue: elementToBeCompared.getAttribute(name),
|
|
78
|
-
oldValue: elementToCompareAgainst.getAttribute(name),
|
|
79
|
-
},
|
|
80
|
-
]);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return attrDiffs;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Function to retrieve the identity to compare 2 children on the same level.
|
|
87
|
-
* This means we only need to last part of the Identity string to compare the children.
|
|
88
|
-
*
|
|
89
|
-
* @param element - The element to retrieve the identity from.
|
|
90
|
-
*/
|
|
91
|
-
export function identityForCompare(element) {
|
|
92
|
-
let identityOfElement = identity(element);
|
|
93
|
-
if (typeof identityOfElement === 'string') {
|
|
94
|
-
identityOfElement = identityOfElement.split('>').pop() ?? '';
|
|
95
|
-
}
|
|
96
|
-
return identityOfElement;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Custom method for comparing to check if 2 elements are the same. Because they are on the same level
|
|
100
|
-
* we don't need to compare the full identity, we just compare the part of the Element itself.
|
|
101
|
-
*
|
|
102
|
-
* <b>Remark</b>Private elements are already filtered out, so we don't need to bother them.
|
|
103
|
-
*
|
|
104
|
-
* @param newValue - The new element to compare with the old element.
|
|
105
|
-
* @param oldValue - The old element to which the new element is compared.
|
|
106
|
-
*/
|
|
107
|
-
export function isSame(newValue, oldValue) {
|
|
108
|
-
return (newValue.tagName === oldValue.tagName &&
|
|
109
|
-
identityForCompare(newValue) === identityForCompare(oldValue));
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* List of all differences between children elements that both old and new element have.
|
|
113
|
-
* The list contains children both elements have and children that were added or removed
|
|
114
|
-
* from the new element.
|
|
115
|
-
* <b>Remark</b>: Private elements are ignored.
|
|
116
|
-
*
|
|
117
|
-
* @param elementToBeCompared - The element to check for differences.
|
|
118
|
-
* @param elementToCompareAgainst - The element used to check against.
|
|
119
|
-
*/
|
|
120
|
-
export function diffSclChilds(elementToBeCompared, elementToCompareAgainst, filterToIgnore, searchElementToBeCompared, searchElementToCompareAgainst) {
|
|
121
|
-
const childDiffs = [];
|
|
122
|
-
const childrenToBeCompared = Array.from(elementToBeCompared.children);
|
|
123
|
-
const childrenToCompareTo = Array.from(elementToCompareAgainst.children);
|
|
124
|
-
childrenToBeCompared.forEach(newElement => {
|
|
125
|
-
if (!newElement.closest('Private')) {
|
|
126
|
-
const shouldFilter = shouldFilterElement(newElement, getDiffFilterSelector(newElement, searchElementToBeCompared, filterToIgnore));
|
|
127
|
-
if (!shouldFilter) {
|
|
128
|
-
const twinIndex = childrenToCompareTo.findIndex(ourChild => isSame(newElement, ourChild));
|
|
129
|
-
const oldElement = twinIndex > -1 ? childrenToCompareTo[twinIndex] : null;
|
|
130
|
-
if (oldElement) {
|
|
131
|
-
childrenToCompareTo.splice(twinIndex, 1);
|
|
132
|
-
childDiffs.push({
|
|
133
|
-
type: 'Element',
|
|
134
|
-
newValue: newElement,
|
|
135
|
-
oldValue: oldElement,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
childDiffs.push({
|
|
140
|
-
type: 'Element',
|
|
141
|
-
newValue: newElement,
|
|
142
|
-
oldValue: null,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
childrenToCompareTo.forEach(oldElement => {
|
|
149
|
-
if (!oldElement.closest('Private')) {
|
|
150
|
-
const shouldFilter = shouldFilterElement(oldElement, getDiffFilterSelector(oldElement, searchElementToCompareAgainst, filterToIgnore));
|
|
151
|
-
if (!shouldFilter) {
|
|
152
|
-
childDiffs.push({
|
|
153
|
-
type: 'Element',
|
|
154
|
-
newValue: null,
|
|
155
|
-
oldValue: oldElement,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
return childDiffs;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Generate HTML (TemplateResult) containing all the differences between the two elements passed.
|
|
164
|
-
* If null is returned there are no differences between the two elements.
|
|
165
|
-
*
|
|
166
|
-
* @param elementToBeCompared - The element to check for differences.
|
|
167
|
-
* @param elementToCompareAgainst - The element used to check against.
|
|
168
|
-
*/
|
|
169
|
-
export function renderDiff(elementToBeCompared, elementToCompareAgainst, filterToIgnore = {}) {
|
|
170
|
-
return renderDiffInternal(elementToBeCompared, elementToCompareAgainst, filterToIgnore, elementToBeCompared, elementToCompareAgainst);
|
|
171
|
-
}
|
|
172
|
-
function renderDiffInternal(elementToBeCompared, elementToCompareAgainst, filterToIgnore = {}, searchElementToBeCompared, searchElementToCompareAgainst) {
|
|
173
|
-
// Determine the ID from the current tag. These can be numbers or strings.
|
|
174
|
-
let idTitle = identity(elementToBeCompared).toString();
|
|
175
|
-
if (idTitle === 'NaN') {
|
|
176
|
-
idTitle = undefined;
|
|
177
|
-
}
|
|
178
|
-
// Set the root elements if they are not defined yet
|
|
179
|
-
searchElementToBeCompared = searchElementToBeCompared || elementToBeCompared;
|
|
180
|
-
searchElementToCompareAgainst =
|
|
181
|
-
searchElementToCompareAgainst || elementToCompareAgainst;
|
|
182
|
-
const attrDiffs = diffSclAttributes(elementToBeCompared, elementToCompareAgainst, filterToIgnore, searchElementToBeCompared);
|
|
183
|
-
// Next check which elements are added, deleted or in both elements.
|
|
184
|
-
const childDiffs = diffSclChilds(elementToBeCompared, elementToCompareAgainst, filterToIgnore, searchElementToBeCompared, searchElementToCompareAgainst);
|
|
185
|
-
const childAddedOrDeleted = [];
|
|
186
|
-
const childToCompare = [];
|
|
187
|
-
childDiffs.forEach(diff => {
|
|
188
|
-
if (!diff.oldValue || !diff.newValue) {
|
|
189
|
-
childAddedOrDeleted.push(diff);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
childToCompare.push(diff);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
// These children exist in both old and new element, let's check if there are any difference in the children.
|
|
196
|
-
const childToCompareTemplates = childToCompare
|
|
197
|
-
.map(diff => renderDiff(diff.newValue, diff.oldValue, filterToIgnore))
|
|
198
|
-
.filter(result => result !== null);
|
|
199
|
-
// If there are difference generate the HTML otherwise just return null.
|
|
200
|
-
if (childToCompareTemplates.length > 0 ||
|
|
201
|
-
attrDiffs.length > 0 ||
|
|
202
|
-
childAddedOrDeleted.length > 0) {
|
|
203
|
-
return html ` ${attrDiffs.length > 0 || childAddedOrDeleted.length > 0
|
|
204
|
-
? html `<div class="container container--alt">
|
|
205
|
-
<div class="list__container list__container--left">
|
|
206
|
-
<mwc-list multi right nonInteractive>
|
|
207
|
-
${repeat(attrDiffs, e => e, ([name, diff]) => html `<mwc-list-item right twoLine graphic="icon">
|
|
208
|
-
${diff.oldValue !== null
|
|
209
|
-
? html `
|
|
210
|
-
<span>
|
|
211
|
-
${name}:
|
|
212
|
-
${diff.oldValue === '' ? '""' : diff.oldValue}
|
|
213
|
-
</span>
|
|
214
|
-
<span slot="secondary">${idTitle}</span>
|
|
215
|
-
<mwc-icon slot="graphic">
|
|
216
|
-
${diffTypeToIcon.get(diff.type)}
|
|
217
|
-
</mwc-icon>
|
|
218
|
-
`
|
|
219
|
-
: ''}
|
|
220
|
-
</mwc-list-item>`)}
|
|
221
|
-
${repeat(childAddedOrDeleted, e => e, diff => html ` <mwc-list-item right twoLine graphic="icon">
|
|
222
|
-
${diff.oldValue
|
|
223
|
-
? html `
|
|
224
|
-
<span>${diff.oldValue.tagName}</span>
|
|
225
|
-
<span slot="secondary">
|
|
226
|
-
${describe(diff.oldValue)}
|
|
227
|
-
</span>
|
|
228
|
-
<mwc-icon slot="graphic">
|
|
229
|
-
${diffTypeToIcon.get(diff.type)}
|
|
230
|
-
</mwc-icon>
|
|
231
|
-
`
|
|
232
|
-
: ''}
|
|
233
|
-
</mwc-list-item>`)}
|
|
234
|
-
</mwc-list>
|
|
235
|
-
</div>
|
|
236
|
-
<div class="list__container">
|
|
237
|
-
<mwc-list multi left nonInteractive>
|
|
238
|
-
${repeat(attrDiffs, e => e, ([name, diff]) => html ` <mwc-list-item left twoLine graphic="icon">
|
|
239
|
-
${diff.newValue !== null
|
|
240
|
-
? html `
|
|
241
|
-
<span>
|
|
242
|
-
${name}:
|
|
243
|
-
${diff.newValue === '' ? '""' : diff.newValue}
|
|
244
|
-
</span>
|
|
245
|
-
<span slot="secondary">${idTitle}</span>
|
|
246
|
-
<mwc-icon slot="graphic">
|
|
247
|
-
${diffTypeToIcon.get(diff.type)}
|
|
248
|
-
</mwc-icon>
|
|
249
|
-
`
|
|
250
|
-
: ''}
|
|
251
|
-
</mwc-list-item>`)}
|
|
252
|
-
${repeat(childAddedOrDeleted, e => e, diff => html ` <mwc-list-item left twoLine graphic="icon">
|
|
253
|
-
${diff.newValue
|
|
254
|
-
? html `
|
|
255
|
-
<span>${diff.newValue.tagName}</span>
|
|
256
|
-
<span slot="secondary">
|
|
257
|
-
${describe(diff.newValue)}
|
|
258
|
-
</span>
|
|
259
|
-
<mwc-icon slot="graphic">
|
|
260
|
-
${diffTypeToIcon.get(diff.type)}
|
|
261
|
-
</mwc-icon>
|
|
262
|
-
`
|
|
263
|
-
: ''}
|
|
264
|
-
</mwc-list-item>`)}
|
|
265
|
-
</mwc-list>
|
|
266
|
-
</div>
|
|
267
|
-
</div>`
|
|
268
|
-
: ''}
|
|
269
|
-
${childToCompareTemplates}`;
|
|
270
|
-
}
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
//# sourceMappingURL=compare.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../../src/foundation/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EA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AAI,CAAC,QAAQ,CAAC,OAAO;;8BAEzB,QAAQ,CAAC,IAAI,CAAC,QAAS,CAAC;;;8BAGxB,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;;yBAElC;gBACH,CAAC,CAAC,EAAE;mCACS,CACpB;;;eAGA;YACT,CAAC,CAAC,EAAE;MACJ,uBAAuB,EAAE,CAAC;KAC7B;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { html, TemplateResult } from 'lit-element';\nimport { repeat } from 'lit-html/directives/repeat';\nimport { get } from 'lit-translate';\n\nimport '@material/mwc-list';\nimport '@material/mwc-list/mwc-list-item';\nimport '@material/mwc-icon';\n\nimport { identity } from '../foundation.js';\nimport { SVGTemplateResult } from 'lit-html';\n\nimport { attributeIcon, contentIcon, elementIcon } from '../icons/compare.js';\n\nconst diffTypeToIcon: Map<DiffType, SVGTemplateResult> = new Map<\n DiffType,\n SVGTemplateResult\n>();\n\ndiffTypeToIcon.set('Attribute', attributeIcon);\ndiffTypeToIcon.set('Content', contentIcon);\ndiffTypeToIcon.set('Element', elementIcon);\n\nexport type DiffType = 'Element' | 'Attribute' | 'Content';\n\nexport type Diff<T> =\n | { type: DiffType; oldValue: T; newValue: null }\n | { type: DiffType; oldValue: null; newValue: T }\n | { type: DiffType; oldValue: T; newValue: T };\n\n/**\n * Type to filter out a difference based on `tagName`.`attributeName`\n *\n * The matcher can be a boolean or a `consumer` that returns a boolean\n */\nexport interface DiffFilter<T> {\n [selector: string]: DiffFilterSelector<T>;\n}\n\ninterface DiffFilterSelector<T> {\n full?: DiffFilterConsumer<T>;\n attributes?: {\n [name: string]: DiffFilterConsumer<T>;\n };\n}\n\n/**\n * Consumer to match if a diff should be filtered out.\n */\ntype DiffFilterConsumer<T> = boolean | ((value: T | null) => boolean);\n\nfunction getDiffFilterSelector(\n elementToBeCompared: Element,\n rootElementToBeCompared: Element,\n filters: DiffFilter<Element>\n): DiffFilterSelector<Element> | undefined {\n const querySelector: string | undefined =\n rootElementToBeCompared === elementToBeCompared\n ? ':scope'\n : Object.keys(filters).find(selector =>\n Array.from(\n rootElementToBeCompared.querySelectorAll(selector)\n ).includes(elementToBeCompared)\n );\n\n return querySelector ? filters[querySelector!] : undefined;\n}\n\nfunction shouldFilterElement(\n element: Element,\n filter: DiffFilterSelector<Element> | undefined\n): boolean {\n if (!filter || !filter.full) {\n return false;\n }\n const consumer: DiffFilterConsumer<Element> = filter!.full!;\n\n return typeof consumer === 'boolean' ? consumer : consumer(element);\n}\n\nfunction shouldFilterAttribute(\n element: Element,\n attribute: string,\n filter: DiffFilterSelector<Element> | undefined\n): boolean {\n if (!filter || !filter.attributes || !filter.attributes![attribute]) {\n return false;\n }\n const consumer: DiffFilterConsumer<Element> = filter!.attributes![attribute];\n\n return typeof consumer === 'boolean' ? consumer : consumer(element);\n}\n\n/**\n * Returns the description of the Element that differs.\n *\n * @param element - The Element to retrieve the identifier from.\n */\nfunction describe(element: Element): string {\n const id = identity(element);\n return typeof id === 'string' ? id : get('unidentifiable');\n}\n\n/**\n * Check if there are any attribute values changed between the two elements.\n *\n * @param elementToBeCompared - The element to check for differences.\n * @param elementToCompareAgainst - The element used to check against.\n */\nexport function diffSclAttributes(\n elementToBeCompared: Element,\n elementToCompareAgainst: Element,\n filterToIgnore: DiffFilter<Element>,\n searchElementToBeCompared: Element\n): [string, Diff<string>][] {\n const attrDiffs: [string, Diff<string>][] = [];\n\n // First check if there is any text inside the element and there should be no child elements.\n const newText = elementToBeCompared.textContent?.trim() ?? '';\n const oldText = elementToCompareAgainst.textContent?.trim() ?? '';\n if (\n elementToBeCompared.childElementCount === 0 &&\n elementToCompareAgainst.childElementCount === 0 &&\n newText !== oldText\n ) {\n const shouldFilter: boolean = shouldFilterElement(\n elementToBeCompared,\n getDiffFilterSelector(\n elementToBeCompared,\n searchElementToBeCompared,\n filterToIgnore\n )\n );\n\n if (!shouldFilter) {\n attrDiffs.push([\n 'value',\n { type: 'Content', newValue: newText, oldValue: oldText },\n ]);\n }\n }\n\n // Next check if there are any difference between attributes.\n const attributeNames = new Set(\n elementToCompareAgainst\n .getAttributeNames()\n .concat(elementToBeCompared.getAttributeNames())\n );\n for (const name of attributeNames) {\n const shouldFilter: boolean = shouldFilterAttribute(\n elementToBeCompared,\n name,\n getDiffFilterSelector(\n elementToBeCompared,\n searchElementToBeCompared,\n filterToIgnore\n )\n );\n if (\n !shouldFilter &&\n elementToCompareAgainst.getAttribute(name) !==\n elementToBeCompared.getAttribute(name)\n ) {\n attrDiffs.push([\n name,\n <Diff<string>>{\n type: 'Attribute',\n newValue: elementToBeCompared.getAttribute(name),\n oldValue: elementToCompareAgainst.getAttribute(name),\n },\n ]);\n }\n }\n return attrDiffs;\n}\n\n/**\n * Function to retrieve the identity to compare 2 children on the same level.\n * This means we only need to last part of the Identity string to compare the children.\n *\n * @param element - The element to retrieve the identity from.\n */\nexport function identityForCompare(element: Element): string | number {\n let identityOfElement = identity(element);\n if (typeof identityOfElement === 'string') {\n identityOfElement = identityOfElement.split('>').pop() ?? '';\n }\n return identityOfElement;\n}\n\n/**\n * Custom method for comparing to check if 2 elements are the same. Because they are on the same level\n * we don't need to compare the full identity, we just compare the part of the Element itself.\n *\n * <b>Remark</b>Private elements are already filtered out, so we don't need to bother them.\n *\n * @param newValue - The new element to compare with the old element.\n * @param oldValue - The old element to which the new element is compared.\n */\nexport function isSame(newValue: Element, oldValue: Element): boolean {\n return (\n newValue.tagName === oldValue.tagName &&\n identityForCompare(newValue) === identityForCompare(oldValue)\n );\n}\n\n/**\n * List of all differences between children elements that both old and new element have.\n * The list contains children both elements have and children that were added or removed\n * from the new element.\n * <b>Remark</b>: Private elements are ignored.\n *\n * @param elementToBeCompared - The element to check for differences.\n * @param elementToCompareAgainst - The element used to check against.\n */\nexport function diffSclChilds(\n elementToBeCompared: Element,\n elementToCompareAgainst: Element,\n filterToIgnore: DiffFilter<Element>,\n searchElementToBeCompared: Element,\n searchElementToCompareAgainst: Element\n): Diff<Element>[] {\n const childDiffs: Diff<Element>[] = [];\n const childrenToBeCompared = Array.from(elementToBeCompared.children);\n const childrenToCompareTo = Array.from(elementToCompareAgainst.children);\n\n childrenToBeCompared.forEach(newElement => {\n if (!newElement.closest('Private')) {\n const shouldFilter: boolean = shouldFilterElement(\n newElement,\n getDiffFilterSelector(\n newElement,\n searchElementToBeCompared,\n filterToIgnore\n )\n );\n if (!shouldFilter) {\n const twinIndex = childrenToCompareTo.findIndex(ourChild =>\n isSame(newElement, ourChild)\n );\n const oldElement =\n twinIndex > -1 ? childrenToCompareTo[twinIndex] : null;\n\n if (oldElement) {\n childrenToCompareTo.splice(twinIndex, 1);\n childDiffs.push({\n type: 'Element',\n newValue: newElement,\n oldValue: oldElement,\n });\n } else {\n childDiffs.push({\n type: 'Element',\n newValue: newElement,\n oldValue: null,\n });\n }\n }\n }\n });\n childrenToCompareTo.forEach(oldElement => {\n if (!oldElement.closest('Private')) {\n const shouldFilter: boolean = shouldFilterElement(\n oldElement,\n getDiffFilterSelector(\n oldElement,\n searchElementToCompareAgainst,\n filterToIgnore\n )\n );\n if (!shouldFilter) {\n childDiffs.push({\n type: 'Element',\n newValue: null,\n oldValue: oldElement,\n });\n }\n }\n });\n return childDiffs;\n}\n\n/**\n * Generate HTML (TemplateResult) containing all the differences between the two elements passed.\n * If null is returned there are no differences between the two elements.\n *\n * @param elementToBeCompared - The element to check for differences.\n * @param elementToCompareAgainst - The element used to check against.\n */\nexport function renderDiff(\n elementToBeCompared: Element,\n elementToCompareAgainst: Element,\n filterToIgnore: DiffFilter<Element> = {}\n): TemplateResult | null {\n return renderDiffInternal(\n elementToBeCompared,\n elementToCompareAgainst,\n filterToIgnore,\n elementToBeCompared,\n elementToCompareAgainst\n );\n}\n\nfunction renderDiffInternal(\n elementToBeCompared: Element,\n elementToCompareAgainst: Element,\n filterToIgnore: DiffFilter<Element> = {},\n searchElementToBeCompared: Element,\n searchElementToCompareAgainst: Element\n): TemplateResult | null {\n // Determine the ID from the current tag. These can be numbers or strings.\n let idTitle: string | undefined = identity(elementToBeCompared).toString();\n if (idTitle === 'NaN') {\n idTitle = undefined;\n }\n\n // Set the root elements if they are not defined yet\n searchElementToBeCompared = searchElementToBeCompared || elementToBeCompared;\n searchElementToCompareAgainst =\n searchElementToCompareAgainst || elementToCompareAgainst;\n\n const attrDiffs: [string, Diff<string>][] = diffSclAttributes(\n elementToBeCompared,\n elementToCompareAgainst,\n filterToIgnore,\n searchElementToBeCompared\n );\n\n // Next check which elements are added, deleted or in both elements.\n const childDiffs: Diff<Element>[] = diffSclChilds(\n elementToBeCompared,\n elementToCompareAgainst,\n filterToIgnore,\n searchElementToBeCompared,\n searchElementToCompareAgainst\n );\n\n const childAddedOrDeleted: Diff<Element>[] = [];\n const childToCompare: Diff<Element>[] = [];\n childDiffs.forEach(diff => {\n if (!diff.oldValue || !diff.newValue) {\n childAddedOrDeleted.push(diff);\n } else {\n childToCompare.push(diff);\n }\n });\n\n // These children exist in both old and new element, let's check if there are any difference in the children.\n const childToCompareTemplates = childToCompare\n .map(diff => renderDiff(diff.newValue!, diff.oldValue!, filterToIgnore))\n .filter(result => result !== null);\n\n // If there are difference generate the HTML otherwise just return null.\n if (\n childToCompareTemplates.length > 0 ||\n attrDiffs.length > 0 ||\n childAddedOrDeleted.length > 0\n ) {\n return html` ${attrDiffs.length > 0 || childAddedOrDeleted.length > 0\n ? html`<div class=\"container container--alt\">\n <div class=\"list__container list__container--left\">\n <mwc-list multi right nonInteractive>\n ${repeat(\n attrDiffs,\n e => e,\n ([name, diff]) =>\n html`<mwc-list-item right twoLine graphic=\"icon\">\n ${diff.oldValue !== null\n ? html`\n <span>\n ${name}:\n ${diff.oldValue === '' ? '\"\"' : diff.oldValue}\n </span>\n <span slot=\"secondary\">${idTitle}</span>\n <mwc-icon slot=\"graphic\">\n ${diffTypeToIcon.get(diff.type)}\n </mwc-icon>\n `\n : ''}\n </mwc-list-item>`\n )}\n ${repeat(\n childAddedOrDeleted,\n e => e,\n diff =>\n html` <mwc-list-item right twoLine graphic=\"icon\">\n ${diff.oldValue\n ? html`\n <span>${diff.oldValue.tagName}</span>\n <span slot=\"secondary\">\n ${describe(diff.oldValue!)}\n </span>\n <mwc-icon slot=\"graphic\">\n ${diffTypeToIcon.get(diff.type)}\n </mwc-icon>\n `\n : ''}\n </mwc-list-item>`\n )}\n </mwc-list>\n </div>\n <div class=\"list__container\">\n <mwc-list multi left nonInteractive>\n ${repeat(\n attrDiffs,\n e => e,\n ([name, diff]) =>\n html` <mwc-list-item left twoLine graphic=\"icon\">\n ${diff.newValue !== null\n ? html`\n <span>\n ${name}:\n ${diff.newValue === '' ? '\"\"' : diff.newValue}\n </span>\n <span slot=\"secondary\">${idTitle}</span>\n <mwc-icon slot=\"graphic\">\n ${diffTypeToIcon.get(diff.type)}\n </mwc-icon>\n `\n : ''}\n </mwc-list-item>`\n )}\n ${repeat(\n childAddedOrDeleted,\n e => e,\n diff =>\n html` <mwc-list-item left twoLine graphic=\"icon\">\n ${diff.newValue\n ? html`\n <span>${diff.newValue.tagName}</span>\n <span slot=\"secondary\">\n ${describe(diff.newValue!)}\n </span>\n <mwc-icon slot=\"graphic\">\n ${diffTypeToIcon.get(diff.type)}\n </mwc-icon>\n `\n : ''}\n </mwc-list-item>`\n )}\n </mwc-list>\n </div>\n </div>`\n : ''}\n ${childToCompareTemplates}`;\n }\n return null;\n}\n"]}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { SCL_NAMESPACE } from '../schemas.js';
|
|
2
|
-
/**
|
|
3
|
-
* Determine which part of the Template Structure still needs to be initialized.
|
|
4
|
-
* With the first call the parent will normally be the LN(0) Element to start from.
|
|
5
|
-
* It will use the list to pop the first element and look if there is a DOI/SDI/DAI
|
|
6
|
-
* Element available with the same name.
|
|
7
|
-
*
|
|
8
|
-
* @param parentElement - The element to search from for a DOI/SDI/DAI
|
|
9
|
-
* @param templateStructure - The templates structure with DO/DA/BDA Elements.
|
|
10
|
-
* @returns The last element initialized element or LN(0) if nothing is initialized. This Element can be used to
|
|
11
|
-
* add the new element to. And the list of Template Elements that still need to be initialized.
|
|
12
|
-
*/
|
|
13
|
-
export function determineUninitializedStructure(parentElement, templateStructure) {
|
|
14
|
-
const templateElement = templateStructure.shift();
|
|
15
|
-
if (templateStructure.length > 0) {
|
|
16
|
-
// If there are still Template Elements we didn't reach the DAI Element, so continue checking if any DOI/SDI
|
|
17
|
-
// Element is found with the same name.
|
|
18
|
-
let instanceElement;
|
|
19
|
-
// DO Elements are initialized as DOI, others as SDI.
|
|
20
|
-
if (templateElement.tagName === 'DO') {
|
|
21
|
-
instanceElement = parentElement.querySelector(`DOI[name="${templateElement.getAttribute('name')}"]`);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
instanceElement = parentElement.querySelector(`SDI[name="${templateElement.getAttribute('name')}"]`);
|
|
25
|
-
}
|
|
26
|
-
if (instanceElement) {
|
|
27
|
-
// If instance element found we will search one level lower again.
|
|
28
|
-
// So the parent will become the instance element and the list is 1 smaller.
|
|
29
|
-
return determineUninitializedStructure(instanceElement, templateStructure);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
// No instance element found, so the element and all other elements still need to be
|
|
33
|
-
// initialized and returned.
|
|
34
|
-
templateStructure.unshift(templateElement);
|
|
35
|
-
return [parentElement, templateStructure];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
// The last template element in the list, so this should be the DA Element that only needs
|
|
40
|
-
// to be initialized.
|
|
41
|
-
return [parentElement, [templateElement]];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Create a new instance structure defined by the array of template elements passed.
|
|
46
|
-
*
|
|
47
|
-
* @param uninitializedTemplateStructure - The Array of Template Elements for which new instance elements need to be
|
|
48
|
-
* created.
|
|
49
|
-
* @returns The Element created from the last Template Element in the Array.
|
|
50
|
-
*/
|
|
51
|
-
export function initializeElements(uninitializedTemplateStructure) {
|
|
52
|
-
const element = uninitializedTemplateStructure.shift();
|
|
53
|
-
if (uninitializedTemplateStructure.length > 0) {
|
|
54
|
-
// If there are more template elements left this will become a DOI or SDI Element.
|
|
55
|
-
let newElement;
|
|
56
|
-
// Depending on the level create a DOI or SDI Element.
|
|
57
|
-
if (element.tagName === 'DO') {
|
|
58
|
-
newElement = element.ownerDocument.createElementNS(SCL_NAMESPACE, 'DOI');
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
newElement = element.ownerDocument.createElementNS(SCL_NAMESPACE, 'SDI');
|
|
62
|
-
}
|
|
63
|
-
newElement.setAttribute('name', element?.getAttribute('name') ?? '');
|
|
64
|
-
// Create an element from the next one (last) from the shortened array.
|
|
65
|
-
const childElement = initializeElements(uninitializedTemplateStructure);
|
|
66
|
-
newElement.append(childElement);
|
|
67
|
-
return newElement;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
// Create Val Element
|
|
71
|
-
const newValElement = element.ownerDocument.createElementNS(SCL_NAMESPACE, 'Val');
|
|
72
|
-
const valElement = element.querySelector('Val');
|
|
73
|
-
if (valElement) {
|
|
74
|
-
newValElement.textContent = valElement.textContent;
|
|
75
|
-
}
|
|
76
|
-
// Create DAI Element
|
|
77
|
-
const daiElement = element.ownerDocument.createElementNS(SCL_NAMESPACE, 'DAI');
|
|
78
|
-
daiElement.setAttribute('name', element?.getAttribute('name') ?? '');
|
|
79
|
-
daiElement.append(newValElement);
|
|
80
|
-
return daiElement;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Use the path configuration of a Common Data Class to search for all DO/SDO/DA/BDA Elements to create
|
|
85
|
-
* a structure for which DOI/SDI/DAI Elements should be created later. Null will be returned when an invalid
|
|
86
|
-
* Template Structure is described by the path.
|
|
87
|
-
*
|
|
88
|
-
* @param lnElement - The LN Element to use for searching the starting DO Element.
|
|
89
|
-
* @param path - The (S)DO/(B)DA Elements to find in the template structure.
|
|
90
|
-
* @returns List of Elements starting with the DO Element followed by one or more SDO or (B)DA Elements describing the structure.
|
|
91
|
-
*/
|
|
92
|
-
export function createTemplateStructure(lnElement, path) {
|
|
93
|
-
let templateStructure = [];
|
|
94
|
-
const doc = lnElement.ownerDocument;
|
|
95
|
-
const lnType = lnElement.getAttribute('lnType') ?? '';
|
|
96
|
-
let typeElement = doc.querySelector(`LNodeType[id="${lnType}"]`);
|
|
97
|
-
path.forEach(name => {
|
|
98
|
-
// There should be a DOType or DAType set for the current element in the list.
|
|
99
|
-
if (!typeElement) {
|
|
100
|
-
templateStructure = null;
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const dataElement = typeElement.querySelector(`:scope > DO[name="${name}"], :scope > SDO[name="${name}"], :scope > DA[name="${name}"], :scope > BDA[name="${name}"]`);
|
|
104
|
-
// If there is no (S)DO/(B)DA Element found the structure is incorrect, so just stop.
|
|
105
|
-
if (dataElement === null) {
|
|
106
|
-
templateStructure = null;
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
templateStructure.push(dataElement);
|
|
110
|
-
if (dataElement.tagName === 'DO' || dataElement.tagName === 'SDO') {
|
|
111
|
-
const type = dataElement.getAttribute('type') ?? '';
|
|
112
|
-
typeElement = doc.querySelector(`DataTypeTemplates > DOType[id="${type}"]`);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
const bType = dataElement.getAttribute('bType') ?? '';
|
|
116
|
-
if (bType === 'Struct') {
|
|
117
|
-
const type = dataElement.getAttribute('type') ?? '';
|
|
118
|
-
typeElement = doc.querySelector(`DataTypeTemplates > DAType[id="${type}"]`);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
typeElement = null;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
return templateStructure;
|
|
126
|
-
}
|
|
127
|
-
//# sourceMappingURL=dai.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dai.js","sourceRoot":"","sources":["../../../../src/foundation/dai.ts"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AE,CAAC;IACtD,IAAI,WAAW,GAAG,GAAG,CAAC,aAAa,CAAC,iBAAiB,MAAM,IAAI,CAAC,CAAC;IACjE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAClB,8EAA8E;QAC9E,IAAI,CAAC,WAAW,EAAE;YAChB,iBAAiB,GAAG,IAAI,CAAC;YACzB,OAAO;SACR;QACD,MAAM,WAAW,GAAG,WAAW,CAAC,aAAa,CAC3C,qBAAqB,IAAI,0BAA0B,IAAI,yBAAyB,IAAI,0BAA0B,IAAI,IAAI,CACvH,CAAC;QACF,qFAAqF;QACrF,IAAI,WAAW,KAAK,IAAI,EAAE;YACxB,iBAAiB,GAAG,IAAI,CAAC;YACzB,OAAO;SACR;QACD,iBAAkB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAErC,IAAI,WAAW,CAAC,OAAO,KAAK,IAAI,IAAI,WAAW,CAAC,OAAO,KAAK,KAAK,EAAE;YACjE,MAAM,IAAI,GAAG,WAAW,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACpD,WAAW,GAAG,GAAG,CAAC,aAAa,CAC7B,kCAAkC,IAAI,IAAI,CAC3C,CAAC;SACH;aAAM;YACL,MAAM,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACtD,IAAI,KAAK,KAAK,QAAQ,EAAE;gBACtB,MAAM,IAAI,GAAG,WAAW,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;gBACpD,WAAW,GAAG,GAAG,CAAC,aAAa,CAC7B,kCAAkC,IAAI,IAAI,CAC3C,CAAC;aACH;iBAAM;gBACL,WAAW,GAAG,IAAI,CAAC;aACpB;SACF;IACH,CAAC,CAAC,CAAC;IACH,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["import { SCL_NAMESPACE } from '../schemas.js';\n\n/**\n * Determine which part of the Template Structure still needs to be initialized.\n * With the first call the parent will normally be the LN(0) Element to start from.\n * It will use the list to pop the first element and look if there is a DOI/SDI/DAI\n * Element available with the same name.\n *\n * @param parentElement - The element to search from for a DOI/SDI/DAI\n * @param templateStructure - The templates structure with DO/DA/BDA Elements.\n * @returns The last element initialized element or LN(0) if nothing is initialized. This Element can be used to\n * add the new element to. And the list of Template Elements that still need to be initialized.\n */\nexport function determineUninitializedStructure(\n parentElement: Element,\n templateStructure: Element[]\n): [Element, Element[]] {\n const templateElement = templateStructure.shift();\n if (templateStructure.length > 0) {\n // If there are still Template Elements we didn't reach the DAI Element, so continue checking if any DOI/SDI\n // Element is found with the same name.\n let instanceElement: Element | null;\n // DO Elements are initialized as DOI, others as SDI.\n if (templateElement!.tagName === 'DO') {\n instanceElement = parentElement.querySelector(\n `DOI[name=\"${templateElement!.getAttribute('name')}\"]`\n );\n } else {\n instanceElement = parentElement.querySelector(\n `SDI[name=\"${templateElement!.getAttribute('name')}\"]`\n );\n }\n\n if (instanceElement) {\n // If instance element found we will search one level lower again.\n // So the parent will become the instance element and the list is 1 smaller.\n return determineUninitializedStructure(\n instanceElement,\n templateStructure\n );\n } else {\n // No instance element found, so the element and all other elements still need to be\n // initialized and returned.\n templateStructure.unshift(templateElement!);\n return [parentElement, templateStructure];\n }\n } else {\n // The last template element in the list, so this should be the DA Element that only needs\n // to be initialized.\n return [parentElement, [templateElement!]];\n }\n}\n\n/**\n * Create a new instance structure defined by the array of template elements passed.\n *\n * @param uninitializedTemplateStructure - The Array of Template Elements for which new instance elements need to be\n * created.\n * @returns The Element created from the last Template Element in the Array.\n */\nexport function initializeElements(\n uninitializedTemplateStructure: Element[]\n): Element {\n const element = uninitializedTemplateStructure.shift();\n if (uninitializedTemplateStructure.length > 0) {\n // If there are more template elements left this will become a DOI or SDI Element.\n let newElement;\n // Depending on the level create a DOI or SDI Element.\n if (element!.tagName === 'DO') {\n newElement = element!.ownerDocument.createElementNS(SCL_NAMESPACE, 'DOI');\n } else {\n newElement = element!.ownerDocument.createElementNS(SCL_NAMESPACE, 'SDI');\n }\n newElement.setAttribute('name', element?.getAttribute('name') ?? '');\n\n // Create an element from the next one (last) from the shortened array.\n const childElement = initializeElements(uninitializedTemplateStructure);\n newElement.append(childElement);\n\n return newElement;\n } else {\n // Create Val Element\n const newValElement = element!.ownerDocument.createElementNS(\n SCL_NAMESPACE,\n 'Val'\n );\n const valElement = element!.querySelector('Val');\n if (valElement) {\n newValElement.textContent = valElement.textContent;\n }\n\n // Create DAI Element\n const daiElement = element!.ownerDocument.createElementNS(\n SCL_NAMESPACE,\n 'DAI'\n );\n daiElement.setAttribute('name', element?.getAttribute('name') ?? '');\n daiElement.append(newValElement);\n return daiElement;\n }\n}\n\n/**\n * Use the path configuration of a Common Data Class to search for all DO/SDO/DA/BDA Elements to create\n * a structure for which DOI/SDI/DAI Elements should be created later. Null will be returned when an invalid\n * Template Structure is described by the path.\n *\n * @param lnElement - The LN Element to use for searching the starting DO Element.\n * @param path - The (S)DO/(B)DA Elements to find in the template structure.\n * @returns List of Elements starting with the DO Element followed by one or more SDO or (B)DA Elements describing the structure.\n */\nexport function createTemplateStructure(\n lnElement: Element,\n path: string[]\n): Element[] | null {\n let templateStructure: Element[] | null = [];\n\n const doc = lnElement.ownerDocument;\n const lnType = lnElement.getAttribute('lnType') ?? '';\n let typeElement = doc.querySelector(`LNodeType[id=\"${lnType}\"]`);\n path.forEach(name => {\n // There should be a DOType or DAType set for the current element in the list.\n if (!typeElement) {\n templateStructure = null;\n return;\n }\n const dataElement = typeElement.querySelector(\n `:scope > DO[name=\"${name}\"], :scope > SDO[name=\"${name}\"], :scope > DA[name=\"${name}\"], :scope > BDA[name=\"${name}\"]`\n );\n // If there is no (S)DO/(B)DA Element found the structure is incorrect, so just stop.\n if (dataElement === null) {\n templateStructure = null;\n return;\n }\n templateStructure!.push(dataElement);\n\n if (dataElement.tagName === 'DO' || dataElement.tagName === 'SDO') {\n const type = dataElement.getAttribute('type') ?? '';\n typeElement = doc.querySelector(\n `DataTypeTemplates > DOType[id=\"${type}\"]`\n );\n } else {\n const bType = dataElement.getAttribute('bType') ?? '';\n if (bType === 'Struct') {\n const type = dataElement.getAttribute('type') ?? '';\n typeElement = doc.querySelector(\n `DataTypeTemplates > DAType[id=\"${type}\"]`\n );\n } else {\n typeElement = null;\n }\n }\n });\n return templateStructure;\n}\n"]}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const maxGseMacAddress = 0x010ccd0101ff;
|
|
2
|
-
const minGseMacAddress = 0x010ccd010000;
|
|
3
|
-
const maxSmvMacAddress = 0x010ccd0401ff;
|
|
4
|
-
const minSmvMacAddress = 0x010ccd040000;
|
|
5
|
-
function convertToMac(mac) {
|
|
6
|
-
const str = 0 + mac.toString(16).toUpperCase();
|
|
7
|
-
const arr = str.match(/.{1,2}/g);
|
|
8
|
-
return arr?.join('-');
|
|
9
|
-
}
|
|
10
|
-
const gseMacRange = Array(maxGseMacAddress - minGseMacAddress)
|
|
11
|
-
.fill(1)
|
|
12
|
-
.map((_, i) => convertToMac(minGseMacAddress + i));
|
|
13
|
-
const smvMacRange = Array(maxSmvMacAddress - minSmvMacAddress)
|
|
14
|
-
.fill(1)
|
|
15
|
-
.map((_, i) => convertToMac(minSmvMacAddress + i));
|
|
16
|
-
/**
|
|
17
|
-
* @param doc - project xml document
|
|
18
|
-
* @param serviceType - SampledValueControl (SMV) or GSEControl (GSE)
|
|
19
|
-
* @returns a function generating increasing unused `MAC-Address` within `doc` on subsequent invocations
|
|
20
|
-
*/
|
|
21
|
-
export function mACAddressGenerator(doc, serviceType) {
|
|
22
|
-
const macs = new Set(Array.from(doc.querySelectorAll(`${serviceType} > Address > P[type="MAC-Address"]`)).map(macs => macs.textContent));
|
|
23
|
-
const range = serviceType === 'SMV' ? smvMacRange : gseMacRange;
|
|
24
|
-
return () => {
|
|
25
|
-
const uniqueMAC = range.find(mac => !macs.has(mac));
|
|
26
|
-
if (uniqueMAC)
|
|
27
|
-
macs.add(uniqueMAC);
|
|
28
|
-
return uniqueMAC ?? '';
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
const maxGseAppId = 0x3fff;
|
|
32
|
-
const minGseAppId = 0x0000;
|
|
33
|
-
// APPID range for Type1A(Trip) GOOSE acc. IEC 61850-8-1
|
|
34
|
-
const maxGseTripAppId = 0xbfff;
|
|
35
|
-
const minGseTripAppId = 0x8000;
|
|
36
|
-
const maxSmvAppId = 0x7fff;
|
|
37
|
-
const minSmvAppId = 0x4000;
|
|
38
|
-
const gseAppIdRange = Array(maxGseAppId - minGseAppId)
|
|
39
|
-
.fill(1)
|
|
40
|
-
.map((_, i) => (minGseAppId + i).toString(16).toUpperCase().padStart(4, '0'));
|
|
41
|
-
const gseTripAppIdRange = Array(maxGseTripAppId - minGseTripAppId)
|
|
42
|
-
.fill(1)
|
|
43
|
-
.map((_, i) => (minGseTripAppId + i).toString(16).toUpperCase().padStart(4, '0'));
|
|
44
|
-
const smvAppIdRange = Array(maxSmvAppId - minSmvAppId)
|
|
45
|
-
.fill(1)
|
|
46
|
-
.map((_, i) => (minSmvAppId + i).toString(16).toUpperCase().padStart(4, '0'));
|
|
47
|
-
/**
|
|
48
|
-
* @param doc - project xml document
|
|
49
|
-
* @param serviceType - SampledValueControl (SMV) or GSEControl (GSE)
|
|
50
|
-
* @param type1A - whether the GOOSE is a Trip GOOSE resulting in different APPID range - default false
|
|
51
|
-
* @returns a function generating increasing unused `APPID` within `doc` on subsequent invocations
|
|
52
|
-
*/
|
|
53
|
-
export function appIdGenerator(doc, serviceType, type1A = false) {
|
|
54
|
-
const appIds = new Set(Array.from(doc.querySelectorAll(`${serviceType} > Address > P[type="APPID"]`)).map(appId => appId.textContent));
|
|
55
|
-
const range = serviceType === 'SMV'
|
|
56
|
-
? smvAppIdRange
|
|
57
|
-
: type1A
|
|
58
|
-
? gseTripAppIdRange
|
|
59
|
-
: gseAppIdRange;
|
|
60
|
-
return () => {
|
|
61
|
-
const uniqueAppId = range.find(appId => !appIds.has(appId));
|
|
62
|
-
if (uniqueAppId)
|
|
63
|
-
appIds.add(uniqueAppId);
|
|
64
|
-
return uniqueAppId ?? '';
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=generators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators.js","sourceRoot":"","sources":["../../../../src/foundation/generators.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,cAAc,CAAC;AACxC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAExC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AACxC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAExC,SAAS,YAAY,CAAC,GAAW;IAC/B,MAAM,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/C,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,SAAS,CAAE,CAAC;IAClC,OAAO,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,WAAW,GAAG,KAAK,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;KAC3D,IAAI,CAAC,CAAC,CAAC;KACP,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,gBAAgB,GAAG,CAAC,CAAC,CAAC,CAAC;AAErD,MAAM,WAAW,GAAG,KAAK,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;KAC3D,IAAI,CAAC,CAAC,CAAC;KACP,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,gBAAgB,GAAG,CAAC,CAAC,CAAC,CAAC;AAErD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAgB,EAChB,WAA0B;IAE1B,MAAM,IAAI,GAAG,IAAI,GAAG,CAClB,KAAK,CAAC,IAAI,CACR,GAAG,CAAC,gBAAgB,CAAC,GAAG,WAAW,oC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AC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAClE,CAAC;AAEJ,MAAM,aAAa,GAAG,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;KACnD,IAAI,CAAC,CAAC,CAAC;KACP,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AAEhF;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,GAAgB,EAChB,WAA0B,EAC1B,MAAM,GAAG,KAAK;IAEd,MAAM,MAAM,GAAG,IAAI,GAAG,CACpB,KAAK,CAAC,IAAI,CACR,GAAG,CAAC,gBAAgB,CAAC,GAAG,WAAW,8BAA8B,CAAC,CACnE,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,WAAY,CAAC,CACnC,CAAC;IAEF,MAAM,KAAK,GACT,WAAW,KAAK,KAAK;QACnB,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,aAAa,CAAC;IAEpB,OAAO,GAAG,EAAE;QACV,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5D,IAAI,WAAW;YAAE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzC,OAAO,WAAW,IAAI,EAAE,CAAC;IAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["const maxGseMacAddress = 0x010ccd0101ff;\nconst minGseMacAddress = 0x010ccd010000;\n\nconst maxSmvMacAddress = 0x010ccd0401ff;\nconst minSmvMacAddress = 0x010ccd040000;\n\nfunction convertToMac(mac: number): string {\n const str = 0 + mac.toString(16).toUpperCase();\n const arr = str.match(/.{1,2}/g)!;\n return arr?.join('-');\n}\n\nconst gseMacRange = Array(maxGseMacAddress - minGseMacAddress)\n .fill(1)\n .map((_, i) => convertToMac(minGseMacAddress + i));\n\nconst smvMacRange = Array(maxSmvMacAddress - minSmvMacAddress)\n .fill(1)\n .map((_, i) => convertToMac(minSmvMacAddress + i));\n\n/**\n * @param doc - project xml document\n * @param serviceType - SampledValueControl (SMV) or GSEControl (GSE)\n * @returns a function generating increasing unused `MAC-Address` within `doc` on subsequent invocations\n */\nexport function mACAddressGenerator(\n doc: XMLDocument,\n serviceType: 'SMV' | 'GSE'\n): () => string {\n const macs = new Set(\n Array.from(\n doc.querySelectorAll(`${serviceType} > Address > P[type=\"MAC-Address\"]`)\n ).map(macs => macs.textContent!)\n );\n\n const range = serviceType === 'SMV' ? smvMacRange : gseMacRange;\n\n return () => {\n const uniqueMAC = range.find(mac => !macs.has(mac));\n if (uniqueMAC) macs.add(uniqueMAC);\n return uniqueMAC ?? '';\n };\n}\n\nconst maxGseAppId = 0x3fff;\nconst minGseAppId = 0x0000;\n\n// APPID range for Type1A(Trip) GOOSE acc. IEC 61850-8-1\nconst maxGseTripAppId = 0xbfff;\nconst minGseTripAppId = 0x8000;\n\nconst maxSmvAppId = 0x7fff;\nconst minSmvAppId = 0x4000;\n\nconst gseAppIdRange = Array(maxGseAppId - minGseAppId)\n .fill(1)\n .map((_, i) => (minGseAppId + i).toString(16).toUpperCase().padStart(4, '0'));\n\nconst gseTripAppIdRange = Array(maxGseTripAppId - minGseTripAppId)\n .fill(1)\n .map((_, i) =>\n (minGseTripAppId + i).toString(16).toUpperCase().padStart(4, '0')\n );\n\nconst smvAppIdRange = Array(maxSmvAppId - minSmvAppId)\n .fill(1)\n .map((_, i) => (minSmvAppId + i).toString(16).toUpperCase().padStart(4, '0'));\n\n/**\n * @param doc - project xml document\n * @param serviceType - SampledValueControl (SMV) or GSEControl (GSE)\n * @param type1A - whether the GOOSE is a Trip GOOSE resulting in different APPID range - default false\n * @returns a function generating increasing unused `APPID` within `doc` on subsequent invocations\n */\nexport function appIdGenerator(\n doc: XMLDocument,\n serviceType: 'SMV' | 'GSE',\n type1A = false\n): () => string {\n const appIds = new Set(\n Array.from(\n doc.querySelectorAll(`${serviceType} > Address > P[type=\"APPID\"]`)\n ).map(appId => appId.textContent!)\n );\n\n const range =\n serviceType === 'SMV'\n ? smvAppIdRange\n : type1A\n ? gseTripAppIdRange\n : gseAppIdRange;\n\n return () => {\n const uniqueAppId = range.find(appId => !appIds.has(appId));\n if (uniqueAppId) appIds.add(uniqueAppId);\n return uniqueAppId ?? '';\n };\n}\n"]}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { find, identity } from '../foundation.js';
|
|
2
|
-
/**
|
|
3
|
-
* All available FCDA references that are used to link ExtRefs.
|
|
4
|
-
*/
|
|
5
|
-
const fcdaReferences = [
|
|
6
|
-
'ldInst',
|
|
7
|
-
'lnClass',
|
|
8
|
-
'lnInst',
|
|
9
|
-
'prefix',
|
|
10
|
-
'doName',
|
|
11
|
-
'daName',
|
|
12
|
-
];
|
|
13
|
-
/**
|
|
14
|
-
* Get all the FCDA attributes containing values from a specific element.
|
|
15
|
-
*
|
|
16
|
-
* @param elementContainingFcdaReferences - The element to use
|
|
17
|
-
* @returns FCDA references
|
|
18
|
-
*/
|
|
19
|
-
export function getFcdaReferences(elementContainingFcdaReferences) {
|
|
20
|
-
return fcdaReferences
|
|
21
|
-
.map(fcdaRef => elementContainingFcdaReferences.getAttribute(fcdaRef)
|
|
22
|
-
? `[${fcdaRef}="${elementContainingFcdaReferences.getAttribute(fcdaRef)}"]`
|
|
23
|
-
: '')
|
|
24
|
-
.join('');
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* All available Control references that are used to link ExtRefs.
|
|
28
|
-
*/
|
|
29
|
-
const controlReferences = ['srcLDInst', 'srcLNClass', 'srcLNInst', 'srcCBName'];
|
|
30
|
-
/**
|
|
31
|
-
* Get all the Control attributes containing values from a specific element.
|
|
32
|
-
*
|
|
33
|
-
* @param extRef - The element to use
|
|
34
|
-
* @returns Control references
|
|
35
|
-
*/
|
|
36
|
-
export function getControlReferences(extRef) {
|
|
37
|
-
return controlReferences
|
|
38
|
-
.map(controlRef => extRef.getAttribute(controlRef)
|
|
39
|
-
? `[${controlRef}="${extRef.getAttribute(controlRef)}"]`
|
|
40
|
-
: '')
|
|
41
|
-
.join('');
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Creating Delete actions in case Inputs elements are empty.
|
|
45
|
-
*
|
|
46
|
-
* @param extRefDeleteActions - All Delete actions for ExtRefs.
|
|
47
|
-
* @returns Possible delete actions for empty Inputs elements.
|
|
48
|
-
*/
|
|
49
|
-
export function emptyInputsDeleteActions(extRefDeleteActions) {
|
|
50
|
-
if (!extRefDeleteActions.length)
|
|
51
|
-
return [];
|
|
52
|
-
const inputDeleteActions = [];
|
|
53
|
-
const inputsMap = {};
|
|
54
|
-
for (const extRefDeleteAction of extRefDeleteActions) {
|
|
55
|
-
const extRef = extRefDeleteAction.old.element;
|
|
56
|
-
const inputsElement = extRefDeleteAction.old.parent;
|
|
57
|
-
const id = identity(inputsElement);
|
|
58
|
-
if (!inputsMap[id])
|
|
59
|
-
inputsMap[id] = inputsElement.cloneNode(true);
|
|
60
|
-
// Search the ExtRef in the Cloned Inputs Element
|
|
61
|
-
const linkedExtRef = inputsMap[id].querySelector(`ExtRef${extRef.getAttribute('iedName')
|
|
62
|
-
? `[iedName="${extRef.getAttribute('iedName')}"]`
|
|
63
|
-
: ''}${getFcdaReferences(extRef)}${extRef.getAttribute('serviceType')
|
|
64
|
-
? `[serviceType="${extRef.getAttribute('serviceType')}"]`
|
|
65
|
-
: ''}${getControlReferences(extRef)}`);
|
|
66
|
-
// And if found remove it as child from the Cloned Inputs Element
|
|
67
|
-
if (linkedExtRef)
|
|
68
|
-
inputsMap[id].removeChild(linkedExtRef);
|
|
69
|
-
}
|
|
70
|
-
// Create delete action for each empty inputs
|
|
71
|
-
Object.entries(inputsMap).forEach(([key, value]) => {
|
|
72
|
-
if (value.children.length == 0) {
|
|
73
|
-
const doc = extRefDeleteActions[0].old.parent.ownerDocument;
|
|
74
|
-
const inputs = find(doc, 'Inputs', key);
|
|
75
|
-
if (inputs && inputs.parentElement) {
|
|
76
|
-
inputDeleteActions.push({
|
|
77
|
-
old: { parent: inputs.parentElement, element: inputs },
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return inputDeleteActions;
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=ied.js.map
|