@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
|
@@ -36,7 +36,7 @@ export function getGroupedRuntimeDescs(multiServiceManager, kernelId, translator
|
|
|
36
36
|
.map(session => {
|
|
37
37
|
const spec = multiServiceManager.browser.kernelspecs.specs.kernelspecs[session.kernel.name];
|
|
38
38
|
return {
|
|
39
|
-
id:
|
|
39
|
+
id: '', // TODO Assign a proper ID.
|
|
40
40
|
kernelId: session.kernel.id,
|
|
41
41
|
name: spec.name,
|
|
42
42
|
language: spec.language,
|
|
@@ -62,7 +62,9 @@ export function getGroupedRuntimeDescs(multiServiceManager, kernelId, translator
|
|
|
62
62
|
.concat((multiServiceManager.remote?.runtimesManager.get() ?? [])
|
|
63
63
|
.filter(k => k.id && !listedAsSession.includes(k.id))
|
|
64
64
|
.map(runtime => {
|
|
65
|
-
const environment = multiServiceManager
|
|
65
|
+
const environment = multiServiceManager
|
|
66
|
+
.remote.environments.get()
|
|
67
|
+
.find(env => env.name === runtime.environment_name);
|
|
66
68
|
return {
|
|
67
69
|
kernelId: runtime.id,
|
|
68
70
|
name: environment.name,
|
|
@@ -82,16 +84,15 @@ export function getGroupedRuntimeDescs(multiServiceManager, kernelId, translator
|
|
|
82
84
|
name: spec.name,
|
|
83
85
|
language: spec.language,
|
|
84
86
|
displayName: spec.display_name,
|
|
85
|
-
location: 'browser'
|
|
87
|
+
location: 'browser',
|
|
86
88
|
};
|
|
87
89
|
}))
|
|
88
90
|
.filter(filterKernels);
|
|
89
91
|
runningSessions.push(...runningKernels);
|
|
90
92
|
if (runningSessions.length) {
|
|
91
|
-
const key =
|
|
92
|
-
ASSIGN_EXISTING_REMOTE_RUNTIME_LABEL
|
|
93
|
-
:
|
|
94
|
-
ASSIGN_EXISTING_RUNTIME_LABEL;
|
|
93
|
+
const key = variant === 'cell'
|
|
94
|
+
? ASSIGN_EXISTING_REMOTE_RUNTIME_LABEL
|
|
95
|
+
: ASSIGN_EXISTING_RUNTIME_LABEL;
|
|
95
96
|
kernels[key] = runningSessions;
|
|
96
97
|
}
|
|
97
98
|
// Environments.
|
|
@@ -113,15 +114,18 @@ export function getGroupedRuntimeDescs(multiServiceManager, kernelId, translator
|
|
|
113
114
|
displayName: spec.title,
|
|
114
115
|
location: 'remote',
|
|
115
116
|
gpu: spec.resources?.['nvidia.com/gpu'],
|
|
116
|
-
burningRate: spec.burning_rate
|
|
117
|
+
burningRate: spec.burning_rate,
|
|
117
118
|
}))
|
|
118
119
|
.filter(filterKernels) ?? []));
|
|
119
|
-
environments.push(...Object.values(multiServiceManager.browser?.kernelspecs.specs?.kernelspecs ?? {})
|
|
120
|
+
environments.push(...Object.values(multiServiceManager.browser?.kernelspecs.specs?.kernelspecs ?? {})
|
|
121
|
+
.filter(spec => !!spec)
|
|
122
|
+
.map(spec => ({
|
|
120
123
|
name: spec.name,
|
|
121
124
|
language: spec.language,
|
|
122
125
|
displayName: spec.display_name,
|
|
123
|
-
location: 'browser'
|
|
124
|
-
}))
|
|
126
|
+
location: 'browser',
|
|
127
|
+
}))
|
|
128
|
+
.filter(filterKernels));
|
|
125
129
|
if (environments.length) {
|
|
126
130
|
kernels[trans.__(ASSIGN_NEW_RUNTIME_LABEL)] = environments;
|
|
127
131
|
}
|
|
@@ -160,7 +164,13 @@ export function getDefaultKernelName(selector) {
|
|
|
160
164
|
}
|
|
161
165
|
if (matches.length === 1) {
|
|
162
166
|
const specName = matches[0];
|
|
163
|
-
console.warn('No exact match found for ' +
|
|
167
|
+
console.warn('No exact match found for ' +
|
|
168
|
+
specName +
|
|
169
|
+
', using runtime ' +
|
|
170
|
+
specName +
|
|
171
|
+
' that matches ' +
|
|
172
|
+
'language=' +
|
|
173
|
+
language);
|
|
164
174
|
return specName;
|
|
165
175
|
}
|
|
166
176
|
// No matches found.
|
|
@@ -5,7 +5,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
5
5
|
*/
|
|
6
6
|
import { useMemo } from 'react';
|
|
7
7
|
import { IconButton, ToggleSwitch, FormControl } from '@primer/react';
|
|
8
|
-
import { Box } from
|
|
8
|
+
import { Box } from '@datalayer/primer-addons';
|
|
9
9
|
import { Blankslate, DataTable, Table } from '@primer/react/experimental';
|
|
10
10
|
import { nullTranslator } from '@jupyterlab/translation';
|
|
11
11
|
import { checkIcon } from '@jupyterlab/ui-components';
|
|
@@ -13,7 +13,7 @@ import { checkIcon } from '@jupyterlab/ui-components';
|
|
|
13
13
|
* Runtime variables selector component.
|
|
14
14
|
*/
|
|
15
15
|
export function RuntimeVariables(props) {
|
|
16
|
-
const { className, translator, selectedVariables, setSelectVariable, transferVariables, setTransferVariable, kernelVariables } = props;
|
|
16
|
+
const { className, translator, selectedVariables, setSelectVariable, transferVariables, setTransferVariable, kernelVariables, } = props;
|
|
17
17
|
const trans = useMemo(() => (translator ?? nullTranslator).load('jupyterlab'), [translator]);
|
|
18
18
|
const nRows = Object.keys(kernelVariables ?? {}).length;
|
|
19
19
|
// Sorting and actions does not play nice together :'(
|
|
@@ -21,11 +21,11 @@ export function RuntimeVariables(props) {
|
|
|
21
21
|
{
|
|
22
22
|
header: trans.__('Name'),
|
|
23
23
|
field: 'name',
|
|
24
|
-
rowHeader: true
|
|
24
|
+
rowHeader: true,
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
header: trans.__('Type'),
|
|
28
|
-
field: 'type'
|
|
28
|
+
field: 'type',
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
id: 'select',
|
|
@@ -63,10 +63,10 @@ export function RuntimeVariables(props) {
|
|
|
63
63
|
setSelectVariable([...selectedVariables, row.name]);
|
|
64
64
|
}
|
|
65
65
|
} }));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
68
|
];
|
|
69
|
-
return (_jsxs(Box, { className: className, sx: { paddingTop:
|
|
69
|
+
return (_jsxs(Box, { className: className, sx: { paddingTop: '10px' }, children: [_jsxs(FormControl, { layout: "horizontal", children: [_jsx(FormControl.Label, { children: trans.__('Transfer variables') }), _jsx(ToggleSwitch, { checked: transferVariables, size: "small", onClick: e => {
|
|
70
70
|
e.preventDefault();
|
|
71
71
|
setTransferVariable(!transferVariables);
|
|
72
72
|
}, "aria-labelledby": "kernel-toggle-variables" })] }), transferVariables && (_jsxs(Table.Container, { sx: { flex: '1 1 auto', marginTop: 3 }, children: [_jsx(Table.Subtitle, { as: "p", id: "dla-kernel-variables-subtitle", children: trans.__('The list of transferable runtime variables.') }), kernelVariables ? (Object.keys(kernelVariables ?? {}).length ? (_jsx(DataTable, { "aria-labelledby": "dla-kernel-variables", "aria-describedby": "dla-kernel-variables-subtitle", data: Object.entries(kernelVariables ?? {})
|
|
@@ -45,7 +45,7 @@ export class ScreenCapture extends Component {
|
|
|
45
45
|
};
|
|
46
46
|
handStartCapture = () => this.setState({ on: true });
|
|
47
47
|
handleMouseMove = (e) => {
|
|
48
|
-
const { isMouseDown, windowWidth, windowHeight, startX, startY, borderWidth } = this.state;
|
|
48
|
+
const { isMouseDown, windowWidth, windowHeight, startX, startY, borderWidth, } = this.state;
|
|
49
49
|
let cropPositionTop = startY;
|
|
50
50
|
let cropPositionLeft = startX;
|
|
51
51
|
const endX = e.clientX;
|
|
@@ -63,28 +63,24 @@ export class ScreenCapture extends Component {
|
|
|
63
63
|
let cropHeigth = 0;
|
|
64
64
|
if (isMouseDown) {
|
|
65
65
|
if (isStartTopLeft) {
|
|
66
|
-
newBorderWidth = `${startY}px ${windowWidth - endX}px ${windowHeight -
|
|
67
|
-
endY}px ${startX}px`;
|
|
66
|
+
newBorderWidth = `${startY}px ${windowWidth - endX}px ${windowHeight - endY}px ${startX}px`;
|
|
68
67
|
cropWidth = endX - startX;
|
|
69
68
|
cropHeigth = endY - startY;
|
|
70
69
|
}
|
|
71
70
|
if (isStartTopRight) {
|
|
72
|
-
newBorderWidth = `${startY}px ${windowWidth - startX}px ${windowHeight -
|
|
73
|
-
endY}px ${endX}px`;
|
|
71
|
+
newBorderWidth = `${startY}px ${windowWidth - startX}px ${windowHeight - endY}px ${endX}px`;
|
|
74
72
|
cropWidth = startX - endX;
|
|
75
73
|
cropHeigth = endY - startY;
|
|
76
74
|
cropPositionLeft = endX;
|
|
77
75
|
}
|
|
78
76
|
if (isStartBottomLeft) {
|
|
79
|
-
newBorderWidth = `${endY}px ${windowWidth - endX}px ${windowHeight -
|
|
80
|
-
startY}px ${startX}px`;
|
|
77
|
+
newBorderWidth = `${endY}px ${windowWidth - endX}px ${windowHeight - startY}px ${startX}px`;
|
|
81
78
|
cropWidth = endX - startX;
|
|
82
79
|
cropHeigth = startY - endY;
|
|
83
80
|
cropPositionTop = endY;
|
|
84
81
|
}
|
|
85
82
|
if (isStartBottomRight) {
|
|
86
|
-
newBorderWidth = `${endY}px ${windowWidth - startX}px ${windowHeight -
|
|
87
|
-
startY}px ${endX}px`;
|
|
83
|
+
newBorderWidth = `${endY}px ${windowWidth - startX}px ${windowHeight - startY}px ${endX}px`;
|
|
88
84
|
cropWidth = startX - endX;
|
|
89
85
|
cropHeigth = startY - endY;
|
|
90
86
|
cropPositionLeft = endX;
|
|
@@ -131,7 +127,7 @@ export class ScreenCapture extends Component {
|
|
|
131
127
|
html2canvas(body, {
|
|
132
128
|
width: windowWidth,
|
|
133
129
|
height: windowHeight,
|
|
134
|
-
scale: scale
|
|
130
|
+
scale: scale,
|
|
135
131
|
}).then(canvas => {
|
|
136
132
|
const croppedCanvas = document.createElement('canvas');
|
|
137
133
|
const croppedCanvasContext = croppedCanvas.getContext('2d');
|
|
@@ -156,7 +152,7 @@ export class ScreenCapture extends Component {
|
|
|
156
152
|
renderChild = () => {
|
|
157
153
|
const { children } = this.props;
|
|
158
154
|
const props = {
|
|
159
|
-
onStartCapture: this.handStartCapture
|
|
155
|
+
onStartCapture: this.handStartCapture,
|
|
160
156
|
};
|
|
161
157
|
if (typeof children === 'function') {
|
|
162
158
|
return children(props);
|
|
@@ -164,11 +160,11 @@ export class ScreenCapture extends Component {
|
|
|
164
160
|
return children;
|
|
165
161
|
};
|
|
166
162
|
render() {
|
|
167
|
-
const { on, crossHairsTop, crossHairsLeft, borderWidth, isMouseDown
|
|
163
|
+
const { on, crossHairsTop, crossHairsLeft, borderWidth, isMouseDown } = this.state;
|
|
168
164
|
if (!on) {
|
|
169
165
|
return this.renderChild();
|
|
170
166
|
}
|
|
171
|
-
return (_jsxs("div", { onMouseMove: this.handleMouseMove, onMouseDown: this.handleMouseDown, onMouseUp: this.handleMouseUp, children: [this.renderChild(), _jsx("div", { className: `overlay ${isMouseDown && 'highlighting'}`, style: { borderWidth: `${borderWidth}` } }), _jsx("div", { className:
|
|
167
|
+
return (_jsxs("div", { onMouseMove: this.handleMouseMove, onMouseDown: this.handleMouseDown, onMouseUp: this.handleMouseUp, children: [this.renderChild(), _jsx("div", { className: `overlay ${isMouseDown && 'highlighting'}`, style: { borderWidth: `${borderWidth}` } }), _jsx("div", { className: "crosshairs", style: { left: crossHairsLeft + 'px', top: crossHairsTop + 'px' } })] }));
|
|
172
168
|
}
|
|
173
169
|
}
|
|
174
170
|
export default ScreenCapture;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Link, Tooltip, Button } from
|
|
3
|
-
import { ScreenFullIcon } from
|
|
4
|
-
import { lazyWithPreload, WithSuspense } from
|
|
5
|
-
import { useToast } from
|
|
6
|
-
import { useLayoutStore } from
|
|
7
|
-
const ScreenCapture = WithSuspense(lazyWithPreload(() => import(
|
|
2
|
+
import { Link, Tooltip, Button } from '@primer/react';
|
|
3
|
+
import { ScreenFullIcon } from '@primer/octicons-react';
|
|
4
|
+
import { lazyWithPreload, WithSuspense } from '../../utils';
|
|
5
|
+
import { useToast } from '../../hooks';
|
|
6
|
+
import { useLayoutStore } from '../../state';
|
|
7
|
+
const ScreenCapture = WithSuspense(lazyWithPreload(() => import('../screenshot/ScreenCapture')));
|
|
8
8
|
export const ScreenCaptureButton = (props) => {
|
|
9
9
|
const { enqueueToast } = useToast();
|
|
10
10
|
const { setScreenCapture, hideScreenshot } = useLayoutStore();
|
|
@@ -15,7 +15,13 @@ export const ScreenCaptureButton = (props) => {
|
|
|
15
15
|
};
|
|
16
16
|
return (_jsx(ScreenCapture, { onEndCapture: handleScreenCapture, children: ({ onStartCapture }) => (_jsx(Tooltip, { text: "Take a screen capture", direction: "s", children: _jsx(Button, { variant: "invisible", children: _jsx(Link, { href: "javascript: return false;", sx: {
|
|
17
17
|
color: 'fg.muted',
|
|
18
|
-
':hover, :focus, &[aria-expanded=true]': {
|
|
19
|
-
|
|
18
|
+
':hover, :focus, &[aria-expanded=true]': {
|
|
19
|
+
background: 'none !important',
|
|
20
|
+
color: 'accent.fg',
|
|
21
|
+
},
|
|
22
|
+
}, onClick: e => {
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
onStartCapture();
|
|
25
|
+
}, children: _jsx(ScreenFullIcon, {}) }) }) })) }));
|
|
20
26
|
};
|
|
21
27
|
export default ScreenCaptureButton;
|
|
@@ -3,12 +3,12 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
6
|
+
import { useCallback, useEffect, useState, } from 'react';
|
|
7
7
|
import { CameraIcon } from '@datalayer/icons-react';
|
|
8
|
-
import { ActionList, ActionMenu, Box, Flash, FormControl, Select, Spinner } from '@primer/react';
|
|
8
|
+
import { ActionList, ActionMenu, Box, Flash, FormControl, Select, Spinner, } from '@primer/react';
|
|
9
9
|
import { Dialog } from '@primer/react/experimental';
|
|
10
10
|
import { useToast } from '../../hooks';
|
|
11
|
-
import { createRuntimeSnapshot, getRuntimeSnapshots, loadBrowserRuntimeSnapshot, loadRuntimeSnapshot } from '../../api';
|
|
11
|
+
import { createRuntimeSnapshot, getRuntimeSnapshots, loadBrowserRuntimeSnapshot, loadRuntimeSnapshot, } from '../../api';
|
|
12
12
|
import { useRuntimesStore } from '../../state';
|
|
13
13
|
import { createRuntimeSnapshotName } from '../../utils';
|
|
14
14
|
/**
|
|
@@ -16,7 +16,7 @@ import { createRuntimeSnapshotName } from '../../utils';
|
|
|
16
16
|
*/
|
|
17
17
|
export function RuntimeSnapshotMenu(props) {
|
|
18
18
|
const { children, connection, podName, multiServiceManager, disabled } = props;
|
|
19
|
-
const { addRuntimeSnapshot, runtimesRunUrl, runtimeSnapshots, setRuntimeSnapshots } = useRuntimesStore();
|
|
19
|
+
const { addRuntimeSnapshot, runtimesRunUrl, runtimeSnapshots, setRuntimeSnapshots, } = useRuntimesStore();
|
|
20
20
|
const { trackAsyncTask } = useToast();
|
|
21
21
|
const [openLoadDialog, setOpenLoadDialog] = useState(false);
|
|
22
22
|
const [loadingKernelSnapshot, setLoadingKernelSnapshot] = useState(false);
|
|
@@ -42,7 +42,7 @@ export function RuntimeSnapshotMenu(props) {
|
|
|
42
42
|
const onKerenelSnapshotChanged = useCallback(event => {
|
|
43
43
|
setSelection(event.target.value);
|
|
44
44
|
}, []);
|
|
45
|
-
const onLoadKernelSnapshotSubmit = useCallback(async ({ id, connection, podName }) => {
|
|
45
|
+
const onLoadKernelSnapshotSubmit = useCallback(async ({ id, connection, podName, }) => {
|
|
46
46
|
if (podName) {
|
|
47
47
|
await loadRuntimeSnapshot({ id: podName, from: id });
|
|
48
48
|
}
|
|
@@ -63,7 +63,7 @@ export function RuntimeSnapshotMenu(props) {
|
|
|
63
63
|
podName,
|
|
64
64
|
name: snapshotName,
|
|
65
65
|
description: snapshotName,
|
|
66
|
-
stop: false
|
|
66
|
+
stop: false,
|
|
67
67
|
});
|
|
68
68
|
ref = podName.split('-', 2).reverse()[0];
|
|
69
69
|
task.then(s => {
|
|
@@ -77,7 +77,7 @@ export function RuntimeSnapshotMenu(props) {
|
|
|
77
77
|
let isPending = true;
|
|
78
78
|
task = createRuntimeSnapshot({
|
|
79
79
|
connection: multiServiceManager.browser.kernels.connectTo({
|
|
80
|
-
model
|
|
80
|
+
model,
|
|
81
81
|
}),
|
|
82
82
|
metadata: { filename: `${snapshotName}.data` },
|
|
83
83
|
onUploadProgress: () => {
|
|
@@ -88,7 +88,7 @@ export function RuntimeSnapshotMenu(props) {
|
|
|
88
88
|
snapshot = snapshots.find(s => s.name === snapshotName);
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
-
}
|
|
91
|
+
},
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
if (task) {
|
|
@@ -99,12 +99,12 @@ export function RuntimeSnapshotMenu(props) {
|
|
|
99
99
|
? `Runtime ${ref} will not be snapshotted as it does not contain any serializable state.`
|
|
100
100
|
: `Failed to pause runtime ${ref} - ${reason}`;
|
|
101
101
|
return msg;
|
|
102
|
-
}
|
|
102
|
+
},
|
|
103
103
|
},
|
|
104
104
|
pending: { message: `Taking a snapshot of runtime ${ref}…` },
|
|
105
105
|
success: {
|
|
106
|
-
message: () => `Runtime ${ref} successfully snapshotted as ${snapshotName}
|
|
107
|
-
}
|
|
106
|
+
message: () => `Runtime ${ref} successfully snapshotted as ${snapshotName}.`,
|
|
107
|
+
},
|
|
108
108
|
});
|
|
109
109
|
await task;
|
|
110
110
|
if (snapshot) {
|
|
@@ -116,7 +116,9 @@ export function RuntimeSnapshotMenu(props) {
|
|
|
116
116
|
setTakingSnapshot(false);
|
|
117
117
|
}
|
|
118
118
|
}, [connection, podName, multiServiceManager]);
|
|
119
|
-
return (_jsxs(_Fragment, { children: [_jsxs(ActionMenu, { children: [_jsx(ActionMenu.Button, { leadingVisual: CameraIcon, variant: "invisible", size: "small", disabled: loadingKernelSnapshot || takingKernelSnapshot || disabled, children: children }), _jsx(ActionMenu.Overlay, { children: _jsxs(ActionList, { children: [_jsx(ActionList.Item, { onSelect: onLoadKernelSnapshot, disabled: loadingKernelSnapshot || runtimeSnapshots.length === 0, children: "Load a runtime snapshot\u2026" }), _jsx(ActionList.Item, { onSelect: onTakeKernelSnapshot, disabled: takingKernelSnapshot, children: "Take a runtime snapshot" })] }) })] }), openLoadDialog && (_jsx(Dialog, { title: "Choose a runtime snapshot to load", onClose: () => {
|
|
119
|
+
return (_jsxs(_Fragment, { children: [_jsxs(ActionMenu, { children: [_jsx(ActionMenu.Button, { leadingVisual: CameraIcon, variant: "invisible", size: "small", disabled: loadingKernelSnapshot || takingKernelSnapshot || disabled, children: children }), _jsx(ActionMenu.Overlay, { children: _jsxs(ActionList, { children: [_jsx(ActionList.Item, { onSelect: onLoadKernelSnapshot, disabled: loadingKernelSnapshot || runtimeSnapshots.length === 0, children: "Load a runtime snapshot\u2026" }), _jsx(ActionList.Item, { onSelect: onTakeKernelSnapshot, disabled: takingKernelSnapshot, children: "Take a runtime snapshot" })] }) })] }), openLoadDialog && (_jsx(Dialog, { title: "Choose a runtime snapshot to load", onClose: () => {
|
|
120
|
+
setOpenLoadDialog(false);
|
|
121
|
+
}, footerButtons: [
|
|
120
122
|
{
|
|
121
123
|
buttonType: 'default',
|
|
122
124
|
content: 'Cancel',
|
|
@@ -125,11 +127,11 @@ export function RuntimeSnapshotMenu(props) {
|
|
|
125
127
|
event.preventDefault();
|
|
126
128
|
setOpenLoadDialog(false);
|
|
127
129
|
}
|
|
128
|
-
}
|
|
130
|
+
},
|
|
129
131
|
},
|
|
130
132
|
{
|
|
131
133
|
buttonType: 'primary',
|
|
132
|
-
content: loadingKernelSnapshot ? _jsx(Spinner, { size: "small" }) : 'Load',
|
|
134
|
+
content: loadingKernelSnapshot ? (_jsx(Spinner, { size: "small" })) : ('Load'),
|
|
133
135
|
disabled: loadingKernelSnapshot,
|
|
134
136
|
onClick: async (event) => {
|
|
135
137
|
if (!event.defaultPrevented) {
|
|
@@ -142,7 +144,7 @@ export function RuntimeSnapshotMenu(props) {
|
|
|
142
144
|
await onLoadKernelSnapshotSubmit({
|
|
143
145
|
connection,
|
|
144
146
|
id: snapshot.id,
|
|
145
|
-
podName
|
|
147
|
+
podName,
|
|
146
148
|
});
|
|
147
149
|
}
|
|
148
150
|
else {
|
|
@@ -155,8 +157,8 @@ export function RuntimeSnapshotMenu(props) {
|
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
},
|
|
158
|
-
autoFocus: true
|
|
159
|
-
}
|
|
160
|
+
autoFocus: true,
|
|
161
|
+
},
|
|
160
162
|
], children: _jsxs(Box, { as: "form", children: [_jsxs(FormControl, { children: [_jsx(FormControl.Label, { children: "Snapshot" }), _jsx(Select, { name: "snapshot", value: selection, onChange: onKerenelSnapshotChanged, block: true, children: runtimeSnapshots.map(s => (_jsx(Select.Option, { value: s.id, children: s.name ? `${s.name} (${s.id})` : s.id }, s.id))) })] }), error && _jsx(Flash, { variant: "danger", children: error })] }) }))] }));
|
|
161
163
|
}
|
|
162
164
|
RuntimeSnapshotMenu.defaultProps = {
|
|
@@ -6,14 +6,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
import { useCallback, useMemo, useState } from 'react';
|
|
7
7
|
import { nullTranslator } from '@jupyterlab/translation';
|
|
8
8
|
import { FormControl, Select, Text } from '@primer/react';
|
|
9
|
-
import { Box } from
|
|
9
|
+
import { Box } from '@datalayer/primer-addons';
|
|
10
10
|
import { Dialog } from '@primer/react/experimental';
|
|
11
11
|
import { Markdown } from '../display';
|
|
12
12
|
/**
|
|
13
13
|
* Dialog to inject snippet in a cell.
|
|
14
14
|
*/
|
|
15
15
|
export function SnippetDialog(props) {
|
|
16
|
-
const { model, onClose, language, snippets, markdownParser, sanitizer, translator } = props;
|
|
16
|
+
const { model, onClose, language, snippets, markdownParser, sanitizer, translator, } = props;
|
|
17
17
|
const [selection, setSelection] = useState(snippets[0]);
|
|
18
18
|
const trans = useMemo(() => (translator ?? nullTranslator).load('jupyterlab'), [translator]);
|
|
19
19
|
const onSelectionChange = useCallback((e) => {
|
|
@@ -29,14 +29,14 @@ export function SnippetDialog(props) {
|
|
|
29
29
|
{
|
|
30
30
|
buttonType: 'default',
|
|
31
31
|
content: trans.__('Cancel'),
|
|
32
|
-
onClick: onClose
|
|
32
|
+
onClick: onClose,
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
buttonType: 'primary',
|
|
36
36
|
content: trans.__('Inject snippet'),
|
|
37
37
|
onClick: injectSnippet,
|
|
38
|
-
autoFocus: true
|
|
39
|
-
}
|
|
38
|
+
autoFocus: true,
|
|
39
|
+
},
|
|
40
40
|
], children: _jsx(Box, { as: "form", children: _jsxs(FormControl, { children: [_jsx(FormControl.Label, {}), _jsx(Select, { block: true, onChange: onSelectionChange, children: snippets.map((snippet, index) => (_jsx(Select.Option, { value: `${index}`, children: snippet.title }, index))) }), _jsxs(FormControl.Caption, { children: [selection.description && (_jsx(Text, { as: "p", children: selection.description })), markdownParser ? (_jsx(Markdown, { markdownParser: markdownParser, sanitizer: sanitizer, text: `\`\`\`${language}\n${selection.code}\`\`\`` })) : (_jsx("code", { children: selection.code }))] })] }) }) }));
|
|
41
41
|
}
|
|
42
42
|
export default SnippetDialog;
|
|
@@ -6,14 +6,14 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
6
6
|
import { useCallback, useEffect, useState } from 'react';
|
|
7
7
|
import { PathExt } from '@jupyterlab/coreutils';
|
|
8
8
|
import { PromiseDelegate } from '@lumino/coreutils';
|
|
9
|
-
import { ActionList, ActionMenu, Heading, IconButton, Spinner, TreeView } from '@primer/react';
|
|
10
|
-
import { Box } from
|
|
9
|
+
import { ActionList, ActionMenu, Heading, IconButton, Spinner, TreeView, } from '@primer/react';
|
|
10
|
+
import { Box } from '@datalayer/primer-addons';
|
|
11
11
|
import { Blankslate, Dialog } from '@primer/react/experimental';
|
|
12
12
|
import { CounterClockWiseIcon } from '@datalayer/icons-react';
|
|
13
13
|
import { useIsMounted } from 'usehooks-ts';
|
|
14
14
|
import { useToast } from '../../hooks';
|
|
15
15
|
import { UploadIconButton } from '../buttons';
|
|
16
|
-
import { DirectoryItem, TreeItem, modelToView } from './ContentsItems';
|
|
16
|
+
import { DirectoryItem, TreeItem, modelToView, } from './ContentsItems';
|
|
17
17
|
/**
|
|
18
18
|
* The maximum upload size (in bytes) for notebook version < 5.1.0
|
|
19
19
|
*/
|
|
@@ -36,7 +36,8 @@ export function ContentsBrowser(props) {
|
|
|
36
36
|
const [openDeleteConfirmation, setOpenDeleteConfirmation] = useState(false);
|
|
37
37
|
const [copyToLocalConfirmation, setCopyToLocalConfirmation] = useState(false);
|
|
38
38
|
const refresh = useCallback(() => {
|
|
39
|
-
contents
|
|
39
|
+
contents
|
|
40
|
+
.get('')
|
|
40
41
|
.then(model => {
|
|
41
42
|
setIsLoading(false);
|
|
42
43
|
setChildren(modelToView(model.content, documentRegistry));
|
|
@@ -98,10 +99,10 @@ export function ContentsBrowser(props) {
|
|
|
98
99
|
const msg = `Failed to upload ${file.name}.`;
|
|
99
100
|
console.error(msg, reason);
|
|
100
101
|
return msg;
|
|
101
|
-
}
|
|
102
|
+
},
|
|
102
103
|
},
|
|
103
104
|
pending: { message: `Uploading ${file.name}…` },
|
|
104
|
-
success: { message: () => `${file.name} uploaded.` }
|
|
105
|
+
success: { message: () => `${file.name} uploaded.` },
|
|
105
106
|
};
|
|
106
107
|
if (chunked) {
|
|
107
108
|
const task = new PromiseDelegate();
|
|
@@ -162,11 +163,12 @@ export function ContentsBrowser(props) {
|
|
|
162
163
|
trackAsyncTask(task, {
|
|
163
164
|
success: { message: () => `${selectedItem.path} deleted.` },
|
|
164
165
|
pending: { message: `Deleting ${selectedItem.path}…` },
|
|
165
|
-
error: {
|
|
166
|
+
error: {
|
|
167
|
+
message: reason => {
|
|
166
168
|
const msg = `Failed to delete ${selectedItem.path}.`;
|
|
167
169
|
console.error(msg, reason);
|
|
168
170
|
return msg;
|
|
169
|
-
}
|
|
171
|
+
},
|
|
170
172
|
},
|
|
171
173
|
});
|
|
172
174
|
task.finally(() => {
|
|
@@ -180,16 +182,17 @@ export function ContentsBrowser(props) {
|
|
|
180
182
|
}, []);
|
|
181
183
|
const copyToLocal = useCallback(() => {
|
|
182
184
|
if (selectedItem && localContents) {
|
|
183
|
-
contents.get(selectedItem.path).then(
|
|
185
|
+
contents.get(selectedItem.path).then(model => {
|
|
184
186
|
const copyTask = localContents?.save(model.path, model);
|
|
185
187
|
trackAsyncTask(copyTask, {
|
|
186
188
|
success: { message: () => `${selectedItem.path} copied to local.` },
|
|
187
189
|
pending: { message: `Copying to local ${selectedItem.path}…` },
|
|
188
|
-
error: {
|
|
190
|
+
error: {
|
|
191
|
+
message: reason => {
|
|
189
192
|
const msg = `Failed to copy to local ${selectedItem.path}.`;
|
|
190
193
|
console.error(msg, reason);
|
|
191
194
|
return msg;
|
|
192
|
-
}
|
|
195
|
+
},
|
|
193
196
|
},
|
|
194
197
|
});
|
|
195
198
|
copyTask.finally(() => {
|
|
@@ -206,50 +209,54 @@ export function ContentsBrowser(props) {
|
|
|
206
209
|
fontSize: 'var(--text-title-size-small)',
|
|
207
210
|
lineHeight: 'var(--text-title-lineHeight-medium)',
|
|
208
211
|
fontWeight: 'var(--text-title-weight-medium)',
|
|
209
|
-
flex: '1 1 auto'
|
|
210
|
-
}, children: "Contents Browser" }), _jsxs(Box, { children: [_jsx(IconButton, { variant: "invisible", "aria-label": 'Refresh contents browser.', title: 'Refresh contents browser.', icon: CounterClockWiseIcon, onClick: refresh }), _jsx(UploadIconButton, { label: 'Upload a file', multiple: true, upload: upload })] })] }), isLoading ?
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
212
|
+
flex: '1 1 auto',
|
|
213
|
+
}, children: "Contents Browser" }), _jsxs(Box, { children: [_jsx(IconButton, { variant: "invisible", "aria-label": 'Refresh contents browser.', title: 'Refresh contents browser.', icon: CounterClockWiseIcon, onClick: refresh }), _jsx(UploadIconButton, { label: 'Upload a file', multiple: true, upload: upload })] })] }), isLoading ? (_jsx(Box, { sx: {
|
|
214
|
+
gridArea: 'content',
|
|
215
|
+
display: 'flex',
|
|
216
|
+
alignItems: 'center',
|
|
217
|
+
justifyContent: 'center',
|
|
218
|
+
minHeight: '40px',
|
|
219
|
+
height: '100vh',
|
|
220
|
+
}, children: _jsx(Spinner, {}) })) : (_jsx(Box, { sx: { gridArea: 'content' }, children: children ? (_jsxs(_Fragment, { children: [_jsx(TreeView, { children: children?.map(child => {
|
|
221
|
+
return child.type === 'directory' ? (_jsx(DirectoryItem, { item: child, contents: contents, current: selectedItem, documentRegistry: documentRegistry, onContextMenu: onContextMenu, onSelect: onSelect }, child.name)) : (_jsx(TreeItem, { item: child, current: selectedItem?.path === child.path, onSelect: item => {
|
|
222
|
+
onSelect(item, refresh);
|
|
223
|
+
}, onContextMenu: onContextMenu }, child.name));
|
|
224
|
+
}) }), _jsx(ActionMenu, { anchorRef: contextMenuAnchor ?? undefined, open: contextMenuAnchor?.current !== null, onOpenChange: () => {
|
|
225
|
+
setContextMenuAnchor(null);
|
|
226
|
+
}, children: _jsx(ActionMenu.Overlay, { children: _jsxs(ActionList, { children: [_jsx(ActionList.Item, { title: "Delete the active item.", onSelect: onSelectDelete, children: "Delete\u2026" }), localContents && (_jsx(ActionList.Item, { title: "Copy the active item to the local drive.", onSelect: onSelectCopyToLocal, children: "Copy to local drive\u2026" }))] }) }) }), openDeleteConfirmation && (_jsx(Dialog, { title: "Confirm deletion", onClose: () => {
|
|
227
|
+
setOpenDeleteConfirmation(false);
|
|
228
|
+
}, footerButtons: [
|
|
229
|
+
{
|
|
230
|
+
buttonType: 'default',
|
|
231
|
+
content: 'Cancel',
|
|
232
|
+
onClick: () => {
|
|
233
|
+
setOpenDeleteConfirmation(false);
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
buttonType: 'danger',
|
|
238
|
+
content: 'Delete',
|
|
239
|
+
onClick: () => {
|
|
240
|
+
deleteItem();
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
], children: `Are you sure you want to delete ${selectedItem?.path}?` })), copyToLocalConfirmation && (_jsx(Dialog, { title: "Confirm copy to local", onClose: () => {
|
|
244
|
+
setCopyToLocalConfirmation(false);
|
|
245
|
+
}, footerButtons: [
|
|
246
|
+
{
|
|
247
|
+
buttonType: 'default',
|
|
248
|
+
content: 'Cancel',
|
|
249
|
+
onClick: () => {
|
|
250
|
+
setCopyToLocalConfirmation(false);
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
buttonType: 'danger',
|
|
255
|
+
content: 'Copy to local',
|
|
256
|
+
onClick: () => {
|
|
257
|
+
copyToLocal();
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
], children: `Are you sure you want to copy to local ${selectedItem?.path}?` }))] })) : (_jsx(Blankslate, { children: _jsx(Blankslate.Heading, { children: "No contents" }) })) }))] }));
|
|
254
261
|
}
|
|
255
262
|
export default ContentsBrowser;
|
|
@@ -9,7 +9,7 @@ import { FileIcon } from '@primer/octicons-react';
|
|
|
9
9
|
export function modelToView(models, docRegistry) {
|
|
10
10
|
let items = models.map(model => ({
|
|
11
11
|
...model,
|
|
12
|
-
fileType: docRegistry?.getFileTypeForModel(model)
|
|
12
|
+
fileType: docRegistry?.getFileTypeForModel(model),
|
|
13
13
|
}));
|
|
14
14
|
items = items.filter(model => !model.name.startsWith('.'));
|
|
15
15
|
items.sort((a, b) => {
|
|
@@ -33,7 +33,8 @@ export function DirectoryItem(props) {
|
|
|
33
33
|
const [isLoading, setIsLoading] = useState(false);
|
|
34
34
|
const refresh = useCallback(() => {
|
|
35
35
|
setIsLoading(true);
|
|
36
|
-
contents
|
|
36
|
+
contents
|
|
37
|
+
.get(item.path)
|
|
37
38
|
.then(model => {
|
|
38
39
|
setIsLoading(false);
|
|
39
40
|
setChildren(modelToView(model.content, documentRegistry));
|
|
@@ -47,7 +48,9 @@ export function DirectoryItem(props) {
|
|
|
47
48
|
refresh();
|
|
48
49
|
}
|
|
49
50
|
}, [children, item, contents]);
|
|
50
|
-
return (_jsxs(TreeView.Item, { ref: ref, id: `${item.type}-${item.name}`, onExpandedChange: onExpandedChange, onSelect: () => {
|
|
51
|
+
return (_jsxs(TreeView.Item, { ref: ref, id: `${item.type}-${item.name}`, onExpandedChange: onExpandedChange, onSelect: () => {
|
|
52
|
+
onSelect(item, refresh);
|
|
53
|
+
}, current: item.path === current?.path, children: [_jsx(TreeView.LeadingVisual, { children: _jsx(TreeView.DirectoryIcon, {}) }), _jsx("span", { onContextMenu: event => {
|
|
51
54
|
event.preventDefault();
|
|
52
55
|
if (current?.path !== item.path) {
|
|
53
56
|
onSelect(item, refresh);
|
|
@@ -58,17 +61,16 @@ export function DirectoryItem(props) {
|
|
|
58
61
|
: (children?.length ?? -1) >= 0
|
|
59
62
|
? 'done'
|
|
60
63
|
: 'initial', children: children?.map(child => {
|
|
61
|
-
return child.type === 'directory' ?
|
|
62
|
-
_jsx(DirectoryItem, { item: child, contents: contents, current: current, documentRegistry: documentRegistry, onContextMenu: onContextMenu, onSelect: onSelect }, child.name)
|
|
63
|
-
:
|
|
64
|
-
_jsx(TreeItem, { item: child, current: child.path === current?.path, onSelect: item => onSelect(item, refresh), onContextMenu: onContextMenu }, child.name);
|
|
64
|
+
return child.type === 'directory' ? (_jsx(DirectoryItem, { item: child, contents: contents, current: current, documentRegistry: documentRegistry, onContextMenu: onContextMenu, onSelect: onSelect }, child.name)) : (_jsx(TreeItem, { item: child, current: child.path === current?.path, onSelect: item => onSelect(item, refresh), onContextMenu: onContextMenu }, child.name));
|
|
65
65
|
}) })] }));
|
|
66
66
|
}
|
|
67
67
|
export function TreeItem(props) {
|
|
68
68
|
const { item, current, onSelect, onContextMenu } = props;
|
|
69
69
|
const ref = useRef(null);
|
|
70
70
|
const icon = item.fileType?.icon;
|
|
71
|
-
return (_jsxs(TreeView.Item, { ref: ref, id: `${item.type}-${item.name}`, current: current, onSelect: () => {
|
|
71
|
+
return (_jsxs(TreeView.Item, { ref: ref, id: `${item.type}-${item.name}`, current: current, onSelect: () => {
|
|
72
|
+
onSelect(item);
|
|
73
|
+
}, children: [_jsx(TreeView.LeadingVisual, { children: icon ? _jsx(icon.react, { tag: 'span' }) : _jsx(FileIcon, {}) }), _jsx("span", { onContextMenu: event => {
|
|
72
74
|
event.preventDefault();
|
|
73
75
|
if (!current) {
|
|
74
76
|
onSelect(item);
|