-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Rowan Cockett <[email protected]>
- Loading branch information
Showing
28 changed files
with
321 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@myst-theme/site': patch | ||
--- | ||
|
||
Remove unused function `isACodeCell` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@myst-theme/site': patch | ||
--- | ||
|
||
Remove deprecated `ArticlePage` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@myst-theme/site': patch | ||
--- | ||
|
||
Remove dependence on `@myst-theme/jupyter` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
'@myst-theme/site': minor | ||
'myst-to-react': patch | ||
'myst-demo': patch | ||
'@myst-theme/providers': patch | ||
'@myst-theme/diagrams': patch | ||
'@myst-theme/article': patch | ||
'@myst-theme/book': patch | ||
--- | ||
|
||
Move ContentBlocks to MyST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@myst-theme/providers': patch | ||
--- | ||
|
||
Move `ReferencesProvider` to `ArticleProvider` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { Details, MyST } from 'myst-to-react'; | ||
import { SourceFileKind } from 'myst-spec-ext'; | ||
import type { GenericParent } from 'myst-common'; | ||
import classNames from 'classnames'; | ||
import { | ||
NotebookClearCell, | ||
NotebookRunCell, | ||
NotebookRunCellSpinnerOnly, | ||
} from './controls/index.js'; | ||
import { useGridSystemProvider, usePageKind } from '@myst-theme/providers'; | ||
import type { NodeRenderers, NodeRenderer } from '@myst-theme/providers'; | ||
|
||
export function NotebookBlock({ | ||
id, | ||
node, | ||
className, | ||
}: { | ||
id: string; | ||
node: GenericParent; | ||
className?: string; | ||
}) { | ||
const pageKind = usePageKind(); | ||
const grid = useGridSystemProvider(); | ||
const subGrid = node.visibility === 'hide' ? '' : `${grid} subgrid-gap col-screen`; | ||
const dataClassName = typeof node.data?.class === 'string' ? node.data?.class : undefined; | ||
// Hide the subgrid if either the dataClass or the className exists and includes `col-` | ||
const noSubGrid = | ||
(dataClassName && dataClassName.includes('col-')) || (className && className.includes('col-')); | ||
const block = ( | ||
<div | ||
key={`block-${id}`} | ||
id={id} | ||
className={classNames('relative group/block', className, dataClassName, { | ||
[subGrid]: !noSubGrid, | ||
hidden: node.visibility === 'remove', | ||
})} | ||
> | ||
{pageKind === SourceFileKind.Notebook && node.kind === 'notebook-code' && ( | ||
<> | ||
<div className="flex sticky top-[80px] z-10 opacity-70 group-hover/block:opacity-100 group-hover/block:hidden"> | ||
<div className="absolute top-0 -right-[28px] flex md:flex-col"> | ||
<NotebookRunCellSpinnerOnly id={id} /> | ||
</div> | ||
</div> | ||
<div className="hidden sticky top-[80px] z-10 opacity-70 group-hover/block:opacity-100 group-hover/block:flex"> | ||
<div className="absolute top-0 -right-[28px] flex md:flex-col"> | ||
<NotebookRunCell id={id} /> | ||
<NotebookClearCell id={id} /> | ||
</div> | ||
</div> | ||
</> | ||
)} | ||
<MyST ast={node.children} /> | ||
</div> | ||
); | ||
if (node.visibility === 'hide') { | ||
return <Details title="Notebook Cell">{block}</Details>; | ||
} | ||
return block; | ||
} | ||
|
||
export const NotebookBlockRenderer: NodeRenderer = ({ node, className }) => { | ||
return ( | ||
<NotebookBlock | ||
key={node.key} | ||
id={node.key} | ||
node={node} | ||
className={classNames(node.class, className)} | ||
/> | ||
); | ||
}; | ||
|
||
/** | ||
* The logic for the selector is complex: | ||
* | ||
* - MD files have `notebook-code` and otherwise blocks with no kind. | ||
* - IPyNB files have both `notebook-code` and `notebook-content` blocks. | ||
* - An article may contain `notebook-code` blocks from the `code-cell` directive even though it is not considered a notebook (i.e., no frontmatter kernelspec). | ||
* | ||
* This component therefore only renders for `code-cells` (both ipynb and .md) and `content-cells` (ipynb). | ||
* | ||
* The benefit of this is that we can use the block-kind to figure out if e.g. the cell is executable. | ||
*/ | ||
export const NOTEBOOK_BLOCK_RENDERERS: NodeRenderers = { | ||
block: { | ||
'block[kind=notebook-code],block[kind=notebook-content]': NotebookBlockRenderer, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Embed } from './embed.js'; | ||
import { Output } from './output.js'; | ||
import { Figure } from './figure.js'; | ||
import { mergeRenderers } from '@myst-theme/providers'; | ||
import { NOTEBOOK_BLOCK_RENDERERS } from './block.js'; | ||
|
||
export { NOTEBOOK_BLOCK_RENDERERS } from './block.js'; | ||
export const OUTPUT_RENDERERS = { | ||
output: Output, | ||
embed: Embed, | ||
container: Figure, | ||
}; | ||
export const JUPYTER_RENDERERS = mergeRenderers([OUTPUT_RENDERERS, NOTEBOOK_BLOCK_RENDERERS]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Details } from './dropdown.js'; | ||
import { MyST } from './MyST.js'; | ||
import type { GenericParent } from 'myst-common'; | ||
import classNames from 'classnames'; | ||
import { useGridSystemProvider } from '@myst-theme/providers'; | ||
import type { NodeRenderer } from '@myst-theme/providers'; | ||
|
||
export function Block({ | ||
id, | ||
node, | ||
className, | ||
}: { | ||
id: string; | ||
node: GenericParent; | ||
className?: string; | ||
}) { | ||
const grid = useGridSystemProvider(); | ||
const subGrid = node.visibility === 'hide' ? '' : `${grid} subgrid-gap col-screen`; | ||
const dataClassName = typeof node.data?.class === 'string' ? node.data?.class : undefined; | ||
// Hide the subgrid if either the dataClass or the className exists and includes `col-` | ||
const noSubGrid = | ||
(dataClassName && dataClassName.includes('col-')) || (className && className.includes('col-')); | ||
const block = ( | ||
<div | ||
key={`block-${id}`} | ||
id={id} | ||
className={classNames('relative group/block', className, dataClassName, { | ||
[subGrid]: !noSubGrid, | ||
hidden: node.visibility === 'remove', | ||
})} | ||
> | ||
<MyST ast={node.children} /> | ||
</div> | ||
); | ||
if (node.visibility === 'hide') { | ||
return <Details title="Block">{block}</Details>; | ||
} | ||
return block; | ||
} | ||
|
||
export const BlockRenderer: NodeRenderer = ({ node, className }) => { | ||
return ( | ||
<Block key={node.key} id={node.key} node={node} className={classNames(node.class, className)} /> | ||
); | ||
}; | ||
|
||
const BLOCK_RENDERERS: Record<string, NodeRenderer> = { | ||
block: BlockRenderer, | ||
}; | ||
|
||
export default BLOCK_RENDERERS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { useContext } from 'react'; | ||
import type { References } from 'myst-common'; | ||
import type { PageLoader } from '@myst-theme/common'; | ||
import { SourceFileKind } from 'myst-spec-ext'; | ||
|
||
const ArticleContext = React.createContext<{ | ||
kind?: SourceFileKind; | ||
frontmatter?: PageLoader['frontmatter']; | ||
references?: References; | ||
}>({}); | ||
|
||
export function ArticleProvider({ | ||
kind, | ||
references, | ||
frontmatter, | ||
children, | ||
}: { | ||
kind: SourceFileKind; | ||
frontmatter?: PageLoader['frontmatter']; | ||
references?: References; | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<ArticleContext.Provider value={{ kind, references, frontmatter }}> | ||
{children} | ||
</ArticleContext.Provider> | ||
); | ||
} | ||
|
||
export function useReferences() { | ||
const data = useContext(ArticleContext); | ||
return data?.references; | ||
} | ||
|
||
export function useFrontmatter() { | ||
const data = useContext(ArticleContext); | ||
return data?.frontmatter; | ||
} | ||
|
||
export function usePageKind() { | ||
const data = useContext(ArticleContext); | ||
return data?.kind ?? SourceFileKind.Article; | ||
} | ||
|
||
/** | ||
* @deprecated This component is not maintained, in favor of the reworked `ArticleProvider` component | ||
*/ | ||
export function ReferencesProvider({ | ||
references, | ||
frontmatter, | ||
children, | ||
}: { | ||
frontmatter?: PageLoader['frontmatter']; | ||
references?: References; | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<ArticleContext.Provider value={{ references, frontmatter }}> | ||
{children} | ||
</ArticleContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.