@myst-theme/jupyter 0.5.13 → 0.5.15

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.
@@ -4,4 +4,5 @@ export * from './provider.js';
4
4
  export * from './selectors.js';
5
5
  export * from './types.js';
6
6
  export * from './busy.js';
7
+ export * from './utils.js';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/execute/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/execute/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
@@ -4,3 +4,4 @@ export * from './provider.js';
4
4
  export * from './selectors.js';
5
5
  export * from './types.js';
6
6
  export * from './busy.js';
7
+ export * from './utils.js';
@@ -1,6 +1,13 @@
1
1
  import type { GenericParent } from 'myst-common';
2
2
  import type { Config, IRenderMimeRegistry, ThebeCore } from 'thebe-core';
3
3
  import type { IdKeyMap } from './types.js';
4
+ /**
5
+ * Return executable code/output from block or single figure inside block
6
+ */
7
+ export declare function executableNodesFromBlock(block: GenericParent): {
8
+ codeCell: import("myst-common").GenericNode<Record<string, any>>;
9
+ output: import("myst-common").GenericNode<Record<string, any>>;
10
+ } | undefined;
4
11
  /**
5
12
  * Use the mdast to create a ThebeNotebook from the mdast tree of a notebook.
6
13
  * This is intended to be used to create an independent ThebeNotebook instance
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/execute/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAkB,MAAM,YAAY,CAAC;AAE3D;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,QAAQ,EAChB,UAAU,EAAE,mBAAmB,uDAuDhC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/execute/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAkB,MAAM,YAAY,CAAC;AAE3D;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,aAAa;;;cAS5D;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,QAAQ,EAChB,UAAU,EAAE,mBAAmB,uDAwDhC"}
@@ -1,3 +1,17 @@
1
+ /**
2
+ * Return executable code/output from block or single figure inside block
3
+ */
4
+ export function executableNodesFromBlock(block) {
5
+ if (!block || block.type !== 'block')
6
+ return;
7
+ let target = block;
8
+ if (block.children && block.children.length === 1 && block.children[0].type === 'container') {
9
+ target = block.children[0];
10
+ }
11
+ if (target.children && target.children.length >= 2 && target.children[0].type === 'code') {
12
+ return { codeCell: target.children[0], output: target.children[1] };
13
+ }
14
+ }
1
15
  /**
2
16
  * Use the mdast to create a ThebeNotebook from the mdast tree of a notebook.
3
17
  * This is intended to be used to create an independent ThebeNotebook instance
@@ -27,8 +41,9 @@ export function notebookFromMdast(core, config, pageSlug, notebookSlug, mdast, i
27
41
  var _a, _b, _c;
28
42
  if (block.type !== 'block')
29
43
  console.warn(`Unexpected block type ${block.type}`);
30
- if (block.children.length == 2 && block.children[0].type === 'code') {
31
- const [codeCell, output] = block.children;
44
+ const executableNodes = executableNodesFromBlock(block);
45
+ if (executableNodes) {
46
+ const { codeCell, output } = executableNodes;
32
47
  // use the block.key to identify the cell but maintain a mapping
33
48
  // to allow code or output keys to look up cells and refs and idenifity
34
49
  // the cell in the correct notebook
@@ -1 +1 @@
1
- {"version":3,"file":"figure.d.ts","sourceRoot":"","sources":["../src/figure.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,wBAAgB,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,2CAoBrD"}
1
+ {"version":3,"file":"figure.d.ts","sourceRoot":"","sources":["../src/figure.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAK/C,wBAAgB,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,2CAyBrD"}
package/dist/figure.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { SourceFileKind } from 'myst-spec-ext';
3
3
  import { DEFAULT_RENDERERS, MyST } from 'myst-to-react';
4
+ import classNames from 'classnames';
4
5
  import { OutputDecoration } from './decoration.js';
5
6
  export function Figure({ node }) {
6
7
  var _a, _b, _c, _d, _e, _f;
@@ -10,7 +11,7 @@ export function Figure({ node }) {
10
11
  if (isFromJupyer && !!output) {
11
12
  const placeholder = (_c = node.children) === null || _c === void 0 ? void 0 : _c.find((child) => child.type === 'image' && child.placeholder);
12
13
  const others = (_d = node.children) === null || _d === void 0 ? void 0 : _d.filter((child) => !(child.type === 'image' && child.placeholder));
13
- return (_jsx(OutputDecoration, { outputId: output.id, placeholder: placeholder, title: (_e = node.source) === null || _e === void 0 ? void 0 : _e.title, url: (_f = node.source) === null || _f === void 0 ? void 0 : _f.url, children: _jsx(MyST, { ast: others }) }, node.key));
14
+ return (_jsx("figure", { id: node.html_id || node.identifier || node.key, className: classNames({ subcontainer: node.subcontainer }, node.class), children: _jsx(OutputDecoration, { outputId: output.id, placeholder: placeholder, title: (_e = node.source) === null || _e === void 0 ? void 0 : _e.title, url: (_f = node.source) === null || _f === void 0 ? void 0 : _f.url, children: _jsx(MyST, { ast: others }) }, node.key) }));
14
15
  }
15
16
  return _jsx(Container, { node: node });
16
17
  }
package/dist/output.d.ts CHANGED
@@ -3,11 +3,12 @@ import type { MinifiedOutput } from 'nbtx';
3
3
  export declare const DIRECT_OUTPUT_TYPES: Set<string>;
4
4
  export declare const DIRECT_MIME_TYPES: Set<string>;
5
5
  export declare function allOutputsAreSafe(outputs: MinifiedOutput[], directOutputTypes: Set<string>, directMimeTypes: Set<string>): boolean;
6
- export declare function JupyterOutput({ outputId, identifier, data, align, }: {
6
+ export declare function JupyterOutput({ outputId, identifier, data, align, className, }: {
7
7
  outputId: string;
8
8
  identifier?: string;
9
9
  data: MinifiedOutput[];
10
10
  align?: 'left' | 'center' | 'right';
11
+ className?: string;
11
12
  }): import("react/jsx-runtime").JSX.Element;
12
13
  export declare function Output({ node }: {
13
14
  node: GenericNode;
@@ -1 +1 @@
1
- {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MA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,IAAI,EAAE,cAAc,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,2CAuCA;AAED,wBAAgB,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,2CAUrD"}
package/dist/output.js CHANGED
@@ -29,7 +29,7 @@ export function allOutputsAreSafe(outputs, directOutputTypes, directMimeTypes) {
29
29
  return flag && safe;
30
30
  }, true);
31
31
  }
32
- export function JupyterOutput({ outputId, identifier, data, align, }) {
32
+ export function JupyterOutput({ outputId, identifier, data, align, className, }) {
33
33
  const { ready } = useCellExecution(outputId);
34
34
  const outputs = data;
35
35
  const allSafe = useMemo(() => allOutputsAreSafe(outputs, DIRECT_OUTPUT_TYPES, DIRECT_MIME_TYPES), [outputs]);
@@ -51,8 +51,8 @@ export function JupyterOutput({ outputId, identifier, data, align, }) {
51
51
  'text-center': align === 'center',
52
52
  'text-right': align === 'right',
53
53
  'mb-5': outputs && outputs.length > 0,
54
- }), children: component }));
54
+ }, className), children: component }));
55
55
  }
56
56
  export function Output({ node }) {
57
- return (_jsx(JupyterOutput, { outputId: node.id, identifier: node.identifier, align: node.align, data: node.data }));
57
+ return (_jsx(JupyterOutput, { className: classNames({ hidden: node.visibility === 'remove' }), outputId: node.id, identifier: node.identifier, align: node.align, data: node.data }));
58
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myst-theme/jupyter",
3
- "version": "0.5.13",
3
+ "version": "0.5.15",
4
4
  "type": "module",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,16 +25,16 @@
25
25
  "@curvenote/ansi-to-react": "^7.0.0",
26
26
  "@headlessui/react": "^1.7.15",
27
27
  "@heroicons/react": "^2.0.18",
28
- "@myst-theme/providers": "^0.5.13",
28
+ "@myst-theme/providers": "^0.5.15",
29
29
  "@scienceicons/react": "^0.0.6",
30
30
  "buffer": "^6.0.3",
31
31
  "classnames": "^2.3.2",
32
- "myst-common": "^1.1.13",
33
- "myst-config": "^1.1.13",
34
- "myst-frontmatter": "^1.1.13",
32
+ "myst-common": "^1.1.15",
33
+ "myst-config": "^1.1.15",
34
+ "myst-frontmatter": "^1.1.15",
35
35
  "myst-spec": "^0.0.4",
36
- "myst-spec-ext": "^1.1.13",
37
- "myst-to-react": "^0.5.13",
36
+ "myst-spec-ext": "^1.1.15",
37
+ "myst-to-react": "^0.5.15",
38
38
  "nanoid": "^4.0.2",
39
39
  "nbtx": "^0.2.3",
40
40
  "react-syntax-highlighter": "^15.5.0",