Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: CRA and Next.js examples #340

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
mamba-version: "*"
channels: conda-forge,defaults
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/slate/package.json → attic/slate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"@datalayer/icons-react": "^0.3.2",
"@datalayer/jupyter-react": "^0.15.0",
"@datalayer/primer-addons": "^0.3.1",
"@datalayer/primer-addons": "^0.3.2",
"@emotion/css": "^11.1.3",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@docusaurus/theme-live-codeblock": "3.5.2",
"@docusaurus/theme-mermaid": "3.5.2",
"@mdx-js/react": "^3.0.1",
"@primer/react-brand": "0.37.0-rc.ab1bfc11",
"@primer/react-brand": "^0.44.1",
"clsx": "^2.1.1",
"docusaurus-lunr-search": "3.5.0",
"docusaurus-plugin-typedoc": "~0.17.5",
Expand Down
2 changes: 1 addition & 1 deletion examples/cra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"@datalayer/icons-react": "^0.3.2",
"@datalayer/jupyter-react": "^0.15.0",
"@datalayer/primer-addons": "^0.3.1",
"@datalayer/primer-addons": "^0.3.2",
"jupyterlab-plotly": "^5.17.0",
"plotly.js": "^2.26.2",
"react": "^18.2.0",
Expand Down
16 changes: 8 additions & 8 deletions examples/cra/src/examples/AllExamples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ ax2.set_xlabel('time (s)')
ax2.set_ylabel('Undamped')
plt.show()`;

const NOTEBOOK_UID = 'notebook-uid-1';
const CELL_ID = 'cell-id-1';

const NOTEBOOK_ID = 'notebook-id-1';

/**
* A simple example for the Jupyter UI.
Expand Down Expand Up @@ -99,8 +101,8 @@ const AllExample = () => {
"print('=> Hello Datalayer again... I am the output of an non-shown editor 👍 <=')"
}
/>
<CellToolbar />
<Cell source={source} />
<CellToolbar cellId={CELL_ID} />
<Cell id={CELL_ID} source={source} />
<CommandsToolbar />
<Commands />
<ConsoleToolbar />
Expand All @@ -110,12 +112,10 @@ const AllExample = () => {
<Dialog />
*/}
<FileBrowserToolbar />
<FileBrowser />
{serviceManager && <FileBrowser serviceManager={serviceManager}/> }
<FileManagerJupyterLab />
<NotebookToolbar notebookId={NOTEBOOK_UID} />
<Notebook
uid={NOTEBOOK_UID} path="ping.ipynb"
/>
<NotebookToolbar notebookId={NOTEBOOK_ID} />
<Notebook id={NOTEBOOK_ID} path="ping.ipynb"/>
<SettingsToolbar />
<Settings />
<LuminoComponent />
Expand Down
28 changes: 17 additions & 11 deletions examples/cra/src/examples/FileBrowserExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@
* MIT License
*/

import {render} from 'react-dom';
import {Jupyter, FileBrowser, FileManagerJupyterLab} from '@datalayer/jupyter-react';
import { createRoot } from 'react-dom/client';
import { FileBrowser, useJupyter, JupyterReactTheme } from '@datalayer/jupyter-react';
import Layers from './../layout/Layers';

import './../App.css';

const FileBrowserExample = () => {
const { serviceManager } = useJupyter();
return (
serviceManager
? <FileBrowser serviceManager={serviceManager}/>
: <></>
)
}

const div = document.createElement('div');
document.body.appendChild(div);
const root = createRoot(div);

render(
<Jupyter collaborative={false} terminals={false}>
<Layers />
<Jupyter collaborative={false} terminals={true}>
<FileBrowser />
<FileManagerJupyterLab />
</Jupyter>
</Jupyter>,
div
root.render(
<JupyterReactTheme>
<Layers/>
<FileBrowserExample />
</JupyterReactTheme>
);
14 changes: 8 additions & 6 deletions examples/cra/src/examples/GalleryExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ const OUTPUTS: IOutput[] = [
},
];

const NOTEBOOK_UID = 'notebook-id-gallery';
const CELL_ID = 'cell-id-gallery';

const NOTEBOOK_ID = 'notebook-id-gallery';

const GalleryExample = () => {
const [tab, setTab] = useState('Notebook');
Expand Down Expand Up @@ -221,18 +223,18 @@ const GalleryExample = () => {
<Box>
{tab === 'Notebook' && (
<>
<NotebookToolbarSimple notebookId={NOTEBOOK_UID} />
<NotebookToolbarSimple notebookId={NOTEBOOK_ID} />
<Notebook
uid={NOTEBOOK_UID}
id={NOTEBOOK_ID}
path="ping.ipynb"
CellSidebar={CellSidebar}
/>
</>
)}
{tab === 'Cell' && (
<>
<CellToolbar />
<Cell source={SOURCE} />
<CellToolbar cellId={CELL_ID} />
<Cell id={CELL_ID} source={SOURCE} />
</>
)}
{tab === 'LabApp' && (
Expand Down Expand Up @@ -288,7 +290,7 @@ const GalleryExample = () => {
<FileBrowserToolbar />
<Box display="flex">
<Box sx={{width: 400}}>
<FileBrowser />
{serviceManager && <FileBrowser serviceManager={serviceManager}/> }
</Box>
<Box ml={3} sx={{width: 400}}>
<FileManagerJupyterLab />
Expand Down
2 changes: 1 addition & 1 deletion examples/cra/src/examples/NotebookExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Example = () => {
<Jupyter collaborative={false} terminals={false}>
<Layers />
<NotebookSimpleToolbar notebookId={NOTEBOOK_UID} />
<Notebook uid={NOTEBOOK_UID} path="ping.ipynb" />
<Notebook id={NOTEBOOK_UID} path="ping.ipynb" />
</Jupyter>
);
};
Expand Down
2 changes: 1 addition & 1 deletion examples/cra/src/examples/NotebookSidebarExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function NotebookSidebarComponent() {
<NotebookToolbar notebookId={NOTEBOOK_UID} />
<Notebook
path="ping.ipynb"
uid={NOTEBOOK_UID}
id={NOTEBOOK_UID}
CellSidebar={CellSidebar}
/>
</Box>
Expand Down
10 changes: 6 additions & 4 deletions examples/cra/src/examples/cell/CellComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import { useCellsStore, Cell } from "@datalayer/jupyter-react";
import CellToolbar from './CellToolbar';

const CELL_ID = "cell-id-1"

const SOURCE_EXAMPLE = `"""
import ipywidgets as widgets
widgets.IntSlider(
Expand Down Expand Up @@ -39,9 +41,9 @@ const CellPreview = () => {
const cellStore = useCellsStore();
return (
<>
<div>source: {cellStore.source}</div>
<div>source: {cellStore.getSource(CELL_ID)}</div>
<br/>
<div>kernel available: {String(cellStore.kernelAvailable)}</div>
<div>kernel available: {String(cellStore.isKernelSessionAvailable)}</div>
<br/>
</>
)
Expand All @@ -50,8 +52,8 @@ const CellPreview = () => {
const CellComponents = () => (
<>
<CellPreview/>
<CellToolbar />
<Cell source={SOURCE_EXAMPLE} />
<CellToolbar cellId={CELL_ID} />
<Cell id={CELL_ID} source={SOURCE_EXAMPLE} />
</>
)

Expand Down
7 changes: 4 additions & 3 deletions examples/cra/src/examples/cell/CellToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { Box, IconButton, Text, Tooltip } from '@primer/react';
import { PlayIcon, ReplyIcon, ThreeBarsIcon } from '@primer/octicons-react';
import { useCellsStore } from '@datalayer/jupyter-react';

const CellToolbar: React.FC = () => {
const CellToolbar = (props: {cellId: string}) => {
const { cellId } = props;
const cellStore = useCellsStore();
const outputsCount = cellStore.outputsCount;
const outputsCount = cellStore.getOutputsCount(cellId);
return (
<>
<Text as="h3">Cell Example</Text>
Expand Down Expand Up @@ -44,7 +45,7 @@ const CellToolbar: React.FC = () => {
variant="invisible"
icon={ReplyIcon}
aria-label="Rest the outputcount"
onClick={() => cellStore.setOutputsCount(0)}
onClick={() => cellStore.setOutputsCount(cellId, 0)}
/>
</Tooltip>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion examples/cra/src/examples/labapp/JupyterLabHeadlessApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const JupyterLabHeadlessAppExample = () => {
}
return (
<>
<Jupyter startDefaultKernel={false} disableCssLoading={true} colorMode="light">
<Jupyter startDefaultKernel={false} disableCssLoading={true} colormode="light">
{ boxPanel &&
<div style={{ position: "relative" }}>
<Box className="jp-LabShell"
Expand Down
8 changes: 4 additions & 4 deletions examples/cra/src/examples/notebook/NotebookToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const NotebookToolbar = (props: {notebookId: string}) => {
onClick={e => {
e.preventDefault();
notebookStore.insertBelow({
uid: notebookId,
id: notebookId,
cellType: 'raw',
});
}}
Expand All @@ -60,7 +60,7 @@ const NotebookToolbar = (props: {notebookId: string}) => {
onClick={e => {
e.preventDefault();
notebookStore.insertBelow({
uid: notebookId,
id: notebookId,
cellType: 'markdown',
});
}}
Expand All @@ -74,7 +74,7 @@ const NotebookToolbar = (props: {notebookId: string}) => {
onClick={e => {
e.preventDefault();
notebookStore.insertBelow({
uid: notebookId,
id: notebookId,
cellType: 'code',
});
}}
Expand Down Expand Up @@ -116,7 +116,7 @@ const NotebookToolbar = (props: {notebookId: string}) => {
leadingVisual={FileIcon}
onClick={() =>
notebookStore.save({
uid: notebookId,
id: notebookId,
date: new Date(),
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const NotebookToolbarSimple = (props: {notebookId: string}) => {
variant="invisible"
icon={FileIcon}
aria-label="Save"
onClick={() => notebookStore.save({uid: notebookId, date: new Date()}) }
onClick={() => notebookStore.save({id: notebookId, date: new Date()}) }
/>
</Tooltip>
</Box>
Expand Down
24 changes: 12 additions & 12 deletions examples/cra/src/examples/notebook/cell/CellSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import { useState } from 'react';
import { PanelLayout } from '@lumino/widgets';
import { ActionMenu, Button, Box } from "@primer/react";
import { ChevronRightIcon, XIcon, ChevronUpIcon, ChevronDownIcon, SquareIcon } from "@primer/octicons-react";
import { useNotebookStore, CellSidebarProps, CellMetadataEditor, DATALAYER_CELL_HEADER_CLASS } from '@datalayer/jupyter-react';
import { useNotebookStore, ICellSidebarProps, CellMetadataEditor, DATALAYER_CELL_SIDEBAR_CLASS_NAME } from '@datalayer/jupyter-react';

export const CellSidebar = (props: CellSidebarProps) => {
export const CellSidebar = (props: ICellSidebarProps) => {
const [visible, setVisible] = useState(false);
const { notebookId, cellId, nbgrader } = props;
const { notebookId, cellNodeId, nbgrader } = props;
const notebookStore = useNotebookStore();
const activeCell = notebookStore.selectActiveCell(notebookId);
const layout = (activeCell?.layout);
if (layout) {
const cellWidget = (layout as PanelLayout).widgets[0];
if (!visible && (cellWidget?.node.id === cellId)) {
if (!visible && (cellWidget?.node.id === cellNodeId)) {
setVisible(true);
}
if (visible && (cellWidget?.node.id !== cellId)) {
if (visible && (cellWidget?.node.id !== cellNodeId)) {
setVisible(false);
}
}
Expand All @@ -31,7 +31,7 @@ export const CellSidebar = (props: CellSidebarProps) => {
return (
activeCell ?
<Box
className={DATALAYER_CELL_HEADER_CLASS}
className={DATALAYER_CELL_SIDEBAR_CLASS_NAME}
sx={{
'& p': {
marginBottom: '0 !important',
Expand All @@ -49,15 +49,15 @@ export const CellSidebar = (props: CellSidebarProps) => {
<span style={{ display: "flex" }}>
<Button leadingVisual={ChevronUpIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
notebookStore.insertAbove({ uid: notebookId, cellType: "code" });
notebookStore.insertAbove({ id: notebookId, cellType: "code" });
}}>
Code
</Button>
</span>
<span style={{ display: "flex" }}>
<Button leadingVisual={ChevronUpIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
notebookStore.insertAbove({ uid: notebookId, cellType: "markdown" });
notebookStore.insertAbove({ id: notebookId, cellType: "markdown" });
}}>
Markdown
</Button>
Expand All @@ -66,14 +66,14 @@ export const CellSidebar = (props: CellSidebarProps) => {
{ activeCell.model.type === "code" ?
<Button leadingVisual={SquareIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
notebookStore.changeCellType({ uid: notebookId, cellType: "markdown" });
notebookStore.changeCellType({ id: notebookId, cellType: "markdown" });
}}>
To Mardown
</Button>
:
<Button leadingVisual={SquareIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
notebookStore.changeCellType({ uid: notebookId, cellType: "code" });
notebookStore.changeCellType({ id: notebookId, cellType: "code" });
}}>
To Code
</Button>
Expand All @@ -82,15 +82,15 @@ export const CellSidebar = (props: CellSidebarProps) => {
<span style={{ display: "flex" }}>
<Button leadingVisual={ChevronDownIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
notebookStore.insertBelow({ uid: notebookId, cellType: "markdown" });
notebookStore.insertBelow({ id: notebookId, cellType: "markdown" });
}}>
Markdown
</Button>
</span>
<span style={{ display: "flex" }}>
<Button leadingVisual={ChevronDownIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
notebookStore.insertBelow({ uid: notebookId, cellType: "code" });
notebookStore.insertBelow({ id: notebookId, cellType: "code" });
}}>
Code
</Button>
Expand Down
2 changes: 1 addition & 1 deletion examples/lexical/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@datalayer/jupyter-lexical": "0.0.1",
"@datalayer/primer-addons": "^0.3.1",
"@datalayer/primer-addons": "^0.3.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-json-tree": "^0.17.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/next-js/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "next/core-web-vitals"
"extends": "next"
}
2 changes: 1 addition & 1 deletion examples/next-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@datalayer/icons-react": "^0.3.2",
"@datalayer/jupyter-react": "^0.15.0",
"@datalayer/primer-addons": "^0.3.1",
"@datalayer/primer-addons": "^0.3.2",
"autoprefixer": "^10.4.14",
"eslint": "^8.40.0",
"eslint-config-next": "^13.4.1",
Expand Down
Loading
Loading