@compas-oscd/open-scd 0.34.2 → 0.34.4

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.
Files changed (160) hide show
  1. package/dist/src/WizardDivider.d.ts +8 -0
  2. package/dist/src/WizardDivider.js +37 -0
  3. package/dist/src/WizardDivider.js.map +1 -0
  4. package/dist/src/Wizarding.d.ts +10 -0
  5. package/dist/src/Wizarding.js +38 -0
  6. package/dist/src/Wizarding.js.map +1 -0
  7. package/dist/src/action-icon.d.ts +25 -0
  8. package/dist/src/action-icon.js +220 -0
  9. package/dist/src/action-icon.js.map +1 -0
  10. package/dist/src/action-pane.d.ts +25 -0
  11. package/dist/src/action-pane.js +176 -0
  12. package/dist/src/action-pane.js.map +1 -0
  13. package/dist/src/addons/Editor.d.ts +25 -0
  14. package/dist/src/addons/Editor.js +106 -0
  15. package/dist/src/addons/Editor.js.map +1 -0
  16. package/dist/src/addons/History.d.ts +93 -0
  17. package/dist/src/addons/History.js +491 -0
  18. package/dist/src/addons/History.js.map +1 -0
  19. package/dist/src/addons/Layout.d.ts +96 -0
  20. package/dist/src/addons/Layout.js +619 -0
  21. package/dist/src/addons/Layout.js.map +1 -0
  22. package/dist/src/addons/Settings.d.ts +68 -0
  23. package/dist/src/addons/Settings.js +465 -0
  24. package/dist/src/addons/Settings.js.map +1 -0
  25. package/dist/src/addons/Waiter.d.ts +14 -0
  26. package/dist/src/addons/Waiter.js +45 -0
  27. package/dist/src/addons/Waiter.js.map +1 -0
  28. package/dist/src/addons/Wizards.d.ts +15 -0
  29. package/dist/src/addons/Wizards.js +48 -0
  30. package/dist/src/addons/Wizards.js.map +1 -0
  31. package/dist/src/addons/editor/edit-action-to-v1-converter.d.ts +3 -0
  32. package/dist/src/addons/editor/edit-action-to-v1-converter.js +96 -0
  33. package/dist/src/addons/editor/edit-action-to-v1-converter.js.map +1 -0
  34. package/dist/src/addons/editor/edit-v1-to-v2-converter.d.ts +2 -0
  35. package/dist/src/addons/editor/edit-v1-to-v2-converter.js +37 -0
  36. package/dist/src/addons/editor/edit-v1-to-v2-converter.js.map +1 -0
  37. package/dist/src/addons/history/get-log-text.d.ts +5 -0
  38. package/dist/src/addons/history/get-log-text.js +26 -0
  39. package/dist/src/addons/history/get-log-text.js.map +1 -0
  40. package/dist/src/addons/menu-tabs/menu-tabs.d.ts +22 -0
  41. package/dist/src/addons/menu-tabs/menu-tabs.js +74 -0
  42. package/dist/src/addons/menu-tabs/menu-tabs.js.map +1 -0
  43. package/dist/src/addons/plugin-manager/custom-plugin-dialog.d.ts +28 -0
  44. package/dist/src/addons/plugin-manager/custom-plugin-dialog.js +177 -0
  45. package/dist/src/addons/plugin-manager/custom-plugin-dialog.js.map +1 -0
  46. package/dist/src/addons/plugin-manager/plugin-manager.d.ts +20 -0
  47. package/dist/src/addons/plugin-manager/plugin-manager.js +165 -0
  48. package/dist/src/addons/plugin-manager/plugin-manager.js.map +1 -0
  49. package/dist/src/filtered-list.d.ts +27 -0
  50. package/dist/src/filtered-list.js +168 -0
  51. package/dist/src/filtered-list.js.map +1 -0
  52. package/dist/src/finder-list.d.ts +37 -0
  53. package/dist/src/finder-list.js +207 -0
  54. package/dist/src/finder-list.js.map +1 -0
  55. package/dist/src/foundation/compare.d.ts +79 -0
  56. package/dist/src/foundation/compare.js +273 -0
  57. package/dist/src/foundation/compare.js.map +1 -0
  58. package/dist/src/foundation/dai.d.ts +30 -0
  59. package/dist/src/foundation/dai.js +127 -0
  60. package/dist/src/foundation/dai.js.map +1 -0
  61. package/dist/src/foundation/generators.d.ts +13 -0
  62. package/dist/src/foundation/generators.js +67 -0
  63. package/dist/src/foundation/generators.js.map +1 -0
  64. package/dist/src/foundation/ied.d.ts +22 -0
  65. package/dist/src/foundation/ied.js +84 -0
  66. package/dist/src/foundation/ied.js.map +1 -0
  67. package/dist/src/foundation/nsd.d.ts +4 -0
  68. package/dist/src/foundation/nsd.js +13 -0
  69. package/dist/src/foundation/nsd.js.map +1 -0
  70. package/dist/src/foundation/nsdoc.d.ts +14 -0
  71. package/dist/src/foundation/nsdoc.js +180 -0
  72. package/dist/src/foundation/nsdoc.js.map +1 -0
  73. package/dist/src/foundation/scl.d.ts +1 -0
  74. package/dist/src/foundation/scl.js +64 -0
  75. package/dist/src/foundation/scl.js.map +1 -0
  76. package/dist/src/foundation.d.ts +230 -0
  77. package/dist/src/foundation.js +1922 -0
  78. package/dist/src/foundation.js.map +1 -0
  79. package/dist/src/icons/compare.d.ts +3 -0
  80. package/dist/src/icons/compare.js +11 -0
  81. package/dist/src/icons/compare.js.map +1 -0
  82. package/dist/src/icons/icons.d.ts +41 -0
  83. package/dist/src/icons/icons.js +611 -0
  84. package/dist/src/icons/icons.js.map +1 -0
  85. package/dist/src/icons/ied-icons.d.ts +3 -0
  86. package/dist/src/icons/ied-icons.js +11 -0
  87. package/dist/src/icons/ied-icons.js.map +1 -0
  88. package/dist/src/icons/lnode.d.ts +16 -0
  89. package/dist/src/icons/lnode.js +50 -0
  90. package/dist/src/icons/lnode.js.map +1 -0
  91. package/dist/src/open-scd.d.ts +131 -0
  92. package/dist/src/open-scd.js +483 -0
  93. package/dist/src/open-scd.js.map +1 -0
  94. package/dist/src/oscd-filter-button.d.ts +27 -0
  95. package/dist/src/oscd-filter-button.js +89 -0
  96. package/dist/src/oscd-filter-button.js.map +1 -0
  97. package/dist/src/plain-compare-list.d.ts +36 -0
  98. package/dist/src/plain-compare-list.js +132 -0
  99. package/dist/src/plain-compare-list.js.map +1 -0
  100. package/dist/src/plugin-tag.d.ts +6 -0
  101. package/dist/src/plugin-tag.js +23 -0
  102. package/dist/src/plugin-tag.js.map +1 -0
  103. package/dist/src/plugin.d.ts +23 -0
  104. package/dist/src/plugin.events.d.ts +15 -0
  105. package/dist/src/plugin.events.js +12 -0
  106. package/dist/src/plugin.events.js.map +1 -0
  107. package/dist/src/plugin.js +2 -0
  108. package/dist/src/plugin.js.map +1 -0
  109. package/dist/src/plugins.d.ts +3 -0
  110. package/dist/src/plugins.js +256 -0
  111. package/dist/src/plugins.js.map +1 -0
  112. package/dist/src/schemas.d.ts +58 -0
  113. package/dist/src/schemas.js +9325 -0
  114. package/dist/src/schemas.js.map +1 -0
  115. package/dist/src/themes.d.ts +3 -0
  116. package/dist/src/themes.js +122 -0
  117. package/dist/src/themes.js.map +1 -0
  118. package/dist/src/translations/de.d.ts +2 -0
  119. package/dist/src/translations/de.js +954 -0
  120. package/dist/src/translations/de.js.map +1 -0
  121. package/dist/src/translations/en.d.ts +963 -0
  122. package/dist/src/translations/en.js +950 -0
  123. package/dist/src/translations/en.js.map +1 -0
  124. package/dist/src/translations/loader.d.ts +12 -0
  125. package/dist/src/translations/loader.js +10 -0
  126. package/dist/src/translations/loader.js.map +1 -0
  127. package/dist/src/wizard-checkbox.d.ts +37 -0
  128. package/dist/src/wizard-checkbox.js +152 -0
  129. package/dist/src/wizard-checkbox.js.map +1 -0
  130. package/dist/src/wizard-dialog.d.ts +45 -0
  131. package/dist/src/wizard-dialog.js +374 -0
  132. package/dist/src/wizard-dialog.js.map +1 -0
  133. package/dist/src/wizard-select.d.ts +31 -0
  134. package/dist/src/wizard-select.js +115 -0
  135. package/dist/src/wizard-select.js.map +1 -0
  136. package/dist/src/wizard-textfield.d.ts +50 -0
  137. package/dist/src/wizard-textfield.js +191 -0
  138. package/dist/src/wizard-textfield.js.map +1 -0
  139. package/dist/src/wizards.d.ts +23 -0
  140. package/dist/src/wizards.js +196 -0
  141. package/dist/src/wizards.js.map +1 -0
  142. package/dist/test/foundation.d.ts +34 -0
  143. package/dist/test/foundation.js +55 -0
  144. package/dist/test/foundation.js.map +1 -0
  145. package/dist/test/mock-editor-logger.d.ts +16 -0
  146. package/dist/test/mock-editor-logger.js +53 -0
  147. package/dist/test/mock-editor-logger.js.map +1 -0
  148. package/dist/test/mock-edits.d.ts +7 -0
  149. package/dist/test/mock-edits.js +12 -0
  150. package/dist/test/mock-edits.js.map +1 -0
  151. package/dist/test/mock-open-scd.d.ts +22 -0
  152. package/dist/test/mock-open-scd.js +53 -0
  153. package/dist/test/mock-open-scd.js.map +1 -0
  154. package/dist/test/mock-plugins.d.ts +33 -0
  155. package/dist/test/mock-plugins.js +239 -0
  156. package/dist/test/mock-plugins.js.map +1 -0
  157. package/dist/test/mock-wizard-editor.d.ts +15 -0
  158. package/dist/test/mock-wizard-editor.js +50 -0
  159. package/dist/test/mock-wizard-editor.js.map +1 -0
  160. package/package.json +42 -22
@@ -0,0 +1,207 @@
1
+ import { __decorate } from "tslib";
2
+ import { css, customElement, html, LitElement, property, query, } from 'lit-element';
3
+ import { until } from 'lit-html/directives/until';
4
+ import { get } from 'lit-translate';
5
+ import '@material/mwc-icon';
6
+ import '@material/mwc-list';
7
+ import '@material/mwc-list/mwc-list-item';
8
+ import './filtered-list.js';
9
+ import { depth } from './foundation.js';
10
+ import { ifDefined } from 'lit-html/directives/if-defined';
11
+ const waitingList = html `<div class="column">
12
+ <mwc-list
13
+ ><mwc-list-item noninteractive hasMeta
14
+ >${get('loading')}<mwc-icon slot="meta">pending</mwc-icon></mwc-list-item
15
+ ></mwc-list
16
+ >
17
+ </div>`;
18
+ let FinderList = class FinderList extends LitElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.selection = {};
22
+ this.multi = false;
23
+ this.read = async (path) => {
24
+ return {
25
+ path,
26
+ header: html `<h2>${'/' + path.join('/')}</h2>`,
27
+ entries: [],
28
+ };
29
+ };
30
+ this.loaded = Promise.resolve();
31
+ }
32
+ get depth() {
33
+ return depth(this.selection);
34
+ }
35
+ get paths() {
36
+ return this.getPaths();
37
+ }
38
+ set paths(paths) {
39
+ const selection = {};
40
+ for (const path of paths) {
41
+ let i = selection;
42
+ for (const name of path) {
43
+ if (!Object.prototype.hasOwnProperty.call(i, name))
44
+ i[name] = {};
45
+ i = i[name];
46
+ }
47
+ }
48
+ this.selection = selection;
49
+ }
50
+ get path() {
51
+ return this.paths[0] ?? [];
52
+ }
53
+ set path(path) {
54
+ this.paths = [path];
55
+ }
56
+ getTitle(path) {
57
+ return path.join('/');
58
+ }
59
+ getDisplayString(entry, path) {
60
+ return entry;
61
+ }
62
+ getPaths(depth) {
63
+ let paths = Object.keys(this.selection).map(key => [key]);
64
+ let i = depth ?? this.depth - 1;
65
+ while (i-- > 0) {
66
+ paths = paths.flatMap(path => {
67
+ let dir = this.selection;
68
+ for (const entry of path)
69
+ dir = dir[entry]; // recursive descent
70
+ const newPaths = Object.keys(dir).map(entry => path.concat(entry));
71
+ return newPaths.length === 0 ? [path] : newPaths;
72
+ });
73
+ }
74
+ return depth === undefined
75
+ ? paths
76
+ : paths.filter(path => path.length > depth);
77
+ }
78
+ multiSelect(event, path, clicked) {
79
+ let dir = this.selection;
80
+ for (const entry of path)
81
+ dir = dir[entry]; // recursive descent
82
+ if (dir && dir[clicked])
83
+ delete dir[clicked];
84
+ // deselect if selected
85
+ else
86
+ dir[clicked] = {}; // select otherwise
87
+ }
88
+ singleSelect(event, path, clicked) {
89
+ if (this.path[path.length] === clicked)
90
+ this.path = path;
91
+ // deselect if selected
92
+ else
93
+ this.path = path.concat(clicked); // select otherwise
94
+ }
95
+ async select(event, path) {
96
+ const clicked = event.target.selected.value;
97
+ if (this.multi)
98
+ this.multiSelect(event, path, clicked);
99
+ else
100
+ this.singleSelect(event, path, clicked);
101
+ this.requestUpdate();
102
+ await this.updateComplete;
103
+ await new Promise(resolve => setTimeout(resolve, 250));
104
+ this.container.scrollLeft = 1000 * this.depth;
105
+ }
106
+ renderDirectory(path, entries) {
107
+ return html `<filtered-list
108
+ @selected=${(e) => this.select(e, path)}
109
+ searchFieldLabel="${this.getTitle(path)}"
110
+ >
111
+ ${entries.map(entry => html `<mwc-list-item
112
+ value="${entry}"
113
+ ?activated=${this.getPaths(path.length)
114
+ .map(p => JSON.stringify(p))
115
+ .includes(JSON.stringify(path.concat(entry)))}
116
+ >${this.getDisplayString(entry, path)}</mwc-list-item
117
+ >`)}
118
+ </filtered-list>`;
119
+ }
120
+ async renderColumn(column) {
121
+ const paths = this.getPaths(column);
122
+ const dirs = paths.map(path => this.read(path));
123
+ const lists = [];
124
+ for await (const { header, entries, path } of dirs) {
125
+ if (header || entries.length > 0)
126
+ lists.push(html `${ifDefined(header)} ${this.renderDirectory(path, entries)}`);
127
+ }
128
+ if (lists.length === 0)
129
+ return html ``;
130
+ return html `<div class="column">${lists}</div>`;
131
+ }
132
+ render() {
133
+ const columns = new Array(this.depth)
134
+ .fill(0)
135
+ .map((_, index) => this.renderColumn(index));
136
+ this.loaded = Promise.allSettled(columns).then();
137
+ return html `<div class="pane">
138
+ ${columns.map(column => until(column, waitingList))}
139
+ </div>`;
140
+ }
141
+ };
142
+ FinderList.styles = css `
143
+ div.pane {
144
+ display: flex;
145
+ flex-direction: row;
146
+ overflow: auto;
147
+ }
148
+
149
+ h2 {
150
+ color: var(--mdc-theme-primary);
151
+ }
152
+
153
+ section {
154
+ display: flex;
155
+ flex-direction: column;
156
+ width: max-content;
157
+ }
158
+
159
+ section > mwc-list {
160
+ margin-top: 76px;
161
+ }
162
+
163
+ a {
164
+ font-weight: 600;
165
+ font-variant: small-caps;
166
+ text-transform: lowercase;
167
+ text-decoration: none;
168
+ color: var(--mdc-theme-primary);
169
+ }
170
+
171
+ a:link {
172
+ color: var(--mdc-theme-error);
173
+ }
174
+
175
+ a:visited {
176
+ color: var(--mdc-theme-secondary);
177
+ }
178
+ `;
179
+ __decorate([
180
+ property({ type: Object })
181
+ ], FinderList.prototype, "selection", void 0);
182
+ __decorate([
183
+ property({ type: Boolean })
184
+ ], FinderList.prototype, "multi", void 0);
185
+ __decorate([
186
+ property({ type: Number })
187
+ ], FinderList.prototype, "depth", null);
188
+ __decorate([
189
+ property({ type: Array })
190
+ ], FinderList.prototype, "paths", null);
191
+ __decorate([
192
+ property({ type: Array })
193
+ ], FinderList.prototype, "path", null);
194
+ __decorate([
195
+ property({ attribute: false })
196
+ ], FinderList.prototype, "read", void 0);
197
+ __decorate([
198
+ property({ attribute: false })
199
+ ], FinderList.prototype, "loaded", void 0);
200
+ __decorate([
201
+ query('div')
202
+ ], FinderList.prototype, "container", void 0);
203
+ FinderList = __decorate([
204
+ customElement('finder-list')
205
+ ], FinderList);
206
+ export { FinderList };
207
+ //# sourceMappingURL=finder-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finder-list.js","sourceRoot":"","sources":["../../src/finder-list.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,GAAG,EACH,aAAa,EACb,IAAI,EACJ,UAAU,EACV,QAAQ,EACR,KAAK,GAEN,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,oBAAoB,CAAC;AAC5B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,kCAAkC,CAAC;AAK1C,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAW3D,MAAM,WAAW,GAAG,IAAI,CAAA;;;SAGf,GAAG,CAAC,SAAS,CAAC;;;OAGhB,CAAC;AAGD,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,UAAU;IAAnC;;QAEL,cAAS,GAAc,EAAE,CAAC;QAG1B,UAAK,GAAG,KAAK,CAAC;QAgCd,SAAI,GAAuC,KAAK,EAAC,IAAI,EAAC,EAAE;YACtD,OAAO;gBACL,IAAI;gBACJ,MAAM,EAAE,IAAI,CAAA,OAAO,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO;gBAC9C,OAAO,EAAE,EAAE;aACZ,CAAC;QACJ,CAAC,CAAC;QAGF,WAAM,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IA4I5C,CAAC;IAlLC,IAAI,KAAK;QACP,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;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M,EAAE,CAAC;6CACD;AAG1B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;yCACd;AAGd;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uCAG1B;AAGD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;uCAGzB;AAcD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;sCAGzB;AAMD;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;wCAO7B;AAGF;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;0CACW;AAW1C;IADC,KAAK,CAAC,KAAK,CAAC;6CACO;AAzDT,UAAU;IADtB,aAAa,CAAC,aAAa,CAAC;GAChB,UAAU,CA0LtB;SA1LY,UAAU","sourcesContent":["import {\n css,\n customElement,\n html,\n LitElement,\n property,\n query,\n TemplateResult,\n} from 'lit-element';\nimport { until } from 'lit-html/directives/until';\nimport { get } from 'lit-translate';\n\nimport '@material/mwc-icon';\nimport '@material/mwc-list';\nimport '@material/mwc-list/mwc-list-item';\nimport { List } from '@material/mwc-list';\nimport { SingleSelectedEvent } from '@material/mwc-list/mwc-list-foundation';\nimport { ListItem } from '@material/mwc-list/mwc-list-item';\n\nimport './filtered-list.js';\nimport { depth } from './foundation.js';\nimport { ifDefined } from 'lit-html/directives/if-defined';\n\nexport type Selection = { [name: string]: Selection };\n\nexport type Path = string[];\nexport interface Directory {\n path: Path;\n header?: TemplateResult;\n entries: string[];\n}\n\nconst waitingList = html`<div class=\"column\">\n <mwc-list\n ><mwc-list-item noninteractive hasMeta\n >${get('loading')}<mwc-icon slot=\"meta\">pending</mwc-icon></mwc-list-item\n ></mwc-list\n >\n</div>`;\n\n@customElement('finder-list')\nexport class FinderList extends LitElement {\n @property({ type: Object })\n selection: Selection = {};\n\n @property({ type: Boolean })\n multi = false;\n\n @property({ type: Number })\n get depth(): number {\n return depth(this.selection);\n }\n\n @property({ type: Array })\n get paths(): Path[] {\n return this.getPaths();\n }\n set paths(paths: Path[]) {\n const selection: Selection = {};\n for (const path of paths) {\n let i = selection;\n for (const name of path) {\n if (!Object.prototype.hasOwnProperty.call(i, name)) i[name] = {};\n i = i[name];\n }\n }\n this.selection = selection;\n }\n\n @property({ type: Array })\n get path(): Path {\n return this.paths[0] ?? [];\n }\n set path(path: Path) {\n this.paths = [path];\n }\n\n @property({ attribute: false })\n read: (path: Path) => Promise<Directory> = async path => {\n return {\n path,\n header: html`<h2>${'/' + path.join('/')}</h2>`,\n entries: [],\n };\n };\n\n @property({ attribute: false })\n loaded: Promise<void> = Promise.resolve();\n\n getTitle(path: string[]): string {\n return path.join('/');\n }\n\n getDisplayString(entry: string, path: string[]): string {\n return entry;\n }\n\n @query('div')\n container!: Element;\n\n private getPaths(depth?: number): Path[] {\n let paths: Path[] = Object.keys(this.selection).map(key => [key]);\n\n let i = depth ?? this.depth - 1;\n while (i-- > 0) {\n paths = paths.flatMap(path => {\n let dir = this.selection;\n for (const entry of path) dir = dir[entry]; // recursive descent\n const newPaths = Object.keys(dir).map(entry => path.concat(entry));\n return newPaths.length === 0 ? [path] : newPaths;\n });\n }\n\n return depth === undefined\n ? paths\n : paths.filter(path => path.length > depth);\n }\n\n multiSelect(event: SingleSelectedEvent, path: Path, clicked: string): void {\n let dir = this.selection;\n for (const entry of path) dir = dir[entry]; // recursive descent\n\n if (dir && dir[clicked]) delete dir[clicked];\n // deselect if selected\n else dir[clicked] = {}; // select otherwise\n }\n\n singleSelect(event: SingleSelectedEvent, path: Path, clicked: string): void {\n if (this.path[path.length] === clicked) this.path = path;\n // deselect if selected\n else this.path = path.concat(clicked); // select otherwise\n }\n\n async select(event: SingleSelectedEvent, path: Path): Promise<void> {\n const clicked = (<ListItem>(<List>event.target).selected).value;\n\n if (this.multi) this.multiSelect(event, path, clicked);\n else this.singleSelect(event, path, clicked);\n\n this.requestUpdate();\n await this.updateComplete;\n await new Promise(resolve => setTimeout(resolve, 250));\n this.container.scrollLeft = 1000 * this.depth;\n }\n\n renderDirectory(path: Path, entries: string[]): TemplateResult {\n return html`<filtered-list\n @selected=${(e: SingleSelectedEvent) => this.select(e, path)}\n searchFieldLabel=\"${this.getTitle(path)}\"\n >\n ${entries.map(\n entry =>\n html`<mwc-list-item\n value=\"${entry}\"\n ?activated=${this.getPaths(path.length)\n .map(p => JSON.stringify(p))\n .includes(JSON.stringify(path.concat(entry)))}\n >${this.getDisplayString(entry, path)}</mwc-list-item\n >`\n )}\n </filtered-list>`;\n }\n\n async renderColumn(column: number): Promise<TemplateResult> {\n const paths = this.getPaths(column);\n\n const dirs = paths.map(path => this.read(path));\n const lists: TemplateResult[] = [];\n\n for await (const { header, entries, path } of dirs) {\n if (header || entries.length > 0)\n lists.push(\n html`${ifDefined(header)} ${this.renderDirectory(path, entries)}`\n );\n }\n\n if (lists.length === 0) return html``;\n return html`<div class=\"column\">${lists}</div>`;\n }\n\n render(): TemplateResult {\n const columns = new Array(this.depth)\n .fill(0)\n .map((_, index) => this.renderColumn(index));\n this.loaded = Promise.allSettled(columns).then();\n return html`<div class=\"pane\">\n ${columns.map(column => until(column, waitingList))}\n </div>`;\n }\n\n static styles = css`\n div.pane {\n display: flex;\n flex-direction: row;\n overflow: auto;\n }\n\n h2 {\n color: var(--mdc-theme-primary);\n }\n\n section {\n display: flex;\n flex-direction: column;\n width: max-content;\n }\n\n section > mwc-list {\n margin-top: 76px;\n }\n\n a {\n font-weight: 600;\n font-variant: small-caps;\n text-transform: lowercase;\n text-decoration: none;\n color: var(--mdc-theme-primary);\n }\n\n a:link {\n color: var(--mdc-theme-error);\n }\n\n a:visited {\n color: var(--mdc-theme-secondary);\n }\n `;\n}\n"]}
@@ -0,0 +1,79 @@
1
+ import { TemplateResult } from 'lit-element';
2
+ import '@material/mwc-list';
3
+ import '@material/mwc-list/mwc-list-item';
4
+ import '@material/mwc-icon';
5
+ export type DiffType = 'Element' | 'Attribute' | 'Content';
6
+ export type Diff<T> = {
7
+ type: DiffType;
8
+ oldValue: T;
9
+ newValue: null;
10
+ } | {
11
+ type: DiffType;
12
+ oldValue: null;
13
+ newValue: T;
14
+ } | {
15
+ type: DiffType;
16
+ oldValue: T;
17
+ newValue: T;
18
+ };
19
+ /**
20
+ * Type to filter out a difference based on `tagName`.`attributeName`
21
+ *
22
+ * The matcher can be a boolean or a `consumer` that returns a boolean
23
+ */
24
+ export interface DiffFilter<T> {
25
+ [selector: string]: DiffFilterSelector<T>;
26
+ }
27
+ interface DiffFilterSelector<T> {
28
+ full?: DiffFilterConsumer<T>;
29
+ attributes?: {
30
+ [name: string]: DiffFilterConsumer<T>;
31
+ };
32
+ }
33
+ /**
34
+ * Consumer to match if a diff should be filtered out.
35
+ */
36
+ type DiffFilterConsumer<T> = boolean | ((value: T | null) => boolean);
37
+ /**
38
+ * Check if there are any attribute values changed between the two elements.
39
+ *
40
+ * @param elementToBeCompared - The element to check for differences.
41
+ * @param elementToCompareAgainst - The element used to check against.
42
+ */
43
+ export declare function diffSclAttributes(elementToBeCompared: Element, elementToCompareAgainst: Element, filterToIgnore: DiffFilter<Element>, searchElementToBeCompared: Element): [string, Diff<string>][];
44
+ /**
45
+ * Function to retrieve the identity to compare 2 children on the same level.
46
+ * This means we only need to last part of the Identity string to compare the children.
47
+ *
48
+ * @param element - The element to retrieve the identity from.
49
+ */
50
+ export declare function identityForCompare(element: Element): string | number;
51
+ /**
52
+ * Custom method for comparing to check if 2 elements are the same. Because they are on the same level
53
+ * we don't need to compare the full identity, we just compare the part of the Element itself.
54
+ *
55
+ * <b>Remark</b>Private elements are already filtered out, so we don't need to bother them.
56
+ *
57
+ * @param newValue - The new element to compare with the old element.
58
+ * @param oldValue - The old element to which the new element is compared.
59
+ */
60
+ export declare function isSame(newValue: Element, oldValue: Element): boolean;
61
+ /**
62
+ * List of all differences between children elements that both old and new element have.
63
+ * The list contains children both elements have and children that were added or removed
64
+ * from the new element.
65
+ * <b>Remark</b>: Private elements are ignored.
66
+ *
67
+ * @param elementToBeCompared - The element to check for differences.
68
+ * @param elementToCompareAgainst - The element used to check against.
69
+ */
70
+ export declare function diffSclChilds(elementToBeCompared: Element, elementToCompareAgainst: Element, filterToIgnore: DiffFilter<Element>, searchElementToBeCompared: Element, searchElementToCompareAgainst: Element): Diff<Element>[];
71
+ /**
72
+ * Generate HTML (TemplateResult) containing all the differences between the two elements passed.
73
+ * If null is returned there are no differences between the two elements.
74
+ *
75
+ * @param elementToBeCompared - The element to check for differences.
76
+ * @param elementToCompareAgainst - The element used to check against.
77
+ */
78
+ export declare function renderDiff(elementToBeCompared: Element, elementToCompareAgainst: Element, filterToIgnore?: DiffFilter<Element>): TemplateResult | null;
79
+ export {};
@@ -0,0 +1,273 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../src/foundation/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAkB,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,oBAAoB,CAAC;AAC5B,OAAO,kCAAkC,CAAC;AAC1C,OAAO,oBAAoB,CAAC;AAE5B,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE9E,MAAM,cAAc,GAAqC,IAAI,GAAG,EAG7D,CAAC;AAEJ,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;AAC/C,cAAc,CAAC,GAAG,CAAC,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OAAO;;8BAEzB,QAAQ,CAAC,IAAI,CAAC,QAAS,CAAC;;;8BAGxB,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;;yBAElC;gBACH,CAAC,CAAC,EAAE;mCACS,CACpB;;;;;gBAKC,MAAM,CACN,SAAS,EACT,CAAC,CAAC,EAAE,CAAC,CAAC,EACN,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CACf,IAAI,CAAA;sBACA,IAAI,CAAC,QAAQ,KAAK,IAAI;gBACtB,CAAC,CAAC,IAAI,CAAA;;8BAEE,IAAI;8BACJ,IAAI,CAAC,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ;;mDAEtB,OAAO;;8BAE5B,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;;yBAElC;gBACH,CAAC,CAAC,EAAE;mCACS,CACpB;gBACC,MAAM,CACN,mBAAmB,EACnB,CAAC,CAAC,EAAE,CAAC,CAAC,EACN,IAAI,CAAC,EAAE,CACL,IAAI,CAAA;sBACA,IAAI,CAAC,QAAQ;gBACb,CAAC,CAAC,IAAI,CAAA;kCACM,IAAI,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"]}