Skip to content

Commit

Permalink
wip: fixed for 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed May 16, 2023
1 parent 5089cc3 commit 696e3fd
Show file tree
Hide file tree
Showing 7 changed files with 12,663 additions and 23 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@
"watch:src": "tsc -w"
},
"dependencies": {
"@jupyterlab/application": "^4.0.0-rc.1",
"@jupyterlab/codeeditor": "^4.0.0-rc.1",
"@jupyterlab/notebook": "^4.0.0-rc.1",
"@jupyterlab/rendermime": "^4.0.0-rc.1",
"@jupyterlab/translation": "^4.0.0-rc.1",
"@jupyterlab/application": "^4.0.0",
"@jupyterlab/codeeditor": "^4.0.0",
"@jupyterlab/notebook": "^4.0.0",
"@jupyterlab/rendermime": "^4.0.0",
"@jupyterlab/translation": "^4.0.0",
"@myst-theme/diagrams": "^0.2.6",
"@myst-theme/frontmatter": "^0.2.6",
"@myst-theme/providers": "^0.2.6",
"katex": "^0.15.2",
"myst-ext-card": "^0.0.7",
"myst-ext-grid": "^0.0.7",
"myst-ext-tabs": "^0.0.7",
"myst-ext-proof": "^0.0.2",
"myst-ext-tabs": "^0.0.7",
"myst-frontmatter": "^0.0.13",
"myst-parser": "^0.0.30",
"myst-to-react": "^0.2.6",
Expand All @@ -79,8 +79,8 @@
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@jupyterlab/builder": "^4.0.0-beta.0",
"@jupyterlab/testutils": "^4.0.0-beta.0",
"@jupyterlab/builder": "^4.0.0",
"@jupyterlab/testutils": "^4.0.0",
"@myst-theme/styles": "^0.2.6",
"@tailwindcss/typography": "^0.5.8",
"@types/jest": "^29.2.0",
Expand All @@ -99,7 +99,7 @@
"npm-run-all": "^4.1.5",
"prettier": "^2.8.7",
"rimraf": "^4.4.1",
"source-map-loader": "^1.0.2",
"source-map-loader": "^4.0.1",
"style-loader": "^3.3.1",
"stylelint": "^14.9.1",
"stylelint-config-prettier": "^9.0.4",
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling>=1.5.0", "jupyterlab>=4.0.0b0,<5", "hatch-nodejs-version"]
requires = ["hatchling>=1.5.0", "jupyterlab>=4.0.0,<5", "hatch-nodejs-version"]
build-backend = "hatchling.build"

[project]
Expand Down Expand Up @@ -78,7 +78,7 @@ version_cmd = "hatch version"

[tool.jupyter-releaser.hooks]
before-build-npm = [
"python -m pip install 'jupyterlab>=4.0.0b0,<5'",
"python -m pip install 'jupyterlab>=4.0.0,<5'",
"jlpm",
"jlpm build:prod"
]
Expand Down
2 changes: 1 addition & 1 deletion src/MySTContentFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NotebookPanel } from '@jupyterlab/notebook';
import { MySTMarkdownCell } from './MySTMarkdownCell';

export class MySTContentFactory extends NotebookPanel.ContentFactory {
createMarkdownCell(options: MarkdownCell.IOptions): MarkdownCell {
createMarkdownCell(options: MarkdownCell.IOptions): MySTMarkdownCell {
if (!options.contentFactory) {
options.contentFactory = this;
}
Expand Down
8 changes: 6 additions & 2 deletions src/MySTMarkdownCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { selectAll } from 'unist-util-select';
import { PromiseDelegate } from '@lumino/coreutils';
import { JupyterCellProvider } from './JupyterCellProvider';
import { ObservableValue } from '@jupyterlab/observables';
import { CellModel } from '@jupyterlab/cells/src/model';
import { CellModel, MarkdownCellModel } from '@jupyterlab/cells';

export class MySTMarkdownCell
extends MarkdownCell
Expand All @@ -41,11 +41,13 @@ export class MySTMarkdownCell

// Listen for changes to the cell trust
// TODO: Fix this ugly hack upstream!
const concreteModel: CellModel = this.model as unknown as CellModel;
const concreteModel: MarkdownCellModel = this
.model as unknown as MarkdownCellModel;
concreteModel.onTrustedChanged = (
trusted: CellModel,
args: ObservableValue.IChangedArgs
) => {
console.log('trust changed', this.model.trusted);
this.mystRender();
};
}
Expand All @@ -55,6 +57,7 @@ export class MySTMarkdownCell
// Create the node if it does not exist
const node = document.createElement('div');
this.myst = { node };
console.debug('Created MyST node for cell');
}

this._doneRendering = new PromiseDelegate<void>();
Expand Down Expand Up @@ -90,6 +93,7 @@ export class MySTMarkdownCell
}

mystRender(): void {
console.log('Rendering MyST cell into', this.node);
const notebook = this.parent as StaticNotebook & {
myst: { frontmatter: PageFrontmatter; references: References };
};
Expand Down
10 changes: 4 additions & 6 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ export async function executeUserExpressions(
await future.done;
}

export function notebookExecuted(
export async function notebookCellExecuted(
notebook: Notebook,
cell: Cell,
tracker: INotebookTracker
): void {
): Promise<void> {
// Find the Notebook panel
const panel = tracker.find((w: NotebookPanel) => {
return w.content === notebook;
Expand All @@ -120,9 +120,7 @@ export function notebookExecuted(
if (!isMarkdownCell(cell)) {
return;
}
console.debug(
`Markdown cell ${cell.model.id} was executed, waiting for render to complete ...`
);
console.debug(`Markdown cell ${cell.model.id} was executed`);

cell.doneRendering?.then(() => executeUserExpressions(cell, ctx));
await executeUserExpressions(cell, ctx);
}
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ITranslator } from '@jupyterlab/translation';
import { LabIcon } from '@jupyterlab/ui-components';

import mystIconSvg from '../style/mystlogo.svg';
import { notebookExecuted } from './actions';
import { notebookCellExecuted } from './actions';

const mystIcon = new LabIcon({
name: 'myst-notebook-extension:mystIcon',
Expand Down Expand Up @@ -134,9 +134,9 @@ const executor: JupyterFrontEndPlugin<void> = {
console.log('Using jupyterlab-myst:executor');

NotebookActions.executed.connect(
(sender: any, value: { notebook: Notebook; cell: Cell }) => {
async (sender: any, value: { notebook: Notebook; cell: Cell }) => {
const { notebook, cell } = value;
notebookExecuted(notebook, cell, tracker);
await notebookCellExecuted(notebook, cell, tracker);
}
);

Expand Down
Loading

0 comments on commit 696e3fd

Please sign in to comment.