Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jupyter-display-area

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jupyter-display-area - npm Package Compare versions

Comparing version 0.0.5 to 0.1.0

143

lib/jupyter-display-area.js

@@ -9,7 +9,7 @@ "use strict";

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _transformime = require("transformime");
var _customRenderers = require("./custom-renderers");
var _transformimeJupyterTransformers = require("transformime-jupyter-transformers");

@@ -19,3 +19,3 @@ (function () {

// Shim & native-safe ownerDocument lookup
var owner = (document._currentScript || document.currentScript).ownerDocument;
var owner = document.currentScript.ownerDocument;

@@ -37,2 +37,4 @@ /**

// Register jupyter-display-area with the document
_createClass(JupyterDisplayArea, [{

@@ -45,3 +47,3 @@ key: "createdCallback",

value: function createdCallback() {
var template = owner.querySelector("#tmpl-jupyter-display-area");
var template = owner.querySelector('#tmpl-jupyter-display-area');
var node = owner.importNode(template.content, true);

@@ -53,9 +55,30 @@

this.el = this.shadow.getElementById("outputs");
this.el = this.shadow.getElementById('outputs');
this.transformime = new _transformime.Transformime();
/**
* Original display order
*
OutputArea.display_order = [
'application/javascript',
'text/html',
'text/markdown',
'text/latex',
'image/svg+xml',
'image/png',
'image/jpeg',
'application/pdf',
'text/plain'
];
*/
this.transformime.renderers.push(new _customRenderers.TracebackRenderer());
this.transformime.renderers.push(new _customRenderers.StreamRenderer());
// Transformers are in reverse priority order
// so that new ones can be `push`ed on with higher priority
var transformers = [new _transformime.TextTransformer(), new _transformimeJupyterTransformers.PDFTransformer(), new _transformime.ImageTransformer('image/jpeg'), new _transformime.ImageTransformer('image/gif'), new _transformime.ImageTransformer('image/png'),
// SVG would go here, IF I HAD ONE
new _transformimeJupyterTransformers.StreamTransformer(), new _transformimeJupyterTransformers.TracebackTransformer(), new _transformimeJupyterTransformers.MarkdownTransformer(), new _transformime.HTMLTransformer()
// JavaScript would go here, IF I HAD ONE
];
this.transformime = new _transformime.Transformime(transformers);
// 'Private'

@@ -65,4 +88,2 @@ this._outputs = [];

}
}, {
key: "fromJSON",

@@ -73,7 +94,7 @@ /**

*/
}, {
key: "fromJSON",
value: function fromJSON(outputs) {
outputs.map(this.append_output.bind(this));
return Promise.all(outputs.map(this.appendOutput.bind(this)));
}
}, {
key: "toJSON",

@@ -84,7 +105,7 @@ /**

*/
}, {
key: "toJSON",
value: function toJSON() {
return this._outputs;
}
}, {
key: "handle",

@@ -96,5 +117,11 @@ /**

* @param {object} msg - See Jupyter msgspec.
* @return {bool} Whether the message resulted in any changes to the display area
* @return {Promise} Happy promise
*/
}, {
key: "handle",
value: function handle(msg) {
if (!msg.header || !msg.header.msg_type) {
return;
}
var json = {};

@@ -104,3 +131,3 @@ var msg_type = json.output_type = msg.header.msg_type;

switch (msg_type) {
case "clear_output":
case 'clear_output':
// msg spec v4 had stdout, stderr, display keys

@@ -111,13 +138,13 @@ // v4.1 replaced these with just wait

// except for the rarely used clearing less than all output.
this.clear_output(msg.content.wait || false);
return;
case "stream":
this.clearOutput(msg.content.wait || false);
return Promise.resolve();
case 'stream':
json.text = content.text;
json.name = content.name;
break;
case "display_data":
case 'display_data':
json.data = content.data;
json.metadata = content.metadata;
break;
case "execute_result":
case 'execute_result':
json.data = content.data;

@@ -127,3 +154,3 @@ json.metadata = content.metadata;

break;
case "error":
case 'error':
json.ename = content.ename;

@@ -133,15 +160,14 @@ json.evalue = content.evalue;

break;
case "status":
case "execute_input":
case 'status':
case 'execute_input':
// Explicit ignore of status changes and input
return false;
return Promise.reject("Jupyter Display Area doesn't handle status or execute_input");
default:
console.log("unhandled output message", msg);
return false;
return Promise.reject("Unhandled output message " + JSON.stringify(msg));
}
this.append_output(json);
return true;
this._outputs.push(json);
return this.appendOutput(json);
}
}, {
key: "clear_output",

@@ -152,3 +178,5 @@ /**

*/
value: function clear_output(wait) {
}, {
key: "clearOutput",
value: function clearOutput(wait) {
if (wait) {

@@ -158,3 +186,3 @@

if (this._clear_queued) {
this.clear_output(false);
this.clearOutput(false);
}

@@ -179,4 +207,2 @@

}
}, {
key: "append_output",

@@ -186,9 +212,9 @@ /**

* @param {object} json - output json. See nbformat.
* @return {bool} whether or not output was appended
* @return {Promise}
*/
/**
* [append_output description]
* @param {[type]} json [description]
*/
value: function append_output(json) {
}, {
key: "appendOutput",
value: function appendOutput(json) {
var _this = this;
var bundle = undefined,

@@ -200,28 +226,28 @@ el = undefined;

if (this._clear_queued) {
this.clear_output(false);
this.clearOutput(false);
}
switch (json.output_type) {
case "execute_result":
case "display_data":
case 'execute_result':
case 'display_data':
bundle = json.data;
break;
case "stream":
bundle = { "jupyter/stream": json };
case 'stream':
bundle = { 'jupyter/stream': json };
break;
case "error":
bundle = { "jupyter/traceback": json };
case 'error':
bundle = { 'jupyter/traceback': json };
break;
default:
console.warn("Unrecognized output type: " + json.output_type);
bundle = { "text/plain": "Unrecognized output type" + JSON.stringify(json) };
console.warn('Unrecognized output type: ' + json.output_type);
bundle = { 'text/plain': 'Unrecognized output type' + JSON.stringify(json) };
}
el = this.transformime.transformRichest(bundle, this.document);
if (el) {
this.el.appendChild(el);
return true;
}
var elementPromise = this.transformime.transformRichest(bundle, this.document);
return false;
elementPromise.then(function (elementBundle) {
_this.el.appendChild(elementBundle.el);
});
return elementPromise;
}

@@ -233,5 +259,4 @@ }]);

// Register jupyter-display-area with the document
owner.registerElement("jupyter-display-area", JupyterDisplayArea);
owner.registerElement('jupyter-display-area', JupyterDisplayArea);
})();
//# sourceMappingURL=jupyter-display-area.js.map
{
"name": "jupyter-display-area",
"version": "0.0.5",
"version": "0.1.0",
"description": "Web component for Jupyter kernel rich output/display",

@@ -44,8 +44,10 @@ "main": "dist/jupyter-display-area.js",

"vulcanize": "^1.10.1",
"whatwg-fetch": "^0.9.0"
"whatwg-fetch": "^0.9.0",
"webcomponents.js": "^0.7.2"
},
"dependencies": {
"ansi-to-html": "^0.3.0",
"transformime": "0.0.4"
"transformime": "1.0.0",
"transformime-jupyter-transformers": "0.0.4"
}
}

@@ -1,8 +0,20 @@

import {Transformime} from "transformime";
import {TracebackRenderer, StreamRenderer} from "./custom-renderers";
import {
Transformime,
TextTransformer,
ImageTransformer,
HTMLTransformer
} from "transformime";
import {
StreamTransformer,
TracebackTransformer,
MarkdownTransformer,
LaTeXTransformer,
PDFTransformer
} from "transformime-jupyter-transformers";
(function() {
// Shim & native-safe ownerDocument lookup
var owner = (document._currentScript || document.currentScript).ownerDocument;
var owner = document.currentScript.ownerDocument;

@@ -29,7 +41,37 @@ /**

this.transformime = new Transformime();
this.transformime.renderers.push(new TracebackRenderer());
this.transformime.renderers.push(new StreamRenderer());
/**
* Original display order
*
OutputArea.display_order = [
'application/javascript',
'text/html',
'text/markdown',
'text/latex',
'image/svg+xml',
'image/png',
'image/jpeg',
'application/pdf',
'text/plain'
];
*/
// Transformers are in reverse priority order
// so that new ones can be `push`ed on with higher priority
var transformers = [
new TextTransformer(),
new PDFTransformer(),
new ImageTransformer('image/jpeg'),
new ImageTransformer('image/gif'),
new ImageTransformer('image/png'),
// SVG would go here, IF I HAD ONE
new StreamTransformer(),
new TracebackTransformer(),
new MarkdownTransformer(),
new HTMLTransformer()
// JavaScript would go here, IF I HAD ONE
];
this.transformime = new Transformime(transformers);
// 'Private'

@@ -45,3 +87,3 @@ this._outputs = [];

fromJSON(outputs) {
outputs.map(this.append_output.bind(this));
return Promise.all(outputs.map(this.appendOutput.bind(this)));
}

@@ -62,5 +104,9 @@

* @param {object} msg - See Jupyter msgspec.
* @return {bool} Whether the message resulted in any changes to the display area
* @return {Promise} Happy promise
*/
handle(msg) {
if(!msg.header || !msg.header.msg_type) {
return;
}
var json = {};

@@ -76,4 +122,4 @@ var msg_type = json.output_type = msg.header.msg_type;

// except for the rarely used clearing less than all output.
this.clear_output(msg.content.wait || false);
return;
this.clearOutput(msg.content.wait || false);
return Promise.resolve();
case 'stream':

@@ -100,9 +146,10 @@ json.text = content.text;

// Explicit ignore of status changes and input
return false;
return Promise.reject("Jupyter Display Area doesn't handle status or execute_input");
default:
console.log('unhandled output message', msg);
return false;
return Promise.reject("Unhandled output message " + JSON.stringify(msg));
}
this.append_output(json);
return true;
this._outputs.push(json);
return this.appendOutput(json);
}

@@ -114,3 +161,3 @@

*/
clear_output(wait) {
clearOutput(wait) {
if (wait) {

@@ -120,3 +167,3 @@

if (this._clear_queued) {
this.clear_output(false);
this.clearOutput(false);
}

@@ -143,9 +190,5 @@

* @param {object} json - output json. See nbformat.
* @return {bool} whether or not output was appended
* @return {Promise}
*/
/**
* [append_output description]
* @param {[type]} json [description]
*/
append_output(json) {
appendOutput(json) {
let bundle, el;

@@ -156,3 +199,3 @@ bundle = {};

if (this._clear_queued) {
this.clear_output(false);
this.clearOutput(false);
}

@@ -176,10 +219,9 @@

el = this.transformime.transformRichest(bundle, this.document);
if (el) {
this.el.appendChild(el);
return true;
}
let elementPromise = this.transformime.transformRichest(bundle, this.document);
return false;
elementPromise.then(elementBundle => {
this.el.appendChild(elementBundle.el);
});
return elementPromise;
}

@@ -186,0 +228,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc