Debian Codegraph @

jupyter-widgets-controls/lib/widget_description.js

raw
1 // Copyright (c) Jupyter Development Team.
2 // Distributed under the terms of the Modified BSD License.
3 import { DOMWidgetModel, DOMWidgetView, StyleModel, } from '@jupyter-widgets/base';
4 import { typeset } from './utils';
5 import { JUPYTER_CONTROLS_VERSION } from './version';
6 export class DescriptionStyleModel extends StyleModel {
7 defaults() {
8 return Object.assign(Object.assign({}, super.defaults()), { _model_name: 'DescriptionStyleModel', _model_module: '@jupyter-widgets/controls', _model_module_version: JUPYTER_CONTROLS_VERSION });
9 }
10 }
11 DescriptionStyleModel.styleProperties = {
12 description_width: {
13 selector: '.widget-label',
14 attribute: 'width',
15 default: null,
16 },
17 };
18 export class DescriptionModel extends DOMWidgetModel {
19 defaults() {
20 return Object.assign(Object.assign({}, super.defaults()), { _model_name: 'DescriptionModel', _view_name: 'DescriptionView', _view_module: '@jupyter-widgets/controls', _model_module: '@jupyter-widgets/controls', _view_module_version: JUPYTER_CONTROLS_VERSION, _model_module_version: JUPYTER_CONTROLS_VERSION, description: '', description_allow_html: false });
21 }
22 }
23 export class DescriptionView extends DOMWidgetView {
24 render() {
25 this.label = document.createElement('label');
26 this.el.appendChild(this.label);
27 this.label.className = 'widget-label';
28 this.label.style.display = 'none';
29 this.listenTo(this.model, 'change:description', this.updateDescription);
30 this.listenTo(this.model, 'change:description_allow_html', this.updateDescription);
31 this.listenTo(this.model, 'change:tabbable', this.updateTabindex);
32 this.updateDescription();
33 this.updateTabindex();
34 this.updateTooltip();
35 }
36 typeset(element, text) {
37 this.displayed.then(() => {
38 var _a, _b, _c;
39 if ((_b = (_a = window.MathJax) === null || _a === void 0 ? void 0 : _a.Hub) === null || _b === void 0 ? void 0 : _b.Queue) {
40 return typeset(element, text);
41 }
42 const widget_manager = this.model.widget_manager;
43 const latexTypesetter = (_c = widget_manager._rendermime) === null || _c === void 0 ? void 0 : _c.latexTypesetter;
44 if (latexTypesetter) {
45 if (text !== void 0) {
46 element.textContent = text;
47 }
48 latexTypesetter.typeset(element);
49 }
50 });
51 }
52 updateDescription() {
53 const description = this.model.get('description');
54 if (description.length === 0) {
55 this.label.style.display = 'none';
56 }
57 else {
58 if (this.model.get('description_allow_html')) {
59 this.label.innerHTML =
60 this.model.widget_manager.inline_sanitize(description);
61 }
62 else {
63 this.label.textContent = description;
64 }
65 this.typeset(this.label);
66 this.label.style.display = '';
67 }
68 }
69 updateTooltip() {
70 if (!this.label)
71 return;
72 this.label.title = this.model.get('tooltip');
73 }
74 }
75 /**
76 * For backwards compatibility with jupyter-js-widgets 2.x.
77 *
78 * Use DescriptionModel instead.
79 */
80 export class LabeledDOMWidgetModel extends DescriptionModel {
81 }
82 /**
83 * For backwards compatibility with jupyter-js-widgets 2.x.
84 *
85 * Use DescriptionView instead.
86 */
87 export class LabeledDOMWidgetView extends DescriptionView {
88 }
89 //# sourceMappingURL=widget_description.js.map