1 | import * as React from 'react';
|
2 |
|
3 | import { VDomModel, VDomRenderer } from '@jupyterlab/apputils';
|
4 |
|
5 | import { IFontFaceOptions } from '.';
|
6 |
|
7 | import '../style/license.css';
|
8 |
|
9 | const WRAPPER_CLASS = 'jp-LicenseViewer-wrapper';
|
10 | const LICENSE_CLASS = 'jp-LicenseViewer';
|
11 |
|
12 | export class LicenseViewer extends VDomRenderer<LicenseViewer.Model> {
|
13 | constructor(options: LicenseViewer.IOptions) {
|
14 | super(new LicenseViewer.Model(options));
|
15 | }
|
16 | protected render(): React.ReactElement<any> {
|
17 | this.addClass(WRAPPER_CLASS);
|
18 | let m = this.model;
|
19 |
|
20 |
|
21 | if (!m) {
|
22 | return <></>;
|
23 | }
|
24 |
|
25 | const text = m.licenseText ? <pre>{m.licenseText}</pre> : <></>;
|
26 |
|
27 | return (
|
28 | <div className={LICENSE_CLASS}>
|
29 | <h1>{m.font.name}</h1>
|
30 | <h2>{m.font.license.name}</h2>
|
31 | {text}
|
32 | </div>
|
33 | );
|
34 | }
|
35 | }
|
36 |
|
37 | export namespace LicenseViewer {
|
38 | export interface IOptions {
|
39 | font: IFontFaceOptions;
|
40 | }
|
41 |
|
42 | export class Model extends VDomModel {
|
43 | private _font: IFontFaceOptions;
|
44 | private _licenseText: string;
|
45 | private _licenseTextPromise: Promise<string>;
|
46 |
|
47 | constructor(options: IOptions) {
|
48 | super();
|
49 | this.font = options.font;
|
50 | console.log(this._font);
|
51 | }
|
52 |
|
53 | get font() {
|
54 | return this._font;
|
55 | }
|
56 |
|
57 | set font(font) {
|
58 | this._font = font;
|
59 | this.stateChanged.emit(void 0);
|
60 | this._licenseTextPromise = new Promise(async (resolve, reject) => {
|
61 | console.log('awaiting');
|
62 | this._licenseText = await this._font.license.text();
|
63 | console.log('resolved');
|
64 | this.stateChanged.emit(void 0);
|
65 | resolve(this._licenseText);
|
66 | });
|
67 | }
|
68 |
|
69 | get licenseText() {
|
70 | return this._licenseText;
|
71 | }
|
72 |
|
73 | get licenseTextPromise() {
|
74 | return this._licenseTextPromise;
|
75 | }
|
76 | }
|
77 | }
|