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

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,776 @@
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
+ * Download the licenses in the requested format.
313
+ */
314
+ async download(options: IDownloadOptions): Promise<void> {
315
+ const url = `${this._licensesUrl}?format=${options.format}&download=1`;
316
+ const element = document.createElement('a');
317
+ element.href = url;
318
+ element.download = '';
319
+ document.body.appendChild(element);
320
+ element.click();
321
+ document.body.removeChild(element);
322
+ URL.revokeObjectURL(url);
323
+ return void 0;
324
+ }
325
+
326
+ /**
327
+ * Fetch the license bundles from the server.
328
+ */
329
+ async getBundles(): Promise<ILicenseResponse> {
330
+ const response = await ServerConnection.makeRequest(
331
+ this._licensesUrl,
332
+ {},
333
+ this._serverSettings
334
+ );
335
+ return response.json();
336
+ }
337
+
338
+ private _serverSettings: ServerConnection.ISettings;
339
+ private _licensesUrl: string;
340
+ }
341
+
342
+ /**
343
+ * A model for license data
344
+ */
345
+ export class Model extends VDomModel implements ICreateArgs {
346
+ constructor(options: IModelOptions) {
347
+ super();
348
+ this._trans = options.trans;
349
+ this._client = options.client;
350
+ if (options.currentBundleName) {
351
+ this._currentBundleName = options.currentBundleName;
352
+ }
353
+ if (options.packageFilter) {
354
+ this._packageFilter = options.packageFilter;
355
+ }
356
+ if (options.currentPackageIndex) {
357
+ this._currentPackageIndex = options.currentPackageIndex;
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Handle the initial request for the licenses from the server.
363
+ */
364
+ async initLicenses(): Promise<void> {
365
+ try {
366
+ this._serverResponse = await this._client.getBundles();
367
+ this._licensesReady.resolve();
368
+ this.stateChanged.emit(void 0);
369
+ } catch (err) {
370
+ this._licensesReady.reject(err);
371
+ }
372
+ }
373
+
374
+ /**
375
+ * Download the licenses in the requested format.
376
+ */
377
+ async download(options: IDownloadOptions): Promise<void> {
378
+ return this._client.download(options);
379
+ }
380
+
381
+ /**
382
+ * A promise that resolves when the licenses from the server change
383
+ */
384
+ get selectedPackageChanged(): ISignal<Model, void> {
385
+ return this._selectedPackageChanged;
386
+ }
387
+
388
+ /**
389
+ * A promise that resolves when the trackable data changes
390
+ */
391
+ get trackerDataChanged(): ISignal<Model, void> {
392
+ return this._trackerDataChanged;
393
+ }
394
+
395
+ /**
396
+ * The names of the license bundles available
397
+ */
398
+ get bundleNames(): string[] {
399
+ return Object.keys(this._serverResponse?.bundles || {});
400
+ }
401
+
402
+ /**
403
+ * The current license bundle
404
+ */
405
+ get currentBundleName(): string | null {
406
+ if (this._currentBundleName) {
407
+ return this._currentBundleName;
408
+ }
409
+ if (this.bundleNames.length) {
410
+ return this.bundleNames[0];
411
+ }
412
+ return null;
413
+ }
414
+
415
+ /**
416
+ * Set the current license bundle, and reset the selected index
417
+ */
418
+ set currentBundleName(currentBundleName: string | null) {
419
+ if (this._currentBundleName !== currentBundleName) {
420
+ this._currentBundleName = currentBundleName;
421
+ this.stateChanged.emit(void 0);
422
+ this._trackerDataChanged.emit(void 0);
423
+ }
424
+ }
425
+
426
+ /**
427
+ * A promise that resolves when the licenses are available from the server
428
+ */
429
+ get licensesReady(): Promise<void> {
430
+ return this._licensesReady.promise;
431
+ }
432
+
433
+ /**
434
+ * All the license bundles, keyed by the distributing packages
435
+ */
436
+ get bundles(): null | { [key: string]: ILicenseBundle } {
437
+ return this._serverResponse?.bundles || {};
438
+ }
439
+
440
+ /**
441
+ * The index of the currently-selected package within its license bundle
442
+ */
443
+ get currentPackageIndex(): number | null {
444
+ return this._currentPackageIndex;
445
+ }
446
+
447
+ /**
448
+ * Update the currently-selected package within its license bundle
449
+ */
450
+ set currentPackageIndex(currentPackageIndex: number | null) {
451
+ if (this._currentPackageIndex === currentPackageIndex) {
452
+ return;
453
+ }
454
+ this._currentPackageIndex = currentPackageIndex;
455
+ this._selectedPackageChanged.emit(void 0);
456
+ this.stateChanged.emit(void 0);
457
+ this._trackerDataChanged.emit(void 0);
458
+ }
459
+
460
+ /**
461
+ * The license data for the currently-selected package
462
+ */
463
+ get currentPackage(): IPackageLicenseInfo | null {
464
+ if (
465
+ this.currentBundleName &&
466
+ this.bundles &&
467
+ this._currentPackageIndex != null
468
+ ) {
469
+ return this.getFilteredPackages(
470
+ this.bundles[this.currentBundleName]?.packages || []
471
+ )[this._currentPackageIndex];
472
+ }
473
+
474
+ return null;
475
+ }
476
+
477
+ /**
478
+ * A translation bundle
479
+ */
480
+ get trans(): TranslationBundle {
481
+ return this._trans;
482
+ }
483
+
484
+ get title(): string {
485
+ return `${this._currentBundleName || ''} ${this._trans.__(
486
+ 'Licenses'
487
+ )}`.trim();
488
+ }
489
+
490
+ /**
491
+ * The current package filter
492
+ */
493
+ get packageFilter(): Partial<IPackageLicenseInfo> {
494
+ return this._packageFilter;
495
+ }
496
+
497
+ set packageFilter(packageFilter: Partial<IPackageLicenseInfo>) {
498
+ this._packageFilter = packageFilter;
499
+ this.stateChanged.emit(void 0);
500
+ this._trackerDataChanged.emit(void 0);
501
+ }
502
+
503
+ /**
504
+ * Get filtered packages from current bundle where at least one token of each
505
+ * key is present.
506
+ */
507
+ getFilteredPackages(allRows: IPackageLicenseInfo[]): IPackageLicenseInfo[] {
508
+ let rows: IPackageLicenseInfo[] = [];
509
+ let filters: [string, string[]][] = Object.entries(this._packageFilter)
510
+ .filter(([k, v]) => v && `${v}`.trim().length)
511
+ .map(([k, v]) => [k, `${v}`.toLowerCase().trim().split(' ')]);
512
+ for (const row of allRows) {
513
+ let keyHits = 0;
514
+ for (const [key, bits] of filters) {
515
+ let bitHits = 0;
516
+ let rowKeyValue = `${row[key]}`.toLowerCase();
517
+ for (const bit of bits) {
518
+ if (rowKeyValue.includes(bit)) {
519
+ bitHits += 1;
520
+ }
521
+ }
522
+ if (bitHits) {
523
+ keyHits += 1;
524
+ }
525
+ }
526
+ if (keyHits === filters.length) {
527
+ rows.push(row);
528
+ }
529
+ }
530
+ return Object.values(rows);
531
+ }
532
+
533
+ private _selectedPackageChanged: Signal<Model, void> = new Signal(this);
534
+ private _trackerDataChanged: Signal<Model, void> = new Signal(this);
535
+ private _serverResponse: ILicenseResponse | null;
536
+ private _client: ILicensesClient;
537
+ private _currentBundleName: string | null;
538
+ private _trans: TranslationBundle;
539
+ private _currentPackageIndex: number | null = 0;
540
+ private _licensesReady = new PromiseDelegate<void>();
541
+ private _packageFilter: Partial<IPackageLicenseInfo> = {};
542
+ }
543
+
544
+ /**
545
+ * A filter form for limiting the packages displayed
546
+ */
547
+ export class Filters extends VDomRenderer<Model> {
548
+ constructor(model: Model) {
549
+ super(model);
550
+ this.addClass('jp-Licenses-Filters');
551
+ this.addClass('jp-RenderedHTMLCommon');
552
+ }
553
+
554
+ protected render(): JSX.Element {
555
+ const { trans } = this.model;
556
+ return (
557
+ <div>
558
+ <label>
559
+ <strong className={FILTER_SECTION_TITLE_CLASS}>
560
+ {trans.__('Filter Licenses By')}
561
+ </strong>
562
+ </label>
563
+ <ul>
564
+ <li>
565
+ <label>{trans.__('Package')}</label>
566
+ {this.renderFilter('name')}
567
+ </li>
568
+ <li>
569
+ <label>{trans.__('Version')}</label>
570
+ {this.renderFilter('versionInfo')}
571
+ </li>
572
+ <li>
573
+ <label>{trans.__('License')}</label>
574
+ {this.renderFilter('licenseId')}
575
+ </li>
576
+ </ul>
577
+ <label>
578
+ <strong className={FILTER_SECTION_TITLE_CLASS}>
579
+ {trans.__('Distributions')}
580
+ </strong>
581
+ </label>
582
+ </div>
583
+ );
584
+ }
585
+
586
+ /**
587
+ * Render a filter input
588
+ */
589
+ protected renderFilter = (key: TFilterKey): JSX.Element => {
590
+ const value = this.model.packageFilter[key] || '';
591
+ return (
592
+ <input
593
+ type="text"
594
+ name={key}
595
+ defaultValue={value}
596
+ className="jp-mod-styled"
597
+ onInput={this.onFilterInput}
598
+ />
599
+ );
600
+ };
601
+
602
+ /**
603
+ * Handle a filter input changing
604
+ */
605
+ protected onFilterInput = (
606
+ evt: React.ChangeEvent<HTMLInputElement>
607
+ ): void => {
608
+ const input = evt.currentTarget;
609
+ const { name, value } = input;
610
+ this.model.packageFilter = { ...this.model.packageFilter, [name]: value };
611
+ };
612
+ }
613
+
614
+ /**
615
+ * A fancy bundle renderer with the package count
616
+ */
617
+ export class BundleTabRenderer extends TabBar.Renderer {
618
+ /**
619
+ * A model of the state of license viewing as well as the underlying data
620
+ */
621
+ model: Model;
622
+
623
+ readonly closeIconSelector = '.lm-TabBar-tabCloseIcon';
624
+
625
+ constructor(model: Model) {
626
+ super();
627
+ this.model = model;
628
+ }
629
+
630
+ /**
631
+ * Render a full bundle
632
+ */
633
+ renderTab(data: TabBar.IRenderData<Widget>): VirtualElement {
634
+ let title = data.title.caption;
635
+ let key = this.createTabKey(data);
636
+ let style = this.createTabStyle(data);
637
+ let className = this.createTabClass(data);
638
+ let dataset = this.createTabDataset(data);
639
+ return h.li(
640
+ { key, className, title, style, dataset },
641
+ this.renderIcon(data),
642
+ this.renderLabel(data),
643
+ this.renderCountBadge(data)
644
+ );
645
+ }
646
+
647
+ /**
648
+ * Render the package count
649
+ */
650
+ renderCountBadge(data: TabBar.IRenderData<Widget>): VirtualElement {
651
+ const bundle = data.title.label;
652
+ const { bundles } = this.model;
653
+ const packages = this.model.getFilteredPackages(
654
+ (bundles && bundle ? bundles[bundle].packages : []) || []
655
+ );
656
+ return h.label({}, `${packages.length}`);
657
+ }
658
+ }
659
+
660
+ /**
661
+ * A grid of licenses
662
+ */
663
+ export class Grid extends VDomRenderer<Licenses.Model> {
664
+ constructor(model: Licenses.Model) {
665
+ super(model);
666
+ this.addClass('jp-Licenses-Grid');
667
+ this.addClass('jp-RenderedHTMLCommon');
668
+ }
669
+
670
+ /**
671
+ * Render a grid of package license information
672
+ */
673
+ protected render(): JSX.Element {
674
+ const { bundles, currentBundleName, trans } = this.model;
675
+ const filteredPackages = this.model.getFilteredPackages(
676
+ bundles && currentBundleName
677
+ ? bundles[currentBundleName]?.packages || []
678
+ : []
679
+ );
680
+ if (!filteredPackages.length) {
681
+ return (
682
+ <blockquote>
683
+ <em>{trans.__('No Packages found')}</em>
684
+ </blockquote>
685
+ );
686
+ }
687
+ return (
688
+ <form>
689
+ <table>
690
+ <thead>
691
+ <tr>
692
+ <td></td>
693
+ <th>{trans.__('Package')}</th>
694
+ <th>{trans.__('Version')}</th>
695
+ <th>{trans.__('License')}</th>
696
+ </tr>
697
+ </thead>
698
+ <tbody>{filteredPackages.map(this.renderRow)}</tbody>
699
+ </table>
700
+ </form>
701
+ );
702
+ }
703
+
704
+ /**
705
+ * Render a single package's license information
706
+ */
707
+ protected renderRow = (
708
+ row: Licenses.IPackageLicenseInfo,
709
+ index: number
710
+ ): JSX.Element => {
711
+ const selected = index === this.model.currentPackageIndex;
712
+ const onCheck = () => (this.model.currentPackageIndex = index);
713
+ return (
714
+ <tr
715
+ key={row.name}
716
+ className={selected ? 'jp-mod-selected' : ''}
717
+ onClick={onCheck}
718
+ >
719
+ <td>
720
+ <input
721
+ type="radio"
722
+ name="show-package-license"
723
+ value={index}
724
+ onChange={onCheck}
725
+ checked={selected}
726
+ />
727
+ </td>
728
+ <th>{row.name}</th>
729
+ <td>
730
+ <code>{row.versionInfo}</code>
731
+ </td>
732
+ <td>
733
+ <code>{row.licenseId}</code>
734
+ </td>
735
+ </tr>
736
+ );
737
+ };
738
+ }
739
+
740
+ /**
741
+ * A package's full license text
742
+ */
743
+ export class FullText extends VDomRenderer<Model> {
744
+ constructor(model: Model) {
745
+ super(model);
746
+ this.addClass('jp-Licenses-Text');
747
+ this.addClass('jp-RenderedHTMLCommon');
748
+ this.addClass('jp-RenderedMarkdown');
749
+ }
750
+
751
+ /**
752
+ * Render the license text, or a null state if no package is selected
753
+ */
754
+ protected render(): JSX.Element[] {
755
+ const { currentPackage, trans } = this.model;
756
+ let head = '';
757
+ let quote = trans.__('No Package selected');
758
+ let code = '';
759
+ if (currentPackage) {
760
+ const { name, versionInfo, licenseId, extractedText } = currentPackage;
761
+ head = `${name} v${versionInfo}`;
762
+ quote = `${trans.__('License')}: ${
763
+ licenseId || trans.__('No License ID found')
764
+ }`;
765
+ code = extractedText || trans.__('No License Text found');
766
+ }
767
+ return [
768
+ <h1 key="h1">{head}</h1>,
769
+ <blockquote key="quote">
770
+ <em>{quote}</em>
771
+ </blockquote>,
772
+ <code key="code">{code}</code>
773
+ ];
774
+ }
775
+ }
776
+ }