|
@@ -1,22 +1,41 @@
|
|
|
// Copyright (c) Jupyter Development Team.
|
|
|
// Distributed under the terms of the Modified BSD License.
|
|
|
|
|
|
+/**
|
|
|
+ * To add an icon to the defaultIconRegistry requires two lines of code:
|
|
|
+ * 1. import the icon's .svg
|
|
|
+ * 2. add a relevant entry to _defaultIcons
|
|
|
+ */
|
|
|
+
|
|
|
+/* tslint:disable */
|
|
|
import html5Svg from '../../style/icons/html5-icon.svg';
|
|
|
import kernelSvg from '../../style/icons/kernel-icon.svg';
|
|
|
import lineFormSvg from '../../style/icons/line-form-icon.svg';
|
|
|
import notTrustedSvg from '../../style/icons/not-trusted-icon.svg';
|
|
|
+import statusBarSvg from '../../style/icons/status-bar-icon.svg';
|
|
|
import terminalSvg from '../../style/icons/terminal-icon.svg';
|
|
|
import trustedSvg from '../../style/icons/trusted-icon.svg';
|
|
|
|
|
|
+const _defaultIcons: ReadonlyArray<IconRegistry.IModel> = [
|
|
|
+ { name: 'html5', svg: html5Svg },
|
|
|
+ { name: 'kernel', svg: kernelSvg },
|
|
|
+ { name: 'line-form', svg: lineFormSvg },
|
|
|
+ { name: 'not-trusted', svg: notTrustedSvg },
|
|
|
+ { name: 'status-bar', svg: statusBarSvg },
|
|
|
+ { name: 'terminal', svg: terminalSvg },
|
|
|
+ { name: 'trusted', svg: trustedSvg }
|
|
|
+];
|
|
|
+/* tslint:enable */
|
|
|
+
|
|
|
/**
|
|
|
- * The icon registry.
|
|
|
+ * The icon registry class.
|
|
|
*/
|
|
|
export class IconRegistry {
|
|
|
constructor(...icons: IconRegistry.IModel[]) {
|
|
|
if (icons.length) {
|
|
|
this.addIcon(...icons);
|
|
|
} else {
|
|
|
- this.addIcon(...IconRegistry.defaultIcons);
|
|
|
+ this.addIcon(..._defaultIcons);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -27,12 +46,8 @@ export class IconRegistry {
|
|
|
}
|
|
|
|
|
|
icon(name: string, title?: string): HTMLElement {
|
|
|
- if (!this._svgs[name]) {
|
|
|
- console.warn(`Invalid icon name: ${name}`);
|
|
|
- }
|
|
|
-
|
|
|
if (title) {
|
|
|
- let svgNode = Private.parseSvg(this._svgs[name]);
|
|
|
+ let svgNode = Private.parseSvg(this.svg(name));
|
|
|
let titleNodes = svgNode.getElementsByTagName('title');
|
|
|
if (titleNodes) {
|
|
|
titleNodes[0].textContent = title;
|
|
@@ -43,11 +58,15 @@ export class IconRegistry {
|
|
|
}
|
|
|
return svgNode;
|
|
|
} else {
|
|
|
- return Private.parseSvg(this._svgs[name]);
|
|
|
+ return Private.parseSvg(this.svg(name));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
svg(name: string): string {
|
|
|
+ if (!(name in this._svgs)) {
|
|
|
+ console.error(`Invalid icon name: ${name}`);
|
|
|
+ }
|
|
|
+
|
|
|
return this._svgs[name];
|
|
|
}
|
|
|
|
|
@@ -64,24 +83,20 @@ export class IconRegistry {
|
|
|
private _svgs: { [key: string]: string } = Object.create(null);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * The defaultIconRegistry instance.
|
|
|
+ */
|
|
|
+export const defaultIconRegistry: IconRegistry = new IconRegistry();
|
|
|
+
|
|
|
export namespace IconRegistry {
|
|
|
export interface IModel {
|
|
|
name: string;
|
|
|
svg: string;
|
|
|
}
|
|
|
|
|
|
- export const defaultIcons: ReadonlyArray<IModel> = [
|
|
|
- { name: 'html5', svg: html5Svg },
|
|
|
- { name: 'kernel', svg: kernelSvg },
|
|
|
- { name: 'line-form', svg: lineFormSvg },
|
|
|
- { name: 'not-trusted', svg: notTrustedSvg },
|
|
|
- { name: 'terminal', svg: terminalSvg },
|
|
|
- { name: 'trusted', svg: trustedSvg }
|
|
|
- ];
|
|
|
+ export const defaultIcons = _defaultIcons;
|
|
|
}
|
|
|
|
|
|
-export const defaultIconRegistry: IconRegistry = new IconRegistry();
|
|
|
-
|
|
|
namespace Private {
|
|
|
export function parseSvg(svg: string): HTMLElement {
|
|
|
let parser = new DOMParser();
|