| 1 |
import { DOMWidgetModel, DOMWidgetView, } from './widget'; |
| 2 |
import { JUPYTER_WIDGETS_VERSION } from './version'; |
| 3 |
import { BROKEN_FILE_SVG_ICON } from './utils'; |
| 4 |
// create a Widget Model that captures an error object |
| 5 |
export function createErrorWidgetModel(error, msg) { |
| 6 |
class ErrorWidget extends DOMWidgetModel { |
| 7 |
constructor(attributes, options) { |
| 8 |
attributes = Object.assign(Object.assign({}, attributes), { _view_name: 'ErrorWidgetView', _view_module: '@jupyter-widgets/base', _model_module_version: JUPYTER_WIDGETS_VERSION, _view_module_version: JUPYTER_WIDGETS_VERSION, msg: msg, error: error }); |
| 9 |
super(attributes, options); |
| 10 |
this.comm_live = true; |
| 11 |
} |
| 12 |
} |
| 13 |
return ErrorWidget; |
| 14 |
} |
| 15 |
export class ErrorWidgetView extends DOMWidgetView { |
| 16 |
generateErrorMessage() { |
| 17 |
return { |
| 18 |
msg: this.model.get('msg'), |
| 19 |
stack: String(this.model.get('error').stack), |
| 20 |
}; |
| 21 |
} |
| 22 |
render() { |
| 23 |
const { msg, stack } = this.generateErrorMessage(); |
| 24 |
this.el.classList.add('jupyter-widgets'); |
| 25 |
const content = document.createElement('div'); |
| 26 |
content.classList.add('jupyter-widgets-error-widget', 'icon-error'); |
| 27 |
content.innerHTML = BROKEN_FILE_SVG_ICON; |
| 28 |
const text = document.createElement('pre'); |
| 29 |
text.style.textAlign = 'center'; |
| 30 |
text.innerText = 'Click to show javascript error.'; |
| 31 |
content.append(text); |
| 32 |
this.el.appendChild(content); |
| 33 |
let width; |
| 34 |
let height; |
| 35 |
this.el.onclick = () => { |
| 36 |
if (content.classList.contains('icon-error')) { |
| 37 |
height = height || content.clientHeight; |
| 38 |
width = width || content.clientWidth; |
| 39 |
content.classList.remove('icon-error'); |
| 40 |
content.innerHTML = ` |
| 41 |
<pre>[Open Browser Console for more detailed log - Double click to close this message]\n${msg}\n${stack}</pre> |
| 42 |
`; |
| 43 |
content.style.height = `${height}px`; |
| 44 |
content.style.width = `${width}px`; |
| 45 |
content.classList.add('text-error'); |
| 46 |
} |
| 47 |
}; |
| 48 |
this.el.ondblclick = () => { |
| 49 |
if (content.classList.contains('text-error')) { |
| 50 |
content.classList.remove('text-error'); |
| 51 |
content.innerHTML = BROKEN_FILE_SVG_ICON; |
| 52 |
content.append(text); |
| 53 |
content.classList.add('icon-error'); |
| 54 |
} |
| 55 |
}; |
| 56 |
} |
| 57 |
} |
| 58 |
export function createErrorWidgetView(error, msg) { |
| 59 |
return class InnerErrorWidgetView extends ErrorWidgetView { |
| 60 |
generateErrorMessage() { |
| 61 |
return { |
| 62 |
msg, |
| 63 |
stack: String(error instanceof Error ? error.stack : error), |
| 64 |
}; |
| 65 |
} |
| 66 |
}; |
| 67 |
} |
| 68 |
//# sourceMappingURL=errorwidget.js.map |