@energinet/watt 4.3.16 → 4.3.18
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.
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { input, computed, ViewEncapsulation, ChangeDetectionStrategy, Component, linkedSignal } from '@angular/core';
|
|
3
|
+
import { WattIconComponent } from '@energinet/watt/icon';
|
|
4
|
+
|
|
5
|
+
//#region License
|
|
6
|
+
/**
|
|
7
|
+
* @license
|
|
8
|
+
* Copyright 2020 Energinet DataHub A/S
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License2");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
//#endregion
|
|
23
|
+
/**
|
|
24
|
+
* Matches JSON tokens for syntax highlighting:
|
|
25
|
+
* - `"(?:[^"\\]|\\.)*":?` - Strings and keys (supports escaped quotes)
|
|
26
|
+
* - `-?\d+\.?\d*` - Numbers (including negative and decimals)
|
|
27
|
+
* - `\b(true|false|null)\b` - Keywords
|
|
28
|
+
*/
|
|
29
|
+
const JSON_TOKEN_REGEX = /"(?:[^"\\]|\\.)*":?|-?\d+\.?\d*|\b(true|false|null)\b/g;
|
|
30
|
+
class WattJsonColorize {
|
|
31
|
+
json = input.required(...(ngDevMode ? [{ debugName: "json" }] : []));
|
|
32
|
+
colorized = computed(() => {
|
|
33
|
+
try {
|
|
34
|
+
const json = JSON.stringify(this.json(), null, ' ');
|
|
35
|
+
return json === undefined
|
|
36
|
+
? `<span class='watt-json-invalid'>${this.json()?.toString() || typeof this.json()}</span>`
|
|
37
|
+
: json.replace(JSON_TOKEN_REGEX, (match) => {
|
|
38
|
+
switch (true) {
|
|
39
|
+
case match.endsWith(':'):
|
|
40
|
+
return `<span class='watt-json-key'>${match.slice(1, -2)}</span>:`;
|
|
41
|
+
case match.startsWith('"'):
|
|
42
|
+
return `<span class='watt-json-string'>${match}</span>`;
|
|
43
|
+
case /\d/.test(match):
|
|
44
|
+
return `<span class='watt-json-number'>${match}</span>`;
|
|
45
|
+
default:
|
|
46
|
+
return `<span class='watt-json-keyword'>${match}</span>`;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return `<span class='watt-json-invalid'>[Circular]</span>`;
|
|
52
|
+
}
|
|
53
|
+
}, ...(ngDevMode ? [{ debugName: "colorized" }] : []));
|
|
54
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: WattJsonColorize, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
55
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "20.3.15", type: WattJsonColorize, isStandalone: true, selector: "watt-json-colorize", inputs: { json: { classPropertyName: "json", publicName: "json", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: `<span [innerHTML]="colorized()"></span>`, isInline: true, styles: [".watt-json-invalid{color:var(--watt-on-light-low-emphasis)}.watt-json-key{color:var(--watt-color-primary)}.watt-json-string{color:var(--watt-color-state-success)}.watt-json-number{color:var(--watt-color-state-warning)}.watt-json-keyword{color:var(--watt-color-state-danger)}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
56
|
+
}
|
|
57
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: WattJsonColorize, decorators: [{
|
|
58
|
+
type: Component,
|
|
59
|
+
args: [{ selector: 'watt-json-colorize', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, template: `<span [innerHTML]="colorized()"></span>`, styles: [".watt-json-invalid{color:var(--watt-on-light-low-emphasis)}.watt-json-key{color:var(--watt-color-primary)}.watt-json-string{color:var(--watt-color-state-success)}.watt-json-number{color:var(--watt-color-state-warning)}.watt-json-keyword{color:var(--watt-color-state-danger)}\n"] }]
|
|
60
|
+
}], propDecorators: { json: [{ type: i0.Input, args: [{ isSignal: true, alias: "json", required: true }] }] } });
|
|
61
|
+
|
|
62
|
+
//#region License
|
|
63
|
+
/**
|
|
64
|
+
* @license
|
|
65
|
+
* Copyright 2020 Energinet DataHub A/S
|
|
66
|
+
*
|
|
67
|
+
* Licensed under the Apache License, Version 2.0 (the "License2");
|
|
68
|
+
* you may not use this file except in compliance with the License.
|
|
69
|
+
* You may obtain a copy of the License at
|
|
70
|
+
*
|
|
71
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
72
|
+
*
|
|
73
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
74
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
75
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
76
|
+
* See the License for the specific language governing permissions and
|
|
77
|
+
* limitations under the License.
|
|
78
|
+
*/
|
|
79
|
+
//#endregion
|
|
80
|
+
class WattJson {
|
|
81
|
+
label = input(...(ngDevMode ? [undefined, { debugName: "label" }] : []));
|
|
82
|
+
json = input.required(...(ngDevMode ? [{ debugName: "json" }] : []));
|
|
83
|
+
tree = input.required(...(ngDevMode ? [{ debugName: "tree" }] : []));
|
|
84
|
+
level = input(0, ...(ngDevMode ? [{ debugName: "level" }] : []));
|
|
85
|
+
isRoot = computed(() => this.level() === 0, ...(ngDevMode ? [{ debugName: "isRoot" }] : []));
|
|
86
|
+
children = computed(() => {
|
|
87
|
+
const json = this.json();
|
|
88
|
+
return typeof json === 'object' && json && Object.keys(json).length
|
|
89
|
+
? Object.entries(json)
|
|
90
|
+
: null;
|
|
91
|
+
}, ...(ngDevMode ? [{ debugName: "children" }] : []));
|
|
92
|
+
// The linkedSignal makes it possible to recursively toggle all nodes
|
|
93
|
+
expandable = computed(() => Boolean(this.children()), ...(ngDevMode ? [{ debugName: "expandable" }] : []));
|
|
94
|
+
expanded = linkedSignal(...(ngDevMode ? [{ debugName: "expanded", source: this.tree,
|
|
95
|
+
computation: (t) => this.level() < t.maxDepth && t.expanded ? this.expandable() : this.isRoot() }] : [{
|
|
96
|
+
source: this.tree,
|
|
97
|
+
computation: (t) => this.level() < t.maxDepth && t.expanded ? this.expandable() : this.isRoot(),
|
|
98
|
+
}]));
|
|
99
|
+
toggleExpanded = () =>
|
|
100
|
+
// Prevent toggle when text is being selected
|
|
101
|
+
this.expanded.update((e) => (getSelection()?.isCollapsed && this.expandable() ? !e : e));
|
|
102
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: WattJson, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
103
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.15", type: WattJson, isStandalone: true, selector: "watt-json", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, json: { classPropertyName: "json", publicName: "json", isSignal: true, isRequired: true, transformFunction: null }, tree: { classPropertyName: "tree", publicName: "tree", isSignal: true, isRequired: true, transformFunction: null }, level: { classPropertyName: "level", publicName: "level", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "style.--watt-json-level": "level()" } }, ngImport: i0, template: `
|
|
104
|
+
@if (!isRoot()) {
|
|
105
|
+
<div class="watt-json-label" (click)="toggleExpanded()">
|
|
106
|
+
@if (expandable()) {
|
|
107
|
+
<watt-icon size="s" [name]="expanded() ? 'down' : 'right'" />
|
|
108
|
+
}
|
|
109
|
+
<span>{{ label() }}: </span>
|
|
110
|
+
<watt-json-colorize [hidden]="expanded()" [json]="json()" />
|
|
111
|
+
</div>
|
|
112
|
+
}
|
|
113
|
+
@defer (when expanded()) {
|
|
114
|
+
@for (child of children(); track child[0]) {
|
|
115
|
+
<watt-json
|
|
116
|
+
[hidden]="!expanded()"
|
|
117
|
+
[label]="child[0]"
|
|
118
|
+
[json]="child[1]"
|
|
119
|
+
[tree]="tree()"
|
|
120
|
+
[level]="level() + 1"
|
|
121
|
+
/>
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
`, isInline: true, styles: ["watt-json{cursor:default}.watt-json-label{position:relative;padding-left:calc(var(--watt-json-level) * 20px);color:var(--watt-color-primary)}.watt-json-label:hover{background:var(--watt-color-neutral-grey-100)}.watt-json-label>watt-icon{position:absolute;top:2px;transform:translate(-100%)}\n"], dependencies: [{ kind: "component", type: WattIconComponent, selector: "watt-icon", inputs: ["name", "label", "size", "state"] }, { kind: "component", type: WattJsonColorize, selector: "watt-json-colorize", inputs: ["json"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None, deferBlockDependencies: [() => [WattJson]] });
|
|
125
|
+
}
|
|
126
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: WattJson, decorators: [{
|
|
127
|
+
type: Component,
|
|
128
|
+
args: [{ selector: 'watt-json', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [WattIconComponent, WattJsonColorize], host: { '[style.--watt-json-level]': 'level()' }, template: `
|
|
129
|
+
@if (!isRoot()) {
|
|
130
|
+
<div class="watt-json-label" (click)="toggleExpanded()">
|
|
131
|
+
@if (expandable()) {
|
|
132
|
+
<watt-icon size="s" [name]="expanded() ? 'down' : 'right'" />
|
|
133
|
+
}
|
|
134
|
+
<span>{{ label() }}: </span>
|
|
135
|
+
<watt-json-colorize [hidden]="expanded()" [json]="json()" />
|
|
136
|
+
</div>
|
|
137
|
+
}
|
|
138
|
+
@defer (when expanded()) {
|
|
139
|
+
@for (child of children(); track child[0]) {
|
|
140
|
+
<watt-json
|
|
141
|
+
[hidden]="!expanded()"
|
|
142
|
+
[label]="child[0]"
|
|
143
|
+
[json]="child[1]"
|
|
144
|
+
[tree]="tree()"
|
|
145
|
+
[level]="level() + 1"
|
|
146
|
+
/>
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
`, styles: ["watt-json{cursor:default}.watt-json-label{position:relative;padding-left:calc(var(--watt-json-level) * 20px);color:var(--watt-color-primary)}.watt-json-label:hover{background:var(--watt-color-neutral-grey-100)}.watt-json-label>watt-icon{position:absolute;top:2px;transform:translate(-100%)}\n"] }]
|
|
150
|
+
}], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], json: [{ type: i0.Input, args: [{ isSignal: true, alias: "json", required: true }] }], tree: [{ type: i0.Input, args: [{ isSignal: true, alias: "tree", required: true }] }], level: [{ type: i0.Input, args: [{ isSignal: true, alias: "level", required: false }] }] } });
|
|
151
|
+
|
|
152
|
+
//#region License
|
|
153
|
+
/**
|
|
154
|
+
* @license
|
|
155
|
+
* Copyright 2020 Energinet DataHub A/S
|
|
156
|
+
*
|
|
157
|
+
* Licensed under the Apache License, Version 2.0 (the "License2");
|
|
158
|
+
* you may not use this file except in compliance with the License.
|
|
159
|
+
* You may obtain a copy of the License at
|
|
160
|
+
*
|
|
161
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
162
|
+
*
|
|
163
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
164
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
165
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
166
|
+
* See the License for the specific language governing permissions and
|
|
167
|
+
* limitations under the License.
|
|
168
|
+
*/
|
|
169
|
+
//#endregion
|
|
170
|
+
class WattJsonViewer {
|
|
171
|
+
/**
|
|
172
|
+
* The JSON data to display. Accepts any value that can be serialized by JSON.stringify.
|
|
173
|
+
*/
|
|
174
|
+
json = input.required(...(ngDevMode ? [{ debugName: "json" }] : []));
|
|
175
|
+
/**
|
|
176
|
+
* Maximum depth for `expandAll()`. Beyond this depth nodes start collapsed but can be
|
|
177
|
+
* expanded manually. Useful when dealing with large objects or circular references.
|
|
178
|
+
*/
|
|
179
|
+
maxDepth = input(50, ...(ngDevMode ? [{ debugName: "maxDepth" }] : []));
|
|
180
|
+
/**
|
|
181
|
+
* Whether the tree starts expanded or collapsed.
|
|
182
|
+
*/
|
|
183
|
+
initialExpanded = input(false, ...(ngDevMode ? [{ debugName: "initialExpanded" }] : []));
|
|
184
|
+
/**
|
|
185
|
+
* Expands all nodes up to `maxDepth`.
|
|
186
|
+
*/
|
|
187
|
+
expandAll = () => this.expanded.set(true);
|
|
188
|
+
/**
|
|
189
|
+
* Collapses all nodes.
|
|
190
|
+
*/
|
|
191
|
+
collapseAll = () => this.expanded.set(false);
|
|
192
|
+
// Use equality function + computed object to always return a new reference, even
|
|
193
|
+
// when `expanded` is "updated" to its current value. This ensures that "Expand all"
|
|
194
|
+
// and "Collapse all" always works, regardless of the current state of `expanded`.
|
|
195
|
+
expanded = linkedSignal(this.initialExpanded, ...(ngDevMode ? [{ debugName: "expanded", equal: () => false }] : [{ equal: () => false }]));
|
|
196
|
+
tree = computed(() => ({
|
|
197
|
+
expanded: this.expanded(),
|
|
198
|
+
maxDepth: this.maxDepth(),
|
|
199
|
+
}), ...(ngDevMode ? [{ debugName: "tree" }] : []));
|
|
200
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: WattJsonViewer, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
201
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "20.3.15", type: WattJsonViewer, isStandalone: true, selector: "watt-json-viewer", inputs: { json: { classPropertyName: "json", publicName: "json", isSignal: true, isRequired: true, transformFunction: null }, maxDepth: { classPropertyName: "maxDepth", publicName: "maxDepth", isSignal: true, isRequired: false, transformFunction: null }, initialExpanded: { classPropertyName: "initialExpanded", publicName: "initialExpanded", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: `<watt-json [json]="json()" [tree]="tree()" />`, isInline: true, dependencies: [{ kind: "component", type: WattJson, selector: "watt-json", inputs: ["label", "json", "tree", "level"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
202
|
+
}
|
|
203
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: WattJsonViewer, decorators: [{
|
|
204
|
+
type: Component,
|
|
205
|
+
args: [{
|
|
206
|
+
// eslint-disable-next-line @angular-eslint/component-selector
|
|
207
|
+
selector: 'watt-json-viewer',
|
|
208
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
209
|
+
imports: [WattJson],
|
|
210
|
+
template: `<watt-json [json]="json()" [tree]="tree()" />`,
|
|
211
|
+
}]
|
|
212
|
+
}], propDecorators: { json: [{ type: i0.Input, args: [{ isSignal: true, alias: "json", required: true }] }], maxDepth: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxDepth", required: false }] }], initialExpanded: [{ type: i0.Input, args: [{ isSignal: true, alias: "initialExpanded", required: false }] }] } });
|
|
213
|
+
|
|
214
|
+
//#region License
|
|
215
|
+
/**
|
|
216
|
+
* @license
|
|
217
|
+
* Copyright 2020 Energinet DataHub A/S
|
|
218
|
+
*
|
|
219
|
+
* Licensed under the Apache License, Version 2.0 (the "License2");
|
|
220
|
+
* you may not use this file except in compliance with the License.
|
|
221
|
+
* You may obtain a copy of the License at
|
|
222
|
+
*
|
|
223
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
224
|
+
*
|
|
225
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
226
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
227
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
228
|
+
* See the License for the specific language governing permissions and
|
|
229
|
+
* limitations under the License.
|
|
230
|
+
*/
|
|
231
|
+
//#endregion
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Generated bundle index. Do not edit.
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
export { WattJsonViewer };
|
|
238
|
+
//# sourceMappingURL=energinet-watt-json-viewer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"energinet-watt-json-viewer.mjs","sources":["../../../libs/watt/package/json-viewer/watt-json-colorize.component.ts","../../../libs/watt/package/json-viewer/watt-json.component.ts","../../../libs/watt/package/json-viewer/watt-json-viewer.component.ts","../../../libs/watt/package/json-viewer/index.ts","../../../libs/watt/package/json-viewer/energinet-watt-json-viewer.ts"],"sourcesContent":["//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nimport {\n ChangeDetectionStrategy,\n Component,\n ViewEncapsulation,\n computed,\n input,\n} from '@angular/core';\n\n/**\n * Matches JSON tokens for syntax highlighting:\n * - `\"(?:[^\"\\\\]|\\\\.)*\":?` - Strings and keys (supports escaped quotes)\n * - `-?\\d+\\.?\\d*` - Numbers (including negative and decimals)\n * - `\\b(true|false|null)\\b` - Keywords\n */\nconst JSON_TOKEN_REGEX = /\"(?:[^\"\\\\]|\\\\.)*\":?|-?\\d+\\.?\\d*|\\b(true|false|null)\\b/g;\n\n@Component({\n selector: 'watt-json-colorize',\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n styles: `\n .watt-json-invalid {\n color: var(--watt-on-light-low-emphasis);\n }\n\n .watt-json-key {\n color: var(--watt-color-primary);\n }\n\n .watt-json-string {\n color: var(--watt-color-state-success);\n }\n\n .watt-json-number {\n color: var(--watt-color-state-warning);\n }\n\n .watt-json-keyword {\n color: var(--watt-color-state-danger);\n }\n `,\n template: `<span [innerHTML]=\"colorized()\"></span>`,\n})\nexport class WattJsonColorize {\n readonly json = input.required<unknown>();\n protected readonly colorized = computed(() => {\n try {\n const json = JSON.stringify(this.json(), null, ' ');\n return json === undefined\n ? `<span class='watt-json-invalid'>${this.json()?.toString() || typeof this.json()}</span>`\n : json.replace(JSON_TOKEN_REGEX, (match) => {\n switch (true) {\n case match.endsWith(':'):\n return `<span class='watt-json-key'>${match.slice(1, -2)}</span>:`;\n case match.startsWith('\"'):\n return `<span class='watt-json-string'>${match}</span>`;\n case /\\d/.test(match):\n return `<span class='watt-json-number'>${match}</span>`;\n default:\n return `<span class='watt-json-keyword'>${match}</span>`;\n }\n });\n } catch {\n return `<span class='watt-json-invalid'>[Circular]</span>`;\n }\n });\n}\n","//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nimport {\n ChangeDetectionStrategy,\n Component,\n ViewEncapsulation,\n computed,\n input,\n linkedSignal,\n} from '@angular/core';\nimport { WattIconComponent } from '@energinet/watt/icon';\nimport { WattJsonColorize } from './watt-json-colorize.component';\n\nexport type TreeState = {\n expanded: boolean;\n maxDepth: number;\n};\n\n@Component({\n // eslint-disable-next-line @angular-eslint/component-selector\n selector: 'watt-json',\n encapsulation: ViewEncapsulation.None,\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [WattIconComponent, WattJsonColorize],\n styles: `\n watt-json {\n cursor: default;\n }\n\n .watt-json-label {\n position: relative;\n padding-left: calc(var(--watt-json-level) * 20px);\n color: var(--watt-color-primary);\n }\n\n .watt-json-label:hover {\n background: var(--watt-color-neutral-grey-100);\n }\n\n .watt-json-label > watt-icon {\n position: absolute;\n top: 2px;\n transform: translateX(-100%);\n }\n `,\n host: { '[style.--watt-json-level]': 'level()' },\n template: `\n @if (!isRoot()) {\n <div class=\"watt-json-label\" (click)=\"toggleExpanded()\">\n @if (expandable()) {\n <watt-icon size=\"s\" [name]=\"expanded() ? 'down' : 'right'\" />\n }\n <span>{{ label() }}: </span>\n <watt-json-colorize [hidden]=\"expanded()\" [json]=\"json()\" />\n </div>\n }\n @defer (when expanded()) {\n @for (child of children(); track child[0]) {\n <watt-json\n [hidden]=\"!expanded()\"\n [label]=\"child[0]\"\n [json]=\"child[1]\"\n [tree]=\"tree()\"\n [level]=\"level() + 1\"\n />\n }\n }\n `,\n})\nexport class WattJson {\n readonly label = input<string>();\n readonly json = input.required<unknown>();\n readonly tree = input.required<TreeState>();\n readonly level = input(0);\n\n protected readonly isRoot = computed(() => this.level() === 0);\n protected readonly children = computed(() => {\n const json = this.json();\n return typeof json === 'object' && json && Object.keys(json).length\n ? Object.entries(json)\n : null;\n });\n\n // The linkedSignal makes it possible to recursively toggle all nodes\n protected readonly expandable = computed(() => Boolean(this.children()));\n protected readonly expanded = linkedSignal({\n source: this.tree,\n computation: (t) =>\n this.level() < t.maxDepth && t.expanded ? this.expandable() : this.isRoot(),\n });\n\n protected readonly toggleExpanded = () =>\n // Prevent toggle when text is being selected\n this.expanded.update((e) => (getSelection()?.isCollapsed && this.expandable() ? !e : e));\n}\n","//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nimport { ChangeDetectionStrategy, Component, computed, input, linkedSignal } from '@angular/core';\nimport { TreeState, WattJson } from './watt-json.component';\n\n@Component({\n // eslint-disable-next-line @angular-eslint/component-selector\n selector: 'watt-json-viewer',\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [WattJson],\n template: `<watt-json [json]=\"json()\" [tree]=\"tree()\" />`,\n})\nexport class WattJsonViewer {\n /**\n * The JSON data to display. Accepts any value that can be serialized by JSON.stringify.\n */\n readonly json = input.required<unknown>();\n\n /**\n * Maximum depth for `expandAll()`. Beyond this depth nodes start collapsed but can be\n * expanded manually. Useful when dealing with large objects or circular references.\n */\n readonly maxDepth = input(50);\n\n /**\n * Whether the tree starts expanded or collapsed.\n */\n readonly initialExpanded = input(false);\n\n /**\n * Expands all nodes up to `maxDepth`.\n */\n readonly expandAll = () => this.expanded.set(true);\n\n /**\n * Collapses all nodes.\n */\n readonly collapseAll = () => this.expanded.set(false);\n\n // Use equality function + computed object to always return a new reference, even\n // when `expanded` is \"updated\" to its current value. This ensures that \"Expand all\"\n // and \"Collapse all\" always works, regardless of the current state of `expanded`.\n protected readonly expanded = linkedSignal(this.initialExpanded, { equal: () => false });\n protected readonly tree = computed<TreeState>(() => ({\n expanded: this.expanded(),\n maxDepth: this.maxDepth(),\n }));\n}\n","//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nexport { WattJsonViewer } from './watt-json-viewer.component';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAAA;AACA;;;;;;;;;;;;;;;AAeG;AACH;AASA;;;;;AAKG;AACH,MAAM,gBAAgB,GAAG,wDAAwD;MA6BpE,gBAAgB,CAAA;AAClB,IAAA,IAAI,GAAG,KAAK,CAAC,QAAQ,+CAAW;AACtB,IAAA,SAAS,GAAG,QAAQ,CAAC,MAAK;AAC3C,QAAA,IAAI;AACF,YAAA,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC;YACnD,OAAO,IAAI,KAAK;AACd,kBAAE,CAAA,gCAAA,EAAmC,IAAI,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,OAAO,IAAI,CAAC,IAAI,EAAE,CAAA,OAAA;kBAChF,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,KAAK,KAAI;oBACvC,QAAQ,IAAI;AACV,wBAAA,KAAK,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;4BACtB,OAAO,CAAA,4BAAA,EAA+B,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA,QAAA,CAAU;AACpE,wBAAA,KAAK,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;4BACxB,OAAO,CAAA,+BAAA,EAAkC,KAAK,CAAA,OAAA,CAAS;AACzD,wBAAA,KAAK,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;4BACnB,OAAO,CAAA,+BAAA,EAAkC,KAAK,CAAA,OAAA,CAAS;AACzD,wBAAA;4BACE,OAAO,CAAA,gCAAA,EAAmC,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AE,kBAAkB;oBAC5B,eAAe,EAAE,uBAAuB,CAAC,MAAM;oBAC/C,OAAO,EAAE,CAAC,QAAQ,CAAC;AACnB,oBAAA,QAAQ,EAAE,CAAA,6CAAA,CAA+C;AAC1D,iBAAA;;;AC3BD;AACA;;;;;;;;;;;;;;;AAeG;AACH;;ACjBA;;AAEG;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as _angular_core from '@angular/core';
|
|
2
|
+
|
|
3
|
+
type TreeState = {
|
|
4
|
+
expanded: boolean;
|
|
5
|
+
maxDepth: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
declare class WattJsonViewer {
|
|
9
|
+
/**
|
|
10
|
+
* The JSON data to display. Accepts any value that can be serialized by JSON.stringify.
|
|
11
|
+
*/
|
|
12
|
+
readonly json: _angular_core.InputSignal<unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Maximum depth for `expandAll()`. Beyond this depth nodes start collapsed but can be
|
|
15
|
+
* expanded manually. Useful when dealing with large objects or circular references.
|
|
16
|
+
*/
|
|
17
|
+
readonly maxDepth: _angular_core.InputSignal<number>;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the tree starts expanded or collapsed.
|
|
20
|
+
*/
|
|
21
|
+
readonly initialExpanded: _angular_core.InputSignal<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Expands all nodes up to `maxDepth`.
|
|
24
|
+
*/
|
|
25
|
+
readonly expandAll: () => void;
|
|
26
|
+
/**
|
|
27
|
+
* Collapses all nodes.
|
|
28
|
+
*/
|
|
29
|
+
readonly collapseAll: () => void;
|
|
30
|
+
protected readonly expanded: _angular_core.WritableSignal<boolean>;
|
|
31
|
+
protected readonly tree: _angular_core.Signal<TreeState>;
|
|
32
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<WattJsonViewer, never>;
|
|
33
|
+
static ɵcmp: _angular_core.ɵɵComponentDeclaration<WattJsonViewer, "watt-json-viewer", never, { "json": { "alias": "json"; "required": true; "isSignal": true; }; "maxDepth": { "alias": "maxDepth"; "required": false; "isSignal": true; }; "initialExpanded": { "alias": "initialExpanded"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { WattJsonViewer };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@energinet/watt",
|
|
4
|
-
"version": "4.3.
|
|
4
|
+
"version": "4.3.18",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -95,6 +95,10 @@
|
|
|
95
95
|
"types": "./icon/index.d.ts",
|
|
96
96
|
"default": "./fesm2022/energinet-watt-icon.mjs"
|
|
97
97
|
},
|
|
98
|
+
"./json-viewer": {
|
|
99
|
+
"types": "./json-viewer/index.d.ts",
|
|
100
|
+
"default": "./fesm2022/energinet-watt-json-viewer.mjs"
|
|
101
|
+
},
|
|
98
102
|
"./menu": {
|
|
99
103
|
"types": "./menu/index.d.ts",
|
|
100
104
|
"default": "./fesm2022/energinet-watt-menu.mjs"
|