1 |
|
2 |
|
3 |
|
4 |
|
5 | import { ellipsesIcon } from '@jupyterlab/ui-components';
|
6 | import { Widget } from '@lumino/widgets';
|
7 | import { nullTranslator } from '@jupyterlab/translation';
|
8 |
|
9 |
|
10 |
|
11 | const PLACEHOLDER_CLASS = 'jp-Placeholder';
|
12 |
|
13 |
|
14 |
|
15 | const INPUT_PROMPT_CLASS = 'jp-Placeholder-prompt jp-InputPrompt';
|
16 |
|
17 |
|
18 |
|
19 | const OUTPUT_PROMPT_CLASS = 'jp-Placeholder-prompt jp-OutputPrompt';
|
20 |
|
21 |
|
22 |
|
23 | const CONTENT_CLASS = 'jp-Placeholder-content';
|
24 |
|
25 |
|
26 |
|
27 | const INPUT_PLACEHOLDER_CLASS = 'jp-InputPlaceholder';
|
28 |
|
29 |
|
30 |
|
31 | const OUTPUT_PLACEHOLDER_CLASS = 'jp-OutputPlaceholder';
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | export class Placeholder extends Widget {
|
40 | |
41 |
|
42 |
|
43 | constructor(options) {
|
44 | var _a, _b, _c;
|
45 | const node = document.createElement('div');
|
46 | super({ node });
|
47 | const trans = ((_a = options.translator) !== null && _a !== void 0 ? _a : nullTranslator).load('jupyterlab');
|
48 | const innerNode = document.createElement('div');
|
49 | innerNode.className = (_b = options.promptClass) !== null && _b !== void 0 ? _b : '';
|
50 | node.insertAdjacentHTML('afterbegin', innerNode.outerHTML);
|
51 | this._cell = document.createElement('div');
|
52 | this._cell.classList.add(CONTENT_CLASS);
|
53 | this._cell.title = trans.__('Click to expand');
|
54 | const container = this._cell.appendChild(document.createElement('div'));
|
55 | container.classList.add('jp-Placeholder-contentContainer');
|
56 | this._textContent = container.appendChild(document.createElement('span'));
|
57 | this._textContent.className = 'jp-PlaceholderText';
|
58 | this._textContent.innerText = (_c = options.text) !== null && _c !== void 0 ? _c : '';
|
59 | node.appendChild(this._cell);
|
60 | ellipsesIcon.element({
|
61 | container: container.appendChild(document.createElement('span')),
|
62 | className: 'jp-MoreHorizIcon',
|
63 | elementPosition: 'center',
|
64 | height: 'auto',
|
65 | width: '32px'
|
66 | });
|
67 | this.addClass(PLACEHOLDER_CLASS);
|
68 | this._callback = options.callback;
|
69 | }
|
70 | |
71 |
|
72 |
|
73 | set text(t) {
|
74 | this._textContent.innerText = t;
|
75 | }
|
76 | get text() {
|
77 | return this._textContent.innerText;
|
78 | }
|
79 | onAfterAttach(msg) {
|
80 | super.onAfterAttach(msg);
|
81 | this.node.addEventListener('click', this._callback);
|
82 | }
|
83 | onBeforeDetach(msg) {
|
84 | this.node.removeEventListener('click', this._callback);
|
85 | super.onBeforeDetach(msg);
|
86 | }
|
87 | }
|
88 |
|
89 |
|
90 |
|
91 | export class InputPlaceholder extends Placeholder {
|
92 | |
93 |
|
94 |
|
95 | constructor(options) {
|
96 | super({ ...options, promptClass: INPUT_PROMPT_CLASS });
|
97 | this.addClass(INPUT_PLACEHOLDER_CLASS);
|
98 | }
|
99 | }
|
100 |
|
101 |
|
102 |
|
103 | export class OutputPlaceholder extends Placeholder {
|
104 | |
105 |
|
106 |
|
107 | constructor(options) {
|
108 | super({ ...options, promptClass: OUTPUT_PROMPT_CLASS });
|
109 | this.addClass(OUTPUT_PLACEHOLDER_CLASS);
|
110 | }
|
111 | }
|
112 |
|
\ | No newline at end of file |