@datalayer/core 0.0.3 → 0.0.5
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.
- package/README.md +114 -3
- package/lib/App.css +2 -2
- package/lib/App.d.ts +1 -1
- package/lib/App.js +9 -9
- package/lib/__tests__/index.test.js +5 -5
- package/lib/api/DatalayerApi.d.ts +1 -1
- package/lib/api/DatalayerApi.js +3 -3
- package/lib/api/index.d.ts +3 -3
- package/lib/api/index.js +3 -3
- package/lib/api/runtimes/actions.js +22 -23
- package/lib/api/runtimes/settings.js +3 -3
- package/lib/api/runtimes/snapshots.d.ts +1 -1
- package/lib/api/runtimes/snapshots.js +8 -8
- package/lib/api/runtimes/utils.js +1 -4
- package/lib/collaboration/DatalayerCollaboration.d.ts +9 -0
- package/lib/collaboration/DatalayerCollaboration.js +28 -0
- package/lib/collaboration/DatalayerCollaborationProvider.d.ts +54 -0
- package/lib/collaboration/DatalayerCollaborationProvider.js +162 -0
- package/lib/collaboration/index.d.ts +2 -0
- package/lib/collaboration/index.js +6 -0
- package/lib/components/avatars/BoringAvatar.d.ts +1 -1
- package/lib/components/avatars/BoringAvatar.js +2 -2
- package/lib/components/avatars/UserProfileAvatar.js +2 -9
- package/lib/components/banners/NoAutomationBanner.js +4 -4
- package/lib/components/buttons/DownloadCSVButton.js +1 -1
- package/lib/components/buttons/UploadButton.js +1 -1
- package/lib/components/checkout/StripeCheckout.d.ts +1 -1
- package/lib/components/checkout/StripeCheckout.js +6 -6
- package/lib/components/confetti/ConfettiSuccess.js +1 -1
- package/lib/components/context/OrganizationSelect.js +5 -5
- package/lib/components/context/SpaceSelect.js +7 -7
- package/lib/components/display/AvatarSkeleton.js +1 -1
- package/lib/components/display/CenteredSpinner.js +4 -4
- package/lib/components/display/CodePreview.js +4 -4
- package/lib/components/display/DatalayerBox.js +13 -14
- package/lib/components/display/HorizontalCenter.d.ts +1 -1
- package/lib/components/display/HorizontalCenter.js +1 -1
- package/lib/components/display/JupyterDialog.js +17 -15
- package/lib/components/display/NavLink.d.ts +4 -2
- package/lib/components/display/NavLink.js +6 -4
- package/lib/components/display/NotebookSkeleton.js +2 -2
- package/lib/components/display/Placeholder.js +1 -1
- package/lib/components/display/ToTopBranded.js +1 -1
- package/lib/components/echarts/EChartsReact.d.ts +1 -1
- package/lib/components/echarts/EChartsReact.js +1 -1
- package/lib/components/flashes/FlashClosable.js +11 -11
- package/lib/components/flashes/FlashDisclaimer.js +2 -3
- package/lib/components/flashes/FlashGuest.js +3 -4
- package/lib/components/flashes/FlashSurveys.js +3 -4
- package/lib/components/flashes/FlashUnauthorized.js +2 -2
- package/lib/components/flashes/surveys/Survey2025_1.d.ts +1 -1
- package/lib/components/flashes/surveys/Survey2025_1.js +62 -85
- package/lib/components/iam/ExternalTokenSilentLogin.js +6 -4
- package/lib/components/icons/ArtifactIcon.d.ts +2 -2
- package/lib/components/icons/ArtifactIcon.js +39 -39
- package/lib/components/labels/VisibilityLabel.js +2 -5
- package/lib/components/landings/StepBlock.d.ts +1 -1
- package/lib/components/landings/StepBlock.js +1 -1
- package/lib/components/navbar/NavigationVisbilityObserver.js +2 -2
- package/lib/components/navbar/SubdomainNavBar.js +45 -23
- package/lib/components/navbar/SubdomainNavBar.module.css +33 -14
- package/lib/components/nbgrader/NbGradesDetails.d.ts +1 -1
- package/lib/components/nbgrader/NbGradesDetails.js +5 -8
- package/lib/components/notebooks/JupyterNotebook.js +5 -5
- package/lib/components/notebooks/JupyterNotebookToolbar.js +3 -3
- package/lib/components/primer/Helper.d.ts +1 -1
- package/lib/components/primer/Helper.js +5 -3
- package/lib/components/primer/Portals.d.ts +1 -1
- package/lib/components/primer/Portals.js +2 -2
- package/lib/components/primer/Styles.js +1 -1
- package/lib/components/progress/ConsumptionBar.js +2 -2
- package/lib/components/progress/CreditsIndicator.d.ts +1 -1
- package/lib/components/progress/CreditsIndicator.js +4 -7
- package/lib/components/progress/ProgressRing.js +2 -2
- package/lib/components/runtimes/RuntimeCellVariables.js +9 -9
- package/lib/components/runtimes/RuntimeCellVariablesDialog.js +3 -3
- package/lib/components/runtimes/RuntimeLauncherDialog.js +30 -34
- package/lib/components/runtimes/RuntimePickerBase.js +42 -31
- package/lib/components/runtimes/RuntimePickerCell.js +9 -12
- package/lib/components/runtimes/RuntimePickerNotebook.js +44 -44
- package/lib/components/runtimes/RuntimeReservationControl.js +10 -15
- package/lib/components/runtimes/RuntimeSimplePicker.js +9 -12
- package/lib/components/runtimes/RuntimeUtils.js +22 -12
- package/lib/components/runtimes/RuntimeVariables.js +7 -7
- package/lib/components/screenshot/ScreenCapture.js +9 -13
- package/lib/components/screenshot/ScreenCaptureButton.d.ts +1 -1
- package/lib/components/screenshot/ScreenCaptureButton.js +14 -8
- package/lib/components/snapshots/RuntimeSnapshotMenu.js +19 -17
- package/lib/components/snippets/SnippetDialog.js +5 -5
- package/lib/components/storage/ContentsBrowser.js +63 -56
- package/lib/components/storage/ContentsItems.js +10 -8
- package/lib/components/students/StudentItemStatus.d.ts +1 -1
- package/lib/components/students/StudentItemStatus.js +35 -16
- package/lib/components/subnav/SubNav.d.ts +1 -1
- package/lib/components/subnav/SubNav.js +30 -15
- package/lib/components/subnav/SubNav.module.css +55 -21
- package/lib/components/tables/DataTable.js +1 -4
- package/lib/components/text-reveal/TextRevealAnimation.js +7 -2
- package/lib/components/text-reveal/TextRevealAnimation.module.css +4 -2
- package/lib/components/tokens/SpaceVariantToken.d.ts +1 -1
- package/lib/components/tokens/SpaceVariantToken.js +5 -5
- package/lib/components/toolbars/AssignmentEditorToolbar.js +1 -3
- package/lib/components/users/PeerIndicator.d.ts +1 -1
- package/lib/components/users/PeerIndicator.js +5 -5
- package/lib/config/Configuration.d.ts +48 -0
- package/lib/config/Configuration.js +42 -0
- package/lib/config/integrations/Loom.js +3 -3
- package/lib/examples/CellExample.d.ts +2 -2
- package/lib/examples/CellExample.js +34 -3
- package/lib/examples/DatalayerNotebookExample.d.ts +16 -0
- package/lib/examples/DatalayerNotebookExample.js +75 -0
- package/lib/examples/NativeNavigationExample.d.ts +8 -0
- package/lib/examples/NativeNavigationExample.js +97 -0
- package/lib/examples/NotebookExample.d.ts +1 -3
- package/lib/examples/NotebookExample.js +9 -7
- package/lib/examples/NotebookMutationsKernel.d.ts +2 -0
- package/lib/examples/NotebookMutationsKernel.js +115 -0
- package/lib/examples/NotebookMutationsServiceManager.d.ts +2 -0
- package/lib/examples/NotebookMutationsServiceManager.js +107 -0
- package/lib/examples/ReactRouterExample.d.ts +6 -0
- package/lib/examples/ReactRouterExample.js +175 -0
- package/lib/examples/example-selector.d.ts +22 -0
- package/lib/examples/example-selector.js +45 -0
- package/lib/examples/index.d.ts +2 -0
- package/lib/examples/index.js +6 -0
- package/lib/examples/main.js +153 -0
- package/lib/examples/notebooks/IPyWidgetsExample.ipynb.json +101 -0
- package/lib/examples/notebooks/IPyWidgetsExampleWithState.ipynb.json +112 -0
- package/lib/examples/{NotebookExample1.ipynb.json → notebooks/Lite.ipynb.json} +45 -53
- package/lib/examples/notebooks/Matplotlib.ipynb.json +137 -0
- package/lib/examples/notebooks/NotebookExample1.ipynb.json +126 -0
- package/lib/examples/notebooks/NotebookExample2.ipynb.json +48 -0
- package/lib/examples/notebooks/NotebookOutputs.ipynb.json +49 -0
- package/lib/examples/notebooks/NotebookToCExample.ipynb.json +102 -0
- package/lib/examples/notebooks/OutputIPyWidgetsExample.d.ts +145 -0
- package/lib/examples/notebooks/OutputIPyWidgetsExample.js +153 -0
- package/lib/examples/notebooks/PyGWalker.ipynb.json +55 -0
- package/lib/hooks/assets/OutputshotPlaceholders.d.ts +10 -10
- package/lib/hooks/assets/OutputshotPlaceholders.js +10 -10
- package/lib/hooks/index.d.ts +29 -28
- package/lib/hooks/index.js +29 -28
- package/lib/hooks/layouts/LayoutBackdrop.js +3 -6
- package/lib/hooks/layouts/LayoutScreenshot.css +1 -1
- package/lib/hooks/layouts/LayoutScreenshot.js +6 -6
- package/lib/hooks/useAIAgents.d.ts +1 -1
- package/lib/hooks/useAIAgents.js +6 -6
- package/lib/hooks/useAuthorization.js +4 -4
- package/lib/hooks/useBackdrop.js +7 -7
- package/lib/hooks/useBackdropJupyterLab.d.ts +1 -1
- package/lib/hooks/useBackdropJupyterLab.js +4 -4
- package/lib/hooks/useCache.d.ts +6 -2
- package/lib/hooks/useCache.js +233 -179
- package/lib/hooks/useCellOutputshot.js +3 -6
- package/lib/hooks/useContainsFocus.js +2 -1
- package/lib/hooks/useDatalayer.js +5 -3
- package/lib/hooks/useError.d.ts +1 -1
- package/lib/hooks/useError.js +2 -2
- package/lib/hooks/useExternalScript.js +4 -4
- package/lib/hooks/useFocusTrap.js +2 -1
- package/lib/hooks/useIAM.js +4 -5
- package/lib/hooks/useId.js +3 -3
- package/lib/hooks/useJupyterLabTheme.js +3 -1
- package/lib/hooks/useLocation.d.ts +22 -0
- package/lib/hooks/useLocation.js +149 -0
- package/lib/hooks/useLocationHandles.d.ts +2 -2
- package/lib/hooks/useLocationHandles.js +6 -4
- package/lib/hooks/useNavigate.d.ts +5 -1
- package/lib/hooks/useNavigate.js +62 -7
- package/lib/hooks/useNotebookAIAgent.js +3 -1
- package/lib/hooks/useParams.d.ts +5 -0
- package/lib/hooks/useParams.js +112 -0
- package/lib/hooks/useRuntimes.js +2 -2
- package/lib/hooks/useScreenshot.js +5 -5
- package/lib/hooks/useToast.js +15 -13
- package/lib/hooks/useUpload.js +9 -9
- package/lib/hooks/useUser.js +1 -1
- package/lib/index.css +1 -1
- package/lib/index.d.ts +6 -3
- package/lib/index.js +7 -3
- package/lib/mocks/components/FlashMock.js +4 -4
- package/lib/mocks/hooks/rests/rests.js +15 -18
- package/lib/mocks/hooks/useDatalayerMock.d.ts +2 -2
- package/lib/mocks/hooks/useDatalayerMock.js +7 -7
- package/lib/mocks/models/CodeBlockMock.js +1 -1
- package/lib/mocks/models/CodelineMock.js +1 -1
- package/lib/mocks/models/CourseMock.d.ts +1 -1
- package/lib/mocks/models/CourseMock.js +10 -10
- package/lib/mocks/models/InviteMock.d.ts +1 -1
- package/lib/mocks/models/InviteMock.js +21 -6
- package/lib/mocks/models/JupyterLabUserMock.js +2 -2
- package/lib/mocks/models/OrganisationMock.d.ts +1 -1
- package/lib/mocks/models/OrganisationMock.js +11 -7
- package/lib/mocks/models/SchoolMock.d.ts +1 -1
- package/lib/mocks/models/SchoolMock.js +6 -6
- package/lib/mocks/models/SpaceMock.d.ts +1 -1
- package/lib/mocks/models/SpaceMock.js +9 -9
- package/lib/mocks/models/TeamMock.d.ts +1 -1
- package/lib/mocks/models/TeamMock.js +6 -6
- package/lib/mocks/models/UserMock.d.ts +1 -1
- package/lib/mocks/models/UserMock.js +4 -6
- package/lib/mocks/views/ActionMenuMock.js +1 -1
- package/lib/mocks/views/ChartMock.js +3 -3
- package/lib/mocks/views/ChartMockOptions.js +24 -24
- package/lib/mocks/views/DashboardMock.js +74 -74
- package/lib/mocks/views/FormMock.js +1 -1
- package/lib/mocks/views/TableMock.js +1 -1
- package/lib/models/Account.d.ts +2 -2
- package/lib/models/Assignment.d.ts +2 -2
- package/lib/models/Cell.d.ts +1 -1
- package/lib/models/CodeBlock.d.ts +1 -1
- package/lib/models/CodefeedBlocks.d.ts +2 -2
- package/lib/models/Contact.d.ts +1 -1
- package/lib/models/Contact.js +14 -14
- package/lib/models/ContactIAMProvider.js +2 -2
- package/lib/models/Course.d.ts +7 -7
- package/lib/models/Dataset.d.ts +1 -1
- package/lib/models/Dean.d.ts +1 -1
- package/lib/models/Document.d.ts +1 -1
- package/lib/models/Environment.d.ts +2 -2
- package/lib/models/Exercise.d.ts +1 -1
- package/lib/models/IAMProviderLinked.js +1 -1
- package/lib/models/Instructor.d.ts +1 -1
- package/lib/models/Invite.d.ts +2 -2
- package/lib/models/Invite.js +1 -1
- package/lib/models/Item.d.ts +5 -5
- package/lib/models/LandingRoles.js +18 -18
- package/lib/models/Lesson.d.ts +1 -1
- package/lib/models/Member.d.ts +1 -1
- package/lib/models/Notebook.d.ts +1 -1
- package/lib/models/Organization.d.ts +4 -4
- package/lib/models/Organization.js +2 -2
- package/lib/models/OrganizationMember.d.ts +2 -2
- package/lib/models/Page.js +4 -2
- package/lib/models/PageTag.d.ts +1 -1
- package/lib/models/PageTag.js +56 -9
- package/lib/models/Profile.d.ts +1 -1
- package/lib/models/RolesOrganization.d.ts +1 -1
- package/lib/models/RolesOrganization.js +4 -12
- package/lib/models/RolesPlatform.d.ts +1 -1
- package/lib/models/RolesPlatform.js +12 -34
- package/lib/models/RolesTeam.d.ts +1 -1
- package/lib/models/RolesTeam.js +3 -10
- package/lib/models/Runtime.js +4 -4
- package/lib/models/RuntimeSnapshot.js +1 -1
- package/lib/models/School.d.ts +4 -4
- package/lib/models/Space.d.ts +5 -5
- package/lib/models/Space.js +3 -3
- package/lib/models/SpaceItem.d.ts +8 -8
- package/lib/models/SpaceMember.d.ts +2 -2
- package/lib/models/Student.d.ts +2 -2
- package/lib/models/StudentItem.d.ts +3 -3
- package/lib/models/Team.d.ts +3 -3
- package/lib/models/Team.js +2 -2
- package/lib/models/TeamMember.d.ts +2 -2
- package/lib/models/URN.js +1 -1
- package/lib/models/User.d.ts +2 -2
- package/lib/models/User.js +5 -3
- package/lib/models/UserOnboarding.d.ts +1 -1
- package/lib/models/UserOnboarding.js +7 -7
- package/lib/models/UserSettings.js +2 -2
- package/lib/models/index.d.ts +2 -2
- package/lib/models/index.js +2 -2
- package/lib/navigation/adapters/native.d.ts +11 -0
- package/lib/navigation/adapters/native.js +48 -0
- package/lib/navigation/adapters/nextjs.d.ts +9 -0
- package/lib/navigation/adapters/nextjs.js +35 -0
- package/lib/navigation/adapters/react-router.d.ts +4 -0
- package/lib/navigation/adapters/react-router.js +12 -0
- package/lib/navigation/components.d.ts +20 -0
- package/lib/navigation/components.js +36 -0
- package/lib/navigation/index.d.ts +4 -0
- package/lib/navigation/index.js +12 -0
- package/lib/routes/index.d.ts +1 -1
- package/lib/routes/index.js +1 -1
- package/lib/services/DatalayerServiceManager.d.ts +22 -0
- package/lib/services/DatalayerServiceManager.js +69 -0
- package/lib/services/index.d.ts +4 -0
- package/lib/services/index.js +7 -0
- package/lib/services/reconnectToRuntime.d.ts +32 -0
- package/lib/services/reconnectToRuntime.js +59 -0
- package/lib/state/State.d.ts +1 -1
- package/lib/state/State.js +1 -1
- package/lib/state/index.d.ts +1 -1
- package/lib/state/index.js +1 -1
- package/lib/state/storage/IAMStorage.js +14 -2
- package/lib/state/storage/index.d.ts +1 -1
- package/lib/state/storage/index.js +1 -1
- package/lib/state/substates/AIAgentState.js +4 -2
- package/lib/state/substates/CellState.js +6 -5
- package/lib/state/substates/CoreState.d.ts +1 -1
- package/lib/state/substates/CoreState.js +26 -17
- package/lib/state/substates/DatasourceState.js +1 -1
- package/lib/state/substates/IAMState.d.ts +4 -0
- package/lib/state/substates/IAMState.js +39 -23
- package/lib/state/substates/JupyterLabState.js +1 -1
- package/lib/state/substates/LayoutState.d.ts +2 -2
- package/lib/state/substates/LayoutState.js +41 -28
- package/lib/state/substates/OrganizationState.js +1 -1
- package/lib/state/substates/RuntimesState.js +11 -6
- package/lib/state/substates/SpaceState.js +1 -1
- package/lib/state/substates/SurveysState.js +4 -4
- package/lib/state/substates/TeamState.js +1 -1
- package/lib/test-setup.js +25 -3
- package/lib/theme/DatalayerTheme.js +1 -1
- package/lib/theme/DatalayerThemeProvider.js +17 -14
- package/lib/theme/Palette.js +1 -1
- package/lib/utils/Avatar.js +2 -2
- package/lib/utils/Browser.js +6 -6
- package/lib/utils/Cells.d.ts +1 -1
- package/lib/utils/Cookie.js +1 -1
- package/lib/utils/Date.js +2 -2
- package/lib/utils/Download.js +5 -3
- package/lib/utils/DownloadFile.js +4 -2
- package/lib/utils/Env.js +2 -1
- package/lib/utils/Lazy.d.ts +1 -1
- package/lib/utils/Lazy.js +2 -2
- package/lib/utils/Name.js +10 -8
- package/lib/utils/Notebook.d.ts +1 -1
- package/lib/utils/Notebook.js +3 -3
- package/lib/utils/Number.js +13 -9
- package/lib/utils/Plots.js +4 -4
- package/lib/utils/Screenshot.js +1 -1
- package/lib/utils/Sleep.js +1 -1
- package/lib/utils/Snapshot.js +2 -2
- package/lib/utils/String.js +2 -2
- package/lib/utils/Uri.js +1 -1
- package/lib/utils/WithSuspense.js +3 -6
- package/lib/utils/logger.d.ts +16 -0
- package/lib/utils/logger.js +52 -0
- package/package.json +49 -5
- package/lib/__tests__/App.test.js +0 -17
- /package/lib/{__tests__/App.test.d.ts → examples/main.d.ts} +0 -0
|
@@ -6,11 +6,11 @@ const IS_LOCALHOST = location.hostname === 'localhost';
|
|
|
6
6
|
export const getLoomPublicAppId = () => {
|
|
7
7
|
return IS_LOCALHOST
|
|
8
8
|
? LOOM_PUBLIC_APP_ID.LOCALHOST
|
|
9
|
-
: LOOM_PUBLIC_APP_ID.
|
|
9
|
+
: LOOM_PUBLIC_APP_ID.DATALAYER_APP;
|
|
10
10
|
};
|
|
11
11
|
// It is safe to expose PUBLIC APP ID here.
|
|
12
12
|
// @see https://dev.loom.com/docs
|
|
13
13
|
const LOOM_PUBLIC_APP_ID = {
|
|
14
|
-
LOCALHOST:
|
|
15
|
-
|
|
14
|
+
LOCALHOST: '05754d5d-4778-4e6f-852a-a22fa0b5e87f',
|
|
15
|
+
DATALAYER_APP: '4b431848-adf7-457e-a545-0b0c7d21602a',
|
|
16
16
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ServiceManager } from '@jupyterlab/services';
|
|
2
2
|
type ICellExampleProps = {
|
|
3
|
-
|
|
3
|
+
serviceManager?: ServiceManager.IManager;
|
|
4
4
|
};
|
|
5
5
|
export declare const CellExample: (props: ICellExampleProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
export default CellExample;
|
|
@@ -8,17 +8,48 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
8
8
|
*
|
|
9
9
|
* MIT License
|
|
10
10
|
*/
|
|
11
|
+
import { useEffect, useState } from 'react';
|
|
11
12
|
import { Box, Button, Label } from '@primer/react';
|
|
12
|
-
import {
|
|
13
|
+
import { ServiceManager } from '@jupyterlab/services';
|
|
14
|
+
import { createServerSettings, getJupyterServerUrl, getJupyterServerToken, } from '@datalayer/jupyter-react';
|
|
15
|
+
import { Cell, KernelIndicator, useKernelsStore, useCellsStore, Kernel, } from '@datalayer/jupyter-react';
|
|
13
16
|
const CELL_ID = 'cell-example-1';
|
|
14
17
|
const DEFAULT_SOURCE = `from IPython.display import display
|
|
15
18
|
|
|
16
19
|
for i in range(10):
|
|
17
20
|
display('I am a long string which is repeatedly added to the dom in separated divs: %d' % i)`;
|
|
18
21
|
export const CellExample = (props) => {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
22
|
+
const [kernel, setKernel] = useState();
|
|
23
|
+
const [serviceManager, setServiceManager] = useState(props.serviceManager);
|
|
21
24
|
const kernelsStore = useKernelsStore();
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
// Create service manager if not provided
|
|
27
|
+
if (!props.serviceManager) {
|
|
28
|
+
const serverSettings = createServerSettings(getJupyterServerUrl(), getJupyterServerToken());
|
|
29
|
+
const manager = new ServiceManager({ serverSettings });
|
|
30
|
+
setServiceManager(manager);
|
|
31
|
+
}
|
|
32
|
+
}, [props.serviceManager]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!kernel && serviceManager) {
|
|
35
|
+
// Create a kernel using the service manager
|
|
36
|
+
const createKernel = async () => {
|
|
37
|
+
// Create a Kernel wrapper
|
|
38
|
+
const k = new Kernel({
|
|
39
|
+
kernelName: 'python3',
|
|
40
|
+
});
|
|
41
|
+
// @ts-expect-error - Set service manager after construction
|
|
42
|
+
k._serviceManager = serviceManager;
|
|
43
|
+
await k.ready;
|
|
44
|
+
setKernel(k);
|
|
45
|
+
};
|
|
46
|
+
createKernel();
|
|
47
|
+
}
|
|
48
|
+
}, [serviceManager]);
|
|
49
|
+
const cellsStore = useCellsStore();
|
|
50
|
+
if (!kernel) {
|
|
51
|
+
return (_jsxs(Box, { p: 4, children: [_jsx(Box, { as: "h1", children: "A Jupyter Cell" }), _jsx(Box, { children: "Loading kernel..." })] }));
|
|
52
|
+
}
|
|
22
53
|
return (_jsxs(_Fragment, { children: [_jsx(Box, { as: "h1", children: "A Jupyter Cell" }), _jsxs(Box, { children: ["Source: ", cellsStore.getSource(CELL_ID)] }), _jsxs(Box, { children: ["Outputs Count: ", cellsStore.getOutputsCount(CELL_ID)] }), _jsxs(Box, { children: ["Kernel State: ", _jsx(Label, { children: kernelsStore.getExecutionState(kernel.id) })] }), _jsxs(Box, { children: ["Kernel Phase: ", _jsx(Label, { children: kernelsStore.getExecutionPhase(kernel.id) })] }), _jsxs(Box, { display: "flex", children: [_jsx(Box, { children: "Kernel Indicator:" }), _jsx(Box, { ml: 3, children: _jsx(KernelIndicator, { kernel: kernel.connection }) })] }), _jsx(Box, { children: _jsx(Button, { onClick: () => cellsStore.execute(CELL_ID), children: "Run cell" }) }), _jsx(Cell, { source: DEFAULT_SOURCE, id: CELL_ID })] }));
|
|
23
54
|
};
|
|
24
55
|
export default CellExample;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ServiceManager } from '@jupyterlab/services';
|
|
2
|
+
/**
|
|
3
|
+
* Example demonstrating how to use Datalayer services with Notebook
|
|
4
|
+
*
|
|
5
|
+
* This example shows:
|
|
6
|
+
* 1. How to create and use DatalayerServiceManager for kernel management
|
|
7
|
+
* 2. How to create and use DatalayerCollaborationProvider for real-time collaboration
|
|
8
|
+
* 3. How to enable/disable Datalayer collaboration
|
|
9
|
+
* 4. How to pass these to the base Notebook component
|
|
10
|
+
* 5. Graceful fallback when Datalayer credentials are not available
|
|
11
|
+
*/
|
|
12
|
+
type IDatalayerNotebookExampleProps = {
|
|
13
|
+
serviceManager?: ServiceManager.IManager;
|
|
14
|
+
};
|
|
15
|
+
declare const DatalayerNotebookExample: (props: IDatalayerNotebookExampleProps) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export default DatalayerNotebookExample;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
import { useState, useEffect, useMemo } from 'react';
|
|
7
|
+
import { Box, Checkbox, FormControl, Heading } from '@primer/react';
|
|
8
|
+
import { loadJupyterConfig, JupyterReactTheme, Notebook2, } from '@datalayer/jupyter-react';
|
|
9
|
+
import { DatalayerCollaborationProvider } from '../collaboration/DatalayerCollaborationProvider';
|
|
10
|
+
import { createDatalayerServiceManager } from '../services/DatalayerServiceManager';
|
|
11
|
+
import { useCoreStore } from '../state/substates/CoreState';
|
|
12
|
+
import nbformatExample from './notebooks/NotebookExample1.ipynb.json';
|
|
13
|
+
// This corresponds to the notebook ID in the URL when you open an existing notbook in your library
|
|
14
|
+
const NOTEBOOK_ID = '01JZQRQ35GG871QQCZW9TB1A8J';
|
|
15
|
+
const DatalayerNotebookExample = (props) => {
|
|
16
|
+
// Load config on component mount
|
|
17
|
+
loadJupyterConfig();
|
|
18
|
+
const [nbformat] = useState(nbformatExample);
|
|
19
|
+
const [enableCollaboration, setEnableCollaboration] = useState(false);
|
|
20
|
+
const [readonly] = useState(false);
|
|
21
|
+
const [serviceManager, setServiceManager] = useState(props.serviceManager);
|
|
22
|
+
const { configuration } = useCoreStore();
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
// Create DatalayerServiceManager if not provided
|
|
25
|
+
const createManager = async () => {
|
|
26
|
+
if (props.serviceManager) {
|
|
27
|
+
// Use provided service manager (should be DatalayerServiceManager from main.tsx)
|
|
28
|
+
// Wait for it to be ready
|
|
29
|
+
await props.serviceManager.ready;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// Create DatalayerServiceManager if we have credentials
|
|
33
|
+
if (configuration?.token && configuration?.runUrl) {
|
|
34
|
+
try {
|
|
35
|
+
console.log('Creating DatalayerServiceManager for Datalayer infrastructure');
|
|
36
|
+
// Now we can pass undefined to use config/defaults
|
|
37
|
+
const manager = await createDatalayerServiceManager(configuration?.cpuEnvironment, configuration?.credits);
|
|
38
|
+
await manager.ready;
|
|
39
|
+
setServiceManager(manager);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error('Failed to create DatalayerServiceManager:', error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.warn('Datalayer credentials not configured. Please set runUrl and token.');
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
createManager();
|
|
50
|
+
}, [props.serviceManager, configuration]);
|
|
51
|
+
// Create the collaboration provider when enabled
|
|
52
|
+
const collaborationProvider = useMemo(() => {
|
|
53
|
+
if (!enableCollaboration) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const runUrl = configuration?.runUrl;
|
|
57
|
+
const token = configuration?.token;
|
|
58
|
+
if (!runUrl || !token) {
|
|
59
|
+
console.warn('Datalayer collaboration enabled but runUrl or token not configured. ' +
|
|
60
|
+
'Please configure them in the Datalayer store or environment.');
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
// Create and return the Datalayer collaboration provider
|
|
64
|
+
return new DatalayerCollaborationProvider({
|
|
65
|
+
runUrl,
|
|
66
|
+
token,
|
|
67
|
+
});
|
|
68
|
+
}, [enableCollaboration, configuration]);
|
|
69
|
+
return (_jsx(JupyterReactTheme, { children: _jsxs(Box, { p: 3, children: [_jsx(Heading, { as: "h2", sx: { mb: 3 }, children: "DatalayerNotebook Collaboration Example" }), _jsx(Box, { sx: { mb: 3 }, children: _jsxs(FormControl, { children: [_jsx(Checkbox, { checked: enableCollaboration, onChange: e => setEnableCollaboration(e.target.checked) }), _jsx(FormControl.Label, { children: "Enable Datalayer Collaboration" })] }) }), (!configuration?.runUrl || !configuration?.token) && (_jsx(Box, { sx: { mb: 2, p: 2, bg: 'danger.subtle' }, children: "Warning: Datalayer configuration is missing. Please configure runUrl and token to use DatalayerServiceManager and collaboration features." })), !serviceManager && (_jsx(Box, { sx: { mb: 2, p: 2, bg: 'attention.subtle' }, children: "Note: DatalayerServiceManager is not available. Notebook functionality will be limited." })), _jsx(Box, { sx: {
|
|
70
|
+
border: '1px solid',
|
|
71
|
+
borderColor: 'border.default',
|
|
72
|
+
borderRadius: 2,
|
|
73
|
+
}, children: serviceManager ? (_jsx(Notebook2, { id: NOTEBOOK_ID, height: "calc(100vh - 200px)", nbformat: nbformat, readonly: readonly, serviceManager: serviceManager, startDefaultKernel: true, collaborationProvider: collaborationProvider })) : (_jsx(Box, { sx: { p: 4, textAlign: 'center' }, children: "Loading ServiceManager..." })) }), _jsxs(Box, { sx: { mt: 2, fontSize: 1, color: 'fg.subtle' }, children: [_jsx("p", { children: "This example demonstrates how to use Datalayer services with Notebook:" }), _jsxs("ul", { children: [_jsxs("li", { children: [_jsx("strong", { children: "DatalayerServiceManager:" }), " Connects to Datalayer infrastructure for kernel management"] }), _jsxs("li", { children: [_jsx("strong", { children: "DatalayerCollaborationProvider:" }), " Enables real-time collaboration"] }), _jsx("li", { children: "Both require Datalayer credentials (runUrl and token)" }), _jsx("li", { children: "Pass them directly to the base Notebook component" }), _jsx("li", { children: "No wrapper components needed - just create the services and pass them as props" }), _jsx("li", { children: "This shows the explicit, composable pattern for Datalayer integration" })] })] })] }) }));
|
|
74
|
+
};
|
|
75
|
+
export default DatalayerNotebookExample;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Native Navigation Example
|
|
4
|
+
* This example demonstrates the navigation hooks WITHOUT React Router.
|
|
5
|
+
* The hooks should automatically detect the absence of React Router and fall back to native browser navigation.
|
|
6
|
+
*/
|
|
7
|
+
export declare const NativeNavigationExample: React.FC;
|
|
8
|
+
export default NativeNavigationExample;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
import { useState, useEffect } from 'react';
|
|
7
|
+
import { Box, Button, Heading, Text, Link as PrimerLink } from '@primer/react';
|
|
8
|
+
import { useNavigate, useLocation, useParams, useHistory } from '../hooks';
|
|
9
|
+
/**
|
|
10
|
+
* Native Navigation Example
|
|
11
|
+
* This example demonstrates the navigation hooks WITHOUT React Router.
|
|
12
|
+
* The hooks should automatically detect the absence of React Router and fall back to native browser navigation.
|
|
13
|
+
*/
|
|
14
|
+
export const NativeNavigationExample = () => {
|
|
15
|
+
const navigate = useNavigate();
|
|
16
|
+
const location = useLocation();
|
|
17
|
+
const params = useParams();
|
|
18
|
+
const history = useHistory();
|
|
19
|
+
const [navigationType, setNavigationType] = useState('detecting...');
|
|
20
|
+
const [navigationCount, setNavigationCount] = useState(0);
|
|
21
|
+
const [currentView, setCurrentView] = useState('home');
|
|
22
|
+
// Track navigation type detection
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
// Since we're not using React Router, this should detect as 'native'
|
|
25
|
+
setNavigationType('native');
|
|
26
|
+
}, []);
|
|
27
|
+
// Track navigation events
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
setNavigationCount(prev => prev + 1);
|
|
30
|
+
// Parse the path to determine which view to show
|
|
31
|
+
const path = location.pathname;
|
|
32
|
+
if (path.includes('page1')) {
|
|
33
|
+
setCurrentView('page1');
|
|
34
|
+
}
|
|
35
|
+
else if (path.includes('page2')) {
|
|
36
|
+
setCurrentView('page2');
|
|
37
|
+
}
|
|
38
|
+
else if (path.includes('page3')) {
|
|
39
|
+
setCurrentView('page3');
|
|
40
|
+
}
|
|
41
|
+
else if (path.includes('user')) {
|
|
42
|
+
setCurrentView('user');
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
setCurrentView('home');
|
|
46
|
+
}
|
|
47
|
+
}, [location]);
|
|
48
|
+
const handleProgrammaticNavigation = () => {
|
|
49
|
+
navigate('/page3', undefined, true);
|
|
50
|
+
};
|
|
51
|
+
const handleNavigateWithQuery = () => {
|
|
52
|
+
navigate('/page2?test=456&native=true', undefined, true);
|
|
53
|
+
};
|
|
54
|
+
const handleNavigateWithHash = () => {
|
|
55
|
+
navigate('/page3#native-section', undefined, true);
|
|
56
|
+
};
|
|
57
|
+
const handleBackNavigation = () => {
|
|
58
|
+
history.back();
|
|
59
|
+
};
|
|
60
|
+
const handleForwardNavigation = () => {
|
|
61
|
+
history.forward();
|
|
62
|
+
};
|
|
63
|
+
const handleReplaceNavigation = () => {
|
|
64
|
+
history.replace('/replaced-page', { replaced: true });
|
|
65
|
+
};
|
|
66
|
+
// Simple link handler for native navigation
|
|
67
|
+
const handleLinkClick = (e, path) => {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
navigate(path, e, true);
|
|
70
|
+
};
|
|
71
|
+
// Render different content based on current view
|
|
72
|
+
const renderContent = () => {
|
|
73
|
+
switch (currentView) {
|
|
74
|
+
case 'page1':
|
|
75
|
+
return (_jsxs(_Fragment, { children: [_jsx(Heading, { as: "h1", sx: { mb: 3 }, children: "Page 1 (Native)" }), _jsx(Text, { as: "p", children: "You've navigated to Page 1 using native browser navigation." })] }));
|
|
76
|
+
case 'page2':
|
|
77
|
+
return (_jsxs(_Fragment, { children: [_jsx(Heading, { as: "h1", sx: { mb: 3 }, children: "Page 2 (Native)" }), _jsx(Text, { as: "p", children: "This is Page 2 with native navigation. Check the query parameters!" })] }));
|
|
78
|
+
case 'page3':
|
|
79
|
+
return (_jsxs(_Fragment, { children: [_jsx(Heading, { as: "h1", sx: { mb: 3 }, children: "Page 3 (Native)" }), _jsx(Text, { as: "p", children: "Welcome to Page 3 using native browser APIs. Notice the hash in the URL!" })] }));
|
|
80
|
+
case 'user':
|
|
81
|
+
return (_jsxs(_Fragment, { children: [_jsx(Heading, { as: "h1", sx: { mb: 3 }, children: "User Page (Native)" }), _jsxs(Text, { as: "p", children: ["User pages with native navigation. Path: ", location.pathname] })] }));
|
|
82
|
+
default:
|
|
83
|
+
return (_jsxs(_Fragment, { children: [_jsx(Heading, { as: "h1", sx: { mb: 3 }, children: "Home Page (Native)" }), _jsx(Text, { as: "p", children: "This is the home page of the Native navigation example." })] }));
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return (_jsxs(Box, { sx: { minHeight: '100vh', p: 4 }, children: [_jsxs(Box, { sx: { mb: 4, p: 3, bg: 'canvas.subtle', borderRadius: 2 }, children: [_jsx(Heading, { as: "h1", sx: { mb: 2 }, children: "Native Browser Navigation Example" }), _jsx(Text, { as: "p", sx: { mb: 2 }, children: "This example demonstrates the navigation hooks WITHOUT React Router context. The hooks automatically fall back to native browser navigation (history API)." }), _jsx(Text, { as: "p", sx: { color: 'attention.fg', fontWeight: 'bold' }, children: "\u26A0\uFE0F No React Router is loaded in this example - using native browser APIs only!" })] }), renderContent(), _jsxs(Box, { sx: { mt: 4 }, children: [_jsx(Heading, { as: "h2", sx: { mb: 3 }, children: "Navigation Information" }), _jsxs(Box, { sx: {
|
|
87
|
+
mb: 4,
|
|
88
|
+
p: 3,
|
|
89
|
+
borderWidth: 1,
|
|
90
|
+
borderStyle: 'solid',
|
|
91
|
+
borderColor: 'border.default',
|
|
92
|
+
borderRadius: 2,
|
|
93
|
+
}, children: [_jsxs(Text, { as: "p", sx: { mb: 2 }, children: [_jsx("strong", { children: "Navigation Type Detected:" }), ' ', _jsx(Text, { as: "span", sx: {
|
|
94
|
+
color: navigationType === 'native' ? 'success.fg' : 'danger.fg',
|
|
95
|
+
}, children: navigationType })] }), _jsxs(Text, { as: "p", sx: { mb: 2 }, children: [_jsx("strong", { children: "Current Path:" }), " ", location.pathname] }), _jsxs(Text, { as: "p", sx: { mb: 2 }, children: [_jsx("strong", { children: "Search Params:" }), " ", location.search || '(none)'] }), _jsxs(Text, { as: "p", sx: { mb: 2 }, children: [_jsx("strong", { children: "Hash:" }), " ", location.hash || '(none)'] }), _jsxs(Text, { as: "p", sx: { mb: 2 }, children: [_jsx("strong", { children: "Location Key:" }), " ", location.key] }), _jsxs(Text, { as: "p", sx: { mb: 2 }, children: [_jsx("strong", { children: "State:" }), " ", JSON.stringify(location.state) || '(none)'] }), _jsxs(Text, { as: "p", sx: { mb: 2 }, children: [_jsx("strong", { children: "URL Params (parsed from search):" }), ' ', JSON.stringify(params)] }), _jsxs(Text, { as: "p", children: [_jsx("strong", { children: "Navigation Count:" }), " ", navigationCount] })] }), _jsxs(Box, { sx: { mb: 3 }, children: [_jsx(Heading, { as: "h3", sx: { mb: 2 }, children: "Test Programmatic Navigation" }), _jsxs(Box, { sx: { display: 'flex', gap: 2, flexWrap: 'wrap' }, children: [_jsx(Button, { onClick: handleProgrammaticNavigation, children: "Navigate to /page3" }), _jsx(Button, { onClick: handleNavigateWithQuery, variant: "default", children: "Navigate with Query Params" }), _jsx(Button, { onClick: handleNavigateWithHash, variant: "default", children: "Navigate with Hash" }), _jsx(Button, { onClick: handleReplaceNavigation, variant: "default", children: "Replace Current Entry" })] })] }), _jsxs(Box, { sx: { mb: 3 }, children: [_jsx(Heading, { as: "h3", sx: { mb: 2 }, children: "Test History API" }), _jsxs(Box, { sx: { display: 'flex', gap: 2, flexWrap: 'wrap' }, children: [_jsx(Button, { onClick: handleBackNavigation, variant: "default", children: "History Back" }), _jsx(Button, { onClick: handleForwardNavigation, variant: "default", children: "History Forward" })] })] }), _jsxs(Box, { sx: { mb: 3 }, children: [_jsx(Heading, { as: "h3", sx: { mb: 2 }, children: "Test Link Navigation" }), _jsxs(Box, { sx: { display: 'flex', gap: 3, flexWrap: 'wrap' }, children: [_jsx(PrimerLink, { href: "/", onClick: e => handleLinkClick(e, '/'), sx: { cursor: 'pointer' }, children: "Home" }), _jsx(PrimerLink, { href: "/page1", onClick: e => handleLinkClick(e, '/page1'), sx: { cursor: 'pointer' }, children: "Page 1" }), _jsx(PrimerLink, { href: "/page2?test=123", onClick: e => handleLinkClick(e, '/page2?test=123'), sx: { cursor: 'pointer' }, children: "Page 2 with Query" }), _jsx(PrimerLink, { href: "/page3#section", onClick: e => handleLinkClick(e, '/page3#section'), sx: { cursor: 'pointer' }, children: "Page 3 with Hash" }), _jsx(PrimerLink, { href: "/user/456", onClick: e => handleLinkClick(e, '/user/456'), sx: { cursor: 'pointer' }, children: "User 456" })] })] }), _jsxs(Box, { sx: { mt: 4, p: 3, bg: 'attention.subtle', borderRadius: 2 }, children: [_jsx(Heading, { as: "h3", sx: { mb: 2 }, children: "How This Works" }), _jsx(Text, { as: "p", sx: { mb: 2 }, children: "This example does NOT include React Router. The navigation hooks automatically detect this and:" }), _jsxs(Box, { as: "ul", sx: { pl: 4 }, children: [_jsxs(Text, { as: "li", children: ["Use ", _jsx("code", { children: "window.history.pushState()" }), " for navigation"] }), _jsxs(Text, { as: "li", children: ["Listen to ", _jsx("code", { children: "popstate" }), " events for browser back/forward"] }), _jsxs(Text, { as: "li", children: ["Parse ", _jsx("code", { children: "window.location" }), " for current path and params"] }), _jsx(Text, { as: "li", children: "Provide the same API as when React Router is present" })] }), _jsx(Text, { as: "p", sx: { mt: 2 }, children: "The beauty is that the same hooks work in both scenarios without any code changes!" })] })] })] }));
|
|
96
|
+
};
|
|
97
|
+
export default NativeNavigationExample;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Kernel } from '@datalayer/jupyter-react';
|
|
2
1
|
import { ServiceManager } from '@jupyterlab/services';
|
|
3
2
|
type INotebookExampleProps = {
|
|
4
|
-
|
|
5
|
-
serviceManager: ServiceManager.IManager;
|
|
3
|
+
serviceManager?: ServiceManager.IManager;
|
|
6
4
|
};
|
|
7
5
|
export declare const NotebookExample: (props: INotebookExampleProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
6
|
export default NotebookExample;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
/*
|
|
3
3
|
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
@@ -10,13 +10,15 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
10
10
|
*/
|
|
11
11
|
import { useMemo } from 'react';
|
|
12
12
|
import { Box } from '@datalayer/primer-addons';
|
|
13
|
-
import { Notebook2, NotebookToolbar, CellSidebarExtension, CellSidebarButton } from '@datalayer/jupyter-react';
|
|
13
|
+
import { Notebook2, NotebookToolbar, CellSidebarExtension, CellSidebarButton, } from '@datalayer/jupyter-react';
|
|
14
|
+
import nbformatExample from './notebooks/NotebookExample1.ipynb.json';
|
|
14
15
|
const NOTEBOOK_ID = 'notebook-example-1';
|
|
15
16
|
export const NotebookExample = (props) => {
|
|
16
|
-
const {
|
|
17
|
-
const extensions = useMemo(() => [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const { serviceManager } = props;
|
|
18
|
+
const extensions = useMemo(() => [new CellSidebarExtension({ factory: CellSidebarButton })], []);
|
|
19
|
+
if (!serviceManager) {
|
|
20
|
+
return (_jsxs(Box, { as: "h1", children: ["A Jupyter Notebook", _jsx("div", { children: "Loading..." })] }));
|
|
21
|
+
}
|
|
22
|
+
return (_jsxs(_Fragment, { children: [_jsx(Box, { as: "h1", children: "A Jupyter Notebook" }), _jsx(Notebook2, { id: NOTEBOOK_ID, nbformat: nbformatExample, serviceManager: serviceManager, startDefaultKernel: true, extensions: extensions, Toolbar: NotebookToolbar })] }));
|
|
21
23
|
};
|
|
22
24
|
export default NotebookExample;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
import { createRoot } from 'react-dom/client';
|
|
8
|
+
import { Box, SegmentedControl, Label, Text } from '@primer/react';
|
|
9
|
+
import { ServiceManager } from '@jupyterlab/services';
|
|
10
|
+
import { createLiteServiceManager, createServerSettings, setJupyterServerUrl, getJupyterServerUrl, getJupyterServerToken, ServiceManagerLess, loadJupyterConfig, DEFAULT_JUPYTER_SERVER_URL, useNotebookStore, Notebook, SpinnerCentered, JupyterReactTheme, } from '@datalayer/jupyter-react';
|
|
11
|
+
import { useCoreStore } from '../state/substates/CoreState';
|
|
12
|
+
import { createDatalayerServiceManager } from '../services/DatalayerServiceManager';
|
|
13
|
+
import nbformatExample from './notebooks/NotebookExample1.ipynb.json';
|
|
14
|
+
const NOTEBOOK_ID = 'notebook-mutations-id';
|
|
15
|
+
loadJupyterConfig();
|
|
16
|
+
const SERVICE_MANAGER_LESS = new ServiceManagerLess();
|
|
17
|
+
const NotebookMutationsKernel = () => {
|
|
18
|
+
const [index, setIndex] = useState(0);
|
|
19
|
+
const [nbformat, setNbformat] = useState(nbformatExample);
|
|
20
|
+
const [readonly, setReadonly] = useState(true);
|
|
21
|
+
const [serverless, setServerless] = useState(true);
|
|
22
|
+
const [kernelIndex, setKernelIndex] = useState(-1);
|
|
23
|
+
const [waiting, setWaiting] = useState(false);
|
|
24
|
+
const [lite, setLite] = useState(false);
|
|
25
|
+
const [serviceManager, setServiceManager] = useState(SERVICE_MANAGER_LESS);
|
|
26
|
+
const [sessions, setSessions] = useState([]);
|
|
27
|
+
const { configuration } = useCoreStore();
|
|
28
|
+
const notebookStore = useNotebookStore();
|
|
29
|
+
const notebook = notebookStore.selectNotebook(NOTEBOOK_ID);
|
|
30
|
+
const onSessionConnection = (session) => {
|
|
31
|
+
console.log('Received a Kernel Session.', session);
|
|
32
|
+
if (session) {
|
|
33
|
+
setSessions(sessions.concat(session));
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const changeIndex = (index) => {
|
|
37
|
+
setIndex(index);
|
|
38
|
+
switch (index) {
|
|
39
|
+
case 0: {
|
|
40
|
+
setKernelIndex(-1);
|
|
41
|
+
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON());
|
|
42
|
+
setServerless(true);
|
|
43
|
+
setReadonly(true);
|
|
44
|
+
setLite(false);
|
|
45
|
+
setServiceManager(SERVICE_MANAGER_LESS);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case 1: {
|
|
49
|
+
setJupyterServerUrl(location.protocol + '//' + location.host);
|
|
50
|
+
createLiteServiceManager().then(liteServiceManager => {
|
|
51
|
+
setKernelIndex(-1);
|
|
52
|
+
console.log('Lite Service Manager is available', liteServiceManager);
|
|
53
|
+
setServiceManager(liteServiceManager);
|
|
54
|
+
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON());
|
|
55
|
+
setServerless(false);
|
|
56
|
+
setReadonly(false);
|
|
57
|
+
setLite(true);
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case 2: {
|
|
62
|
+
setJupyterServerUrl(DEFAULT_JUPYTER_SERVER_URL);
|
|
63
|
+
setKernelIndex(-1);
|
|
64
|
+
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON());
|
|
65
|
+
setServerless(false);
|
|
66
|
+
setReadonly(false);
|
|
67
|
+
setLite(false);
|
|
68
|
+
const serverSettings = createServerSettings(getJupyterServerUrl(), getJupyterServerToken());
|
|
69
|
+
const serviceManager = new ServiceManager({ serverSettings });
|
|
70
|
+
serviceManager['__NAME__'] = 'MutatingServiceManager';
|
|
71
|
+
setServiceManager(serviceManager);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case 3: {
|
|
75
|
+
// setWaiting(true);
|
|
76
|
+
setLite(false);
|
|
77
|
+
createDatalayerServiceManager(configuration?.cpuEnvironment || 'python-simple-env', configuration?.credits || 1).then(serviceManager => {
|
|
78
|
+
serviceManager['__NAME__'] = 'DatalayerCPUServiceManager';
|
|
79
|
+
setServiceManager(serviceManager);
|
|
80
|
+
setServerless(false);
|
|
81
|
+
setReadonly(false);
|
|
82
|
+
setKernelIndex(0);
|
|
83
|
+
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON());
|
|
84
|
+
// setWaiting(false);
|
|
85
|
+
});
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 4: {
|
|
89
|
+
setWaiting(true);
|
|
90
|
+
setLite(false);
|
|
91
|
+
createDatalayerServiceManager(configuration?.gpuEnvironment || 'pytorch-cuda-env', configuration?.credits || 1).then(serviceManager => {
|
|
92
|
+
setKernelIndex(0);
|
|
93
|
+
serviceManager['__NAME__'] = 'DatalayerGPUServiceManager';
|
|
94
|
+
setServiceManager(serviceManager);
|
|
95
|
+
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON());
|
|
96
|
+
setServerless(false);
|
|
97
|
+
setReadonly(false);
|
|
98
|
+
setWaiting(false);
|
|
99
|
+
});
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
return (_jsx(JupyterReactTheme, { children: _jsxs(_Fragment, { children: [_jsxs(Box, { display: "flex", children: [_jsx(Box, { children: _jsxs(SegmentedControl, { onChange: index => changeIndex(index), "aria-label": "jupyter-react-example", children: [_jsx(SegmentedControl.Button, { defaultSelected: index === 0, children: "Readonly" }), _jsx(SegmentedControl.Button, { defaultSelected: index === 1, children: "Browser Kernel" }), _jsx(SegmentedControl.Button, { defaultSelected: index === 2, children: "OSS Kernel (CPU)" }), _jsx(SegmentedControl.Button, { defaultSelected: index === 3, children: "Kernel (CPU)" }), _jsx(SegmentedControl.Button, { defaultSelected: index === 4, children: "Kernel (GPU)" })] }) }), _jsxs(Box, { ml: 1, mt: 1, children: [_jsxs(Label, { children: ["Lite: ", String(notebook?.adapter?.lite)] }), _jsxs(Label, { children: ["Service Manager URL:", ' ', notebook?.adapter?.serviceManager.serverSettings.baseUrl] }), _jsxs(Label, { children: ["Service Manager is ready:", ' ', String(notebook?.adapter?.serviceManager.isReady)] }), _jsxs(Label, { children: ["Kernel ID: ", notebook?.adapter?.kernel?.id] }), _jsxs(Label, { children: ["Kernel Banner: ", notebook?.adapter?.kernel?.info?.banner] })] })] }), _jsx(Box, { children: _jsx(Text, { as: "h3", children: "Kernel Sessions" }) }), _jsx(Box, { children: sessions.map(session => {
|
|
105
|
+
return (_jsx(Box, { children: _jsxs(Text, { children: [session.name, " ", session.id, " ", _jsx(Label, { children: "Kernel" }), " clientId [", session.kernel?.clientId, ") - id ", session.kernel?.id] }) }, session.id));
|
|
106
|
+
}) }), waiting ? (_jsx(SpinnerCentered, {})) : (_jsx(Notebook, { height: "calc(100vh - 2.6rem)", id: NOTEBOOK_ID, lite: lite, nbformat: nbformat, onSessionConnection: onSessionConnection, readonly: readonly, serverless: serverless, serviceManager: serviceManager, useRunningKernelIndex: kernelIndex }))] }) }));
|
|
107
|
+
};
|
|
108
|
+
export default NotebookMutationsKernel;
|
|
109
|
+
// For standalone testing
|
|
110
|
+
if (typeof window !== 'undefined' && window.location.pathname === '/test') {
|
|
111
|
+
const div = document.createElement('div');
|
|
112
|
+
document.body.appendChild(div);
|
|
113
|
+
const root = createRoot(div);
|
|
114
|
+
root.render(_jsx(NotebookMutationsKernel, {}));
|
|
115
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
import { createRoot } from 'react-dom/client';
|
|
8
|
+
import { Box, SegmentedControl, Label, Text } from '@primer/react';
|
|
9
|
+
import { ServiceManager } from '@jupyterlab/services';
|
|
10
|
+
import { createLiteServiceManager, createServerSettings, setJupyterServerUrl, getJupyterServerUrl, getJupyterServerToken, ServiceManagerLess, loadJupyterConfig, DEFAULT_JUPYTER_SERVER_URL, useNotebookStore, Notebook, SpinnerCentered, JupyterReactTheme, } from '@datalayer/jupyter-react';
|
|
11
|
+
import { useCoreStore } from '../state/substates/CoreState';
|
|
12
|
+
import { createDatalayerServiceManager } from '../services/DatalayerServiceManager';
|
|
13
|
+
import nbformatExample from './notebooks/NotebookExample1.ipynb.json';
|
|
14
|
+
const NOTEBOOK_ID = 'notebook-mutations-id';
|
|
15
|
+
loadJupyterConfig();
|
|
16
|
+
const SERVICE_MANAGER_LESS = new ServiceManagerLess();
|
|
17
|
+
const NotebookMutationsServiceManager = () => {
|
|
18
|
+
const [index, setIndex] = useState(0);
|
|
19
|
+
const [nbformat, setNbformat] = useState(nbformatExample);
|
|
20
|
+
const [readonly, setReadonly] = useState(true);
|
|
21
|
+
const [waiting, setWaiting] = useState(false);
|
|
22
|
+
const [lite, setLite] = useState(false);
|
|
23
|
+
const [serviceManager, setServiceManager] = useState(SERVICE_MANAGER_LESS);
|
|
24
|
+
const [sessions, setSessions] = useState([]);
|
|
25
|
+
const { configuration } = useCoreStore();
|
|
26
|
+
const notebookStore = useNotebookStore();
|
|
27
|
+
const notebook = notebookStore.selectNotebook(NOTEBOOK_ID);
|
|
28
|
+
const onSessionConnection = (session) => {
|
|
29
|
+
console.log('Received a Kernel Session.', session);
|
|
30
|
+
if (session) {
|
|
31
|
+
setSessions(sessions.concat(session));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const changeIndex = (index) => {
|
|
35
|
+
setIndex(index);
|
|
36
|
+
switch (index) {
|
|
37
|
+
case 0: {
|
|
38
|
+
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON());
|
|
39
|
+
setReadonly(true);
|
|
40
|
+
setLite(false);
|
|
41
|
+
setServiceManager(SERVICE_MANAGER_LESS);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case 1: {
|
|
45
|
+
setJupyterServerUrl(location.protocol + '//' + location.host);
|
|
46
|
+
createLiteServiceManager().then(liteServiceManager => {
|
|
47
|
+
console.log('Lite Service Manager is available', liteServiceManager);
|
|
48
|
+
setServiceManager(liteServiceManager);
|
|
49
|
+
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON());
|
|
50
|
+
setReadonly(false);
|
|
51
|
+
setLite(true);
|
|
52
|
+
});
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case 2: {
|
|
56
|
+
setJupyterServerUrl(DEFAULT_JUPYTER_SERVER_URL);
|
|
57
|
+
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON());
|
|
58
|
+
setReadonly(false);
|
|
59
|
+
setLite(false);
|
|
60
|
+
const serverSettings = createServerSettings(getJupyterServerUrl(), getJupyterServerToken());
|
|
61
|
+
const serviceManager = new ServiceManager({ serverSettings });
|
|
62
|
+
serviceManager['__NAME__'] = 'MutatingServiceManager';
|
|
63
|
+
setServiceManager(serviceManager);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case 3: {
|
|
67
|
+
setReadonly(false);
|
|
68
|
+
setWaiting(true);
|
|
69
|
+
setLite(false);
|
|
70
|
+
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON());
|
|
71
|
+
createDatalayerServiceManager(configuration?.cpuEnvironment || 'python-simple-env', configuration?.credits || 1).then(serviceManager => {
|
|
72
|
+
serviceManager['__NAME__'] = 'DatalayerCPUServiceManager';
|
|
73
|
+
setServiceManager(serviceManager);
|
|
74
|
+
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON());
|
|
75
|
+
setReadonly(false);
|
|
76
|
+
setWaiting(false);
|
|
77
|
+
});
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case 4: {
|
|
81
|
+
setReadonly(false);
|
|
82
|
+
setWaiting(true);
|
|
83
|
+
setLite(false);
|
|
84
|
+
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON());
|
|
85
|
+
createDatalayerServiceManager(configuration?.gpuEnvironment || 'pytorch-cuda-env', configuration?.credits || 1).then(serviceManager => {
|
|
86
|
+
serviceManager['__NAME__'] = 'DatalayerGPUServiceManager';
|
|
87
|
+
setServiceManager(serviceManager);
|
|
88
|
+
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON());
|
|
89
|
+
setReadonly(false);
|
|
90
|
+
setWaiting(false);
|
|
91
|
+
});
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return (_jsx(JupyterReactTheme, { children: _jsxs(_Fragment, { children: [_jsxs(Box, { display: "flex", children: [_jsx(Box, { children: _jsxs(SegmentedControl, { onChange: index => changeIndex(index), "aria-label": "jupyter-react-example", children: [_jsx(SegmentedControl.Button, { defaultSelected: index === 0, children: "Readonly" }), _jsx(SegmentedControl.Button, { defaultSelected: index === 1, children: "Browser Kernel" }), _jsx(SegmentedControl.Button, { defaultSelected: index === 2, children: "OSS Kernel (CPU)" }), _jsx(SegmentedControl.Button, { defaultSelected: index === 3, children: "Kernel (CPU)" }), _jsx(SegmentedControl.Button, { defaultSelected: index === 4, children: "Kernel (GPU)" })] }) }), _jsxs(Box, { ml: 1, mt: 1, children: [_jsxs(Label, { children: ["Lite: ", String(notebook?.adapter?.lite)] }), _jsxs(Label, { children: ["Service Manager URL:", ' ', notebook?.adapter?.serviceManager.serverSettings.baseUrl] }), _jsxs(Label, { children: ["Service Manager is ready:", ' ', String(notebook?.adapter?.serviceManager.isReady)] }), _jsxs(Label, { children: ["Kernel ID: ", notebook?.adapter?.kernel?.id] }), _jsxs(Label, { children: ["Kernel Banner: ", notebook?.adapter?.kernel?.info?.banner] })] })] }), _jsx(Box, { children: _jsx(Text, { as: "h3", children: "Kernel Sessions" }) }), _jsx(Box, { children: sessions.map(session => {
|
|
97
|
+
return (_jsx(Box, { children: _jsxs(Text, { children: [session.name, " ", session.id, " ", _jsx(Label, { children: "Kernel" }), " clientId [", session.kernel?.clientId, ") - id ", session.kernel?.id] }) }, session.id));
|
|
98
|
+
}) }), waiting ? (_jsx(SpinnerCentered, {})) : (_jsx(Notebook, { height: "calc(100vh - 2.6rem)", id: NOTEBOOK_ID, lite: lite, nbformat: nbformat, onSessionConnection: onSessionConnection, readonly: readonly, serviceManager: serviceManager }))] }) }));
|
|
99
|
+
};
|
|
100
|
+
export default NotebookMutationsServiceManager;
|
|
101
|
+
// For standalone testing
|
|
102
|
+
if (typeof window !== 'undefined' && window.location.pathname === '/test') {
|
|
103
|
+
const div = document.createElement('div');
|
|
104
|
+
document.body.appendChild(div);
|
|
105
|
+
const root = createRoot(div);
|
|
106
|
+
root.render(_jsx(NotebookMutationsServiceManager, {}));
|
|
107
|
+
}
|