@difizen/libro-sql-cell 0.2.34
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/index.d.ts +2 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +1 -0
- package/es/index.less +116 -0
- package/es/libro-formatter-sql-magic-contribution.d.ts +25 -0
- package/es/libro-formatter-sql-magic-contribution.d.ts.map +1 -0
- package/es/libro-formatter-sql-magic-contribution.js +50 -0
- package/es/libro-formatter-sql-trans-contribution.d.ts +13 -0
- package/es/libro-formatter-sql-trans-contribution.d.ts.map +1 -0
- package/es/libro-formatter-sql-trans-contribution.js +26 -0
- package/es/libro-sql-cell-color-registry.d.ts +6 -0
- package/es/libro-sql-cell-color-registry.d.ts.map +1 -0
- package/es/libro-sql-cell-color-registry.js +57 -0
- package/es/libro-sql-cell-contribution.d.ts +15 -0
- package/es/libro-sql-cell-contribution.d.ts.map +1 -0
- package/es/libro-sql-cell-contribution.js +75 -0
- package/es/libro-sql-cell-model.d.ts +33 -0
- package/es/libro-sql-cell-model.d.ts.map +1 -0
- package/es/libro-sql-cell-model.js +161 -0
- package/es/libro-sql-cell-protocol.d.ts +16 -0
- package/es/libro-sql-cell-protocol.d.ts.map +1 -0
- package/es/libro-sql-cell-protocol.js +1 -0
- package/es/libro-sql-cell-script.d.ts +4 -0
- package/es/libro-sql-cell-script.d.ts.map +1 -0
- package/es/libro-sql-cell-script.js +12 -0
- package/es/libro-sql-cell-view.d.ts +52 -0
- package/es/libro-sql-cell-view.d.ts.map +1 -0
- package/es/libro-sql-cell-view.js +712 -0
- package/es/libro-sql-utils.d.ts +3 -0
- package/es/libro-sql-utils.d.ts.map +1 -0
- package/es/libro-sql-utils.js +33 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +25 -0
- package/package.json +65 -0
- package/src/index.less +116 -0
- package/src/index.spec.ts +9 -0
- package/src/index.ts +1 -0
- package/src/libro-formatter-sql-magic-contribution.ts +53 -0
- package/src/libro-formatter-sql-trans-contribution.ts +22 -0
- package/src/libro-sql-cell-color-registry.ts +35 -0
- package/src/libro-sql-cell-contribution.ts +46 -0
- package/src/libro-sql-cell-model.ts +111 -0
- package/src/libro-sql-cell-protocol.ts +19 -0
- package/src/libro-sql-cell-script.ts +7 -0
- package/src/libro-sql-cell-view.tsx +600 -0
- package/src/libro-sql-utils.ts +22 -0
- package/src/module.ts +38 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libro-sql-utils.d.ts","sourceRoot":"","sources":["../src/libro-sql-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,eAAO,MAAM,iBAAiB,UAAW,gBAAgB,EAAE,WAmB1D,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
|
+
export var getDfVariableName = function getDfVariableName(cells) {
|
|
5
|
+
var maxNumber = 0; // 记录目前找到的最大数字
|
|
6
|
+
|
|
7
|
+
// 遍历数组中的每个变量名
|
|
8
|
+
var _iterator = _createForOfIteratorHelper(cells),
|
|
9
|
+
_step;
|
|
10
|
+
try {
|
|
11
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
12
|
+
var _cell$model$resultVar;
|
|
13
|
+
var cell = _step.value;
|
|
14
|
+
// 检查变量名是否符合 "df_" 开头,并且后面跟着数字的格式
|
|
15
|
+
if ((_cell$model$resultVar = cell.model.resultVariable) !== null && _cell$model$resultVar !== void 0 && _cell$model$resultVar.startsWith('df_')) {
|
|
16
|
+
var numberPart = cell.model.resultVariable.slice(3); // 提取 "df_" 后面的部分
|
|
17
|
+
var num = parseInt(numberPart, 10); // 将提取出来的部分转成数字
|
|
18
|
+
|
|
19
|
+
// 确保提取出来的是有效数字,并更新最大数字
|
|
20
|
+
if (!isNaN(num)) {
|
|
21
|
+
maxNumber = Math.max(maxNumber, num);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 返回下一个可用的变量名
|
|
27
|
+
} catch (err) {
|
|
28
|
+
_iterator.e(err);
|
|
29
|
+
} finally {
|
|
30
|
+
_iterator.f();
|
|
31
|
+
}
|
|
32
|
+
return "df_".concat(maxNumber + 1);
|
|
33
|
+
};
|
package/es/module.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAW/C,eAAO,MAAM,kBAAkB,YAwBgB,CAAC"}
|
package/es/module.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CellOptions, LibroModule } from '@difizen/libro-jupyter';
|
|
2
|
+
import { LibroRenderMimeModule } from '@difizen/libro-rendermime';
|
|
3
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
4
|
+
import { FormatterSqlMagicContribution } from "./libro-formatter-sql-magic-contribution.js";
|
|
5
|
+
import { FormatterStringTransSqlContribution } from "./libro-formatter-sql-trans-contribution.js";
|
|
6
|
+
import { LibroSQLCellColorRegistry } from "./libro-sql-cell-color-registry.js";
|
|
7
|
+
import { SqlCellContribution } from "./libro-sql-cell-contribution.js";
|
|
8
|
+
import { LibroSqlCellModel } from "./libro-sql-cell-model.js";
|
|
9
|
+
import { LibroSqlCellModelFactory } from "./libro-sql-cell-protocol.js";
|
|
10
|
+
import { SqlScript } from "./libro-sql-cell-script.js";
|
|
11
|
+
import { LibroSqlCellView } from "./libro-sql-cell-view.js";
|
|
12
|
+
export var LibroSqlCellModule = ManaModule.create().register(SqlCellContribution, LibroSqlCellView, LibroSqlCellModel, LibroSQLCellColorRegistry, FormatterSqlMagicContribution, FormatterStringTransSqlContribution, SqlScript, {
|
|
13
|
+
token: LibroSqlCellModelFactory,
|
|
14
|
+
useFactory: function useFactory(ctx) {
|
|
15
|
+
return function (options) {
|
|
16
|
+
var child = ctx.container.createChild();
|
|
17
|
+
child.register({
|
|
18
|
+
token: CellOptions,
|
|
19
|
+
useValue: options
|
|
20
|
+
});
|
|
21
|
+
var model = child.get(LibroSqlCellModel);
|
|
22
|
+
return model;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}).dependOn(LibroModule, LibroRenderMimeModule);
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@difizen/libro-sql-cell",
|
|
3
|
+
"version": "0.2.34",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"libro",
|
|
7
|
+
"notebook"
|
|
8
|
+
],
|
|
9
|
+
"repository": "git@github.com:difizen/libro.git",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"typings": "./es/index.d.ts",
|
|
15
|
+
"default": "./es/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./mock": {
|
|
18
|
+
"typings": "./es/mock/index.d.ts",
|
|
19
|
+
"default": "./es/mock/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./es/mock": {
|
|
22
|
+
"typings": "./es/mock/index.d.ts",
|
|
23
|
+
"default": "./es/mock/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"main": "es/index.js",
|
|
28
|
+
"module": "es/index.js",
|
|
29
|
+
"typings": "es/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"es",
|
|
32
|
+
"src"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@difizen/libro-code-editor": "^0.2.34",
|
|
36
|
+
"@difizen/libro-jupyter": "^0.2.34",
|
|
37
|
+
"@difizen/libro-rendermime": "^0.2.34",
|
|
38
|
+
"@difizen/libro-common": "^0.2.34",
|
|
39
|
+
"@ant-design/icons": "^5.1.0",
|
|
40
|
+
"@difizen/mana-app": "latest",
|
|
41
|
+
"@difizen/mana-l10n": "latest"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": ">=16",
|
|
45
|
+
"antd": "^5.8.6"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/react": "^18.2.25",
|
|
49
|
+
"@types/uuid": "^9.0.2",
|
|
50
|
+
"@types/react-dom": "^18.2.4"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"setup": "father build",
|
|
54
|
+
"build": "father build",
|
|
55
|
+
"test": ": Note: lint task is delegated to test:* scripts",
|
|
56
|
+
"test:vitest": "vitest run",
|
|
57
|
+
"test:jest": "jest",
|
|
58
|
+
"coverage": ": Note: lint task is delegated to coverage:* scripts",
|
|
59
|
+
"coverage:vitest": "vitest run --coverage",
|
|
60
|
+
"coverage:jest": "jest --coverage",
|
|
61
|
+
"lint": ": Note: lint task is delegated to lint:* scripts",
|
|
62
|
+
"lint:eslint": "eslint src",
|
|
63
|
+
"typecheck:tsc": "tsc --noEmit"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/src/index.less
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// The prefix to use on all css classes from ant.
|
|
2
|
+
@ant-prefix: ant;
|
|
3
|
+
|
|
4
|
+
.libro-sql-cell-header {
|
|
5
|
+
height: 36px;
|
|
6
|
+
border-bottom: 1px solid var(--mana-libro-code-border-color);
|
|
7
|
+
display: flex;
|
|
8
|
+
|
|
9
|
+
span {
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.libro-sql-source {
|
|
15
|
+
padding: 0 16px;
|
|
16
|
+
border-right: 1px solid var(--mana-libro-cell-border-color);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.libro-sql-input-warning-text,
|
|
20
|
+
.libro-sql-variable-name-input {
|
|
21
|
+
display: block !important;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.libro-sql-variable-name-input {
|
|
25
|
+
width: 120px !important;
|
|
26
|
+
height: 32px;
|
|
27
|
+
border: 1px solid #d6d8da !important;
|
|
28
|
+
border-radius: 6px !important;
|
|
29
|
+
box-shadow: unset !important;
|
|
30
|
+
&.@{ant-prefix}-input-status-warning {
|
|
31
|
+
border-color: #faad14 !important;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.libro-sql-variable-name-title {
|
|
36
|
+
padding-left: 16px;
|
|
37
|
+
color: var(--mana-libro-cell-header-title);
|
|
38
|
+
font-weight: 400;
|
|
39
|
+
font-size: 14px;
|
|
40
|
+
font-family: SFProText;
|
|
41
|
+
line-height: 36px;
|
|
42
|
+
letter-spacing: 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.libro-sql-source-content,
|
|
46
|
+
.libro-sql-variable-content {
|
|
47
|
+
padding-left: 3px;
|
|
48
|
+
color: var(--mana-libro-cell-header-content);
|
|
49
|
+
font-weight: 400;
|
|
50
|
+
font-size: 14px;
|
|
51
|
+
font-family: SFProText;
|
|
52
|
+
line-height: 36px;
|
|
53
|
+
letter-spacing: 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.libro-sql-variable-name {
|
|
57
|
+
margin-left: 8px;
|
|
58
|
+
|
|
59
|
+
svg {
|
|
60
|
+
margin-left: 4px;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.libro-sql-input-save,
|
|
65
|
+
.libro-sql-input-cancel {
|
|
66
|
+
width: 28px;
|
|
67
|
+
height: 20px;
|
|
68
|
+
color: #1890ff;
|
|
69
|
+
font-weight: 400;
|
|
70
|
+
font-size: 14px;
|
|
71
|
+
letter-spacing: 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.libro-sql-input-save {
|
|
75
|
+
margin-left: 8px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.libro-sql-edit-icon {
|
|
79
|
+
color: #bdc0c4 !important;
|
|
80
|
+
|
|
81
|
+
&:hover {
|
|
82
|
+
color: #1590ff !important;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.libro-sql-popover-container {
|
|
87
|
+
padding-top: 10px !important;
|
|
88
|
+
.@{ant-prefix}-popover-inner {
|
|
89
|
+
border-radius: 8px;
|
|
90
|
+
}
|
|
91
|
+
.@{ant-prefix}-popover-inner-content {
|
|
92
|
+
height: 100% !important;
|
|
93
|
+
text-align: right;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.@{ant-prefix}-popover-content {
|
|
97
|
+
transform: translateX(-18px) !important;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.libro-sql-input-warning-text {
|
|
102
|
+
width: 112px;
|
|
103
|
+
height: 20px;
|
|
104
|
+
margin-top: 4px;
|
|
105
|
+
color: #faad14;
|
|
106
|
+
font-weight: 400;
|
|
107
|
+
font-size: 14px;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.libro-sql-input-button {
|
|
111
|
+
margin-top: 12px;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.libro-sql-variable-name-popover {
|
|
115
|
+
vertical-align: middle;
|
|
116
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './module.js';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { concatMultilineString } from '@difizen/libro-common';
|
|
3
|
+
import { FormatterContribution } from '@difizen/libro-jupyter';
|
|
4
|
+
import type {
|
|
5
|
+
DefaultEncodedFormatter,
|
|
6
|
+
DefaultDecodedFormatter,
|
|
7
|
+
} from '@difizen/libro-jupyter';
|
|
8
|
+
import { singleton } from '@difizen/mana-app';
|
|
9
|
+
|
|
10
|
+
export interface SqlDecodedFormatter extends DefaultDecodedFormatter {
|
|
11
|
+
result_variable?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@singleton({ contrib: FormatterContribution })
|
|
15
|
+
export class FormatterSqlMagicContribution
|
|
16
|
+
implements FormatterContribution<SqlDecodedFormatter>
|
|
17
|
+
{
|
|
18
|
+
formatter = 'formatter-sql-magic';
|
|
19
|
+
formatterOptions?: object;
|
|
20
|
+
|
|
21
|
+
canHandle = (libroFormatter: string) => {
|
|
22
|
+
return libroFormatter === this.formatter ? 100 : 1;
|
|
23
|
+
};
|
|
24
|
+
encode = (source: SqlDecodedFormatter) => {
|
|
25
|
+
const sqlEncodedValue = `%%sql \n{"result_variable":"${source.result_variable}", "sql_script":"${source.value}"}`;
|
|
26
|
+
return {
|
|
27
|
+
source: sqlEncodedValue,
|
|
28
|
+
metadata: {
|
|
29
|
+
libroFormatter: this.formatter,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
decode = (formatterValue: DefaultEncodedFormatter) => {
|
|
34
|
+
const value = concatMultilineString(formatterValue.source);
|
|
35
|
+
if (value.startsWith('%%sql \n')) {
|
|
36
|
+
const run = value.split('%%sql \n')[1];
|
|
37
|
+
const runValue = JSON.parse(run);
|
|
38
|
+
const result_variable: string = runValue.result_variable;
|
|
39
|
+
const codeValue: string = runValue.sql_script;
|
|
40
|
+
return {
|
|
41
|
+
result_variable,
|
|
42
|
+
value: codeValue,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
value: '',
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
validate = (source: SqlDecodedFormatter): source is SqlDecodedFormatter => {
|
|
51
|
+
return 'result_variable' in source && 'sql_script' in source;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { FormatterTransContribution } from '@difizen/libro-jupyter';
|
|
3
|
+
import type { DefaultDecodedFormatter } from '@difizen/libro-jupyter';
|
|
4
|
+
import { singleton } from '@difizen/mana-app';
|
|
5
|
+
|
|
6
|
+
import type { SqlDecodedFormatter } from './libro-formatter-sql-magic-contribution.js';
|
|
7
|
+
|
|
8
|
+
@singleton({ contrib: FormatterTransContribution })
|
|
9
|
+
export class FormatterStringTransSqlContribution
|
|
10
|
+
implements FormatterTransContribution<DefaultDecodedFormatter, SqlDecodedFormatter>
|
|
11
|
+
{
|
|
12
|
+
origin = 'formatter-string';
|
|
13
|
+
target = 'formatter-sql-magic';
|
|
14
|
+
priority = 100;
|
|
15
|
+
|
|
16
|
+
decodedValueTrans = (source: DefaultDecodedFormatter) => {
|
|
17
|
+
return {
|
|
18
|
+
...source,
|
|
19
|
+
result_variable: source['result_variable'] || 'df_from_trans',
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ColorRegistry } from '@difizen/mana-app';
|
|
2
|
+
import { Color, ColorContribution, singleton } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
@singleton({ contrib: ColorContribution })
|
|
5
|
+
export class LibroSQLCellColorRegistry implements ColorContribution {
|
|
6
|
+
registerColors(colors: ColorRegistry): void {
|
|
7
|
+
colors.register(
|
|
8
|
+
{
|
|
9
|
+
id: 'libro.sql.tab',
|
|
10
|
+
defaults: { dark: '#B2B2B3', light: Color.rgba(0, 10, 26, 0.68) },
|
|
11
|
+
description: '',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: 'libro.sql.tab.background',
|
|
15
|
+
defaults: { dark: '#1C1C1D', light: '#FAFAFB' },
|
|
16
|
+
description: '',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: 'libro.sql.button.border',
|
|
20
|
+
defaults: { dark: '#505559', light: Color.rgba(0, 10, 26, 0.1) },
|
|
21
|
+
description: '',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: 'libro.sql.button.background',
|
|
25
|
+
defaults: { dark: '#2F3032', light: '#FFFFFF' },
|
|
26
|
+
description: '',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'libro.sql.button.text.color',
|
|
30
|
+
defaults: { dark: '#BDC0C4', light: Color.rgba(0, 10, 26, 0.68) },
|
|
31
|
+
description: '',
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { LanguageSpecRegistry } from '@difizen/libro-code-editor';
|
|
2
|
+
import { LanguageSpecContribution } from '@difizen/libro-code-editor';
|
|
3
|
+
import type { CellMeta, CellModel, CellOptions } from '@difizen/libro-jupyter';
|
|
4
|
+
import { CellModelContribution, CellViewContribution } from '@difizen/libro-jupyter';
|
|
5
|
+
import { inject } from '@difizen/mana-app';
|
|
6
|
+
import { singleton } from '@difizen/mana-app';
|
|
7
|
+
|
|
8
|
+
import { LibroSqlCellModelFactory } from './libro-sql-cell-protocol.js';
|
|
9
|
+
import { LibroSqlCellView } from './libro-sql-cell-view.js';
|
|
10
|
+
|
|
11
|
+
@singleton({
|
|
12
|
+
contrib: [CellModelContribution, CellViewContribution, LanguageSpecContribution],
|
|
13
|
+
})
|
|
14
|
+
export class SqlCellContribution
|
|
15
|
+
implements CellModelContribution, CellViewContribution, LanguageSpecContribution
|
|
16
|
+
{
|
|
17
|
+
@inject(LibroSqlCellModelFactory)
|
|
18
|
+
sqlCellModelFactory: LibroSqlCellModelFactory;
|
|
19
|
+
|
|
20
|
+
cellMeta: CellMeta = {
|
|
21
|
+
type: 'sql',
|
|
22
|
+
name: 'SQL',
|
|
23
|
+
order: 'e',
|
|
24
|
+
nbformatType: 'code',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
canHandle(options: CellOptions, libroType?: string): number {
|
|
28
|
+
return libroType === this.cellMeta.type ? 2000 : -1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async createModel(options: CellOptions): Promise<CellModel> {
|
|
32
|
+
const model = this.sqlCellModelFactory(options);
|
|
33
|
+
return model;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
view = LibroSqlCellView;
|
|
37
|
+
|
|
38
|
+
registerLanguageSpec = (register: LanguageSpecRegistry) => {
|
|
39
|
+
register.registerLanguageSpec({
|
|
40
|
+
name: 'SQL',
|
|
41
|
+
language: 'sql-odps',
|
|
42
|
+
mime: 'application/vnd.libro.sql+json',
|
|
43
|
+
ext: ['.sql'],
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ICellMetadata,
|
|
3
|
+
ICodeCell,
|
|
4
|
+
ICodeCellMetadata,
|
|
5
|
+
} from '@difizen/libro-common';
|
|
6
|
+
import type { ExecutionCount } from '@difizen/libro-common';
|
|
7
|
+
import { CellOptions, LibroCellModel } from '@difizen/libro-jupyter';
|
|
8
|
+
import type { ExecutableCellModel } from '@difizen/libro-jupyter';
|
|
9
|
+
import type { Event as ManaEvent } from '@difizen/mana-app';
|
|
10
|
+
import { Emitter, inject, prop, transient, ViewManager } from '@difizen/mana-app';
|
|
11
|
+
|
|
12
|
+
import type { SqlDecodedFormatter } from './libro-formatter-sql-magic-contribution.js';
|
|
13
|
+
|
|
14
|
+
export interface SqlCellMetadata extends ICodeCellMetadata {
|
|
15
|
+
resultVariable: string;
|
|
16
|
+
}
|
|
17
|
+
@transient()
|
|
18
|
+
export class LibroSqlCellModel extends LibroCellModel implements ExecutableCellModel {
|
|
19
|
+
@prop()
|
|
20
|
+
resultVariable: string | undefined;
|
|
21
|
+
@prop()
|
|
22
|
+
executeCount: ExecutionCount;
|
|
23
|
+
@prop()
|
|
24
|
+
executing: boolean;
|
|
25
|
+
@prop()
|
|
26
|
+
hasOutputHidden: boolean;
|
|
27
|
+
@prop()
|
|
28
|
+
hasOutputsScrolled: boolean;
|
|
29
|
+
|
|
30
|
+
@prop()
|
|
31
|
+
kernelExecuting = false;
|
|
32
|
+
|
|
33
|
+
@prop()
|
|
34
|
+
hasExecutedSuccess = false;
|
|
35
|
+
@prop()
|
|
36
|
+
hasExecutedError = false;
|
|
37
|
+
@prop()
|
|
38
|
+
override metadata: Partial<SqlCellMetadata | ICellMetadata>;
|
|
39
|
+
|
|
40
|
+
declare _decodeObject: SqlDecodedFormatter;
|
|
41
|
+
|
|
42
|
+
// Emitter Msg
|
|
43
|
+
msgChangeEmitter: Emitter<any>;
|
|
44
|
+
|
|
45
|
+
get msgChange(): ManaEvent<any> {
|
|
46
|
+
return this.msgChangeEmitter.event;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
viewManager: ViewManager;
|
|
50
|
+
|
|
51
|
+
constructor(
|
|
52
|
+
@inject(CellOptions) options: CellOptions,
|
|
53
|
+
@inject(ViewManager) viewManager: ViewManager,
|
|
54
|
+
) {
|
|
55
|
+
super(options);
|
|
56
|
+
this.viewManager = viewManager;
|
|
57
|
+
this.executing = false;
|
|
58
|
+
this.msgChangeEmitter = new Emitter<any>();
|
|
59
|
+
this.executeCount = (options.cell as ICodeCell).execution_count || null;
|
|
60
|
+
this.mimeType = 'application/vnd.libro.sql+json';
|
|
61
|
+
this.hasOutputHidden = false;
|
|
62
|
+
this.hasOutputsScrolled = false;
|
|
63
|
+
this.libroFormatType = 'formatter-sql-magic';
|
|
64
|
+
this.metadata = {
|
|
65
|
+
...options?.cell?.metadata,
|
|
66
|
+
libroFormatter: this.libroFormatType,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override toJSON(): Omit<ICodeCell, 'outputs'> {
|
|
71
|
+
// const outputs = this.outputArea?.toJSON() ?? this.outputs;
|
|
72
|
+
return {
|
|
73
|
+
id: this.id,
|
|
74
|
+
cell_type: this.type,
|
|
75
|
+
source: this.source,
|
|
76
|
+
metadata: this.metadata,
|
|
77
|
+
execution_count: this.executeCount,
|
|
78
|
+
// outputs: this.outputs,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
override set decodeObject(data: SqlDecodedFormatter) {
|
|
83
|
+
this.value = data.value;
|
|
84
|
+
this.resultVariable = data.result_variable;
|
|
85
|
+
this._decodeObject = data;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
override get decodeObject() {
|
|
89
|
+
return {
|
|
90
|
+
...this._decodeObject,
|
|
91
|
+
value: this.value,
|
|
92
|
+
result_variable: this.resultVariable || this._decodeObject.result_variable,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
clearExecution = () => {
|
|
97
|
+
this.executeCount = null;
|
|
98
|
+
this.executing = false;
|
|
99
|
+
this.kernelExecuting = false;
|
|
100
|
+
this.metadata['execution'] = {};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
override dispose() {
|
|
104
|
+
super.dispose();
|
|
105
|
+
this.msgChangeEmitter.dispose();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
getSource() {
|
|
109
|
+
return this.value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CellOptions, CellView } from '@difizen/libro-jupyter';
|
|
2
|
+
|
|
3
|
+
import type { LibroSqlCellModel } from './libro-sql-cell-model.js';
|
|
4
|
+
|
|
5
|
+
export type LibroSqlCellModelFactory = (options: CellOptions) => LibroSqlCellModel;
|
|
6
|
+
export const LibroSqlCellModelFactory = Symbol('LibroSqlCellModelFactory');
|
|
7
|
+
|
|
8
|
+
export interface VisAnalysis {
|
|
9
|
+
addAnalysisCell: (cellView: CellView, dfName?: string) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface DatabaseConfig {
|
|
13
|
+
db_type: string;
|
|
14
|
+
username: string;
|
|
15
|
+
password: string;
|
|
16
|
+
host: string;
|
|
17
|
+
port: number;
|
|
18
|
+
database: string;
|
|
19
|
+
}
|