@difizen/libro-rendermime 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ .libro-text-display-action {
2
+ color: var(--mana-libro-link-color);
3
+ }
4
+
5
+ .libro-text-display-action-container {
6
+ cursor: pointer;
7
+ color: var(--mana-libro-toptoolbar-icon-color);
8
+ font-style: italic;
9
+ }
@@ -1,5 +1,6 @@
1
1
  import type { BaseOutputView } from '@difizen/libro-core';
2
2
  import React from 'react';
3
+ import './index.less';
3
4
  export declare const RawTextRender: React.FC<{
4
5
  model: BaseOutputView;
5
6
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"text-render.d.ts","sourceRoot":"","sources":["../../src/components/text-render.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAA4B,MAAM,OAAO,CAAC;AAMjD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,KAAK,EAAE,cAAc,CAAA;CAAE,CAsC7D,CAAC;AAEF,eAAO,MAAM,UAAU;WAxCuB,cAAc;EAwCT,CAAC"}
1
+ {"version":3,"file":"text-render.d.ts","sourceRoot":"","sources":["../../src/components/text-render.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,cAAc,CAAC;AAWtB,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,KAAK,EAAE,cAAc,CAAA;CAAE,CAiH7D,CAAC;AAEF,eAAO,MAAM,UAAU;WAnHuB,cAAc;EAmHT,CAAC"}
@@ -1,15 +1,36 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1
11
  import { concatMultilineString } from '@difizen/libro-common';
2
12
  import { useInject } from '@difizen/libro-common/app';
3
- import React, { useEffect, useRef } from 'react';
13
+ import { removeOverwrittenChars } from '@difizen/libro-core';
14
+ import React, { useEffect, useRef, useState } from 'react';
15
+ import "./index.less";
4
16
  import { renderText } from "../renderers.js";
5
17
  import { RenderMimeRegistry } from "../rendermime-registry.js";
6
18
  import { jsx as _jsx } from "react/jsx-runtime";
19
+ import { jsxs as _jsxs } from "react/jsx-runtime";
20
+ function getLastThreeAfterFirstTwo(arr) {
21
+ var startIndex = Math.max(2, arr.length - 3);
22
+ return arr.slice(startIndex);
23
+ }
7
24
  export var RawTextRender = function RawTextRender(props) {
8
25
  var model = props.model;
9
26
  var renderTextRef = useRef(null);
10
27
  var renderTextContainerRef = useRef(null);
11
28
  var defaultRenderMime = useInject(RenderMimeRegistry);
12
- var mimeType = defaultRenderMime.defaultPreferredMimeType(model
29
+ var _useState = useState(model.cell.isLargeOutputDisplay),
30
+ _useState2 = _slicedToArray(_useState, 2),
31
+ isLargeOutputDisplay = _useState2[0],
32
+ setIsLargeOutputDisplay = _useState2[1];
33
+ var mimeType = defaultRenderMime.defaultPreferredMimeType(model, isLargeOutputDisplay ? 'largeOutput' : undefined
13
34
  // model.trusted ? 'any' : 'ensure'
14
35
  );
15
36
  var dataContent = null;
@@ -18,26 +39,66 @@ export var RawTextRender = function RawTextRender(props) {
18
39
  }
19
40
  useEffect(function () {
20
41
  if (dataContent && mimeType) {
42
+ var displaySource;
43
+ if ((mimeType === 'application/vnd.libro.large.output.stdout' || mimeType === 'application/vnd.libro.large.output.stderr') && Array.isArray(dataContent) && dataContent.length > 1) {
44
+ displaySource = removeOverwrittenChars(concatMultilineString([].concat(_toConsumableArray(dataContent.slice(0, 2)), _toConsumableArray(getLastThreeAfterFirstTwo(dataContent)))));
45
+ } else {
46
+ displaySource = removeOverwrittenChars(concatMultilineString(JSON.parse(JSON.stringify(dataContent))));
47
+ }
21
48
  renderText({
22
49
  host: renderTextRef.current,
23
- source: concatMultilineString(JSON.parse(JSON.stringify(dataContent))),
50
+ source: displaySource,
24
51
  sanitizer: defaultRenderMime.sanitizer,
25
52
  mimeType: mimeType
26
53
  });
27
- if (mimeType === 'application/vnd.jupyter.stderr') {
54
+ if (mimeType === 'application/vnd.jupyter.stderr' || mimeType === 'application/vnd.libro.large.output.stderr') {
28
55
  var _renderTextContainerR;
29
56
  (_renderTextContainerR = renderTextContainerRef.current) === null || _renderTextContainerR === void 0 || _renderTextContainerR.setAttribute('data-mime-type', 'application/vnd.jupyter.stderr');
30
57
  }
31
58
  }
32
59
  // eslint-disable-next-line react-hooks/exhaustive-deps
33
60
  }, [mimeType, dataContent]);
34
- return /*#__PURE__*/_jsx("div", {
61
+ return /*#__PURE__*/_jsxs("div", {
35
62
  className: "libro-text-render-container",
36
63
  ref: renderTextContainerRef,
37
- children: /*#__PURE__*/_jsx("div", {
64
+ children: [/*#__PURE__*/_jsx("div", {
38
65
  className: "libro-text-render",
39
- ref: renderTextRef
40
- })
66
+ ref: renderTextRef,
67
+ style: {
68
+ overflowY: 'auto',
69
+ maxHeight: "".concat(isLargeOutputDisplay ? '420px' : 'unset')
70
+ }
71
+ }), model.raw['display_text'] && /*#__PURE__*/_jsxs("div", {
72
+ className: "libro-text-display-action-container",
73
+ children: [/*#__PURE__*/_jsx("span", {
74
+ children: "\u8BE5\u6BB5\u8F93\u51FA\u592A\u957F\uFF0C\u70B9\u51FB\u53EF\u8FDB\u884C"
75
+ }), /*#__PURE__*/_jsx("a", {
76
+ onClick: function onClick() {
77
+ model.cell.isLargeOutputDisplay = !model.cell.isLargeOutputDisplay;
78
+ setIsLargeOutputDisplay(!isLargeOutputDisplay);
79
+ },
80
+ className: "libro-text-display-action",
81
+ children: isLargeOutputDisplay ? ' 展开查看' : ' 截断查看'
82
+ }), isLargeOutputDisplay && /*#__PURE__*/_jsxs("span", {
83
+ children: ["\uFF0C\u6216\u5728", /*#__PURE__*/_jsx("a", {
84
+ className: "libro-text-display-action",
85
+ onClick: function onClick() {
86
+ var mimeType = defaultRenderMime.defaultPreferredMimeType(model, undefined);
87
+ var dataContent = null;
88
+ if (mimeType) {
89
+ dataContent = model.data[mimeType];
90
+ if (dataContent !== null) {
91
+ model.cell.parent.outputRenderTabEmitter.fire({
92
+ mimeType: mimeType,
93
+ data: dataContent || ''
94
+ });
95
+ }
96
+ }
97
+ },
98
+ children: "\u6587\u672C\u7F16\u8F91\u5668"
99
+ }), "\u4E2D\u6253\u5F00"]
100
+ })]
101
+ })]
41
102
  });
42
103
  };
43
104
  export var TextRender = /*#__PURE__*/React.memo(RawTextRender);
@@ -1 +1 @@
1
- {"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../src/renderers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAUlC;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmGrE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqCvE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuErE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BnE;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBnF"}
1
+ {"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../src/renderers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAUlC;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmFrE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqCvE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuErE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BnE;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBnF"}
package/es/renderers.js CHANGED
@@ -21,82 +21,61 @@ import { ansiSpan, autolink, evalInnerHTMLScriptTags, handleDefaults, handleUrls
21
21
  * @returns A promise which resolves when rendering is complete.
22
22
  */
23
23
  export function renderText(options) {
24
- // Unpack the options.
25
24
  var host = options.host,
26
25
  sanitizer = options.sanitizer,
27
26
  source = options.source,
28
27
  mimeType = options.mimeType;
29
28
  var data = concatMultilineString(JSON.parse(JSON.stringify(source)));
30
- // Create the HTML content.
31
29
  var content = sanitizer.sanitize(ansiSpan(data), {
32
30
  allowedTags: ['span']
33
31
  });
34
32
  if (mimeType === 'application/vnd.jupyter.stderr') {
35
33
  host.setAttribute('data-mime-type', 'application/vnd.jupyter.stderr');
36
34
  }
37
- // Set the sanitized content for the host node.
38
- var pre = document.createElement('pre');
35
+ var pre = host.querySelector('pre');
36
+ if (!pre) {
37
+ pre = document.createElement('pre');
38
+ host.appendChild(pre);
39
+ }
39
40
  pre.innerHTML = content;
40
41
  var preTextContent = pre.textContent;
41
42
  if (preTextContent) {
42
- // Note: only text nodes and span elements should be present after sanitization in the `<pre>` element.
43
43
  var linkedNodes = autolink(preTextContent);
44
44
  var inAnchorElement = false;
45
45
  var combinedNodes = [];
46
46
  var preNodes = Array.from(pre.childNodes);
47
+
48
+ // 使用 shift/unshift 替代索引遍历,确保所有节点被处理
47
49
  while (preNodes.length && linkedNodes.length) {
48
50
  var _preNode$textContent, _linkNode$textContent;
49
- // Use non-null assertions to workaround TypeScript context awareness limitation
50
- // (if any of the arrays were empty, we would not enter the body of the loop).
51
51
  var preNode = preNodes.shift();
52
52
  var linkNode = linkedNodes.shift();
53
+ var preLen = ((_preNode$textContent = preNode.textContent) === null || _preNode$textContent === void 0 ? void 0 : _preNode$textContent.length) || 0;
54
+ var linkLen = ((_linkNode$textContent = linkNode.textContent) === null || _linkNode$textContent === void 0 ? void 0 : _linkNode$textContent.length) || 0;
53
55
 
54
- // This should never happen because we modify the arrays in flight so they should end simultaneously,
55
- // but this makes the coding assistance happy and might make it easier to conceptualize.
56
- if (typeof preNode === 'undefined') {
57
- combinedNodes.push(linkNode);
58
- break;
59
- }
60
- if (typeof linkNode === 'undefined') {
61
- combinedNodes.push(preNode);
62
- break;
63
- }
64
- var preLen = (_preNode$textContent = preNode.textContent) === null || _preNode$textContent === void 0 ? void 0 : _preNode$textContent.length;
65
- var linkLen = (_linkNode$textContent = linkNode.textContent) === null || _linkNode$textContent === void 0 ? void 0 : _linkNode$textContent.length;
66
- if (preLen && linkLen) {
67
- if (preLen > linkLen) {
68
- // Split pre node and only keep the shorter part
69
- var _splitShallowNode = splitShallowNode(preNode, linkLen),
70
- keep = _splitShallowNode.pre,
71
- postpone = _splitShallowNode.post;
72
- preNodes.unshift(postpone);
73
- preNode = keep;
74
- } else if (linkLen > preLen) {
75
- var _splitShallowNode2 = splitShallowNode(linkNode, preLen),
76
- _keep = _splitShallowNode2.pre,
77
- _postpone = _splitShallowNode2.post;
78
- linkedNodes.unshift(_postpone);
79
- linkNode = _keep;
80
- }
56
+ // 如果长度不一致,进行分割处理
57
+ if (preLen > linkLen) {
58
+ var _splitShallowNode = splitShallowNode(preNode, linkLen),
59
+ keep = _splitShallowNode.pre,
60
+ postpone = _splitShallowNode.post;
61
+ preNodes.unshift(postpone); // 剩余部分放回数组头部
62
+ preNode.textContent = keep.textContent;
63
+ } else if (linkLen > preLen) {
64
+ var _splitShallowNode2 = splitShallowNode(linkNode, preLen),
65
+ _keep = _splitShallowNode2.pre,
66
+ _postpone = _splitShallowNode2.post;
67
+ linkedNodes.unshift(_postpone);
68
+ linkNode.textContent = _keep.textContent;
81
69
  }
82
70
  var lastCombined = combinedNodes[combinedNodes.length - 1];
83
-
84
- // If we are already in an anchor element and the anchor element did not change,
85
- // we should insert the node from <pre> which is either Text node or coloured span Element
86
- // into the anchor content as a child
87
71
  if (inAnchorElement && linkNode.href === lastCombined.href) {
88
72
  lastCombined.appendChild(preNode);
89
73
  } else {
90
- // the `linkNode` is either Text or AnchorElement;
91
74
  var isAnchor = linkNode.nodeType !== Node.TEXT_NODE;
92
- // if we are NOT about to start an anchor element, just add the pre Node
93
75
  if (!isAnchor) {
94
76
  combinedNodes.push(preNode);
95
77
  inAnchorElement = false;
96
78
  } else {
97
- // otherwise start a new anchor; the contents of the `linkNode` and `preNode` should be the same,
98
- // so we just put the neatly formatted `preNode` inside the anchor node (`linkNode`)
99
- // and append that to combined nodes.
100
79
  linkNode.textContent = '';
101
80
  linkNode.appendChild(preNode);
102
81
  combinedNodes.push(linkNode);
@@ -104,17 +83,18 @@ export function renderText(options) {
104
83
  }
105
84
  }
106
85
  }
107
- // TODO: replace with `.replaceChildren()` once the target ES version allows it
108
- pre.innerHTML = '';
86
+
87
+ // 使用 DocumentFragment 一次性插入 DOM,提升性能
88
+ var fragment = document.createDocumentFragment();
109
89
  for (var _i = 0, _combinedNodes = combinedNodes; _i < _combinedNodes.length; _i++) {
110
90
  var child = _combinedNodes[_i];
111
- pre.appendChild(child);
91
+ fragment.appendChild(child);
112
92
  }
93
+ pre.innerHTML = ''; // 清空内容
94
+ pre.appendChild(fragment); // 一次性插入
113
95
  }
114
96
  host.appendChild(pre);
115
97
  host.classList.add('libro-text-render');
116
-
117
- // Return the rendered promise.
118
98
  return Promise.resolve(undefined);
119
99
  }
120
100
 
@@ -23,6 +23,10 @@ export declare const svgRendererFactory: IRendererFactory;
23
23
  * A mime renderer factory for plain and jupyter console text data.
24
24
  */
25
25
  export declare const textRendererFactory: IRendererFactory;
26
+ /**
27
+ * A mime renderer factory for plain and jupyter console text data.
28
+ */
29
+ export declare const largeOutputRendererFactory: IRendererFactory;
26
30
  /**
27
31
  * The standard factories provided by the rendermime package.
28
32
  */
@@ -1 +1 @@
1
- {"version":3,"file":"rendermime-factory.d.ts","sourceRoot":"","sources":["../src/rendermime-factory.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAMjC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,gBAMlC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,gBAMlC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,gBAMrC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBAMhC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAUjC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,gBAAgB,EAQvD,CAAC"}
1
+ {"version":3,"file":"rendermime-factory.d.ts","sourceRoot":"","sources":["../src/rendermime-factory.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAMjC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,gBAMlC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,gBAMlC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,gBAMrC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBAMhC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAUjC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,0BAA0B,EAAE,gBASxC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,gBAAgB,EASvD,CAAC"}
@@ -65,9 +65,20 @@ export var textRendererFactory = {
65
65
  render: TextRender
66
66
  };
67
67
 
68
+ /**
69
+ * A mime renderer factory for plain and jupyter console text data.
70
+ */
71
+ export var largeOutputRendererFactory = {
72
+ renderType: 'largeOutputRenderer',
73
+ safe: true,
74
+ mimeTypes: ['application/vnd.libro.large.output.stdout', 'application/vnd.libro.large.output.stderr'],
75
+ defaultRank: 100,
76
+ render: TextRender
77
+ };
78
+
68
79
  /**
69
80
  * The standard factories provided by the rendermime package.
70
81
  */
71
82
  export var standardRendererFactories = [htmlRendererFactory, markdownRendererFactory, latexRendererFactory, svgRendererFactory, imageRendererFactory,
72
83
  // javaScriptRendererFactory,
73
- textRendererFactory];
84
+ textRendererFactory, largeOutputRendererFactory];
@@ -146,7 +146,7 @@ export interface IRenderMimeRegistry {
146
146
  *
147
147
  * @param bundle - The bundle of mime data.
148
148
  *
149
- * @param safe - How to consider safe/unsafe factories. If 'ensure',
149
+ * @param mode - How to consider safe/unsafe factories. If 'ensure',
150
150
  * it will only consider safe factories. If 'any', any factory will be
151
151
  * considered. If 'prefer', unsafe factories will be considered, but
152
152
  * only after the safe options have been exhausted.
@@ -154,8 +154,8 @@ export interface IRenderMimeRegistry {
154
154
  * @returns The preferred mime type from the available factories,
155
155
  * or `undefined` if the mime type cannot be rendered.
156
156
  */
157
- preferredMimeType: (model: BaseOutputView, safe?: 'ensure' | 'prefer' | 'any') => string | undefined;
158
- defaultPreferredMimeType: (model: BaseOutputView, safe?: 'ensure' | 'prefer' | 'any') => string | undefined;
157
+ preferredMimeType: (model: BaseOutputView, mode?: 'ensure' | 'prefer' | 'any' | 'largeOutput') => string | undefined;
158
+ defaultPreferredMimeType: (model: BaseOutputView, mode?: 'ensure' | 'prefer' | 'any' | 'largeOutput') => string | undefined;
159
159
  /**
160
160
  * Create a renderer for a mime type.
161
161
  *
@@ -1 +1 @@
1
- {"version":3,"file":"rendermime-protocol.d.ts","sourceRoot":"","sources":["../src/rendermime-protocol.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD,eAAO,MAAM,yBAAyB,eAA+B,CAAC;AACtE,eAAO,MAAM,0BAA0B,eAAuC,CAAC;AAC/E,eAAO,MAAM,sBAAsB,sBAAoD,CAAC;AACxF,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC9D,SAAS,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,MAAM,CAAC;IAC7C,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;QAAE,KAAK,EAAE,cAAc,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,CAAC,CAAC;CAC5E;AACD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;;;;;OASG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAEvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAEtC;;OAEG;IACH,QAAQ,CAAC,W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AE,SAAS,gBAAgB,EAAE,CAAC;IAE/C;;;;OAIG;IACH,SAAS,CAAC,EAAE,UAAU,CAAC;IAEvB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC;IAErB;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;IAE3B;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CAMjC;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtE;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC"}
@@ -51,7 +51,7 @@ export declare class RenderMimeRegistry implements IRenderMimeRegistry {
51
51
  */
52
52
  get mimeTypes(): readonly string[];
53
53
  protected getSortedRenderMimes(model: BaseOutputView): RenderMimeContribution[];
54
- defaultPreferredMimeType(model: BaseOutputView): string | undefined;
54
+ defaultPreferredMimeType(model: BaseOutputView, mode?: 'ensure' | 'prefer' | 'any' | 'largeOutput'): string | undefined;
55
55
  /**
56
56
  * Find the preferred mime type for a mime bundle.
57
57
  *
@@ -65,7 +65,7 @@ export declare class RenderMimeRegistry implements IRenderMimeRegistry {
65
65
  * @returns The preferred mime type from the available factories,
66
66
  * or `undefined` if the mime type cannot be rendered.
67
67
  */
68
- preferredMimeType(model: BaseOutputView): string | undefined;
68
+ preferredMimeType(model: BaseOutputView, mode?: 'ensure' | 'prefer' | 'any' | 'largeOutput'): string | undefined;
69
69
  /**
70
70
  * Create a renderer for a mime type.
71
71
  *
@@ -1 +1 @@
1
- {"version":3,"file":"rendermime-registry.d.ts","sourceRoot":"","sources":["../src/rendermime-registry.ts"],"names":[],"mappings":"AACA,OAAO,KA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,gBAAgB,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;IAe3D;;;;OAIG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAMtC;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAK7C;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAS7C,SAAS,CAAC,GAAG,SAAK;IAClB,SAAS,CAAC,MAAM,EAAE,OAAO,CAAM;IAC/B,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAQ;IACzC,SAAS,CAAC,UAAU,EAAE,UAAU,CAAM;CACvC"}
@@ -15,6 +15,7 @@ import { defaultSanitizer } from '@difizen/libro-common';
15
15
  import { MarkdownParser } from '@difizen/libro-markdown';
16
16
  import { contrib, inject, singleton, Priority } from '@difizen/libro-common/app';
17
17
  import { Emitter } from '@difizen/libro-common/app';
18
+ import { largeOutputRendererFactory } from "./rendermime-factory.js";
18
19
  import { RenderMimeContribution, IRenderMimeRegistryOptions } from "./rendermime-protocol.js";
19
20
  import { sortedTypes } from "./rendermime-utils.js";
20
21
 
@@ -116,15 +117,16 @@ export var RenderMimeRegistry = (_dec = singleton(), _dec2 = contrib(RenderMimeC
116
117
  }
117
118
  }, {
118
119
  key: "defaultPreferredMimeType",
119
- value: function defaultPreferredMimeType(model
120
- // safe: 'ensure' | 'prefer' | 'any' = 'ensure',
121
- ) {
120
+ value: function defaultPreferredMimeType(model, mode) {
122
121
  var _iterator2 = _createForOfIteratorHelper(this.mimeTypes),
123
122
  _step2;
124
123
  try {
125
124
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
126
125
  var mt = _step2.value;
127
126
  if (mt in model.data) {
127
+ if (mode !== 'largeOutput' && largeOutputRendererFactory.mimeTypes.includes(mt)) {
128
+ continue;
129
+ }
128
130
  return mt;
129
131
  }
130
132
  }
@@ -153,9 +155,7 @@ export var RenderMimeRegistry = (_dec = singleton(), _dec2 = contrib(RenderMimeC
153
155
  */
154
156
  }, {
155
157
  key: "preferredMimeType",
156
- value: function preferredMimeType(model
157
- // safe: 'ensure' | 'prefer' | 'any' = 'ensure',
158
- ) {
158
+ value: function preferredMimeType(model, mode) {
159
159
  // // Try to find a safe factory first, if preferred.
160
160
  // if (safe === 'ensure' || safe === 'prefer') {
161
161
  // for (const mt of this.mimeTypes) {
@@ -185,6 +185,9 @@ export var RenderMimeRegistry = (_dec = singleton(), _dec2 = contrib(RenderMimeC
185
185
  for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
186
186
  var mt = _step5.value;
187
187
  if (mt in model.data) {
188
+ if (mode !== 'largeOutput' && largeOutputRendererFactory.mimeTypes.includes(mt)) {
189
+ continue;
190
+ }
188
191
  return mt;
189
192
  }
190
193
  }
@@ -205,6 +208,9 @@ export var RenderMimeRegistry = (_dec = singleton(), _dec2 = contrib(RenderMimeC
205
208
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
206
209
  var _mt = _step4.value;
207
210
  if (_mt in model.data) {
211
+ if (mode !== 'largeOutput' && largeOutputRendererFactory.mimeTypes.includes(_mt)) {
212
+ continue;
213
+ }
208
214
  return _mt;
209
215
  }
210
216
  }
@@ -1,13 +1,5 @@
1
- import type { IOutput, ISanitizer, PartialJSONObject, PartialJSONValue, ReadonlyPartialJSONObject } from '@difizen/libro-common';
1
+ import type { ISanitizer } from '@difizen/libro-common';
2
2
  import type { ILinkHandler, IResolver, RankMap } from './rendermime-protocol.js';
3
- /**
4
- * Get the data from a notebook output.
5
- */
6
- export declare function getData(output: IOutput): PartialJSONObject;
7
- /**
8
- * Extract a value from a JSONObject.
9
- */
10
- export declare function extract(value: ReadonlyPartialJSONObject, key: string): PartialJSONValue | undefined;
11
3
  /**
12
4
  * Transform ANSI color escape codes into HTML <span> tags with CSS
13
5
  * classes such as "ansi-green-intense-fg".
@@ -1 +1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AEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CA8BnF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,SAAS,EACnB,WAAW,EAAE,YAAY,GAAG,IAAI,GAC/B,OAAO,CAAC,IAAI,CAAC,CAwBf;AAoFD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAEtD;AAED;;GAEG"}
@@ -2,51 +2,9 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
2
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
4
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
- import { isDisplayData, isDisplayUpdate, isError, isExecuteResult, isPrimitive, isStream, URL } from '@difizen/libro-common';
5
+ import { URL } from '@difizen/libro-common';
6
6
  import { URI } from '@difizen/libro-common/app';
7
7
  import escape from 'lodash.escape';
8
- /**
9
- * Get the data from a notebook output.
10
- */
11
- export function getData(output) {
12
- var bundle = {};
13
- if (isExecuteResult(output) || isDisplayData(output) || isDisplayUpdate(output)) {
14
- bundle = output.data;
15
- } else if (isStream(output)) {
16
- if (output.name === 'stderr') {
17
- bundle['application/vnd.jupyter.stderr'] = output.text;
18
- } else {
19
- bundle['application/vnd.jupyter.stdout'] = output.text;
20
- }
21
- } else if (isError(output)) {
22
- bundle['application/vnd.jupyter.error'] = output;
23
- var traceback = output.traceback.join('\n');
24
- bundle['application/vnd.jupyter.stderr'] = traceback || "".concat(output.ename, ": ").concat(output.evalue);
25
- }
26
- return convertBundle(bundle);
27
- }
28
-
29
- /**
30
- * Extract a value from a JSONObject.
31
- */
32
- export function extract(value, key) {
33
- var item = value[key];
34
- if (item === undefined || isPrimitive(item)) {
35
- return item;
36
- }
37
- return JSON.parse(JSON.stringify(item));
38
- }
39
-
40
- /**
41
- * Convert a mime bundle to mime data.
42
- */
43
- function convertBundle(bundle) {
44
- var map = Object.create(null);
45
- for (var mimeType in bundle) {
46
- map[mimeType] = extract(bundle, mimeType);
47
- }
48
- return map;
49
- }
50
8
  var ANSI_COLORS = ['ansi-black', 'ansi-red', 'ansi-green', 'ansi-yellow', 'ansi-blue', 'ansi-magenta', 'ansi-cyan', 'ansi-white', 'ansi-black-intense', 'ansi-red-intense', 'ansi-green-intense', 'ansi-yellow-intense', 'ansi-blue-intense', 'ansi-magenta-intense', 'ansi-cyan-intense', 'ansi-white-intense'];
51
9
 
52
10
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-rendermime",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro",
@@ -32,9 +32,9 @@
32
32
  "src"
33
33
  ],
34
34
  "dependencies": {
35
- "@difizen/libro-common": "^1.0.1",
36
- "@difizen/libro-core": "^1.0.1",
37
- "@difizen/libro-markdown": "^1.0.1",
35
+ "@difizen/libro-common": "^1.0.3",
36
+ "@difizen/libro-core": "^1.0.3",
37
+ "@difizen/libro-markdown": "^1.0.3",
38
38
  "lodash.escape": "^4.0.1"
39
39
  },
40
40
  "peerDependencies": {
@@ -0,0 +1,9 @@
1
+ .libro-text-display-action {
2
+ color: var(--mana-libro-link-color);
3
+ }
4
+
5
+ .libro-text-display-action-container {
6
+ cursor: pointer;
7
+ color: var(--mana-libro-toptoolbar-icon-color);
8
+ font-style: italic;
9
+ }
@@ -1,13 +1,20 @@
1
- import type { JSONValue } from '@difizen/libro-common';
1
+ import type { JSONValue, MultilineString } from '@difizen/libro-common';
2
2
  import { concatMultilineString } from '@difizen/libro-common';
3
- import type { BaseOutputView } from '@difizen/libro-core';
4
3
  import { useInject } from '@difizen/libro-common/app';
5
- import React, { useEffect, useRef } from 'react';
4
+ import type { BaseOutputView } from '@difizen/libro-core';
5
+ import { removeOverwrittenChars } from '@difizen/libro-core';
6
+ import React, { useEffect, useRef, useState } from 'react';
7
+ import './index.less';
6
8
 
7
9
  import { renderText } from '../renderers.js';
8
10
  import type { IRenderMimeRegistry } from '../rendermime-protocol.js';
9
11
  import { RenderMimeRegistry } from '../rendermime-registry.js';
10
12
 
13
+ function getLastThreeAfterFirstTwo(arr: string[]): string[] {
14
+ const startIndex = Math.max(2, arr.length - 3);
15
+ return arr.slice(startIndex);
16
+ }
17
+
11
18
  export const RawTextRender: React.FC<{ model: BaseOutputView }> = (props: {
12
19
  model: BaseOutputView;
13
20
  }) => {
@@ -15,24 +22,51 @@ export const RawTextRender: React.FC<{ model: BaseOutputView }> = (props: {
15
22
  const renderTextRef = useRef<HTMLDivElement>(null);
16
23
  const renderTextContainerRef = useRef<HTMLDivElement>(null);
17
24
  const defaultRenderMime = useInject<IRenderMimeRegistry>(RenderMimeRegistry);
25
+ const [isLargeOutputDisplay, setIsLargeOutputDisplay] = useState(
26
+ model.cell.isLargeOutputDisplay,
27
+ );
18
28
 
19
29
  const mimeType = defaultRenderMime.defaultPreferredMimeType(
20
30
  model,
31
+ isLargeOutputDisplay ? 'largeOutput' : undefined,
21
32
  // model.trusted ? 'any' : 'ensure'
22
33
  );
23
- let dataContent: JSONValue | null = null;
34
+ let dataContent: JSONValue | MultilineString | null = null;
24
35
  if (mimeType) {
25
36
  dataContent = model.data[mimeType];
26
37
  }
38
+
27
39
  useEffect(() => {
28
40
  if (dataContent && mimeType) {
41
+ let displaySource: string;
42
+ if (
43
+ (mimeType === 'application/vnd.libro.large.output.stdout' ||
44
+ mimeType === 'application/vnd.libro.large.output.stderr') &&
45
+ Array.isArray(dataContent) &&
46
+ dataContent.length > 1
47
+ ) {
48
+ displaySource = removeOverwrittenChars(
49
+ concatMultilineString([
50
+ ...(dataContent as string[]).slice(0, 2),
51
+ ...getLastThreeAfterFirstTwo(dataContent as string[]),
52
+ ]),
53
+ );
54
+ } else {
55
+ displaySource = removeOverwrittenChars(
56
+ concatMultilineString(JSON.parse(JSON.stringify(dataContent))),
57
+ );
58
+ }
59
+
29
60
  renderText({
30
61
  host: renderTextRef.current as HTMLElement,
31
- source: concatMultilineString(JSON.parse(JSON.stringify(dataContent))),
62
+ source: displaySource,
32
63
  sanitizer: defaultRenderMime.sanitizer,
33
64
  mimeType: mimeType,
34
65
  });
35
- if (mimeType === 'application/vnd.jupyter.stderr') {
66
+ if (
67
+ mimeType === 'application/vnd.jupyter.stderr' ||
68
+ mimeType === 'application/vnd.libro.large.output.stderr'
69
+ ) {
36
70
  renderTextContainerRef.current?.setAttribute(
37
71
  'data-mime-type',
38
72
  'application/vnd.jupyter.stderr',
@@ -43,7 +77,55 @@ export const RawTextRender: React.FC<{ model: BaseOutputView }> = (props: {
43
77
  }, [mimeType, dataContent]);
44
78
  return (
45
79
  <div className="libro-text-render-container" ref={renderTextContainerRef}>
46
- <div className="libro-text-render" ref={renderTextRef} />
80
+ <div
81
+ className="libro-text-render"
82
+ ref={renderTextRef}
83
+ style={{
84
+ overflowY: 'auto',
85
+ maxHeight: `${isLargeOutputDisplay ? '420px' : 'unset'}`,
86
+ }}
87
+ />
88
+ {model.raw['display_text'] && (
89
+ <div className="libro-text-display-action-container">
90
+ <span>该段输出太长,点击可进行</span>
91
+ <a
92
+ onClick={() => {
93
+ model.cell.isLargeOutputDisplay = !model.cell.isLargeOutputDisplay;
94
+ setIsLargeOutputDisplay(!isLargeOutputDisplay);
95
+ }}
96
+ className="libro-text-display-action"
97
+ >
98
+ {isLargeOutputDisplay ? ' 展开查看' : ' 截断查看'}
99
+ </a>
100
+ {isLargeOutputDisplay && (
101
+ <span>
102
+ ,或在
103
+ <a
104
+ className="libro-text-display-action"
105
+ onClick={() => {
106
+ const mimeType = defaultRenderMime.defaultPreferredMimeType(
107
+ model,
108
+ undefined,
109
+ );
110
+ let dataContent: JSONValue | MultilineString | null = null;
111
+ if (mimeType) {
112
+ dataContent = model.data[mimeType];
113
+ if (dataContent !== null) {
114
+ model.cell.parent.outputRenderTabEmitter.fire({
115
+ mimeType,
116
+ data: (dataContent as MultilineString | null) || '',
117
+ });
118
+ }
119
+ }
120
+ }}
121
+ >
122
+ 文本编辑器
123
+ </a>
124
+ 中打开
125
+ </span>
126
+ )}
127
+ </div>
128
+ )}
47
129
  </div>
48
130
  );
49
131
  };
package/src/renderers.ts CHANGED
@@ -24,10 +24,8 @@ import {
24
24
  * @returns A promise which resolves when rendering is complete.
25
25
  */
26
26
  export function renderText(options: IRenderTextOptions): Promise<void> {
27
- // Unpack the options.
28
27
  const { host, sanitizer, source, mimeType } = options;
29
28
  const data = concatMultilineString(JSON.parse(JSON.stringify(source)));
30
- // Create the HTML content.
31
29
  const content = sanitizer.sanitize(ansiSpan(data), {
32
30
  allowedTags: ['span'],
33
31
  });
@@ -35,57 +33,44 @@ export function renderText(options: IRenderTextOptions): Promise<void> {
35
33
  if (mimeType === 'application/vnd.jupyter.stderr') {
36
34
  host.setAttribute('data-mime-type', 'application/vnd.jupyter.stderr');
37
35
  }
38
- // Set the sanitized content for the host node.
39
- const pre = document.createElement('pre');
36
+
37
+ let pre = host.querySelector('pre');
38
+ if (!pre) {
39
+ pre = document.createElement('pre');
40
+ host.appendChild(pre);
41
+ }
42
+
40
43
  pre.innerHTML = content;
41
44
 
42
45
  const preTextContent = pre.textContent;
43
-
44
46
  if (preTextContent) {
45
- // Note: only text nodes and span elements should be present after sanitization in the `<pre>` element.
46
47
  const linkedNodes = autolink(preTextContent);
47
48
  let inAnchorElement = false;
48
49
 
49
50
  const combinedNodes: (HTMLAnchorElement | Text | HTMLSpanElement)[] = [];
50
51
  const preNodes = Array.from(pre.childNodes) as (Text | HTMLSpanElement)[];
51
52
 
53
+ // 使用 shift/unshift 替代索引遍历,确保所有节点被处理
52
54
  while (preNodes.length && linkedNodes.length) {
53
- // Use non-null assertions to workaround TypeScript context awareness limitation
54
- // (if any of the arrays were empty, we would not enter the body of the loop).
55
- let preNode = preNodes.shift()!;
56
- let linkNode = linkedNodes.shift()!;
57
-
58
- // This should never happen because we modify the arrays in flight so they should end simultaneously,
59
- // but this makes the coding assistance happy and might make it easier to conceptualize.
60
- if (typeof preNode === 'undefined') {
61
- combinedNodes.push(linkNode);
62
- break;
63
- }
64
- if (typeof linkNode === 'undefined') {
65
- combinedNodes.push(preNode);
66
- break;
67
- }
68
-
69
- const preLen = preNode.textContent?.length;
70
- const linkLen = linkNode.textContent?.length;
71
- if (preLen && linkLen) {
72
- if (preLen > linkLen) {
73
- // Split pre node and only keep the shorter part
74
- const { pre: keep, post: postpone } = splitShallowNode(preNode, linkLen);
75
- preNodes.unshift(postpone);
76
- preNode = keep;
77
- } else if (linkLen > preLen) {
78
- const { pre: keep, post: postpone } = splitShallowNode(linkNode, preLen);
79
- linkedNodes.unshift(postpone);
80
- linkNode = keep;
81
- }
55
+ const preNode = preNodes.shift()!;
56
+ const linkNode = linkedNodes.shift()!;
57
+
58
+ const preLen = preNode.textContent?.length || 0;
59
+ const linkLen = linkNode.textContent?.length || 0;
60
+
61
+ // 如果长度不一致,进行分割处理
62
+ if (preLen > linkLen) {
63
+ const { pre: keep, post: postpone } = splitShallowNode(preNode, linkLen);
64
+ preNodes.unshift(postpone); // 剩余部分放回数组头部
65
+ preNode.textContent = keep.textContent;
66
+ } else if (linkLen > preLen) {
67
+ const { pre: keep, post: postpone } = splitShallowNode(linkNode, preLen);
68
+ linkedNodes.unshift(postpone);
69
+ linkNode.textContent = keep.textContent;
82
70
  }
83
71
 
84
72
  const lastCombined = combinedNodes[combinedNodes.length - 1];
85
73
 
86
- // If we are already in an anchor element and the anchor element did not change,
87
- // we should insert the node from <pre> which is either Text node or coloured span Element
88
- // into the anchor content as a child
89
74
  if (
90
75
  inAnchorElement &&
91
76
  (linkNode as HTMLAnchorElement).href ===
@@ -93,16 +78,12 @@ export function renderText(options: IRenderTextOptions): Promise<void> {
93
78
  ) {
94
79
  lastCombined.appendChild(preNode);
95
80
  } else {
96
- // the `linkNode` is either Text or AnchorElement;
97
81
  const isAnchor = linkNode.nodeType !== Node.TEXT_NODE;
98
- // if we are NOT about to start an anchor element, just add the pre Node
82
+
99
83
  if (!isAnchor) {
100
84
  combinedNodes.push(preNode);
101
85
  inAnchorElement = false;
102
86
  } else {
103
- // otherwise start a new anchor; the contents of the `linkNode` and `preNode` should be the same,
104
- // so we just put the neatly formatted `preNode` inside the anchor node (`linkNode`)
105
- // and append that to combined nodes.
106
87
  linkNode.textContent = '';
107
88
  linkNode.appendChild(preNode);
108
89
  combinedNodes.push(linkNode);
@@ -110,17 +91,20 @@ export function renderText(options: IRenderTextOptions): Promise<void> {
110
91
  }
111
92
  }
112
93
  }
113
- // TODO: replace with `.replaceChildren()` once the target ES version allows it
114
- pre.innerHTML = '';
94
+
95
+ // 使用 DocumentFragment 一次性插入 DOM,提升性能
96
+ const fragment = document.createDocumentFragment();
115
97
  for (const child of combinedNodes) {
116
- pre.appendChild(child);
98
+ fragment.appendChild(child);
117
99
  }
100
+
101
+ pre.innerHTML = ''; // 清空内容
102
+ pre.appendChild(fragment); // 一次性插入
118
103
  }
119
104
 
120
105
  host.appendChild(pre);
121
106
  host.classList.add('libro-text-render');
122
107
 
123
- // Return the rendered promise.
124
108
  return Promise.resolve(undefined);
125
109
  }
126
110
 
@@ -78,6 +78,20 @@ export const textRendererFactory: IRendererFactory = {
78
78
  render: TextRender,
79
79
  };
80
80
 
81
+ /**
82
+ * A mime renderer factory for plain and jupyter console text data.
83
+ */
84
+ export const largeOutputRendererFactory: IRendererFactory = {
85
+ renderType: 'largeOutputRenderer',
86
+ safe: true,
87
+ mimeTypes: [
88
+ 'application/vnd.libro.large.output.stdout',
89
+ 'application/vnd.libro.large.output.stderr',
90
+ ],
91
+ defaultRank: 100,
92
+ render: TextRender,
93
+ };
94
+
81
95
  /**
82
96
  * The standard factories provided by the rendermime package.
83
97
  */
@@ -89,4 +103,5 @@ export const standardRendererFactories: IRendererFactory[] = [
89
103
  imageRendererFactory,
90
104
  // javaScriptRendererFactory,
91
105
  textRendererFactory,
106
+ largeOutputRendererFactory,
92
107
  ];
@@ -163,7 +163,7 @@ export interface IRenderMimeRegistry {
163
163
  *
164
164
  * @param bundle - The bundle of mime data.
165
165
  *
166
- * @param safe - How to consider safe/unsafe factories. If 'ensure',
166
+ * @param mode - How to consider safe/unsafe factories. If 'ensure',
167
167
  * it will only consider safe factories. If 'any', any factory will be
168
168
  * considered. If 'prefer', unsafe factories will be considered, but
169
169
  * only after the safe options have been exhausted.
@@ -173,12 +173,12 @@ export interface IRenderMimeRegistry {
173
173
  */
174
174
  preferredMimeType: (
175
175
  model: BaseOutputView,
176
- safe?: 'ensure' | 'prefer' | 'any',
176
+ mode?: 'ensure' | 'prefer' | 'any' | 'largeOutput',
177
177
  ) => string | undefined;
178
178
 
179
179
  defaultPreferredMimeType: (
180
180
  model: BaseOutputView,
181
- safe?: 'ensure' | 'prefer' | 'any',
181
+ mode?: 'ensure' | 'prefer' | 'any' | 'largeOutput',
182
182
  ) => string | undefined;
183
183
  // preferredMimeType: (
184
184
  // bundle: ReadonlyPartialJSONObject,
@@ -5,6 +5,7 @@ import type { Contribution } from '@difizen/libro-common/app';
5
5
  import { contrib, inject, singleton, Priority } from '@difizen/libro-common/app';
6
6
  import { Emitter } from '@difizen/libro-common/app';
7
7
 
8
+ import { largeOutputRendererFactory } from './rendermime-factory.js';
8
9
  import {
9
10
  RenderMimeContribution,
10
11
  IRenderMimeRegistryOptions,
@@ -105,10 +106,16 @@ export class RenderMimeRegistry implements IRenderMimeRegistry {
105
106
 
106
107
  defaultPreferredMimeType(
107
108
  model: BaseOutputView,
108
- // safe: 'ensure' | 'prefer' | 'any' = 'ensure',
109
+ mode?: 'ensure' | 'prefer' | 'any' | 'largeOutput',
109
110
  ): string | undefined {
110
111
  for (const mt of this.mimeTypes) {
111
112
  if (mt in model.data) {
113
+ if (
114
+ mode !== 'largeOutput' &&
115
+ largeOutputRendererFactory.mimeTypes.includes(mt)
116
+ ) {
117
+ continue;
118
+ }
112
119
  return mt;
113
120
  }
114
121
  }
@@ -132,7 +139,7 @@ export class RenderMimeRegistry implements IRenderMimeRegistry {
132
139
  */
133
140
  preferredMimeType(
134
141
  model: BaseOutputView,
135
- // safe: 'ensure' | 'prefer' | 'any' = 'ensure',
142
+ mode?: 'ensure' | 'prefer' | 'any' | 'largeOutput',
136
143
  ): string | undefined {
137
144
  // // Try to find a safe factory first, if preferred.
138
145
  // if (safe === 'ensure' || safe === 'prefer') {
@@ -156,6 +163,12 @@ export class RenderMimeRegistry implements IRenderMimeRegistry {
156
163
  for (const renderMime of sortedRenderMimes) {
157
164
  for (const mt of renderMime.mimeTypes) {
158
165
  if (mt in model.data) {
166
+ if (
167
+ mode !== 'largeOutput' &&
168
+ largeOutputRendererFactory.mimeTypes.includes(mt)
169
+ ) {
170
+ continue;
171
+ }
159
172
  return mt;
160
173
  }
161
174
  }
@@ -163,6 +176,12 @@ export class RenderMimeRegistry implements IRenderMimeRegistry {
163
176
 
164
177
  for (const mt of this.mimeTypes) {
165
178
  if (mt in model.data) {
179
+ if (
180
+ mode !== 'largeOutput' &&
181
+ largeOutputRendererFactory.mimeTypes.includes(mt)
182
+ ) {
183
+ continue;
184
+ }
166
185
  return mt;
167
186
  }
168
187
  }
@@ -1,73 +1,10 @@
1
- import type {
2
- IExecuteResult,
3
- IMimeBundle,
4
- IOutput,
5
- ISanitizer,
6
- PartialJSONObject,
7
- PartialJSONValue,
8
- ReadonlyPartialJSONObject,
9
- } from '@difizen/libro-common';
10
- import {
11
- isDisplayData,
12
- isDisplayUpdate,
13
- isError,
14
- isExecuteResult,
15
- isPrimitive,
16
- isStream,
17
- URL,
18
- } from '@difizen/libro-common';
1
+ import type { ISanitizer } from '@difizen/libro-common';
2
+ import { URL } from '@difizen/libro-common';
19
3
  import { URI } from '@difizen/libro-common/app';
20
4
  import escape from 'lodash.escape';
21
5
 
22
6
  import type { ILinkHandler, IResolver, RankMap } from './rendermime-protocol.js';
23
7
 
24
- /**
25
- * Get the data from a notebook output.
26
- */
27
- export function getData(output: IOutput): PartialJSONObject {
28
- let bundle: IMimeBundle = {};
29
- if (isExecuteResult(output) || isDisplayData(output) || isDisplayUpdate(output)) {
30
- bundle = (output as IExecuteResult).data;
31
- } else if (isStream(output)) {
32
- if (output.name === 'stderr') {
33
- bundle['application/vnd.jupyter.stderr'] = output.text;
34
- } else {
35
- bundle['application/vnd.jupyter.stdout'] = output.text;
36
- }
37
- } else if (isError(output)) {
38
- bundle['application/vnd.jupyter.error'] = output;
39
- const traceback = output.traceback.join('\n');
40
- bundle['application/vnd.jupyter.stderr'] =
41
- traceback || `${output.ename}: ${output.evalue}`;
42
- }
43
- return convertBundle(bundle);
44
- }
45
-
46
- /**
47
- * Extract a value from a JSONObject.
48
- */
49
- export function extract(
50
- value: ReadonlyPartialJSONObject,
51
- key: string,
52
- ): PartialJSONValue | undefined {
53
- const item = value[key];
54
- if (item === undefined || isPrimitive(item)) {
55
- return item;
56
- }
57
- return JSON.parse(JSON.stringify(item));
58
- }
59
-
60
- /**
61
- * Convert a mime bundle to mime data.
62
- */
63
- function convertBundle(bundle: IMimeBundle): PartialJSONObject {
64
- const map: PartialJSONObject = Object.create(null);
65
- for (const mimeType in bundle) {
66
- map[mimeType] = extract(bundle, mimeType);
67
- }
68
- return map;
69
- }
70
-
71
8
  const ANSI_COLORS = [
72
9
  'ansi-black',
73
10
  'ansi-red',