@difizen/libro-code-cell 0.3.20 → 0.3.21
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/es/code-cell-view.d.ts +2 -0
- package/es/code-cell-view.d.ts.map +1 -1
- package/es/code-cell-view.js +26 -2
- package/es/index.less +6 -0
- package/package.json +6 -5
- package/src/code-cell-view.tsx +31 -2
- package/src/index.less +6 -0
package/es/code-cell-view.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ import type { LibroCell, CellViewOptions } from '@difizen/libro-core';
|
|
|
6
6
|
import { CellService, EditorStatus, LibroEditableExecutableCellView, LibroOutputArea } from '@difizen/libro-core';
|
|
7
7
|
import type { ViewSize } from '@difizen/mana-app';
|
|
8
8
|
import { ViewManager, Deferred } from '@difizen/mana-app';
|
|
9
|
+
import 'highlight.js/styles/vs.css';
|
|
10
|
+
import './index.less';
|
|
9
11
|
import type { LibroCodeCellModel } from './code-cell-model.js';
|
|
10
12
|
export declare const CellEditorMemo: import("react").NamedExoticComponent<{}>;
|
|
11
13
|
export declare class LibroCodeCellView extends LibroEditableExecutableCellView {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-cell-view.d.ts","sourceRoot":"","sources":["../src/code-cell-view.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGhE,OAAO,KAAK,EAEV,SAAS,EACT,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,+BAA+B,EAC/B,eAAe,EAEhB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAQL,WAAW,EAIX,QAAQ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X,MAAM,IAAI,SAAS;IAQnB,WAAW;IAKpB,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC;cAK/B,eAAe,IAAI,qBAAqB;IAclD,cAAc,aAGrB;CACH"}
|
package/es/code-cell-view.js
CHANGED
|
@@ -32,7 +32,12 @@ import { isOutput } from '@difizen/libro-common';
|
|
|
32
32
|
import { CellService, EditorStatus, LibroEditableExecutableCellView, LibroOutputArea, VirtualizedManagerHelper } from '@difizen/libro-core';
|
|
33
33
|
import { getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch, Deferred } from '@difizen/mana-app';
|
|
34
34
|
import { l10n } from '@difizen/mana-l10n'; /* eslint-disable react-hooks/exhaustive-deps */
|
|
35
|
+
import hljs from 'highlight.js';
|
|
35
36
|
import { useEffect, useRef, memo, forwardRef } from 'react';
|
|
37
|
+
|
|
38
|
+
// 引入高亮样式
|
|
39
|
+
import 'highlight.js/styles/vs.css';
|
|
40
|
+
import "./index.less";
|
|
36
41
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
37
42
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
38
43
|
function countLines(inputString) {
|
|
@@ -73,15 +78,34 @@ var CellEditor = function CellEditor() {
|
|
|
73
78
|
});
|
|
74
79
|
}
|
|
75
80
|
};
|
|
81
|
+
var CellWithoutEditor = function CellWithoutEditor() {
|
|
82
|
+
var instance = useInject(ViewInstance);
|
|
83
|
+
var codeRef = useRef(null);
|
|
84
|
+
useEffect(function () {
|
|
85
|
+
if (codeRef.current) {
|
|
86
|
+
// 先高亮代码
|
|
87
|
+
var hljsValue = hljs.highlight(instance.model.value, {
|
|
88
|
+
language: 'python'
|
|
89
|
+
});
|
|
90
|
+
codeRef.current.innerHTML = hljsValue.value;
|
|
91
|
+
}
|
|
92
|
+
}, [instance.model.value]);
|
|
93
|
+
return /*#__PURE__*/_jsx("pre", {
|
|
94
|
+
className: "cell-no-editor-input",
|
|
95
|
+
children: /*#__PURE__*/_jsx("code", {
|
|
96
|
+
ref: codeRef
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
};
|
|
76
100
|
export var CellEditorMemo = /*#__PURE__*/memo(CellEditor);
|
|
77
101
|
var CodeEditorViewComponent = /*#__PURE__*/forwardRef(function CodeEditorViewComponent(props, ref) {
|
|
78
102
|
var instance = useInject(ViewInstance);
|
|
79
103
|
return /*#__PURE__*/_jsx("div", {
|
|
80
|
-
className:
|
|
104
|
+
className: instance.className,
|
|
81
105
|
ref: ref,
|
|
82
106
|
tabIndex: 10,
|
|
83
107
|
onBlur: instance.blur,
|
|
84
|
-
children: /*#__PURE__*/_jsx(CellEditorMemo, {})
|
|
108
|
+
children: instance.parent.model.noEditorMode ? /*#__PURE__*/_jsx(CellWithoutEditor, {}) : /*#__PURE__*/_jsx(CellEditorMemo, {})
|
|
85
109
|
});
|
|
86
110
|
});
|
|
87
111
|
export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-cell-view'), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroEditableExecuta) {
|
package/es/index.less
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-code-cell",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro",
|
|
@@ -32,11 +32,12 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@difizen/libro-code-editor": "^0.3.
|
|
36
|
-
"@difizen/libro-common": "^0.3.
|
|
37
|
-
"@difizen/libro-core": "^0.3.
|
|
35
|
+
"@difizen/libro-code-editor": "^0.3.21",
|
|
36
|
+
"@difizen/libro-common": "^0.3.21",
|
|
37
|
+
"@difizen/libro-core": "^0.3.21",
|
|
38
38
|
"@difizen/mana-app": "latest",
|
|
39
|
-
"@difizen/mana-l10n": "latest"
|
|
39
|
+
"@difizen/mana-l10n": "latest",
|
|
40
|
+
"highlight.js": "^11.11.1"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
43
|
"react": ">=16"
|
package/src/code-cell-view.tsx
CHANGED
|
@@ -33,8 +33,13 @@ import {
|
|
|
33
33
|
Deferred,
|
|
34
34
|
} from '@difizen/mana-app';
|
|
35
35
|
import { l10n } from '@difizen/mana-l10n'; /* eslint-disable react-hooks/exhaustive-deps */
|
|
36
|
+
import hljs from 'highlight.js';
|
|
36
37
|
import { useEffect, useRef, memo, forwardRef } from 'react';
|
|
37
38
|
|
|
39
|
+
// 引入高亮样式
|
|
40
|
+
import 'highlight.js/styles/vs.css';
|
|
41
|
+
import './index.less';
|
|
42
|
+
|
|
38
43
|
import type { LibroCodeCellModel } from './code-cell-model.js';
|
|
39
44
|
|
|
40
45
|
function countLines(inputString: string) {
|
|
@@ -78,6 +83,26 @@ const CellEditor: React.FC = () => {
|
|
|
78
83
|
}
|
|
79
84
|
};
|
|
80
85
|
|
|
86
|
+
const CellWithoutEditor: React.FC = () => {
|
|
87
|
+
const instance = useInject<LibroCodeCellView>(ViewInstance);
|
|
88
|
+
const codeRef = useRef<HTMLDivElement>(null);
|
|
89
|
+
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (codeRef.current) {
|
|
92
|
+
// 先高亮代码
|
|
93
|
+
const hljsValue = hljs.highlight(instance.model.value, {
|
|
94
|
+
language: 'python',
|
|
95
|
+
});
|
|
96
|
+
codeRef.current.innerHTML = hljsValue.value;
|
|
97
|
+
}
|
|
98
|
+
}, [instance.model.value]);
|
|
99
|
+
return (
|
|
100
|
+
<pre className="cell-no-editor-input">
|
|
101
|
+
<code ref={codeRef}></code>
|
|
102
|
+
</pre>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
81
106
|
export const CellEditorMemo = memo(CellEditor);
|
|
82
107
|
|
|
83
108
|
const CodeEditorViewComponent = forwardRef<HTMLDivElement>(
|
|
@@ -86,12 +111,16 @@ const CodeEditorViewComponent = forwardRef<HTMLDivElement>(
|
|
|
86
111
|
|
|
87
112
|
return (
|
|
88
113
|
<div
|
|
89
|
-
className=
|
|
114
|
+
className={instance.className}
|
|
90
115
|
ref={ref}
|
|
91
116
|
tabIndex={10}
|
|
92
117
|
onBlur={instance.blur}
|
|
93
118
|
>
|
|
94
|
-
|
|
119
|
+
{instance.parent.model.noEditorMode ? (
|
|
120
|
+
<CellWithoutEditor />
|
|
121
|
+
) : (
|
|
122
|
+
<CellEditorMemo />
|
|
123
|
+
)}
|
|
95
124
|
</div>
|
|
96
125
|
);
|
|
97
126
|
},
|