@myst-theme/jupyter 0.5.22 → 0.6.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"convertImages.d.ts","sourceRoot":"","sources":["../src/convertImages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,cAAc,EAAE,MAAM,MAAM,CAAC;AA6B/D,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,cAAc,EAAE,GACxB,OAAO,CAAC,cAAc,EAAE,CAAC,CAmC3B"}
1
+ {"version":3,"file":"convertImages.d.ts","sourceRoot":"","sources":["../src/convertImages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,cAAc,EAAE,MAAM,MAAM,CAAC;AA6B/D,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,cAAc,EAAE,GACxB,OAAO,CAAC,cAAc,EAAE,CAAC,CAoC3B"}
@@ -38,7 +38,7 @@ export function fetchAndEncodeOutputImages(outputs) {
38
38
  return Promise.all(outputs.map((output) => __awaiter(this, void 0, void 0, function* () {
39
39
  if (!('data' in output))
40
40
  return output;
41
- const imageMimetypes = Object.keys(output.data).filter((mimetype) => mimetype !== 'image/svg' && mimetype.startsWith('image/'));
41
+ const imageMimetypes = Object.keys(output.data).filter((mimetype) => mimetype !== 'image/svg' && mimetype !== 'image/svg+xml' && mimetype.startsWith('image/'));
42
42
  if (imageMimetypes.length === 0)
43
43
  return output;
44
44
  // this is an async fetch, so we need to await the result
@@ -1 +1 @@
1
- {"version":3,"file":"leaf.d.ts","sourceRoot":"","sources":["../../src/execute/leaf.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAW9D,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,GAAG,EACH,QAAQ,GACT,EAA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AC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;CAC9C,kDAkBA;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,KAAK,EACL,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,QAAQ,CAAC;IACjB,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;CAC9C,QAiDA;AAED,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;CAC9C,QAmFA;AAED,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;CAC9C,QA4BA"}
@@ -4,6 +4,7 @@ import { useThebeLoader, useThebeConfig, useThebeServer } from 'thebe-react';
4
4
  import { notebookFromMdast } from './utils.js';
5
5
  import { selectAreAllNotebookScopesBuilt, selectAreAllSessionsStarted, selectNotebookForPage, } from './selectors.js';
6
6
  import { useFetchMdast } from 'myst-to-react';
7
+ import { useLoadPlotly } from '../plotly.js';
7
8
  export function MdastFetcher({ slug, url, dispatch, }) {
8
9
  const { data, error } = useFetchMdast({ remote: true, dataUrl: `${url}.json` });
9
10
  useEffect(() => {
@@ -22,13 +23,16 @@ export function NotebookBuilder({ pageSlug, notebookSlug, idkmap, state, dispatc
22
23
  const { config } = useThebeConfig();
23
24
  const lock = useRef(false); // TODO can be removed if we solve double render from provider
24
25
  const scopeHasNotebook = !!((_a = state.pages[pageSlug]) === null || _a === void 0 ? void 0 : _a.scopes[notebookSlug]);
26
+ const { plotly } = useLoadPlotly();
25
27
  useEffect(() => {
26
28
  var _a;
27
- if (!core || !config || scopeHasNotebook || lock.current)
29
+ if (!core || !config || !plotly || scopeHasNotebook || lock.current)
28
30
  return;
29
31
  lock.current = true;
30
32
  console.debug(`Jupyter: NotebookBuilder - ${notebookSlug} being added to scope ${pageSlug}`);
31
33
  const rendermime = core === null || core === void 0 ? void 0 : core.makeRenderMimeRegistry(config === null || config === void 0 ? void 0 : config.mathjax);
34
+ if (plotly)
35
+ rendermime.addFactory(plotly.rendererFactory, 41);
32
36
  const notebook = notebookFromMdast(core, config, pageSlug, notebookSlug, state.mdast[notebookSlug].root, idkmap, rendermime);
33
37
  // hook up computable targets
34
38
  const computables = (_a = state.pages[pageSlug]) === null || _a === void 0 ? void 0 : _a.computables;
@@ -42,10 +46,10 @@ export function NotebookBuilder({ pageSlug, notebookSlug, idkmap, state, dispatc
42
46
  type: 'ADD_NOTEBOOK',
43
47
  payload: { pageSlug, notebookSlug, rendermime, notebook },
44
48
  });
45
- }, [core, config, pageSlug, notebookSlug, scopeHasNotebook, lock]);
49
+ }, [core, config, pageSlug, notebookSlug, scopeHasNotebook, lock, plotly]);
46
50
  // TODO find a way to check if the all the notebooks are built and do a single dispatch
47
51
  // potentilly use a move the loop down into this component
48
- const allNotebooksAreBuilt = selectAreAllNotebookScopesBuilt(state, pageSlug);
52
+ const allNotebooksAreBuilt = plotly && selectAreAllNotebookScopesBuilt(state, pageSlug);
49
53
  useEffect(() => {
50
54
  if (!allNotebooksAreBuilt)
51
55
  return;
@@ -60,7 +64,7 @@ export function SessionStarter({ pageSlug, notebookSlug, location, state, dispat
60
64
  const lock = useRef(false); // TODO can be removed if we solve double render from provider
61
65
  const scope = (_a = state.pages[pageSlug]) === null || _a === void 0 ? void 0 : _a.scopes[notebookSlug];
62
66
  useEffect(() => {
63
- if (!core || !server || scope.session || lock.current)
67
+ if (!core || !server || (scope === null || scope === void 0 ? void 0 : scope.session) || lock.current)
64
68
  return;
65
69
  lock.current = true;
66
70
  console.debug(`Jupyter: Starting session for ${pageSlug}-${notebookSlug} at ${location}`);
@@ -117,7 +121,7 @@ export function SessionStarter({ pageSlug, notebookSlug, location, state, dispat
117
121
  });
118
122
  }
119
123
  });
120
- }, [core, config, pageSlug, notebookSlug, lock]);
124
+ }, [core, config, scope, pageSlug, notebookSlug, lock]);
121
125
  // TODO avoid multiple dispatch?
122
126
  const allSessionsAreStarted = selectAreAllSessionsStarted(state, pageSlug);
123
127
  useEffect(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"jupyter.d.ts","sourceRoot":"","sources":["../src/jupyter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAsF3C,eAAO,MAAM,cAAc;QACD,MAAM;aAAW,cAAc,EAAE;8CAwD1D,CAAC"}
1
+ {"version":3,"file":"jupyter.d.ts","sourceRoot":"","sources":["../src/jupyter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AA4F3C,eAAO,MAAM,cAAc;QACD,MAAM;aAAW,cAAc,EAAE;8CAwD1D,CAAC"}
package/dist/jupyter.js CHANGED
@@ -10,6 +10,7 @@ import { useCellExecution } from './execute/index.js';
10
10
  import { usePlaceholder } from './decoration.js';
11
11
  import { MyST } from 'myst-to-react';
12
12
  import classNames from 'classnames';
13
+ import { usePlotlyPassively } from './plotly.js';
13
14
  function ActiveOutputRenderer({ id, initialData, core, }) {
14
15
  var _a;
15
16
  const exec = useCellExecution(id);
@@ -37,15 +38,18 @@ function ActiveOutputRenderer({ id, initialData, core, }) {
37
38
  return (_jsxs("div", { children: [_jsx("div", { ref: ref, "data-thebe-active-ref": "true", className: classNames('relative', { 'invisible h-0': !executed && placeholder }) }), placeholder && !executed && _jsx(MyST, { ast: placeholder })] }));
38
39
  }
39
40
  function PassiveOutputRenderer({ id, data, core, }) {
40
- const cell = useRef(new core.PassiveCellRenderer(id, undefined, undefined));
41
+ const rendermime = core.makeRenderMimeRegistry();
42
+ const cell = useRef(new core.PassiveCellRenderer(id, rendermime, undefined));
41
43
  const ref = useRef(null);
44
+ const { loaded } = usePlotlyPassively(rendermime, data);
42
45
  useEffect(() => {
43
- var _a;
44
- if (!ref.current)
46
+ var _a, _b;
47
+ if (!ref.current || !loaded)
45
48
  return;
46
- cell.current.attachToDOM(ref.current, true);
47
- cell.current.render((_a = core === null || core === void 0 ? void 0 : core.stripWidgets(data)) !== null && _a !== void 0 ? _a : data);
48
- }, [ref]);
49
+ // eslint-disable-next-line import/no-extraneous-dependencies
50
+ cell.current.attachToDOM((_a = ref.current) !== null && _a !== void 0 ? _a : undefined, true);
51
+ cell.current.render((_b = core === null || core === void 0 ? void 0 : core.stripWidgets(data)) !== null && _b !== void 0 ? _b : data);
52
+ }, [ref, loaded]);
49
53
  return _jsx("div", { ref: ref, "data-thebe-passive-ref": "true" });
50
54
  }
51
55
  export const JupyterOutputs = React.memo(({ id, outputs }) => {
@@ -0,0 +1,12 @@
1
+ import type { IRenderMime, IRenderMimeRegistry } from '@jupyterlab/rendermime';
2
+ import type { IOutput } from '@jupyterlab/nbformat';
3
+ export declare function useLoadPlotly(): {
4
+ plotly: {
5
+ rendererFactory: IRenderMime.IRendererFactory;
6
+ } | undefined;
7
+ };
8
+ export declare function isPlotly(outputs: IOutput[]): boolean;
9
+ export declare function usePlotlyPassively(rendermime: IRenderMimeRegistry, outputs: IOutput[]): {
10
+ loaded: boolean;
11
+ };
12
+ //# sourceMappingURL=plotly.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plotly.d.ts","sourceRoot":"","sources":["../src/plotly.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,wBAAgB,aAAa;;yBAEN,YAAY,gBAAgB;;EAiBlD;AAID,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,WAE1C;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,EAAE;;EAoBrF"}
package/dist/plotly.js ADDED
@@ -0,0 +1,38 @@
1
+ import { useEffect, useState } from 'react';
2
+ export function useLoadPlotly() {
3
+ const [plotly, setPlotly] = useState();
4
+ useEffect(() => {
5
+ if (plotly)
6
+ return;
7
+ // eslint-disable-next-line import/no-extraneous-dependencies
8
+ import('jupyterlab-plotly/lib/plotly-renderer.js').then((module) => {
9
+ console.debug('Jupyter: Adding plotly renderer factory to rendermime registry', {
10
+ module,
11
+ });
12
+ setPlotly(module);
13
+ });
14
+ }, [plotly]);
15
+ return { plotly };
16
+ }
17
+ const PLOTLY_MIMETYPE = 'application/vnd.plotly.v1+json';
18
+ export function isPlotly(outputs) {
19
+ return outputs.some((output) => { var _a; return Object.keys((_a = output.data) !== null && _a !== void 0 ? _a : []).includes(PLOTLY_MIMETYPE); });
20
+ }
21
+ export function usePlotlyPassively(rendermime, outputs) {
22
+ const isPlotlyOutput = isPlotly(outputs);
23
+ // skip loading for non plotly outputs
24
+ const [loaded, setLoaded] = useState(!isPlotlyOutput);
25
+ useEffect(() => {
26
+ if (loaded || !isPlotlyOutput)
27
+ return;
28
+ // eslint-disable-next-line import/no-extraneous-dependencies
29
+ import('jupyterlab-plotly/lib/plotly-renderer.js').then((module) => {
30
+ console.debug('Jupyter: Adding plotly renderer factory to rendermime registry', {
31
+ module,
32
+ });
33
+ rendermime.addFactory(module.rendererFactory, 41);
34
+ setLoaded(true);
35
+ });
36
+ }, [loaded, isPlotlyOutput]);
37
+ return { loaded };
38
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myst-theme/jupyter",
3
- "version": "0.5.22",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,16 +25,17 @@
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.22",
28
+ "@myst-theme/providers": "^0.6.1",
29
29
  "@scienceicons/react": "^0.0.6",
30
30
  "buffer": "^6.0.3",
31
31
  "classnames": "^2.3.2",
32
+ "jupyterlab-plotly": "^5.18.0",
32
33
  "myst-common": "^1.1.18",
33
34
  "myst-config": "^1.1.18",
34
35
  "myst-frontmatter": "^1.1.18",
35
36
  "myst-spec": "^0.0.4",
36
37
  "myst-spec-ext": "^1.1.18",
37
- "myst-to-react": "^0.5.22",
38
+ "myst-to-react": "^0.6.1",
38
39
  "nanoid": "^4.0.2",
39
40
  "nbtx": "^0.2.3",
40
41
  "react-syntax-highlighter": "^15.5.0",
@@ -49,6 +50,5 @@
49
50
  "@types/react-dom": "^16.8 || ^17.0 || ^18.0",
50
51
  "react": "^16.8 || ^17.0 || ^18.0",
51
52
  "react-dom": "^16.8 || ^17.0 || ^18.0"
52
- },
53
- "devDependencies": {}
53
+ }
54
54
  }