Skip to content

Commit

Permalink
docs: update samples (#116)
Browse files Browse the repository at this point in the history
* docs: update esm-vite sample

* docs: update esm-plain-webpack sample

* docs: update esm-monaco-webpack-plugin sample
  • Loading branch information
HaydenOrz authored Apr 1, 2024
1 parent 93a8c8a commit 8a13207
Show file tree
Hide file tree
Showing 19 changed files with 397 additions and 156 deletions.
39 changes: 25 additions & 14 deletions samples/esm-monaco-webpack-plugin/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>esm-monaco-webpack-plugin-sample</title>
</head>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>esm-monaco-webpack-plugin-sample</title>
</head>

<body>
<h2>FlinkSQL Demo</h2>
<div style="width: 700px;height: 400px;border: 1px solid #ddd;">
<div id="container" style="height: 100%; width: 100%;"></div>
</div>
</body>

<body>
<h2>ESM Monaco Webpack Plugin Demo</h2>
<select
name="language"
style="width: 120px; height: 32px; margin-bottom: 8px; font-size: 16px"
id="lang-select"
>
<option value="mysql">MYSQL</option>
<option value="flinksql" selected>FLINK</option>
<option value="hivesql">HIVE</option>
<option value="sparksql">SPARK</option>
<option value="impalasql">IMPALA</option>
<option value="trinosql">TRINO</option>
<option value="pgsql">PGSQL</option>
</select>
<div style="width: 700px; height: 400px; border: 1px solid #ddd">
<div id="container" style="height: 100%; width: 100%"></div>
</div>
</body>
</html>
<!doctype html>
<!DOCTYPE html>
66 changes: 33 additions & 33 deletions samples/esm-monaco-webpack-plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion samples/esm-monaco-webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"dependencies": {
"monaco-editor": "0.31.0",
"monaco-editor-webpack-plugin": "7.0.1",
"monaco-sql-languages": "0.12.0-beta.ng.1"
"monaco-sql-languages": "0.12.0-beta.11"
}
}
31 changes: 29 additions & 2 deletions samples/esm-monaco-webpack-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
import * as monaco from 'monaco-editor';
import { LanguageIdEnum } from 'monaco-sql-languages';
import './languageSetup';

let editorIns: monaco.editor.IStandaloneCodeEditor | null = null;

function render() {
const container = document.getElementById('container');
if (container) {
monaco.editor.create(container, {
language: LanguageIdEnum.FLINK
editorIns = monaco.editor.create(container, {
language: LanguageIdEnum.TRINO
});
}
}

function listenLangChange() {
const langSelect = document.getElementById('lang-select') as HTMLSelectElement;
if (langSelect && editorIns) {
langSelect.addEventListener('change', () => {
if (!editorIns) return;

const lang = langSelect.options[langSelect.selectedIndex].value;
const model = editorIns.getModel();

if (model && model.getLanguageId() !== lang) {
monaco.editor.setModelLanguage(model, lang);
setTimeout(() => {
console.log(
'language changed, current is: ',
editorIns?.getModel()?.getLanguageId()
);
}, 200);
}
});
}
}

render();

listenLangChange();
8 changes: 8 additions & 0 deletions samples/esm-monaco-webpack-plugin/src/languageSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** import contribution files */
import 'monaco-sql-languages/esm/languages/mysql/mysql.contribution';
import 'monaco-sql-languages/esm/languages/flink/flink.contribution';
import 'monaco-sql-languages/esm/languages/spark/spark.contribution';
import 'monaco-sql-languages/esm/languages/hive/hive.contribution';
import 'monaco-sql-languages/esm/languages/trino/trino.contribution';
import 'monaco-sql-languages/esm/languages/pgsql/pgsql.contribution';
import 'monaco-sql-languages/esm/languages/impala/impala.contribution';
55 changes: 52 additions & 3 deletions samples/esm-monaco-webpack-plugin/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,61 @@ module.exports = {
features: [],
languages: [],
customLanguages: [
// 包含 Monaco SQL Languages 所提供的语言功能
{
label: 'mysql',
entry: 'monaco-sql-languages/esm/languages/mysql/mysql.contribution',
worker: {
id: '/esm/languages/mysql/',
entry: 'monaco-sql-languages/esm/languages/mysql/mysql.worker'
}
},
{
label: 'flinksql',
entry: 'monaco-sql-languages/out/esm/flinksql/flinksql.contribution',
entry: 'monaco-sql-languages/esm/languages/flink/flink.contribution',
worker: {
id: '/esm/languages/flink/',
entry: 'monaco-sql-languages/esm/languages/flink/flink.worker'
}
},
{
label: 'sparksql',
entry: 'monaco-sql-languages/esm/languages/spark/spark.contribution',
worker: {
id: '/esm/languages/spark/',
entry: 'monaco-sql-languages/esm/languages/spark/spark.worker'
}
},
{
label: 'hivesql',
entry: 'monaco-sql-languages/esm/languages/hive/hive.contribution',
worker: {
id: '/esm/languages/hive/',
entry: 'monaco-sql-languages/esm/languages/hive/hive.worker'
}
},
{
label: 'trinosql',
entry: 'monaco-sql-languages/esm/languages/trino/trino.contribution',
worker: {
id: '/esm/languages/trino/',
entry: 'monaco-sql-languages/esm/languages/trino/trino.worker'
}
},
{
label: 'pgsql',
entry: 'monaco-sql-languages/esm/languages/pgsql/pgsql.contribution',
worker: {
id: '/esm/languages/pgsql/',
entry: 'monaco-sql-languages/esm/languages/pgsql/pgsql.worker'
}
},
{
label: 'impalasql',
entry: 'monaco-sql-languages/esm/languages/impala/impala.contribution',
worker: {
id: 'monaco-sql-languages/out/esm/flinksql/flinkSQLWorker',
entry: 'monaco-sql-languages/out/esm/flinksql/flinksql.worker'
id: '/esm/languages/impala/',
entry: 'monaco-sql-languages/esm/languages/impala/impala.worker'
}
}
]
Expand Down
3 changes: 0 additions & 3 deletions samples/esm-monaco-webpack-plugin/webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ delete devConfig.devServer;
delete devConfig.devtool;

devConfig.mode = 'production';
devConfig.optimization = {
minimize: false
};

module.exports = devConfig;
39 changes: 25 additions & 14 deletions samples/esm-plain-webpack/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>esm-plain-webpack-sample</title>
</head>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>esm-plain-webpack-sample</title>
</head>

<body>
<h2>FlinkSQL Demo</h2>
<div style="width: 700px;height: 400px;border: 1px solid #ddd;">
<div id="container" style="height: 100%; width: 100%;"></div>
</div>
</body>

<body>
<h2>ESM Plain Webpack Demo</h2>
<select
name="language"
style="width: 120px; height: 32px; margin-bottom: 8px; font-size: 16px"
id="lang-select"
>
<option value="mysql">MYSQL</option>
<option value="flinksql" selected>FLINK</option>
<option value="hivesql">HIVE</option>
<option value="sparksql">SPARK</option>
<option value="impalasql">IMPALA</option>
<option value="trinosql">TRINO</option>
<option value="pgsql">PGSQL</option>
</select>
<div style="width: 700px; height: 400px; border: 1px solid #ddd">
<div id="container" style="height: 100%; width: 100%"></div>
</div>
</body>
</html>
<!doctype html>
<!DOCTYPE html>
Loading

0 comments on commit 8a13207

Please sign in to comment.