@jupyterlab/apputils 4.5.0-beta.0 → 4.5.0-beta.1

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,777 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ import { ServerConnection } from '@jupyterlab/services';
5
+ import { TranslationBundle } from '@jupyterlab/translation';
6
+ import {
7
+ jsonIcon,
8
+ LabIcon,
9
+ markdownIcon,
10
+ spreadsheetIcon,
11
+ VDomModel,
12
+ VDomRenderer
13
+ } from '@jupyterlab/ui-components';
14
+ import { PromiseDelegate, ReadonlyJSONObject } from '@lumino/coreutils';
15
+ import { ISignal, Signal } from '@lumino/signaling';
16
+ import { h, VirtualElement } from '@lumino/virtualdom';
17
+ import { Panel, SplitPanel, TabBar, Widget } from '@lumino/widgets';
18
+ import * as React from 'react';
19
+ import { ILicensesClient } from './tokens';
20
+
21
+ const FILTER_SECTION_TITLE_CLASS = 'jp-Licenses-Filters-title';
22
+
23
+ /**
24
+ * A license viewer
25
+ */
26
+ export class Licenses extends SplitPanel {
27
+ readonly model: Licenses.Model;
28
+
29
+ constructor(options: Licenses.IOptions) {
30
+ super();
31
+ this.addClass('jp-Licenses');
32
+ this.model = options.model;
33
+ this.initLeftPanel();
34
+ this.initFilters();
35
+ this.initBundles();
36
+ this.initGrid();
37
+ this.initLicenseText();
38
+ this.setRelativeSizes([1, 2, 3]);
39
+ void this.model.initLicenses().then(() => this._updateBundles());
40
+ this.model.trackerDataChanged.connect(() => {
41
+ this.title.label = this.model.title;
42
+ });
43
+ }
44
+
45
+ /**
46
+ * Handle disposing of the widget
47
+ */
48
+ dispose(): void {
49
+ if (this.isDisposed) {
50
+ return;
51
+ }
52
+ this._bundles.currentChanged.disconnect(this.onBundleSelected, this);
53
+ this.model.dispose();
54
+ super.dispose();
55
+ }
56
+
57
+ /**
58
+ * Initialize the left area for filters and bundles
59
+ */
60
+ protected initLeftPanel(): void {
61
+ this._leftPanel = new Panel();
62
+ this._leftPanel.addClass('jp-Licenses-FormArea');
63
+ this.addWidget(this._leftPanel);
64
+ SplitPanel.setStretch(this._leftPanel, 1);
65
+ }
66
+
67
+ /**
68
+ * Initialize the filters
69
+ */
70
+ protected initFilters(): void {
71
+ this._filters = new Licenses.Filters(this.model);
72
+ SplitPanel.setStretch(this._filters, 1);
73
+ this._leftPanel.addWidget(this._filters);
74
+ }
75
+
76
+ /**
77
+ * Initialize the listing of available bundles
78
+ */
79
+ protected initBundles(): void {
80
+ this._bundles = new TabBar({
81
+ orientation: 'vertical',
82
+ renderer: new Licenses.BundleTabRenderer(this.model)
83
+ });
84
+ this._bundles.addClass('jp-Licenses-Bundles');
85
+ SplitPanel.setStretch(this._bundles, 1);
86
+ this._leftPanel.addWidget(this._bundles);
87
+ this._bundles.currentChanged.connect(this.onBundleSelected, this);
88
+ this.model.stateChanged.connect(() => this._bundles.update());
89
+ }
90
+
91
+ /**
92
+ * Initialize the listing of packages within the current bundle
93
+ */
94
+ protected initGrid(): void {
95
+ this._grid = new Licenses.Grid(this.model);
96
+ SplitPanel.setStretch(this._grid, 1);
97
+ this.addWidget(this._grid);
98
+ }
99
+
100
+ /**
101
+ * Initialize the full text of the current package
102
+ */
103
+ protected initLicenseText(): void {
104
+ this._licenseText = new Licenses.FullText(this.model);
105
+ SplitPanel.setStretch(this._grid, 1);
106
+ this.addWidget(this._licenseText);
107
+ }
108
+
109
+ /**
110
+ * Event handler for updating the model with the current bundle
111
+ */
112
+ protected onBundleSelected(): void {
113
+ if (this._bundles.currentTitle?.label) {
114
+ this.model.currentBundleName = this._bundles.currentTitle.label;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Update the bundle tabs.
120
+ */
121
+ protected _updateBundles(): void {
122
+ this._bundles.clearTabs();
123
+ let i = 0;
124
+ const { currentBundleName } = this.model;
125
+ let currentIndex = 0;
126
+ for (const bundle of this.model.bundleNames) {
127
+ const tab = new Widget();
128
+ tab.title.label = bundle;
129
+ if (bundle === currentBundleName) {
130
+ currentIndex = i;
131
+ }
132
+ this._bundles.insertTab(++i, tab.title);
133
+ }
134
+ this._bundles.currentIndex = currentIndex;
135
+ }
136
+
137
+ /**
138
+ * An area for selecting licenses by bundle and filters
139
+ */
140
+ protected _leftPanel: Panel;
141
+
142
+ /**
143
+ * Filters on visible licenses
144
+ */
145
+ protected _filters: Licenses.Filters;
146
+
147
+ /**
148
+ * Tabs reflecting available bundles
149
+ */
150
+ protected _bundles: TabBar<Widget>;
151
+
152
+ /**
153
+ * A grid of the current bundle's packages' license metadata
154
+ */
155
+ protected _grid: Licenses.Grid;
156
+
157
+ /**
158
+ * The currently-selected package's full license text
159
+ */
160
+ protected _licenseText: Licenses.FullText;
161
+ }
162
+
163
+ /** A namespace for license components */
164
+ export namespace Licenses {
165
+ /** The information about a license report format */
166
+ export interface IReportFormat {
167
+ title: string;
168
+ icon: LabIcon;
169
+ id: string;
170
+ }
171
+
172
+ /**
173
+ * License report formats understood by the server (once lower-cased)
174
+ */
175
+ export const REPORT_FORMATS: Record<string, IReportFormat> = {
176
+ markdown: {
177
+ id: 'markdown',
178
+ title: 'Markdown',
179
+ icon: markdownIcon
180
+ },
181
+ csv: {
182
+ id: 'csv',
183
+ title: 'CSV',
184
+ icon: spreadsheetIcon
185
+ },
186
+ json: {
187
+ id: 'json',
188
+ title: 'JSON',
189
+ icon: jsonIcon
190
+ }
191
+ };
192
+
193
+ /**
194
+ * The default format (most human-readable)
195
+ */
196
+ export const DEFAULT_FORMAT = 'markdown';
197
+
198
+ /**
199
+ * Options for instantiating a license viewer
200
+ */
201
+ export interface IOptions {
202
+ model: Model;
203
+ }
204
+ /**
205
+ * Options for instantiating a license model
206
+ */
207
+ export interface IModelOptions extends ICreateArgs {
208
+ client: ILicensesClient;
209
+ trans: TranslationBundle;
210
+ }
211
+
212
+ /**
213
+ * A top-level report of the licenses for all code included in a bundle
214
+ *
215
+ * ### Note
216
+ *
217
+ * This is roughly informed by the terms defined in the SPDX spec, though is not
218
+ * an SPDX Document, since there seem to be several (incompatible) specs
219
+ * in that repo.
220
+ *
221
+ * @see https://github.com/spdx/spdx-spec/blob/development/v2.2.1/schemas/spdx-schema.json
222
+ **/
223
+ export interface ILicenseBundle extends ReadonlyJSONObject {
224
+ packages: IPackageLicenseInfo[];
225
+ }
226
+
227
+ /**
228
+ * A best-effort single bundled package's information.
229
+ *
230
+ * ### Note
231
+ *
232
+ * This is roughly informed by SPDX `packages` and `hasExtractedLicenseInfos`,
233
+ * as making it conformant would vastly complicate the structure.
234
+ *
235
+ * @see https://github.com/spdx/spdx-spec/blob/development/v2.2.1/schemas/spdx-schema.json
236
+ **/
237
+ export interface IPackageLicenseInfo extends ReadonlyJSONObject {
238
+ /**
239
+ * the name of the package as it appears in package.json
240
+ */
241
+ name: string;
242
+ /**
243
+ * the version of the package, or an empty string if unknown
244
+ */
245
+ versionInfo: string;
246
+ /**
247
+ * an SPDX license identifier or LicenseRef, or an empty string if unknown
248
+ */
249
+ licenseId: string;
250
+ /**
251
+ * the verbatim extracted text of the license, or an empty string if unknown
252
+ */
253
+ extractedText: string;
254
+ }
255
+
256
+ /**
257
+ * The format information for a download
258
+ */
259
+ export interface IDownloadOptions {
260
+ format: string;
261
+ }
262
+
263
+ /**
264
+ * The fields which can be filtered
265
+ */
266
+ export type TFilterKey = 'name' | 'versionInfo' | 'licenseId';
267
+
268
+ export interface ICreateArgs {
269
+ currentBundleName?: string | null;
270
+ packageFilter?: Partial<IPackageLicenseInfo> | null;
271
+ currentPackageIndex?: number | null;
272
+ }
273
+
274
+ /**
275
+ * The options for a new license client.
276
+ */
277
+ export interface ILicenseClientOptions {
278
+ /**
279
+ * The URL for the licenses API
280
+ */
281
+ licensesUrl?: string;
282
+
283
+ /**
284
+ * The server settings
285
+ */
286
+ serverSettings?: ServerConnection.ISettings;
287
+ }
288
+
289
+ /**
290
+ * The JSON response from the API
291
+ */
292
+ export interface ILicenseResponse {
293
+ bundles: {
294
+ [key: string]: Licenses.ILicenseBundle;
295
+ };
296
+ }
297
+
298
+ /**
299
+ * A class used for fetching licenses from the server.
300
+ */
301
+ export class LicensesClient implements ILicensesClient {
302
+ /**
303
+ * Create a new license client.
304
+ */
305
+ constructor(options: ILicenseClientOptions = {}) {
306
+ this._licensesUrl = options.licensesUrl || '';
307
+ this._serverSettings =
308
+ options.serverSettings ?? ServerConnection.makeSettings();
309
+ }
310
+
311
+ /**
312
+ * Get the link to download the licenses in a given format.
313
+ */
314
+ async getDownloadLink(options: IDownloadOptions): Promise<string> {
315
+ return `${this._licensesUrl}?format=${options.format}&download=1`;
316
+ }
317
+
318
+ /**
319
+ * Fetch the license bundles from the server.
320
+ */
321
+ async getBundles(): Promise<ILicenseResponse> {
322
+ const response = await ServerConnection.makeRequest(
323
+ this._licensesUrl,
324
+ {},
325
+ this._serverSettings
326
+ );
327
+ return response.json();
328
+ }
329
+
330
+ private _serverSettings: ServerConnection.ISettings;
331
+ private _licensesUrl: string;
332
+ }
333
+
334
+ /**
335
+ * A model for license data
336
+ */
337
+ export class Model extends VDomModel implements ICreateArgs {
338
+ constructor(options: IModelOptions) {
339
+ super();
340
+ this._trans = options.trans;
341
+ this._client = options.client;
342
+ if (options.currentBundleName) {
343
+ this._currentBundleName = options.currentBundleName;
344
+ }
345
+ if (options.packageFilter) {
346
+ this._packageFilter = options.packageFilter;
347
+ }
348
+ if (options.currentPackageIndex) {
349
+ this._currentPackageIndex = options.currentPackageIndex;
350
+ }
351
+ }
352
+
353
+ /**
354
+ * Handle the initial request for the licenses from the server.
355
+ */
356
+ async initLicenses(): Promise<void> {
357
+ try {
358
+ this._serverResponse = await this._client.getBundles();
359
+ this._licensesReady.resolve();
360
+ this.stateChanged.emit(void 0);
361
+ } catch (err) {
362
+ this._licensesReady.reject(err);
363
+ }
364
+ }
365
+
366
+ /**
367
+ * Create a temporary download link, and emulate clicking it to trigger a named
368
+ * file download.
369
+ */
370
+ async download(options: IDownloadOptions): Promise<void> {
371
+ const url = await this._client.getDownloadLink(options);
372
+ const element = document.createElement('a');
373
+ element.href = url;
374
+ element.download = '';
375
+ document.body.appendChild(element);
376
+ element.click();
377
+ document.body.removeChild(element);
378
+ URL.revokeObjectURL(url);
379
+ return void 0;
380
+ }
381
+
382
+ /**
383
+ * A promise that resolves when the licenses from the server change
384
+ */
385
+ get selectedPackageChanged(): ISignal<Model, void> {
386
+ return this._selectedPackageChanged;
387
+ }
388
+
389
+ /**
390
+ * A promise that resolves when the trackable data changes
391
+ */
392
+ get trackerDataChanged(): ISignal<Model, void> {
393
+ return this._trackerDataChanged;
394
+ }
395
+
396
+ /**
397
+ * The names of the license bundles available
398
+ */
399
+ get bundleNames(): string[] {
400
+ return Object.keys(this._serverResponse?.bundles || {});
401
+ }
402
+
403
+ /**
404
+ * The current license bundle
405
+ */
406
+ get currentBundleName(): string | null {
407
+ if (this._currentBundleName) {
408
+ return this._currentBundleName;
409
+ }
410
+ if (this.bundleNames.length) {
411
+ return this.bundleNames[0];
412
+ }
413
+ return null;
414
+ }
415
+
416
+ /**
417
+ * Set the current license bundle, and reset the selected index
418
+ */
419
+ set currentBundleName(currentBundleName: string | null) {
420
+ if (this._currentBundleName !== currentBundleName) {
421
+ this._currentBundleName = currentBundleName;
422
+ this.stateChanged.emit(void 0);
423
+ this._trackerDataChanged.emit(void 0);
424
+ }
425
+ }
426
+
427
+ /**
428
+ * A promise that resolves when the licenses are available from the server
429
+ */
430
+ get licensesReady(): Promise<void> {
431
+ return this._licensesReady.promise;
432
+ }
433
+
434
+ /**
435
+ * All the license bundles, keyed by the distributing packages
436
+ */
437
+ get bundles(): null | { [key: string]: ILicenseBundle } {
438
+ return this._serverResponse?.bundles || {};
439
+ }
440
+
441
+ /**
442
+ * The index of the currently-selected package within its license bundle
443
+ */
444
+ get currentPackageIndex(): number | null {
445
+ return this._currentPackageIndex;
446
+ }
447
+
448
+ /**
449
+ * Update the currently-selected package within its license bundle
450
+ */
451
+ set currentPackageIndex(currentPackageIndex: number | null) {
452
+ if (this._currentPackageIndex === currentPackageIndex) {
453
+ return;
454
+ }
455
+ this._currentPackageIndex = currentPackageIndex;
456
+ this._selectedPackageChanged.emit(void 0);
457
+ this.stateChanged.emit(void 0);
458
+ this._trackerDataChanged.emit(void 0);
459
+ }
460
+
461
+ /**
462
+ * The license data for the currently-selected package
463
+ */
464
+ get currentPackage(): IPackageLicenseInfo | null {
465
+ if (
466
+ this.currentBundleName &&
467
+ this.bundles &&
468
+ this._currentPackageIndex != null
469
+ ) {
470
+ return this.getFilteredPackages(
471
+ this.bundles[this.currentBundleName]?.packages || []
472
+ )[this._currentPackageIndex];
473
+ }
474
+
475
+ return null;
476
+ }
477
+
478
+ /**
479
+ * A translation bundle
480
+ */
481
+ get trans(): TranslationBundle {
482
+ return this._trans;
483
+ }
484
+
485
+ get title(): string {
486
+ return `${this._currentBundleName || ''} ${this._trans.__(
487
+ 'Licenses'
488
+ )}`.trim();
489
+ }
490
+
491
+ /**
492
+ * The current package filter
493
+ */
494
+ get packageFilter(): Partial<IPackageLicenseInfo> {
495
+ return this._packageFilter;
496
+ }
497
+
498
+ set packageFilter(packageFilter: Partial<IPackageLicenseInfo>) {
499
+ this._packageFilter = packageFilter;
500
+ this.stateChanged.emit(void 0);
501
+ this._trackerDataChanged.emit(void 0);
502
+ }
503
+
504
+ /**
505
+ * Get filtered packages from current bundle where at least one token of each
506
+ * key is present.
507
+ */
508
+ getFilteredPackages(allRows: IPackageLicenseInfo[]): IPackageLicenseInfo[] {
509
+ let rows: IPackageLicenseInfo[] = [];
510
+ let filters: [string, string[]][] = Object.entries(this._packageFilter)
511
+ .filter(([k, v]) => v && `${v}`.trim().length)
512
+ .map(([k, v]) => [k, `${v}`.toLowerCase().trim().split(' ')]);
513
+ for (const row of allRows) {
514
+ let keyHits = 0;
515
+ for (const [key, bits] of filters) {
516
+ let bitHits = 0;
517
+ let rowKeyValue = `${row[key]}`.toLowerCase();
518
+ for (const bit of bits) {
519
+ if (rowKeyValue.includes(bit)) {
520
+ bitHits += 1;
521
+ }
522
+ }
523
+ if (bitHits) {
524
+ keyHits += 1;
525
+ }
526
+ }
527
+ if (keyHits === filters.length) {
528
+ rows.push(row);
529
+ }
530
+ }
531
+ return Object.values(rows);
532
+ }
533
+
534
+ private _selectedPackageChanged: Signal<Model, void> = new Signal(this);
535
+ private _trackerDataChanged: Signal<Model, void> = new Signal(this);
536
+ private _serverResponse: ILicenseResponse | null;
537
+ private _client: ILicensesClient;
538
+ private _currentBundleName: string | null;
539
+ private _trans: TranslationBundle;
540
+ private _currentPackageIndex: number | null = 0;
541
+ private _licensesReady = new PromiseDelegate<void>();
542
+ private _packageFilter: Partial<IPackageLicenseInfo> = {};
543
+ }
544
+
545
+ /**
546
+ * A filter form for limiting the packages displayed
547
+ */
548
+ export class Filters extends VDomRenderer<Model> {
549
+ constructor(model: Model) {
550
+ super(model);
551
+ this.addClass('jp-Licenses-Filters');
552
+ this.addClass('jp-RenderedHTMLCommon');
553
+ }
554
+
555
+ protected render(): JSX.Element {
556
+ const { trans } = this.model;
557
+ return (
558
+ <div>
559
+ <label>
560
+ <strong className={FILTER_SECTION_TITLE_CLASS}>
561
+ {trans.__('Filter Licenses By')}
562
+ </strong>
563
+ </label>
564
+ <ul>
565
+ <li>
566
+ <label>{trans.__('Package')}</label>
567
+ {this.renderFilter('name')}
568
+ </li>
569
+ <li>
570
+ <label>{trans.__('Version')}</label>
571
+ {this.renderFilter('versionInfo')}
572
+ </li>
573
+ <li>
574
+ <label>{trans.__('License')}</label>
575
+ {this.renderFilter('licenseId')}
576
+ </li>
577
+ </ul>
578
+ <label>
579
+ <strong className={FILTER_SECTION_TITLE_CLASS}>
580
+ {trans.__('Distributions')}
581
+ </strong>
582
+ </label>
583
+ </div>
584
+ );
585
+ }
586
+
587
+ /**
588
+ * Render a filter input
589
+ */
590
+ protected renderFilter = (key: TFilterKey): JSX.Element => {
591
+ const value = this.model.packageFilter[key] || '';
592
+ return (
593
+ <input
594
+ type="text"
595
+ name={key}
596
+ defaultValue={value}
597
+ className="jp-mod-styled"
598
+ onInput={this.onFilterInput}
599
+ />
600
+ );
601
+ };
602
+
603
+ /**
604
+ * Handle a filter input changing
605
+ */
606
+ protected onFilterInput = (
607
+ evt: React.ChangeEvent<HTMLInputElement>
608
+ ): void => {
609
+ const input = evt.currentTarget;
610
+ const { name, value } = input;
611
+ this.model.packageFilter = { ...this.model.packageFilter, [name]: value };
612
+ };
613
+ }
614
+
615
+ /**
616
+ * A fancy bundle renderer with the package count
617
+ */
618
+ export class BundleTabRenderer extends TabBar.Renderer {
619
+ /**
620
+ * A model of the state of license viewing as well as the underlying data
621
+ */
622
+ model: Model;
623
+
624
+ readonly closeIconSelector = '.lm-TabBar-tabCloseIcon';
625
+
626
+ constructor(model: Model) {
627
+ super();
628
+ this.model = model;
629
+ }
630
+
631
+ /**
632
+ * Render a full bundle
633
+ */
634
+ renderTab(data: TabBar.IRenderData<Widget>): VirtualElement {
635
+ let title = data.title.caption;
636
+ let key = this.createTabKey(data);
637
+ let style = this.createTabStyle(data);
638
+ let className = this.createTabClass(data);
639
+ let dataset = this.createTabDataset(data);
640
+ return h.li(
641
+ { key, className, title, style, dataset },
642
+ this.renderIcon(data),
643
+ this.renderLabel(data),
644
+ this.renderCountBadge(data)
645
+ );
646
+ }
647
+
648
+ /**
649
+ * Render the package count
650
+ */
651
+ renderCountBadge(data: TabBar.IRenderData<Widget>): VirtualElement {
652
+ const bundle = data.title.label;
653
+ const { bundles } = this.model;
654
+ const packages = this.model.getFilteredPackages(
655
+ (bundles && bundle ? bundles[bundle].packages : []) || []
656
+ );
657
+ return h.label({}, `${packages.length}`);
658
+ }
659
+ }
660
+
661
+ /**
662
+ * A grid of licenses
663
+ */
664
+ export class Grid extends VDomRenderer<Licenses.Model> {
665
+ constructor(model: Licenses.Model) {
666
+ super(model);
667
+ this.addClass('jp-Licenses-Grid');
668
+ this.addClass('jp-RenderedHTMLCommon');
669
+ }
670
+
671
+ /**
672
+ * Render a grid of package license information
673
+ */
674
+ protected render(): JSX.Element {
675
+ const { bundles, currentBundleName, trans } = this.model;
676
+ const filteredPackages = this.model.getFilteredPackages(
677
+ bundles && currentBundleName
678
+ ? bundles[currentBundleName]?.packages || []
679
+ : []
680
+ );
681
+ if (!filteredPackages.length) {
682
+ return (
683
+ <blockquote>
684
+ <em>{trans.__('No Packages found')}</em>
685
+ </blockquote>
686
+ );
687
+ }
688
+ return (
689
+ <form>
690
+ <table>
691
+ <thead>
692
+ <tr>
693
+ <td></td>
694
+ <th>{trans.__('Package')}</th>
695
+ <th>{trans.__('Version')}</th>
696
+ <th>{trans.__('License')}</th>
697
+ </tr>
698
+ </thead>
699
+ <tbody>{filteredPackages.map(this.renderRow)}</tbody>
700
+ </table>
701
+ </form>
702
+ );
703
+ }
704
+
705
+ /**
706
+ * Render a single package's license information
707
+ */
708
+ protected renderRow = (
709
+ row: Licenses.IPackageLicenseInfo,
710
+ index: number
711
+ ): JSX.Element => {
712
+ const selected = index === this.model.currentPackageIndex;
713
+ const onCheck = () => (this.model.currentPackageIndex = index);
714
+ return (
715
+ <tr
716
+ key={row.name}
717
+ className={selected ? 'jp-mod-selected' : ''}
718
+ onClick={onCheck}
719
+ >
720
+ <td>
721
+ <input
722
+ type="radio"
723
+ name="show-package-license"
724
+ value={index}
725
+ onChange={onCheck}
726
+ checked={selected}
727
+ />
728
+ </td>
729
+ <th>{row.name}</th>
730
+ <td>
731
+ <code>{row.versionInfo}</code>
732
+ </td>
733
+ <td>
734
+ <code>{row.licenseId}</code>
735
+ </td>
736
+ </tr>
737
+ );
738
+ };
739
+ }
740
+
741
+ /**
742
+ * A package's full license text
743
+ */
744
+ export class FullText extends VDomRenderer<Model> {
745
+ constructor(model: Model) {
746
+ super(model);
747
+ this.addClass('jp-Licenses-Text');
748
+ this.addClass('jp-RenderedHTMLCommon');
749
+ this.addClass('jp-RenderedMarkdown');
750
+ }
751
+
752
+ /**
753
+ * Render the license text, or a null state if no package is selected
754
+ */
755
+ protected render(): JSX.Element[] {
756
+ const { currentPackage, trans } = this.model;
757
+ let head = '';
758
+ let quote = trans.__('No Package selected');
759
+ let code = '';
760
+ if (currentPackage) {
761
+ const { name, versionInfo, licenseId, extractedText } = currentPackage;
762
+ head = `${name} v${versionInfo}`;
763
+ quote = `${trans.__('License')}: ${
764
+ licenseId || trans.__('No License ID found')
765
+ }`;
766
+ code = extractedText || trans.__('No License Text found');
767
+ }
768
+ return [
769
+ <h1 key="h1">{head}</h1>,
770
+ <blockquote key="quote">
771
+ <em>{quote}</em>
772
+ </blockquote>,
773
+ <code key="code">{code}</code>
774
+ ];
775
+ }
776
+ }
777
+ }