Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dt-react-codemirror-editor

Package Overview
Dependencies
Maintainers
4
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dt-react-codemirror-editor - npm Package Compare versions

Comparing version 0.9.1 to 0.9.3

lib/codemirror/config.d.ts

9

CHANGELOG.md

@@ -5,12 +5,9 @@ # Changelog

### [0.9.1](https://github.com/DTStack/dt-react-codemirror-editor/compare/v0.9.0...v0.9.1) (2020-07-14)
### [0.9.3](https://github.com/DTStack/dt-react-codemirror-editor/compare/v0.9.2...v0.9.3) (2021-08-24)
## 0.9.0 (2020-07-13)
### Bug Fixes
### Features
* modify the style import mode and update dt-react-component ([4fa22c1](https://github.com/DTStack/dt-react-codemirror-editor/commit/4fa22c154140c851477d5cda0ebe471240551d9a))
* add code ([51ffc1e](https://github.com/DTStack/dt-react-codemirror-editor/commit/51ffc1e133fa07df211025afb2fb68ba65d0e420))
* add dt-react-codemirror-editor component ([ec63107](https://github.com/DTStack/dt-react-codemirror-editor/commit/ec631076370b19c376cc611fc117d457295e510e))
## 0.9.0 (2020-07-13)

@@ -17,0 +14,0 @@

@@ -1,46 +0,4 @@

import * as React from 'react';
import CodeMirror from 'codemirror';
import './languages/log';
import './languages/simpleLog';
import 'codemirror/lib/codemirror.css';
import 'codemirror/addon/lint/lint.css';
import 'codemirror/addon/scroll/simplescrollbars.css';
import './style.scss';
declare type EditorEventCallback = (prevValue: string, nextValue: string, editorDoc: CodeMirror.Doc) => void;
interface CodeMirrorEditorProps {
value: string;
/**
* The cursor position
*/
cursor?: CodeMirror.Position;
/**
* Whether sync the editor value when props value changed
*/
sync?: boolean;
/**
* Editor option
*/
options?: CodeMirror.EditorConfiguration;
/**
* Always show cursor in the end.
* This option be used when streaming output, such as typing logs.
*/
cursorAlwaysInEnd?: boolean;
editorRef?: (inst: CodeMirror.Editor) => void;
cursorActivity?: EditorEventCallback;
onChange?: EditorEventCallback;
onFocus?: EditorEventCallback;
focusOut?: EditorEventCallback;
className?: string;
style?: React.CSSProperties;
}
declare class CodeMirrorEditor extends React.Component<CodeMirrorEditorProps, any> {
private _editorRef;
private _codeMirrorInstance;
componentDidMount(): void;
static fromTextArea(ele: HTMLTextAreaElement, options: CodeMirror.EditorConfiguration): any;
UNSAFE_componentWillReceiveProps(nextProps: any): void;
renderTextMark(): void;
render(): JSX.Element;
}
export * from './codemirror/utils';
export * from './codemirror/config';
import CodeMirrorEditor from './codemirror';
export default CodeMirrorEditor;

@@ -1,148 +0,4 @@

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import * as React from 'react';
import { defaultEditorOptions } from './config';
import CodeMirror from 'codemirror';
import './languages/log';
import './languages/simpleLog';
import 'codemirror/lib/codemirror.css';
import 'codemirror/addon/lint/lint.css';
import 'codemirror/addon/scroll/simplescrollbars.css';
import './style.scss';
import { getLinkMark, getLogMark } from './utils';
require('codemirror/mode/sql/sql');
require('codemirror/mode/python/python');
require('codemirror/mode/javascript/javascript');
require('codemirror/mode/properties/properties');
require('codemirror/addon/display/placeholder');
require('codemirror/addon/edit/matchbrackets');
require('codemirror/addon/scroll/simplescrollbars');
var CodeMirrorEditor = /** @class */ (function (_super) {
__extends(CodeMirrorEditor, _super);
function CodeMirrorEditor() {
return _super !== null && _super.apply(this, arguments) || this;
}
CodeMirrorEditor.prototype.componentDidMount = function () {
var ele = this._editorRef;
if (!ele)
return;
var _a = this.props, value = _a.value, onChange = _a.onChange, onFocus = _a.onFocus, cursor = _a.cursor, options = _a.options, focusOut = _a.focusOut, cursorActivity = _a.cursorActivity, editorRef = _a.editorRef;
var editorConfig = Object.assign({}, defaultEditorOptions, options);
this._codeMirrorInstance = CodeMirror.fromTextArea(ele, editorConfig);
var editorIns = this._codeMirrorInstance;
this.renderTextMark();
// 设置 cursor 位置
if (cursor)
editorIns.setCursor(cursor);
editorIns.on('change', function (doc) {
if (onChange) {
onChange(value, doc.getValue(), doc);
}
});
editorIns.on('focus', function (doc) {
if (onFocus) {
onFocus(value, doc.getValue(), doc);
}
});
editorIns.on('blur', function (doc) {
if (focusOut) {
focusOut(value, doc.getValue(), doc);
}
});
editorIns.on('cursorActivity', function (doc) {
if (cursorActivity) {
cursorActivity(value, doc.getValue(), doc);
}
});
if (editorRef) {
editorRef(editorIns);
}
};
CodeMirrorEditor.fromTextArea = function (ele, options) {
throw new Error("Method not implemented.");
};
// eslint-disable-next-line
CodeMirrorEditor.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
var editorIns = this._codeMirrorInstance;
var value = nextProps.value, sync = nextProps.sync, cursor = nextProps.cursor, cursorAlwaysInEnd = nextProps.cursorAlwaysInEnd, _a = nextProps.options, options = _a === void 0 ? {} : _a;
if (options) {
editorIns.setOption('readOnly', options.readOnly);
}
if (this.props.value !== value) {
if (cursor)
editorIns.setCursor(cursor);
if (sync) {
var scrollInfo = editorIns.getScrollInfo();
/**
* 判断滚动条是不是在底部
*/
var isInBottom = (scrollInfo.top + scrollInfo.clientHeight) - scrollInfo.height > -10;
console.log(isInBottom);
if (!value) {
editorIns.setValue('');
}
else {
editorIns.setValue(value);
}
if (cursorAlwaysInEnd) {
editorIns.setCursor(editorIns.lineCount());
}
else if (!isInBottom) {
/**
* 不在底部并且不设置自动滚到底部,则滚到原来位置
*/
editorIns.scrollTo(scrollInfo.left, scrollInfo.top);
}
else if (isInBottom) {
/**
* 在底部,则自动到底部
* 需要等setValue这个动作结束之后,再获取内容的高度。
*/
Promise.resolve().then(function () {
var nowScrollInfo = editorIns.getScrollInfo();
editorIns.scrollTo(nowScrollInfo.left, nowScrollInfo.height);
});
}
}
this.renderTextMark();
}
};
CodeMirrorEditor.prototype.renderTextMark = function () {
var editorIns = this._codeMirrorInstance;
var marks = editorIns.getAllMarks();
for (var _a = 0, marks_1 = marks; _a < marks_1.length; _a++) { // 重置marks
var mark = marks_1[_a];
mark.clear();
}
var value = editorIns.getValue();
var linkMarks = [].concat(getLinkMark(value)).concat(getLogMark(value));
for (var _i = 0; _i < linkMarks.length; _i++) {
var mark = linkMarks[_i];
editorIns.markText(editorIns.posFromIndex(mark.start), editorIns.posFromIndex(mark.end), { replacedWith: mark.node });
}
};
CodeMirrorEditor.prototype.render = function () {
var _this = this;
var _a = this.props, className = _a.className, style = _a.style;
var renderClass = "code-editor " + (className || '');
var renderStyle = {
position: 'relative'
};
Object.assign(renderStyle, style);
return (React.createElement("div", { className: renderClass, style: renderStyle },
React.createElement("textarea", { ref: function (e) { _this._editorRef = e; }, defaultValue: this.props.value || '' })));
};
return CodeMirrorEditor;
}(React.Component));
export * from './codemirror/utils';
export * from './codemirror/config';
import CodeMirrorEditor from './codemirror';
export default CodeMirrorEditor;
{
"name": "dt-react-codemirror-editor",
"version": "0.9.1",
"version": "0.9.3",
"description": "The CodeMirror editor for React.",

@@ -9,7 +9,16 @@ "repository": {

},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"main": "lib/index.js",
"module": "lib/index.js",
"types": "lib/index.d.ts",
"exports": {
"./": "lib/"
},
"files": [
"lib"
],
"scripts": {
"storybook": "start-storybook -p 9001 -c .storybook",
"storybook": "npm run compile && start-storybook -p 9001 -c .storybook",
"build-storybook": "build-storybook -c .storybook",

@@ -19,11 +28,11 @@ "deploy-storybook": "storybook-to-ghpages",

"build-ts": "tsc -p tsconfig.build.json",
"build-css": "node-sass ./src/codemirror/style.scss ./lib/style.css",
"build-css": "node-sass ./src/codemirror/style.scss ./lib/codemirror/style.css",
"release": "./scripts/release.sh",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
"check-types": "tsc --skipLibCheck",
"test": "jest --no-chche",
"test": "jest --passWithNoTests --no-chche",
"test:update": "npm run test -u",
"lint": "npx eslint './src/**/*.tsx' ",
"lint-doc": "node ./node_modules/lint-md/bin ./*.md src/stories/**/*.md",
"lint-fix": "npx eslint './src/**/*.tsx' --fix && lint-md ./*.md src/stories/markdown/*.md --fix"
"lint-doc": "node ./node_modules/lint-md/bin ./*.md ./stories/**/*.d",
"lint-fix": "npx eslint './src/**/*.tsx' --fix && lint-md ./*.md ./stories/markdown/*.md --fix"
},

@@ -60,3 +69,3 @@ "keywords": [

"@babel/preset-typescript": "^7.3.3",
"@commitlint/cli": "^8.3.5",
"@commitlint/cli": "^9.1.2",
"@commitlint/config-angular": "^8.3.4",

@@ -75,2 +84,3 @@ "@sambego/storybook-state": "^1.3.6",

"@storybook/theming": "^5.1.10",
"@types/codemirror": "^0.0.96",
"@types/enzyme": "^3.10.5",

@@ -83,4 +93,4 @@ "@types/history": "^4.7.0",

"@types/storybook__react": "^4.0.2",
"@typescript-eslint/eslint-plugin": "^3.6.0",
"@typescript-eslint/parser": "^3.6.0",
"@typescript-eslint/eslint-plugin": "^3.6.1",
"@typescript-eslint/parser": "^3.6.1",
"awesome-typescript-loader": "^5.2.1",

@@ -99,13 +109,15 @@ "babel-cli": "^6.26.0",

"cz-conventional-changelog": "^3.0.2",
"dt-react-component": "^2.0.9",
"babel-plugin-treasure": "^0.9.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^5.16.0",
"eslint": "^7.4.0",
"eslint-config-standard": "^12.0.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^22.14.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-sort-requires": "^2.1.0",

@@ -128,7 +140,5 @@ "eslint-plugin-standard": "^4.0.0",

"style-loader": "^0.23.1",
"typescript": "^3.5.3",
"typescript": "^3.9.6",
"url-loader": "^4.1.0",
"warning": "^4.0.3",
"@types/codemirror": "^0.0.96",
"dt-react-component": "^1.2.0"
"warning": "^4.0.3"
},

@@ -135,0 +145,0 @@ "dependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc