@difizen/libro-code-cell 0.1.3 → 0.1.4

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.
@@ -1,11 +1,11 @@
1
1
  /// <reference types="react" resolution-mode="require"/>
2
2
  import type { CodeEditorViewOptions, CodeEditorView } from '@difizen/libro-code-editor';
3
- import { CodeEditorManager, CodeEditorSettings } from '@difizen/libro-code-editor';
3
+ import { CodeEditorManager } from '@difizen/libro-code-editor';
4
4
  import type { IOutput } from '@difizen/libro-common';
5
5
  import type { LibroCell, CellViewOptions } from '@difizen/libro-core';
6
6
  import { CellService, EditorStatus, LibroExecutableCellView, LibroOutputArea } from '@difizen/libro-core';
7
- import { ViewManager } from '@difizen/mana-app';
8
- import { Deferred } from '@difizen/mana-app';
7
+ import type { ViewSize } from '@difizen/mana-app';
8
+ import { ViewManager, Deferred } from '@difizen/mana-app';
9
9
  import type { LibroCodeCellModel } from './code-cell-model.js';
10
10
  export declare const CellEditorMemo: import("react").NamedExoticComponent<{}>;
11
11
  export declare class LibroCodeCellView extends LibroExecutableCellView {
@@ -23,10 +23,10 @@ export declare class LibroCodeCellView extends LibroExecutableCellView {
23
23
  get editorReady(): Promise<void>;
24
24
  protected outputAreaDeferred: Deferred<LibroOutputArea>;
25
25
  get outputAreaReady(): Promise<LibroOutputArea>;
26
- protected codeEditorSettings: CodeEditorSettings;
27
26
  renderEditor: () => import("react/jsx-runtime").JSX.Element | null;
27
+ onViewResize(size: ViewSize): void;
28
28
  calcEditorAreaHeight(): number;
29
- constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager, codeEditorManager: CodeEditorManager, codeEditorSettings: CodeEditorSettings);
29
+ constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager, codeEditorManager: CodeEditorManager);
30
30
  outputWatch(): void;
31
31
  toJSON(): LibroCell;
32
32
  onViewMount(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"code-cell-view.d.ts","sourceRoot":"","sources":["../src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G5B,gBAAgB,SAAK;IAGZ,kBAAkB,SAAK;IAGvB,cAAc,SAAK;IAGnB,YAAY,EAAE,YAAY,CAA0B;IAE7D,SAAS,CAAC,uBAAuB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAwB;IAEzE,IAAI,WAAW,kBAEd;IAED,SAAS,CAAC,kBAAkB,4BAAmC;IAC/D,IAAI,eAAe,6BAElB;IAEQ,YAAY,uDAKnB;IAEO,YAAY,CAAC,IAAI,EAAE,QAAQ;IAMpC,oBAAoB;gBAqBE,OAAO,EAAE,eAAe,EACvB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EAClB,iBAAiB,EAAE,iBAAiB;IA6BxD,WAAW;IAQX,MAAM,IAAI,SAAS;IAQnB,WAAW;IAQpB,aAAa,CAAC,GAAG,EAAE,GAAG;IAMtB,SAAS,CAAC,eAAe,IAAI,qBAAqB;cAalC,YAAY;cAoBZ,gBAAgB;IAUvB,qBAAqB,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;IAMtD,IAAI,aAGX;IAEO,KAAK,WAAY,OAAO,UAkC/B;IAEO,cAAc,aAGrB;CACH"}
@@ -27,12 +27,11 @@ function _initializerWarningHelper(descriptor, context) { throw new Error('Decor
27
27
  /* eslint-disable @typescript-eslint/no-parameter-properties */
28
28
  /* eslint-disable @typescript-eslint/parameter-properties */
29
29
 
30
- import { CodeEditorManager, CodeEditorSettings } from '@difizen/libro-code-editor';
30
+ import { CodeEditorManager } from '@difizen/libro-code-editor';
31
31
  import { isOutput } from '@difizen/libro-common';
32
32
  import { CellService, EditorStatus, LibroExecutableCellView, LibroOutputArea, VirtualizedManagerHelper } from '@difizen/libro-core';
33
- import { getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch } from '@difizen/mana-app';
34
- import { Deferred } from '@difizen/mana-app';
35
- import { useEffect, useMemo, useRef, memo, forwardRef } from 'react';
33
+ import { getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch, Deferred } from '@difizen/mana-app';
34
+ import { useEffect, useRef, memo, forwardRef } from 'react';
36
35
  import { jsx as _jsx } from "react/jsx-runtime";
37
36
  import { Fragment as _Fragment } from "react/jsx-runtime";
38
37
  function countLines(inputString) {
@@ -52,14 +51,12 @@ var CellEditor = function CellEditor() {
52
51
  instance.editor = getOrigin((_instance$editorView2 = instance.editorView) === null || _instance$editorView2 === void 0 ? void 0 : _instance$editorView2.editor);
53
52
  }
54
53
  }, [instance, (_instance$editorView3 = instance.editorView) === null || _instance$editorView3 === void 0 ? void 0 : _instance$editorView3.editor]);
55
- var editorAreaHeight = useMemo(function () {
56
- return instance.calcEditorAreaHeight();
57
- }, [instance.model.value]);
58
54
  if (virtualizedManager.isVirtualized) {
59
55
  instance.renderEditorIntoVirtualized = true;
60
56
  if (instance.setEditorHost) {
61
57
  instance.setEditorHost(editorRef);
62
58
  }
59
+ var editorAreaHeight = instance.calcEditorAreaHeight();
63
60
  return /*#__PURE__*/_jsx("div", {
64
61
  style: {
65
62
  height: "".concat(editorAreaHeight || 0, "px"),
@@ -89,7 +86,7 @@ var CodeEditorViewComponent = /*#__PURE__*/forwardRef(function CodeEditorViewCom
89
86
  export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-cell-view'), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec7 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroExecutableCellV) {
90
87
  _inherits(LibroCodeCellView, _LibroExecutableCellV);
91
88
  var _super = _createSuper(LibroCodeCellView);
92
- function LibroCodeCellView(options, cellService, viewManager, codeEditorManager, codeEditorSettings) {
89
+ function LibroCodeCellView(options, cellService, viewManager, codeEditorManager) {
93
90
  var _options$cell;
94
91
  var _this;
95
92
  _classCallCheck(this, LibroCodeCellView);
@@ -105,7 +102,6 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
105
102
  _initializerDefineProperty(_this, "editorStatus", _descriptor5, _assertThisInitialized(_this));
106
103
  _this.editorViewReadyDeferred = new Deferred();
107
104
  _this.outputAreaDeferred = new Deferred();
108
- _this.codeEditorSettings = void 0;
109
105
  _this.renderEditor = function () {
110
106
  if (_this.editorView) {
111
107
  return /*#__PURE__*/_jsx(ViewRender, {
@@ -163,7 +159,6 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
163
159
  _this.options = options;
164
160
  _this.viewManager = viewManager;
165
161
  _this.codeEditorManager = codeEditorManager;
166
- _this.codeEditorSettings = codeEditorSettings;
167
162
  _this.outputs = (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.outputs;
168
163
  _this.className = _this.className + ' code';
169
164
 
@@ -201,7 +196,6 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
201
196
  }()).catch(console.error);
202
197
  return _this;
203
198
  }
204
- LibroCodeCellView = inject(CodeEditorSettings)(LibroCodeCellView, undefined, 4) || LibroCodeCellView;
205
199
  LibroCodeCellView = inject(CodeEditorManager)(LibroCodeCellView, undefined, 3) || LibroCodeCellView;
206
200
  LibroCodeCellView = inject(ViewManager)(LibroCodeCellView, undefined, 2) || LibroCodeCellView;
207
201
  LibroCodeCellView = inject(CellService)(LibroCodeCellView, undefined, 1) || LibroCodeCellView;
@@ -216,27 +210,27 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
216
210
  get: function get() {
217
211
  return this.outputAreaDeferred.promise;
218
212
  }
213
+ }, {
214
+ key: "onViewResize",
215
+ value: function onViewResize(size) {
216
+ if (size.height) {
217
+ this.editorAreaHeight = size.height;
218
+ }
219
+ }
219
220
  }, {
220
221
  key: "calcEditorAreaHeight",
221
- value:
222
- // onViewResize(size: ViewSize) {
223
- // if (size.height) this.editorAreaHeight = size.height;
224
- // }
225
- function calcEditorAreaHeight() {
226
- // if (
227
- // this.editorStatus === EditorStatus.NOTLOADED ||
228
- // this.editorStatus === EditorStatus.LOADING
229
- // ) {
230
-
231
- var _this$codeEditorManag = this.codeEditorManager.getUserEditorConfig(this.model),
232
- lineHeight = _this$codeEditorManag.lineHeight,
233
- paddingTop = _this$codeEditorManag.paddingTop,
234
- paddingBottom = _this$codeEditorManag.paddingBottom,
235
- scrollBarHeight = _this$codeEditorManag.scrollBarHeight;
236
- var codeHeight = countLines(this.model.value) * (lineHeight || 20);
237
- var editorPadding = paddingTop + paddingBottom;
238
- var editorAreaHeight = codeHeight + editorPadding + scrollBarHeight;
239
- this.editorAreaHeight = editorAreaHeight;
222
+ value: function calcEditorAreaHeight() {
223
+ if (this.editorStatus === EditorStatus.NOTLOADED || this.editorStatus === EditorStatus.LOADING) {
224
+ var _this$codeEditorManag = this.codeEditorManager.getUserEditorConfig(this.model),
225
+ lineHeight = _this$codeEditorManag.lineHeight,
226
+ paddingTop = _this$codeEditorManag.paddingTop,
227
+ paddingBottom = _this$codeEditorManag.paddingBottom,
228
+ scrollBarHeight = _this$codeEditorManag.scrollBarHeight;
229
+ var codeHeight = countLines(this.model.value) * (lineHeight !== null && lineHeight !== void 0 ? lineHeight : 20);
230
+ var editorPadding = paddingTop + paddingBottom;
231
+ var editorAreaHeight = codeHeight + editorPadding + scrollBarHeight;
232
+ this.editorAreaHeight = editorAreaHeight;
233
+ }
240
234
 
241
235
  // 编辑器已经加载的情况下cell高度都由对它的高度监听得到。
242
236
  return this.editorAreaHeight;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-code-cell",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro",
@@ -32,9 +32,9 @@
32
32
  "src"
33
33
  ],
34
34
  "dependencies": {
35
- "@difizen/libro-code-editor": "^0.1.3",
36
- "@difizen/libro-common": "^0.1.3",
37
- "@difizen/libro-core": "^0.1.3",
35
+ "@difizen/libro-code-editor": "^0.1.4",
36
+ "@difizen/libro-common": "^0.1.4",
37
+ "@difizen/libro-core": "^0.1.4",
38
38
  "@difizen/mana-app": "latest"
39
39
  },
40
40
  "peerDependencies": {
@@ -2,7 +2,7 @@
2
2
  /* eslint-disable @typescript-eslint/no-parameter-properties */
3
3
  /* eslint-disable @typescript-eslint/parameter-properties */
4
4
  import type { CodeEditorViewOptions, CodeEditorView } from '@difizen/libro-code-editor';
5
- import { CodeEditorManager, CodeEditorSettings } from '@difizen/libro-code-editor';
5
+ import { CodeEditorManager } from '@difizen/libro-code-editor';
6
6
  import type { ICodeCell, IOutput } from '@difizen/libro-common';
7
7
  import { isOutput } from '@difizen/libro-common';
8
8
  import type {
@@ -17,6 +17,7 @@ import {
17
17
  LibroOutputArea,
18
18
  VirtualizedManagerHelper,
19
19
  } from '@difizen/libro-core';
20
+ import type { ViewSize } from '@difizen/mana-app';
20
21
  import {
21
22
  getOrigin,
22
23
  inject,
@@ -29,9 +30,9 @@ import {
29
30
  ViewOption,
30
31
  ViewRender,
31
32
  watch,
33
+ Deferred,
32
34
  } from '@difizen/mana-app';
33
- import { Deferred } from '@difizen/mana-app';
34
- import { useEffect, useMemo, useRef, memo, forwardRef } from 'react';
35
+ import { useEffect, useRef, memo, forwardRef } from 'react';
35
36
 
36
37
  import type { LibroCodeCellModel } from './code-cell-model.js';
37
38
 
@@ -54,16 +55,14 @@ const CellEditor: React.FC = () => {
54
55
  }
55
56
  }, [instance, instance.editorView?.editor]);
56
57
 
57
- const editorAreaHeight = useMemo(() => {
58
- return instance.calcEditorAreaHeight();
59
- }, [instance.model.value]);
60
-
61
58
  if (virtualizedManager.isVirtualized) {
62
59
  instance.renderEditorIntoVirtualized = true;
63
60
  if (instance.setEditorHost) {
64
61
  instance.setEditorHost(editorRef);
65
62
  }
66
63
 
64
+ const editorAreaHeight = instance.calcEditorAreaHeight();
65
+
67
66
  return (
68
67
  <div
69
68
  style={{
@@ -136,8 +135,6 @@ export class LibroCodeCellView extends LibroExecutableCellView {
136
135
  return this.outputAreaDeferred.promise;
137
136
  }
138
137
 
139
- protected codeEditorSettings: CodeEditorSettings;
140
-
141
138
  override renderEditor = () => {
142
139
  if (this.editorView) {
143
140
  return <ViewRender view={this.editorView} />;
@@ -145,25 +142,27 @@ export class LibroCodeCellView extends LibroExecutableCellView {
145
142
  return null;
146
143
  };
147
144
 
148
- // onViewResize(size: ViewSize) {
149
- // if (size.height) this.editorAreaHeight = size.height;
150
- // }
145
+ override onViewResize(size: ViewSize) {
146
+ if (size.height) {
147
+ this.editorAreaHeight = size.height;
148
+ }
149
+ }
151
150
 
152
151
  calcEditorAreaHeight() {
153
- // if (
154
- // this.editorStatus === EditorStatus.NOTLOADED ||
155
- // this.editorStatus === EditorStatus.LOADING
156
- // ) {
157
-
158
- const { lineHeight, paddingTop, paddingBottom, scrollBarHeight } =
159
- this.codeEditorManager.getUserEditorConfig(this.model);
152
+ if (
153
+ this.editorStatus === EditorStatus.NOTLOADED ||
154
+ this.editorStatus === EditorStatus.LOADING
155
+ ) {
156
+ const { lineHeight, paddingTop, paddingBottom, scrollBarHeight } =
157
+ this.codeEditorManager.getUserEditorConfig(this.model);
160
158
 
161
- const codeHeight = countLines(this.model.value) * (lineHeight || 20);
162
- const editorPadding = paddingTop + paddingBottom;
159
+ const codeHeight = countLines(this.model.value) * (lineHeight ?? 20);
160
+ const editorPadding = paddingTop + paddingBottom;
163
161
 
164
- const editorAreaHeight = codeHeight + editorPadding + scrollBarHeight;
162
+ const editorAreaHeight = codeHeight + editorPadding + scrollBarHeight;
165
163
 
166
- this.editorAreaHeight = editorAreaHeight;
164
+ this.editorAreaHeight = editorAreaHeight;
165
+ }
167
166
 
168
167
  // 编辑器已经加载的情况下cell高度都由对它的高度监听得到。
169
168
  return this.editorAreaHeight;
@@ -174,13 +173,11 @@ export class LibroCodeCellView extends LibroExecutableCellView {
174
173
  @inject(CellService) cellService: CellService,
175
174
  @inject(ViewManager) viewManager: ViewManager,
176
175
  @inject(CodeEditorManager) codeEditorManager: CodeEditorManager,
177
- @inject(CodeEditorSettings) codeEditorSettings: CodeEditorSettings,
178
176
  ) {
179
177
  super(options, cellService);
180
178
  this.options = options;
181
179
  this.viewManager = viewManager;
182
180
  this.codeEditorManager = codeEditorManager;
183
- this.codeEditorSettings = codeEditorSettings;
184
181
 
185
182
  this.outputs = options.cell?.outputs as IOutput[];
186
183
  this.className = this.className + ' code';