@difizen/libro-jupyter 0.0.2-alpha.0
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/LICENSE +21 -0
- package/README.md +1 -0
- package/es/add-between-cell/add-between-cell-command-contribution.d.ts +14 -0
- package/es/add-between-cell/add-between-cell-command-contribution.d.ts.map +1 -0
- package/es/add-between-cell/add-between-cell-command-contribution.js +97 -0
- package/es/add-between-cell/add-between-cell.d.ts +5 -0
- package/es/add-between-cell/add-between-cell.d.ts.map +1 -0
- package/es/add-between-cell/add-between-cell.js +243 -0
- package/es/add-between-cell/index.d.ts +3 -0
- package/es/add-between-cell/index.d.ts.map +1 -0
- package/es/add-between-cell/index.js +2 -0
- package/es/add-between-cell/index.less +103 -0
- package/es/add-between-cell/module.d.ts +3 -0
- package/es/add-between-cell/module.d.ts.map +1 -0
- package/es/add-between-cell/module.js +8 -0
- package/es/cell/index.d.ts +3 -0
- package/es/cell/index.d.ts.map +1 -0
- package/es/cell/index.js +2 -0
- package/es/cell/jupyter-code-cell-model.d.ts +12 -0
- package/es/cell/jupyter-code-cell-model.d.ts.map +1 -0
- package/es/cell/jupyter-code-cell-model.js +56 -0
- package/es/cell/jupyter-code-cell-view.d.ts +18 -0
- package/es/cell/jupyter-code-cell-view.d.ts.map +1 -0
- package/es/cell/jupyter-code-cell-view.js +280 -0
- package/es/command/command-contribution.d.ts +10 -0
- package/es/command/command-contribution.d.ts.map +1 -0
- package/es/command/command-contribution.js +161 -0
- package/es/command/index.d.ts +3 -0
- package/es/command/index.d.ts.map +1 -0
- package/es/command/index.js +2 -0
- package/es/command/keybinding-contribution.d.ts +8 -0
- package/es/command/keybinding-contribution.d.ts.map +1 -0
- package/es/command/keybinding-contribution.js +37 -0
- package/es/components/cell-execution-tip.d.ts +6 -0
- package/es/components/cell-execution-tip.d.ts.map +1 -0
- package/es/components/cell-execution-tip.js +69 -0
- package/es/components/cell-input-bottom-blank.d.ts +5 -0
- package/es/components/cell-input-bottom-blank.d.ts.map +1 -0
- package/es/components/cell-input-bottom-blank.js +21 -0
- package/es/components/icons.d.ts +5 -0
- package/es/components/icons.d.ts.map +1 -0
- package/es/components/icons.js +154 -0
- package/es/components/index.d.ts +4 -0
- package/es/components/index.d.ts.map +1 -0
- package/es/components/index.js +3 -0
- package/es/components/index.less +82 -0
- package/es/config/config-contribution.d.ts +10 -0
- package/es/config/config-contribution.d.ts.map +1 -0
- package/es/config/config-contribution.js +50 -0
- package/es/config/config.d.ts +3 -0
- package/es/config/config.d.ts.map +1 -0
- package/es/config/config.js +11 -0
- package/es/config/index.d.ts +2 -0
- package/es/config/index.d.ts.map +1 -0
- package/es/config/index.js +1 -0
- package/es/configuration/index.d.ts +3 -0
- package/es/configuration/index.d.ts.map +1 -0
- package/es/configuration/index.js +2 -0
- package/es/configuration/libro-configuration-contribution.d.ts +5 -0
- package/es/configuration/libro-configuration-contribution.d.ts.map +1 -0
- package/es/configuration/libro-configuration-contribution.js +24 -0
- package/es/configuration/libro-configuration.d.ts +3 -0
- package/es/configuration/libro-configuration.d.ts.map +1 -0
- package/es/configuration/libro-configuration.js +12 -0
- package/es/contents/content-contribution.d.ts +7 -0
- package/es/contents/content-contribution.d.ts.map +1 -0
- package/es/contents/content-contribution.js +63 -0
- package/es/contents/index.d.ts +2 -0
- package/es/contents/index.d.ts.map +1 -0
- package/es/contents/index.js +1 -0
- package/es/file/file-name-alias.d.ts +7 -0
- package/es/file/file-name-alias.d.ts.map +1 -0
- package/es/file/file-name-alias.js +26 -0
- package/es/file/file-protocol.d.ts +8 -0
- package/es/file/file-protocol.d.ts.map +1 -0
- package/es/file/file-protocol.js +7 -0
- package/es/file/file-service.d.ts +31 -0
- package/es/file/file-service.d.ts.map +1 -0
- package/es/file/file-service.js +329 -0
- package/es/file/file-tree-label-provider.d.ts +13 -0
- package/es/file/file-tree-label-provider.d.ts.map +1 -0
- package/es/file/file-tree-label-provider.js +62 -0
- package/es/file/file-view/index.d.ts +14 -0
- package/es/file/file-view/index.d.ts.map +1 -0
- package/es/file/file-view/index.js +101 -0
- package/es/file/file-view/index.less +5 -0
- package/es/file/index.d.ts +7 -0
- package/es/file/index.d.ts.map +1 -0
- package/es/file/index.js +6 -0
- package/es/file/module.d.ts +3 -0
- package/es/file/module.d.ts.map +1 -0
- package/es/file/module.js +8 -0
- package/es/file/navigatable-view.d.ts +24 -0
- package/es/file/navigatable-view.d.ts.map +1 -0
- package/es/file/navigatable-view.js +151 -0
- package/es/file/open-handler-contribution.d.ts +11 -0
- package/es/file/open-handler-contribution.d.ts.map +1 -0
- package/es/file/open-handler-contribution.js +102 -0
- package/es/index.d.ts +32 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +31 -0
- package/es/keybind-instructions/index.d.ts +6 -0
- package/es/keybind-instructions/index.d.ts.map +1 -0
- package/es/keybind-instructions/index.js +5 -0
- package/es/keybind-instructions/index.less +177 -0
- package/es/keybind-instructions/keybind-instructions-contribution.d.ts +11 -0
- package/es/keybind-instructions/keybind-instructions-contribution.d.ts.map +1 -0
- package/es/keybind-instructions/keybind-instructions-contribution.js +84 -0
- package/es/keybind-instructions/keybind-instructions-icon.d.ts +3 -0
- package/es/keybind-instructions/keybind-instructions-icon.d.ts.map +1 -0
- package/es/keybind-instructions/keybind-instructions-icon.js +23 -0
- package/es/keybind-instructions/keybind-instructions-items.d.ts +14 -0
- package/es/keybind-instructions/keybind-instructions-items.d.ts.map +1 -0
- package/es/keybind-instructions/keybind-instructions-items.js +589 -0
- package/es/keybind-instructions/keybind-instructions-view.d.ts +16 -0
- package/es/keybind-instructions/keybind-instructions-view.d.ts.map +1 -0
- package/es/keybind-instructions/keybind-instructions-view.js +224 -0
- package/es/keybind-instructions/module.d.ts +3 -0
- package/es/keybind-instructions/module.d.ts.map +1 -0
- package/es/keybind-instructions/module.js +5 -0
- package/es/libro-jupyter-file-service.d.ts +106 -0
- package/es/libro-jupyter-file-service.d.ts.map +1 -0
- package/es/libro-jupyter-file-service.js +127 -0
- package/es/libro-jupyter-model.d.ts +49 -0
- package/es/libro-jupyter-model.d.ts.map +1 -0
- package/es/libro-jupyter-model.js +505 -0
- package/es/libro-jupyter-protocol.d.ts +38 -0
- package/es/libro-jupyter-protocol.d.ts.map +1 -0
- package/es/libro-jupyter-protocol.js +9 -0
- package/es/libro-jupyter-server-launch-manager.d.ts +11 -0
- package/es/libro-jupyter-server-launch-manager.d.ts.map +1 -0
- package/es/libro-jupyter-server-launch-manager.js +59 -0
- package/es/libro-jupyter-view.d.ts +10 -0
- package/es/libro-jupyter-view.d.ts.map +1 -0
- package/es/libro-jupyter-view.js +42 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +48 -0
- package/es/output/index.d.ts +2 -0
- package/es/output/index.d.ts.map +1 -0
- package/es/output/index.js +1 -0
- package/es/output/libro-jupyter-outputarea.d.ts +8 -0
- package/es/output/libro-jupyter-outputarea.d.ts.map +1 -0
- package/es/output/libro-jupyter-outputarea.js +77 -0
- package/es/rendermime/assets/plotly.svg +31 -0
- package/es/rendermime/index.d.ts +5 -0
- package/es/rendermime/index.d.ts.map +1 -0
- package/es/rendermime/index.js +4 -0
- package/es/rendermime/index.less +22 -0
- package/es/rendermime/module.d.ts +3 -0
- package/es/rendermime/module.d.ts.map +1 -0
- package/es/rendermime/module.js +3 -0
- package/es/rendermime/plotly-render.d.ts +7 -0
- package/es/rendermime/plotly-render.d.ts.map +1 -0
- package/es/rendermime/plotly-render.js +30 -0
- package/es/rendermime/plotly-renderers.d.ts +58 -0
- package/es/rendermime/plotly-renderers.d.ts.map +1 -0
- package/es/rendermime/plotly-renderers.js +211 -0
- package/es/rendermime/plotly-rendermime-contribution.d.ts +12 -0
- package/es/rendermime/plotly-rendermime-contribution.d.ts.map +1 -0
- package/es/rendermime/plotly-rendermime-contribution.js +22 -0
- package/es/theme/color-registry.d.ts +6 -0
- package/es/theme/color-registry.d.ts.map +1 -0
- package/es/theme/color-registry.js +393 -0
- package/es/theme/index.d.ts +2 -0
- package/es/theme/index.d.ts.map +1 -0
- package/es/theme/index.js +1 -0
- package/es/toolbar/index.d.ts +6 -0
- package/es/toolbar/index.d.ts.map +1 -0
- package/es/toolbar/index.js +5 -0
- package/es/toolbar/index.less +194 -0
- package/es/toolbar/kernel-selector-dropdown.d.ts +13 -0
- package/es/toolbar/kernel-selector-dropdown.d.ts.map +1 -0
- package/es/toolbar/kernel-selector-dropdown.js +165 -0
- package/es/toolbar/kernel-status-and-selector.d.ts +18 -0
- package/es/toolbar/kernel-status-and-selector.d.ts.map +1 -0
- package/es/toolbar/kernel-status-and-selector.js +164 -0
- package/es/toolbar/run-selector.d.ts +3 -0
- package/es/toolbar/run-selector.d.ts.map +1 -0
- package/es/toolbar/run-selector.js +98 -0
- package/es/toolbar/save-file-error-contribution.d.ts +5 -0
- package/es/toolbar/save-file-error-contribution.d.ts.map +1 -0
- package/es/toolbar/save-file-error-contribution.js +23 -0
- package/es/toolbar/save-file-error.d.ts +5 -0
- package/es/toolbar/save-file-error.d.ts.map +1 -0
- package/es/toolbar/save-file-error.js +27 -0
- package/es/toolbar/side-toolbar-run-selector.d.ts +3 -0
- package/es/toolbar/side-toolbar-run-selector.d.ts.map +1 -0
- package/es/toolbar/side-toolbar-run-selector.js +67 -0
- package/es/toolbar/toolbar-contribution.d.ts +9 -0
- package/es/toolbar/toolbar-contribution.d.ts.map +1 -0
- package/es/toolbar/toolbar-contribution.js +67 -0
- package/es/typings/index.d.ts +31 -0
- package/es/utils/index.d.ts +11 -0
- package/es/utils/index.d.ts.map +1 -0
- package/es/utils/index.js +47 -0
- package/package.json +75 -0
- package/src/add-between-cell/add-between-cell-command-contribution.ts +63 -0
- package/src/add-between-cell/add-between-cell.tsx +201 -0
- package/src/add-between-cell/index.less +103 -0
- package/src/add-between-cell/index.ts +2 -0
- package/src/add-between-cell/module.ts +13 -0
- package/src/cell/index.ts +2 -0
- package/src/cell/jupyter-code-cell-model.ts +36 -0
- package/src/cell/jupyter-code-cell-view.tsx +221 -0
- package/src/command/command-contribution.ts +163 -0
- package/src/command/index.ts +2 -0
- package/src/command/keybinding-contribution.ts +25 -0
- package/src/components/cell-execution-tip.tsx +107 -0
- package/src/components/cell-input-bottom-blank.tsx +24 -0
- package/src/components/icons.tsx +117 -0
- package/src/components/index.less +82 -0
- package/src/components/index.ts +3 -0
- package/src/config/config-contribution.ts +21 -0
- package/src/config/config.ts +14 -0
- package/src/config/index.ts +1 -0
- package/src/configuration/index.ts +2 -0
- package/src/configuration/libro-configuration-contribution.ts +11 -0
- package/src/configuration/libro-configuration.ts +14 -0
- package/src/contents/content-contribution.ts +32 -0
- package/src/contents/index.ts +1 -0
- package/src/file/file-name-alias.ts +15 -0
- package/src/file/file-protocol.ts +7 -0
- package/src/file/file-service.ts +179 -0
- package/src/file/file-tree-label-provider.ts +42 -0
- package/src/file/file-view/index.less +5 -0
- package/src/file/file-view/index.tsx +90 -0
- package/src/file/index.ts +6 -0
- package/src/file/module.ts +19 -0
- package/src/file/navigatable-view.tsx +93 -0
- package/src/file/open-handler-contribution.ts +44 -0
- package/src/index.ts +32 -0
- package/src/keybind-instructions/index.less +177 -0
- package/src/keybind-instructions/index.ts +5 -0
- package/src/keybind-instructions/keybind-instructions-contribution.ts +47 -0
- package/src/keybind-instructions/keybind-instructions-icon.tsx +28 -0
- package/src/keybind-instructions/keybind-instructions-items.tsx +597 -0
- package/src/keybind-instructions/keybind-instructions-view.tsx +239 -0
- package/src/keybind-instructions/module.ts +11 -0
- package/src/libro-jupyter-file-service.ts +158 -0
- package/src/libro-jupyter-model.ts +289 -0
- package/src/libro-jupyter-protocol.ts +59 -0
- package/src/libro-jupyter-server-launch-manager.ts +36 -0
- package/src/libro-jupyter-view.tsx +24 -0
- package/src/module.ts +105 -0
- package/src/output/index.ts +1 -0
- package/src/output/libro-jupyter-outputarea.tsx +71 -0
- package/src/rendermime/assets/plotly.svg +31 -0
- package/src/rendermime/index.less +13 -0
- package/src/rendermime/index.ts +4 -0
- package/src/rendermime/module.ts +7 -0
- package/src/rendermime/plotly-render.tsx +35 -0
- package/src/rendermime/plotly-renderers.ts +191 -0
- package/src/rendermime/plotly-rendermime-contribution.ts +15 -0
- package/src/theme/color-registry.ts +301 -0
- package/src/theme/index.ts +1 -0
- package/src/toolbar/index.less +194 -0
- package/src/toolbar/index.ts +5 -0
- package/src/toolbar/kernel-selector-dropdown.tsx +204 -0
- package/src/toolbar/kernel-status-and-selector.tsx +195 -0
- package/src/toolbar/run-selector.tsx +110 -0
- package/src/toolbar/save-file-error-contribution.ts +10 -0
- package/src/toolbar/save-file-error.tsx +35 -0
- package/src/toolbar/side-toolbar-run-selector.tsx +77 -0
- package/src/toolbar/toolbar-contribution.tsx +62 -0
- package/src/typings/index.d.ts +31 -0
- package/src/utils/index.ts +65 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { DisplayWrapComponent } from '@difizen/libro-common';
|
|
2
|
+
import type { BetweenCellProvider, LibroView } from '@difizen/libro-core';
|
|
3
|
+
import { CellService } from '@difizen/libro-core';
|
|
4
|
+
import { CommandRegistry, useInject, ViewInstance } from '@difizen/mana-app';
|
|
5
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
6
|
+
import { Tooltip, Popover, Menu } from 'antd';
|
|
7
|
+
import type { MenuProps } from 'antd';
|
|
8
|
+
import { useEffect, useRef, useState, forwardRef } from 'react';
|
|
9
|
+
|
|
10
|
+
import { LibroAddBetweenCellCommand } from './add-between-cell-command-contribution.js';
|
|
11
|
+
|
|
12
|
+
import './index.less';
|
|
13
|
+
|
|
14
|
+
const AddCellOutlined: React.FC = () => (
|
|
15
|
+
<svg
|
|
16
|
+
width="18px"
|
|
17
|
+
height="18px"
|
|
18
|
+
viewBox="0 0 18 18"
|
|
19
|
+
version="1.1"
|
|
20
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
21
|
+
xmlnsXlink="http://www.w3.org/1999/xlink"
|
|
22
|
+
>
|
|
23
|
+
<g id="页面-1" stroke="none" strokeWidth="1" fill="#6982A9" fillRule="evenodd">
|
|
24
|
+
<g id="2.0-添加-cell" transform="translate(-1539.000000, -240.000000)">
|
|
25
|
+
<g id="Icon/01-Line/add备份-3" transform="translate(1539.937500, 240.562500)">
|
|
26
|
+
<path
|
|
27
|
+
d="M15.9375,7.546875 C16.040625,7.546875 16.125,7.63125 16.125,7.734375 L16.125,9.140625 C16.125,9.24375 16.040625,9.328125 15.9375,9.328125 L8.953125,9.328125 L8.953125,16.6875 C8.953125,16.7910534 8.86917839,16.875 8.765625,16.875 L7.359375,16.875 C7.25582161,16.875 7.171875,16.7910534 7.171875,16.6875 L7.171875,9.328125 L0.1875,9.328125 C0.084375,9.328125 0,9.24375 0,9.140625 L0,7.734375 C0,7.63125 0.084375,7.546875 0.1875,7.546875 L7.171875,7.546875 L7.171875,0.1875 C7.171875,0.0839466094 7.25582161,0 7.359375,0 L8.765625,0 C8.86917839,0 8.953125,0.0839466094 8.953125,0.1875 L8.953125,7.546875 L15.9375,7.546875 Z"
|
|
28
|
+
id="path-1"
|
|
29
|
+
fill="currentColor"
|
|
30
|
+
/>
|
|
31
|
+
</g>
|
|
32
|
+
</g>
|
|
33
|
+
</g>
|
|
34
|
+
</svg>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
38
|
+
export const LibroCommonBetweenCellContent: BetweenCellProvider = forwardRef(
|
|
39
|
+
function LibroCommonBetweenCellContent(props, _ref) {
|
|
40
|
+
// eslint-disable-next-line react/prop-types
|
|
41
|
+
const { addCell, index } = props;
|
|
42
|
+
const { cellsMeta } = useInject<CellService>(CellService);
|
|
43
|
+
const anchorRef = useRef<HTMLDivElement>(null);
|
|
44
|
+
const gutterRef = useRef<HTMLDivElement>(null);
|
|
45
|
+
const [position, setPosition] = useState({ top: 0, left: 0 });
|
|
46
|
+
const [GutterVisible, setGutterVisible] = useState(false);
|
|
47
|
+
const [tooltipVisible, setTooltipVisible] = useState(false);
|
|
48
|
+
const [menuVisible, setMenuVisible] = useState(false);
|
|
49
|
+
const command = useInject(CommandRegistry);
|
|
50
|
+
|
|
51
|
+
const innerOpenTooltip = () => {
|
|
52
|
+
if (menuVisible) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
setTooltipVisible(true);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//====== delay ========
|
|
59
|
+
const delayRef = useRef<any>();
|
|
60
|
+
|
|
61
|
+
const clearDelay = () => {
|
|
62
|
+
clearTimeout(delayRef.current);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const openTooltip = (_nextOpen: boolean, delay = 0.5) => {
|
|
66
|
+
clearDelay();
|
|
67
|
+
|
|
68
|
+
if (delay === 0) {
|
|
69
|
+
innerOpenTooltip();
|
|
70
|
+
} else {
|
|
71
|
+
delayRef.current = setTimeout(() => {
|
|
72
|
+
innerOpenTooltip();
|
|
73
|
+
}, delay * 1000);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const closeTooltip = () => {
|
|
78
|
+
clearDelay();
|
|
79
|
+
setTooltipVisible(false);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
|
+
useEffect(() => closeTooltip, []);
|
|
84
|
+
|
|
85
|
+
const items: MenuProps['items'] = cellsMeta
|
|
86
|
+
.filter((item) => item.type !== 'raw')
|
|
87
|
+
.sort((a, b) => a.order.localeCompare(b.order))
|
|
88
|
+
.map((item) => {
|
|
89
|
+
return {
|
|
90
|
+
label: item.name,
|
|
91
|
+
key: item.type,
|
|
92
|
+
onClick: async () => {
|
|
93
|
+
command.executeCommand(
|
|
94
|
+
LibroAddBetweenCellCommand.AddBetweenCell.id,
|
|
95
|
+
item.type,
|
|
96
|
+
addCell,
|
|
97
|
+
index,
|
|
98
|
+
);
|
|
99
|
+
anchorRef.current?.blur();
|
|
100
|
+
setMenuVisible(false);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div className="libro-add-between-cell">
|
|
107
|
+
<Popover
|
|
108
|
+
content={<Menu items={items} />}
|
|
109
|
+
trigger="click"
|
|
110
|
+
getPopupContainer={(trigger) => anchorRef.current ?? trigger}
|
|
111
|
+
placement="bottomLeft"
|
|
112
|
+
overlayClassName="libro-add-cell-menu"
|
|
113
|
+
destroyTooltipOnHide
|
|
114
|
+
open={menuVisible}
|
|
115
|
+
>
|
|
116
|
+
<div
|
|
117
|
+
tabIndex={10}
|
|
118
|
+
className="libro-add-between-cell-anchor"
|
|
119
|
+
style={{
|
|
120
|
+
position: 'fixed',
|
|
121
|
+
top: position.top + 5,
|
|
122
|
+
left: position.left + 5,
|
|
123
|
+
width: 1,
|
|
124
|
+
height: 1,
|
|
125
|
+
zIndex: 1000,
|
|
126
|
+
}}
|
|
127
|
+
ref={anchorRef}
|
|
128
|
+
onBlur={(e) => {
|
|
129
|
+
if (!anchorRef.current?.contains(e.relatedTarget)) {
|
|
130
|
+
setMenuVisible(false);
|
|
131
|
+
}
|
|
132
|
+
setGutterVisible(false);
|
|
133
|
+
closeTooltip();
|
|
134
|
+
}}
|
|
135
|
+
/>
|
|
136
|
+
</Popover>
|
|
137
|
+
<div
|
|
138
|
+
ref={gutterRef}
|
|
139
|
+
className="libro-add-between-cell-area"
|
|
140
|
+
onMouseEnter={() => {
|
|
141
|
+
setGutterVisible(true);
|
|
142
|
+
}}
|
|
143
|
+
onMouseLeave={() => {
|
|
144
|
+
closeTooltip();
|
|
145
|
+
if (menuVisible) {
|
|
146
|
+
setGutterVisible(true);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
setGutterVisible(false);
|
|
151
|
+
}}
|
|
152
|
+
onMouseUp={(e) => {
|
|
153
|
+
closeTooltip();
|
|
154
|
+
setGutterVisible(true);
|
|
155
|
+
setMenuVisible(true);
|
|
156
|
+
setPosition({ top: e.clientY, left: e.clientX });
|
|
157
|
+
anchorRef.current?.focus();
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
160
|
+
{GutterVisible && (
|
|
161
|
+
<>
|
|
162
|
+
<Tooltip
|
|
163
|
+
title={l10n.t('添加 Cell')}
|
|
164
|
+
open={tooltipVisible}
|
|
165
|
+
overlayClassName="libro-add-between-cell-tooltip"
|
|
166
|
+
destroyTooltipOnHide
|
|
167
|
+
>
|
|
168
|
+
<span
|
|
169
|
+
className="libro-add-between-cell-icon"
|
|
170
|
+
onMouseEnter={() => {
|
|
171
|
+
openTooltip(true);
|
|
172
|
+
}}
|
|
173
|
+
onMouseLeave={() => {
|
|
174
|
+
closeTooltip();
|
|
175
|
+
if (menuVisible) {
|
|
176
|
+
setGutterVisible(true);
|
|
177
|
+
}
|
|
178
|
+
}}
|
|
179
|
+
>
|
|
180
|
+
<AddCellOutlined />
|
|
181
|
+
</span>
|
|
182
|
+
</Tooltip>
|
|
183
|
+
<div className="libro-cell-divider" />
|
|
184
|
+
</>
|
|
185
|
+
)}
|
|
186
|
+
</div>
|
|
187
|
+
</div>
|
|
188
|
+
);
|
|
189
|
+
},
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
export const LibroWrappedBetweenCellContent: BetweenCellProvider = (props) => {
|
|
193
|
+
// eslint-disable-next-line react/prop-types
|
|
194
|
+
const { index, addCell } = props;
|
|
195
|
+
const instance = useInject<LibroView>(ViewInstance);
|
|
196
|
+
return (
|
|
197
|
+
<DisplayWrapComponent mode={instance.model.readOnly}>
|
|
198
|
+
<LibroCommonBetweenCellContent index={index} addCell={addCell} />
|
|
199
|
+
</DisplayWrapComponent>
|
|
200
|
+
);
|
|
201
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
@ant-prefix: ant;
|
|
2
|
+
|
|
3
|
+
.libro-add-between-cell {
|
|
4
|
+
position: relative;
|
|
5
|
+
.@{ant-prefix}-popover-arrow {
|
|
6
|
+
display: none;
|
|
7
|
+
}
|
|
8
|
+
.@{ant-prefix}-popover {
|
|
9
|
+
padding: 0;
|
|
10
|
+
max-width: unset;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.@{ant-prefix}-popover-inner {
|
|
14
|
+
border-radius: 8px;
|
|
15
|
+
background-color: var(--mana-libro-add-between-popover-background-color);
|
|
16
|
+
padding: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.@{ant-prefix}-popover-inner-content {
|
|
20
|
+
padding: 0;
|
|
21
|
+
width: unset;
|
|
22
|
+
max-width: unset;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.libro-add-cell-menu {
|
|
26
|
+
z-index: 1000;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.@{ant-prefix}-menu {
|
|
30
|
+
border-radius: 8px !important;
|
|
31
|
+
background-color: var(--mana-libro-add-between-popover-background-color) !important;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.@{ant-prefix}-menu-vertical {
|
|
35
|
+
border-right: unset !important;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.@{ant-prefix}-menu-item {
|
|
39
|
+
height: 32px !important;
|
|
40
|
+
line-height: 32px !important;
|
|
41
|
+
}
|
|
42
|
+
.@{ant-prefix}-menu-item:hover {
|
|
43
|
+
background-color: var(--mana-libro-add-between-hover-color) !important;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.@{ant-prefix}-menu-title-content {
|
|
47
|
+
color: var(--mana-libro-add-between-menu-label-color);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.@{ant-prefix}-menu-item-selected {
|
|
51
|
+
background-color: var(--mana-libro-add-between-hover-color) !important;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.libro-cell-divider {
|
|
56
|
+
width: 100%;
|
|
57
|
+
height: 4px;
|
|
58
|
+
background-color: var(--mana-libro-add-between-divider-color);
|
|
59
|
+
border-radius: 2px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.libro-add-between-cell-icon {
|
|
63
|
+
z-index: 20;
|
|
64
|
+
margin-right: 10px;
|
|
65
|
+
margin-left: 30px;
|
|
66
|
+
height: 18px;
|
|
67
|
+
line-height: 18px;
|
|
68
|
+
text-align: center;
|
|
69
|
+
|
|
70
|
+
svg {
|
|
71
|
+
color: var(--mana-libro-add-between-icon-color);
|
|
72
|
+
|
|
73
|
+
&:hover {
|
|
74
|
+
color: var(--mana-libro-add-between-icon-hover-color);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.libro-add-between-cell-area {
|
|
80
|
+
position: absolute;
|
|
81
|
+
top: -16px;
|
|
82
|
+
z-index: 10;
|
|
83
|
+
display: flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
width: 100%;
|
|
86
|
+
height: 16px;
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.libro-add-between-cell-tooltip {
|
|
91
|
+
.@{ant-prefix}-tooltip-inner {
|
|
92
|
+
font-weight: 400;
|
|
93
|
+
font-size: 14px;
|
|
94
|
+
line-height: 22px;
|
|
95
|
+
text-align: center;
|
|
96
|
+
border-radius: 6px;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.libro-add-between-cell-anchor:focus {
|
|
101
|
+
outline: none;
|
|
102
|
+
cursor: pointer;
|
|
103
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BetweenCellProvider } from '@difizen/libro-core';
|
|
2
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
import { LibroAddBetweenCellCommandContribution } from './add-between-cell-command-contribution.js';
|
|
5
|
+
import { LibroWrappedBetweenCellContent } from './add-between-cell.js';
|
|
6
|
+
|
|
7
|
+
export const LibroBetweenCellModule = ManaModule.create().register(
|
|
8
|
+
{
|
|
9
|
+
token: BetweenCellProvider,
|
|
10
|
+
useValue: LibroWrappedBetweenCellContent,
|
|
11
|
+
},
|
|
12
|
+
LibroAddBetweenCellCommandContribution,
|
|
13
|
+
);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { LibroCodeCellModel } from '@difizen/libro-codemirror-code-cell';
|
|
2
|
+
import type { ICellMetadata } from '@difizen/libro-common';
|
|
3
|
+
import { CellOptions } from '@difizen/libro-core';
|
|
4
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
5
|
+
import { prop, ViewManager } from '@difizen/mana-app';
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
ExecutedWithKernelCellModel,
|
|
9
|
+
CodeCellMetadata,
|
|
10
|
+
} from '../libro-jupyter-protocol.js';
|
|
11
|
+
|
|
12
|
+
@transient()
|
|
13
|
+
export class JupyterCodeCellModel
|
|
14
|
+
extends LibroCodeCellModel
|
|
15
|
+
implements ExecutedWithKernelCellModel
|
|
16
|
+
{
|
|
17
|
+
@prop()
|
|
18
|
+
override metadata: Partial<CodeCellMetadata | ICellMetadata>;
|
|
19
|
+
@prop()
|
|
20
|
+
kernelExecuting = false;
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
@inject(CellOptions) options: CellOptions,
|
|
24
|
+
@inject(ViewManager) viewManager: ViewManager,
|
|
25
|
+
) {
|
|
26
|
+
super(options, viewManager);
|
|
27
|
+
this.metadata = options.cell?.metadata || {};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override clearExecution = () => {
|
|
31
|
+
this.executeCount = null;
|
|
32
|
+
this.executing = false;
|
|
33
|
+
this.kernelExecuting = false;
|
|
34
|
+
this.metadata.execution = {};
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { CodeEditorView } from '@difizen/libro-code-editor';
|
|
2
|
+
import type {
|
|
3
|
+
CodeEditorViewOptions,
|
|
4
|
+
CompletionProvider,
|
|
5
|
+
CompletionProviderOption,
|
|
6
|
+
TooltipProvider,
|
|
7
|
+
TooltipProviderOption,
|
|
8
|
+
} from '@difizen/libro-code-editor';
|
|
9
|
+
import { codeMirrorEditorFactory } from '@difizen/libro-codemirror';
|
|
10
|
+
import { CellEditorMemo, LibroCodeCellView } from '@difizen/libro-codemirror-code-cell';
|
|
11
|
+
import type { CellViewOptions } from '@difizen/libro-core';
|
|
12
|
+
import { CellService } from '@difizen/libro-core';
|
|
13
|
+
import { KernelError } from '@difizen/libro-kernel';
|
|
14
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
15
|
+
import { view, ViewInstance, ViewManager, ViewOption } from '@difizen/mana-app';
|
|
16
|
+
import { getOrigin, useInject, watch } from '@difizen/mana-app';
|
|
17
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
18
|
+
import { forwardRef } from 'react';
|
|
19
|
+
|
|
20
|
+
import { LibroJupyterModel } from '../libro-jupyter-model.js';
|
|
21
|
+
import type { ExecutionMeta } from '../libro-jupyter-protocol.js';
|
|
22
|
+
|
|
23
|
+
import type { JupyterCodeCellModel } from './jupyter-code-cell-model.js';
|
|
24
|
+
|
|
25
|
+
const JupyterCodeCellComponent = forwardRef<HTMLDivElement>(
|
|
26
|
+
function JupyterCodeCellComponent(_props, ref) {
|
|
27
|
+
const instance = useInject<JupyterCodeCellView>(ViewInstance);
|
|
28
|
+
return (
|
|
29
|
+
<div
|
|
30
|
+
className={instance.className}
|
|
31
|
+
ref={ref}
|
|
32
|
+
tabIndex={10}
|
|
33
|
+
onBlur={instance.blur}
|
|
34
|
+
>
|
|
35
|
+
<CellEditorMemo />
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
@transient()
|
|
42
|
+
@view('jupyter-code-cell-view')
|
|
43
|
+
export class JupyterCodeCellView extends LibroCodeCellView {
|
|
44
|
+
override view = JupyterCodeCellComponent;
|
|
45
|
+
declare model: JupyterCodeCellModel;
|
|
46
|
+
|
|
47
|
+
constructor(
|
|
48
|
+
@inject(ViewOption) options: CellViewOptions,
|
|
49
|
+
@inject(CellService) cellService: CellService,
|
|
50
|
+
@inject(ViewManager) viewManager: ViewManager,
|
|
51
|
+
) {
|
|
52
|
+
super(options, cellService, viewManager);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override clearExecution = () => {
|
|
56
|
+
this.model.clearExecution();
|
|
57
|
+
this.outputArea.clear();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
override onViewMount() {
|
|
61
|
+
const option: CodeEditorViewOptions = {
|
|
62
|
+
...this.options,
|
|
63
|
+
factory: (editorOption) =>
|
|
64
|
+
codeMirrorEditorFactory({
|
|
65
|
+
...editorOption,
|
|
66
|
+
config: {
|
|
67
|
+
...editorOption.config,
|
|
68
|
+
...{ readOnly: this.parent.model.readOnly },
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
model: this.model,
|
|
72
|
+
tooltipProvider: this.tooltipProvider,
|
|
73
|
+
completionProvider: this.completionProvider,
|
|
74
|
+
lspProvider: undefined,
|
|
75
|
+
};
|
|
76
|
+
this.viewManager
|
|
77
|
+
.getOrCreateView<CodeEditorView, CodeEditorViewOptions>(CodeEditorView, option)
|
|
78
|
+
.then((editorView) => {
|
|
79
|
+
this.editorView = editorView;
|
|
80
|
+
this.editorViewReadyDeferred.resolve();
|
|
81
|
+
watch(this.parent.model, 'readOnly', () => {
|
|
82
|
+
this.editorView?.editor?.setOption('readOnly', this.parent.model.readOnly);
|
|
83
|
+
});
|
|
84
|
+
this.editorView.onModalChange((val) => (this.hasModal = val));
|
|
85
|
+
return;
|
|
86
|
+
})
|
|
87
|
+
.catch(() => {
|
|
88
|
+
//
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
tooltipProvider: TooltipProvider = async (option: TooltipProviderOption) => {
|
|
93
|
+
const cellContent = this.model.value;
|
|
94
|
+
const kernelConnection = getOrigin(
|
|
95
|
+
(this.parent.model as LibroJupyterModel).kernelConnection,
|
|
96
|
+
);
|
|
97
|
+
if (!kernelConnection) {
|
|
98
|
+
alert(l10n.t('Kernel Connection 还没有建立'));
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const reply = await kernelConnection.requestInspect({
|
|
102
|
+
code: cellContent,
|
|
103
|
+
cursor_pos: option.cursorPosition,
|
|
104
|
+
detail_level: 1,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const value = reply.content;
|
|
108
|
+
|
|
109
|
+
if (value.status !== 'ok' || !value.found) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
return value.data['text/plain'] as string;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
completionProvider: CompletionProvider = async (option: CompletionProviderOption) => {
|
|
116
|
+
const cellContent = this.model.value;
|
|
117
|
+
const kernelConnection = getOrigin(
|
|
118
|
+
(this.parent.model as LibroJupyterModel).kernelConnection,
|
|
119
|
+
);
|
|
120
|
+
if (!kernelConnection) {
|
|
121
|
+
alert(l10n.t('Kernel Connection 还没有建立'));
|
|
122
|
+
throw new Error(l10n.t('Kernel Connection 还没有建立'));
|
|
123
|
+
}
|
|
124
|
+
const reply = await kernelConnection.requestComplete({
|
|
125
|
+
code: cellContent,
|
|
126
|
+
cursor_pos: option.cursorPosition,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const value = reply.content;
|
|
130
|
+
|
|
131
|
+
if (value.status === 'abort') {
|
|
132
|
+
throw new Error('abort');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (value.status === 'error') {
|
|
136
|
+
throw new Error(value.ename);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
matches: value.matches,
|
|
141
|
+
cursor_start: value.cursor_start,
|
|
142
|
+
cursor_end: value.cursor_end,
|
|
143
|
+
metadata: value.metadata,
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
override async run() {
|
|
148
|
+
const libroModel = this.parent.model;
|
|
149
|
+
|
|
150
|
+
if (
|
|
151
|
+
!libroModel ||
|
|
152
|
+
!(libroModel instanceof LibroJupyterModel) ||
|
|
153
|
+
!libroModel.kernelConnection ||
|
|
154
|
+
libroModel.kernelConnection.isDisposed
|
|
155
|
+
) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const kernelConnection = getOrigin(libroModel.kernelConnection);
|
|
160
|
+
const cellContent = this.model.value;
|
|
161
|
+
const cellModel = this.model;
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
this.clearExecution();
|
|
165
|
+
const future = kernelConnection.requestExecute({
|
|
166
|
+
code: cellContent,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
let startTimeStr = '';
|
|
170
|
+
cellModel.executing = true;
|
|
171
|
+
|
|
172
|
+
cellModel.metadata['execution'] = {
|
|
173
|
+
'shell.execute_reply.started': '',
|
|
174
|
+
'shell.execute_reply.end': '',
|
|
175
|
+
to_execute: new Date().toISOString(),
|
|
176
|
+
} as ExecutionMeta;
|
|
177
|
+
|
|
178
|
+
// Handle iopub messages
|
|
179
|
+
future.onIOPub = (msg: any) => {
|
|
180
|
+
cellModel.msgChangeEmitter.fire(msg);
|
|
181
|
+
if (msg.header.msg_type === 'execute_input') {
|
|
182
|
+
cellModel.kernelExecuting = true;
|
|
183
|
+
startTimeStr = msg.header.date as string;
|
|
184
|
+
const meta = cellModel.metadata['execution'] as ExecutionMeta;
|
|
185
|
+
if (meta) {
|
|
186
|
+
meta['shell.execute_reply.started'] = startTimeStr;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
// Handle the execute reply.
|
|
191
|
+
future.onReply = (msg: any) => {
|
|
192
|
+
cellModel.msgChangeEmitter.fire(msg);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const msgPromise = await future.done;
|
|
196
|
+
cellModel.executing = false;
|
|
197
|
+
cellModel.kernelExecuting = false;
|
|
198
|
+
|
|
199
|
+
startTimeStr = msgPromise.metadata['started'] as string;
|
|
200
|
+
const endTimeStr = msgPromise.header.date;
|
|
201
|
+
|
|
202
|
+
cellModel.metadata['execution']['shell.execute_reply.started'] = startTimeStr;
|
|
203
|
+
cellModel.metadata['execution']['shell.execute_reply.end'] = endTimeStr;
|
|
204
|
+
|
|
205
|
+
if (!msgPromise) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (msgPromise.content.status === 'ok') {
|
|
210
|
+
return true;
|
|
211
|
+
} else {
|
|
212
|
+
throw new KernelError(msgPromise.content);
|
|
213
|
+
}
|
|
214
|
+
} catch (reason: any) {
|
|
215
|
+
if (reason.message.startsWith('Canceled')) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
throw reason;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|