Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WIP: resolve packaging issues with monaco-editor in jupyterlab. #392

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"node-fetch": "^3.3.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"use-immer": "^0.9.0"
"use-immer": "^0.9.0",
"webpack-bundle-analyzer": "^4.10.2"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.18.6",
Expand All @@ -64,6 +65,7 @@
"husky": "^8.0.3",
"less-loader": "^11.0.0",
"mini-css-extract-plugin": "^2.7.6",
"monaco-editor-webpack-plugin": "^7.1.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.1.1",
"rimraf": "^3.0.2",
Expand Down
142 changes: 43 additions & 99 deletions packages/gsp/example/jupyter_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,113 +2,33 @@
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"id": "6e7b67a4-e4bf-44ed-b19f-51f1ec8f9b2e",
"metadata": {},
"outputs": [],
"source": [
"import gsp"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0a12aac4-48ab-48fb-ab6a-f495abefa7f6",
"execution_count": 1,
"id": "f9557365-4129-4881-ab51-72d2ca6f7db7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Jupyter Notebook\n"
"0.1.0\n",
"/Users/pomelo/Desktop/github/portal/packages/gsp/.venv/bin/python\n"
]
}
],
"source": [
"print(gsp.detect_environment())"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "542d2ce9-268e-44c3-96d0-f0efbba19988",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<!doctype html>\n",
"<html lang=\"en\">\n",
" <head>\n",
" <meta charset=\"UTF-8\" />\n",
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n",
" <title>Document</title>\n",
" </head>\n",
" <body>\n",
" <div id=\"root-hlv04tpag\"></div>\n",
" <script>\n",
" function loadScript(url) {\n",
" return new Promise(function (resolve, reject) {\n",
" var script = document.createElement('script');\n",
" script.type = 'text/javascript';\n",
" script.src = url;\n",
" script.onload = resolve;\n",
" script.onerror = reject;\n",
" document.head.appendChild(script);\n",
" });\n",
" }\n",
" function loadCSS(url) {\n",
" return new Promise(function (resolve, reject) {\n",
" var link = document.createElement('link');\n",
" link.rel = 'stylesheet';\n",
" link.href = url;\n",
" link.onload = resolve;\n",
" link.onerror = reject;\n",
" document.head.appendChild(link);\n",
" });\n",
" }\n",
"\n",
" // 先加载必须的两个 JavaScript 文件\n",
" Promise.all([\n",
" loadScript('https://gw.alipayobjects.com/os/lib/react/18.2.0/umd/react.production.min.js'),\n",
" loadScript('https://gw.alipayobjects.com/os/lib/react-dom/18.2.0/umd/react-dom.production.min.js'),\n",
" ])\n",
" .then(function () {\n",
" // 必须的两个脚本加载完成后,再加载其他的 JavaScript 文件\n",
" return Promise.all([\n",
" loadScript('http://127.0.0.1:5500/packages/studio-importor/dist/index.min.js'),\n",
" loadCSS('http://127.0.0.1:5500/packages/studio-importor/dist/index.css'),\n",
" ]);\n",
" })\n",
" .then(function () {\n",
" const { default: STUDIO_IMPORTOR, sdk } = window.STUDIO_IMPORTOR;\n",
" const id = 'root-hlv04tpag';\n",
" sdk.render_modeling({ id });\n",
" })\n",
" .catch(function (error) {\n",
" console.error('加载脚本时出错:', error);\n",
" });\n",
" </script>\n",
" </body>\n",
"</html>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gsp.modeling()"
"import gsp\n",
"import sys\n",
"print(gsp.__version__)\n",
"print(sys.executable)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "0662b123-3865-42e2-971c-3ada20bcd408",
"metadata": {},
"execution_count": 4,
"id": "4046c77f",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
Expand All @@ -121,7 +41,7 @@
" <title>Document</title>\n",
" </head>\n",
" <body>\n",
" <div id=\"root-9fthsctkh\"></div>\n",
" <div id=\"root-ujumao5pp\"></div>\n",
" <script>\n",
" function loadScript(url) {\n",
" return new Promise(function (resolve, reject) {\n",
Expand Down Expand Up @@ -152,14 +72,14 @@
" // 必须的两个脚本加载完成后,再加载其他的 JavaScript 文件\n",
" return Promise.all([\n",
" loadScript('http://127.0.0.1:5500/packages/studio-query/dist/index.min.js'),\n",
" loadScript('http://127.0.0.1:5500/packages/studio-query/dist/5.index.min.js'),\n",
" loadScript('http://127.0.0.1:5500/packages/studio-query/dist/597.index.min.js'),\n",
" // loadScript('http://127.0.0.1:5500/packages/studio-query/dist/5.index.min.js'),\n",
" // loadScript('http://127.0.0.1:5500/packages/studio-query/dist/597.index.min.js'),\n",
" loadCSS('http://127.0.0.1:5500/packages/studio-query/dist/index.css'),\n",
" ]);\n",
" })\n",
" .then(function () {\n",
" const { default: sdk } = window.STUDIO_QUERY_SDK;\n",
" const id = 'root-9fthsctkh';\n",
" const id = 'root-ujumao5pp';\n",
" sdk.render_query_statement({ id });\n",
" })\n",
" .catch(function (error) {\n",
Expand All @@ -180,13 +100,37 @@
"source": [
"gsp.querying()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6eb68ce9-d2de-4313-8c33-ea6c96508f7c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "63d8e284-18bd-4696-b6d0-092917144a77",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "bc739360-b441-46ed-b34c-73e0e1ef8cd6",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python (gsp_venv)",
"language": "python",
"name": "python3"
"name": "gsp_venv"
},
"language_info": {
"codemirror_mode": {
Expand Down
84 changes: 44 additions & 40 deletions packages/gsp/gsp/template/modeling.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,51 @@
<body>
<div id="ROOT_ID"></div>
<script>
function loadScript(url) {
return new Promise(function (resolve, reject) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
function loadCSS(url) {
return new Promise(function (resolve, reject) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = url;
link.onload = resolve;
link.onerror = reject;
document.head.appendChild(link);
});
}
try {
function loadScript(url) {
return new Promise(function (resolve, reject) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
function loadCSS(url) {
return new Promise(function (resolve, reject) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = url;
link.onload = resolve;
link.onerror = reject;
document.head.appendChild(link);
});
}

// 先加载必须的两个 JavaScript 文件
Promise.all([
loadScript('https://gw.alipayobjects.com/os/lib/react/18.2.0/umd/react.production.min.js'),
loadScript('https://gw.alipayobjects.com/os/lib/react-dom/18.2.0/umd/react-dom.production.min.js'),
])
.then(function () {
// 必须的两个脚本加载完成后,再加载其他的 JavaScript 文件
return Promise.all([
loadScript('http://127.0.0.1:5500/packages/studio-importor/dist/index.min.js'),
loadCSS('http://127.0.0.1:5500/packages/studio-importor/dist/index.css'),
]);
})
.then(function () {
const { default: STUDIO_IMPORTOR, sdk } = window.STUDIO_IMPORTOR;
const id = 'ROOT_ID';
sdk.render_modeling({ id });
})
.catch(function (error) {
console.error('加载脚本时出错:', error);
});
// 先加载必须的两个 JavaScript 文件
Promise.all([
loadScript('https://gw.alipayobjects.com/os/lib/react/18.2.0/umd/react.production.min.js'),
loadScript('https://gw.alipayobjects.com/os/lib/react-dom/18.2.0/umd/react-dom.production.min.js'),
])
.then(function () {
// 必须的两个脚本加载完成后,再加载其他的 JavaScript 文件
return Promise.all([
loadScript('http://127.0.0.1:5500/packages/studio-importor/dist/index.min.js'),
loadCSS('http://127.0.0.1:5500/packages/studio-importor/dist/index.css'),
]);
})
.then(function () {
const { default: STUDIO_IMPORTOR, sdk } = window.STUDIO_IMPORTOR;
const id = 'ROOT_ID';
sdk.render_modeling({ id });
})
.catch(function (error) {
console.error('加载脚本时出错:', error);
});
} catch (error) {
document.getElementById('ROOT_ID').innerHTML = error;
}
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions packages/gsp/gsp/template/querying.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
// 必须的两个脚本加载完成后,再加载其他的 JavaScript 文件
return Promise.all([
loadScript('http://127.0.0.1:5500/packages/studio-query/dist/index.min.js'),
loadScript('http://127.0.0.1:5500/packages/studio-query/dist/5.index.min.js'),
loadScript('http://127.0.0.1:5500/packages/studio-query/dist/597.index.min.js'),
// loadScript('http://127.0.0.1:5500/packages/studio-query/dist/5.index.min.js'),
// loadScript('http://127.0.0.1:5500/packages/studio-query/dist/597.index.min.js'),
loadCSS('http://127.0.0.1:5500/packages/studio-query/dist/index.css'),
]);
})
Expand Down
2 changes: 2 additions & 0 deletions packages/gsp/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
flask = "^3.0.3"
gradio = "^4.37.1"
ipykernel = "^6.29.4"


[tool.poetry.group.dev.dependencies]
Expand Down
5 changes: 3 additions & 2 deletions packages/studio-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"start": "father dev",
"build": "father build",
"build:umd": "webpack --mode production -c ../../webpack.config.js --env path=/packages/studio-query",
"build:umd:sdk": "webpack --mode production -c ../../webpack.config.js --env path=/packages/studio-query entry=/packages/studio-query/src/sdk/index.tsx global=STUDIO_QUERY_SDK",
"build:umd:sdk": "webpack --mode production -c ../../webpack.config.js --env path=/packages/studio-query entry=/packages/studio-query/src/sdk/index.tsx global=STUDIO_QUERY_SDK analysis=true",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
Expand All @@ -40,7 +40,8 @@
"neo4j-driver": "^5.12.0",
"@difizen/cofine-editor-core": "^0.0.1-alpha.8",
"@difizen/cofine-language-cypher": "^0.0.1-alpha.8",
"@difizen/cofine-language-gremlin": "^0.0.1-alpha.8"
"@difizen/cofine-language-gremlin": "^0.0.1-alpha.8",
"monaco-editor": "latest"
},
"author": "",
"license": "ISC",
Expand Down
37 changes: 17 additions & 20 deletions packages/studio-query/src/app/content/header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { lazy, useRef, useState, Suspense } from 'react';
import React, { useRef, useState } from 'react';
import { InsertRowAboveOutlined, OrderedListOutlined, PlayCircleOutlined } from '@ant-design/icons';
import { Tooltip, Segmented, Button, Space, Flex, Typography } from 'antd';
import { localStorageVars } from '../context';
Expand All @@ -8,8 +8,7 @@ import { countLines } from '../utils';
import { v4 as uuidv4 } from 'uuid';
import { useThemeContainer } from '@graphscope/studio-components';
import Loading from './loading';

const CypherEditor = lazy(() => import('../../cypher-editor'));
import CypherEditor from '../../cypher-editor';

interface IHeaderProps {}

Expand Down Expand Up @@ -152,23 +151,21 @@ const Header: React.FunctionComponent<IHeaderProps> = props => {
borderRadius: '6px',
}}
>
<Suspense fallback={<Loading />}>
<CypherEditor
language={language}
onChangeContent={onChangeContent}
value={globalScript}
ref={editorRef}
onChange={handleChange}
onInit={(initEditor: any) => {
if (autoRun) {
handleQuery();
}
}}
maxRows={25}
minRows={minRows}
clear={state.clear}
/>
</Suspense>
<CypherEditor
language={language}
onChangeContent={onChangeContent}
value={globalScript}
ref={editorRef}
onChange={handleChange}
onInit={(initEditor: any) => {
if (autoRun) {
handleQuery();
}
}}
maxRows={25}
minRows={minRows}
clear={state.clear}
/>
</div>
<div style={{ flexBasis: '48px', flexShrink: 0 }}>
<Button
Expand Down
Loading