react-codemirror-runmode 1.0.5 → 2.0.1

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/lib/index.js DELETED
@@ -1,83 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
-
16
- class MirrorLight extends _react["default"].Component {
17
- render() {
18
- const {
19
- inline,
20
- codeMirror,
21
- value,
22
- language,
23
- className,
24
- prefix,
25
- theme
26
- } = this.props;
27
- const elements = [];
28
- let index = 0;
29
- let lastStyle = null;
30
- let tokenBuf = '';
31
-
32
- const pushElement = (token, style) => {
33
- elements.push(_react["default"].createElement("span", {
34
- className: style ? prefix + style : '',
35
- key: ++index
36
- }, token));
37
- };
38
-
39
- const mode = codeMirror.findModeByName(language);
40
- codeMirror.runMode(value, mode ? mode.mime : language, (token, style) => {
41
- if (lastStyle === style) {
42
- tokenBuf += token;
43
- lastStyle = style;
44
- } else {
45
- if (tokenBuf) {
46
- pushElement(tokenBuf, lastStyle);
47
- }
48
-
49
- tokenBuf = token;
50
- lastStyle = style;
51
- }
52
- });
53
- pushElement(tokenBuf, lastStyle);
54
-
55
- const code = _react["default"].createElement("code", {
56
- className: inline ? `inline ${prefix}s-${theme}` : ''
57
- }, elements);
58
-
59
- return inline ? code : _react["default"].createElement("pre", {
60
- className: `${className} ${prefix}s-${theme}`
61
- }, code);
62
- }
63
-
64
- }
65
-
66
- exports["default"] = MirrorLight;
67
-
68
- _defineProperty(MirrorLight, "propTypes", {
69
- codeMirror: _propTypes["default"].func.isRequired,
70
- className: _propTypes["default"].string,
71
- theme: _propTypes["default"].string,
72
- inline: _propTypes["default"].bool,
73
- language: _propTypes["default"].string,
74
- prefix: _propTypes["default"].string,
75
- value: _propTypes["default"].string.isRequired
76
- });
77
-
78
- _defineProperty(MirrorLight, "defaultProps", {
79
- className: '',
80
- prefix: 'cm-'
81
- });
82
-
83
- module.exports = exports["default"];
package/src/index.js DELETED
@@ -1,68 +0,0 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
-
4
- export default class MirrorLight extends React.Component {
5
- static propTypes = {
6
- codeMirror: PropTypes.func.isRequired,
7
- className: PropTypes.string,
8
- theme: PropTypes.string,
9
- inline: PropTypes.bool,
10
- language: PropTypes.string,
11
- prefix: PropTypes.string,
12
- value: PropTypes.string.isRequired
13
- }
14
-
15
- static defaultProps = {
16
- className: '',
17
- prefix: 'cm-'
18
- }
19
-
20
- render() {
21
- const {
22
- inline,
23
- codeMirror,
24
- value,
25
- language,
26
- className,
27
- prefix,
28
- theme
29
- } = this.props
30
- const elements = []
31
- let index = 0
32
- let lastStyle = null
33
- let tokenBuf = ''
34
- const pushElement = (token, style) => {
35
- elements.push(
36
- <span className={style ? prefix + style : ''} key={++index}>
37
- {token}
38
- </span>
39
- )
40
- }
41
- const mode = codeMirror.findModeByName(language)
42
- codeMirror.runMode(value, mode ? mode.mime : language, (token, style) => {
43
- if (lastStyle === style) {
44
- tokenBuf += token
45
- lastStyle = style
46
- } else {
47
- if (tokenBuf) {
48
- pushElement(tokenBuf, lastStyle)
49
- }
50
- tokenBuf = token
51
- lastStyle = style
52
- }
53
- })
54
- pushElement(tokenBuf, lastStyle)
55
-
56
- const code = (
57
- <code className={inline ? `inline ${prefix}s-${theme}` : ''}>
58
- {elements}
59
- </code>
60
- )
61
-
62
- return inline ? (
63
- code
64
- ) : (
65
- <pre className={`${className} ${prefix}s-${theme}`}>{code}</pre>
66
- )
67
- }
68
- }
@@ -1,32 +0,0 @@
1
- import React from 'react'
2
- import { mount } from 'enzyme'
3
- import assert from 'assert'
4
-
5
- import CodeMirror from 'codemirror'
6
- import 'codemirror/addon/runmode/runmode'
7
- import 'codemirror/mode/meta'
8
- import 'codemirror/mode/javascript/javascript'
9
- import Highlighter from '../lib/'
10
-
11
- describe('highlight', () => {
12
- it('render code using CodeMirror', () => {
13
- const code = 'function blah(arg1) {};'
14
- const actual = (
15
- <Highlighter
16
- codeMirror={CodeMirror}
17
- value={code}
18
- theme="solarized"
19
- language="javascript"
20
- />
21
- )
22
- const wrapper = mount(actual)
23
- assert.ok(wrapper.find('pre').hasClass('cm-s-solarized'))
24
- assert.equal(wrapper.find('pre > code > span').length, 8)
25
- assert.ok(
26
- wrapper
27
- .find('pre > code > span')
28
- .first()
29
- .hasClass('cm-keyword')
30
- )
31
- })
32
- })
package/test/setup.js DELETED
@@ -1,20 +0,0 @@
1
- import { JSDOM } from 'jsdom'
2
- import Enzyme from 'enzyme'
3
- import Adapter from 'enzyme-adapter-react-16'
4
-
5
- Enzyme.configure({ adapter: new Adapter() })
6
-
7
- const { window } = new JSDOM('', {
8
- url: 'http://localhost/'
9
- })
10
- global.window = window
11
- global.document = window.document
12
- Object.keys(global.window).forEach(property => {
13
- if (typeof global[property] === 'undefined') {
14
- global[property] = document.defaultView[property]
15
- }
16
- })
17
-
18
- global.navigator = {
19
- userAgent: 'node.js'
20
- }
@@ -1,58 +0,0 @@
1
- import webpack from 'webpack'
2
- import path from 'path'
3
-
4
- console.log('process.env.NODE_ENV:', process.env.NODE_ENV)
5
-
6
- const isDev = process.env.NODE_ENV !== 'production'
7
-
8
- const config = {
9
- mode: isDev ? 'development' : 'production',
10
- entry: path.join(__dirname, 'demo', 'js', 'demo.js'),
11
- output: {
12
- path: path.join(__dirname, 'demo', 'js'),
13
- filename: 'demo.min.js'
14
- },
15
- externals: {
16
- react: 'React',
17
- 'react-dom': 'ReactDOM'
18
- },
19
- module: {
20
- rules: [
21
- {
22
- test: /\.jsx?$/,
23
- use: {
24
- loader: 'babel-loader',
25
- options: {
26
- presets: [
27
- [
28
- '@babel/preset-env',
29
- {
30
- useBuiltIns: 'entry',
31
- debug: true,
32
- modules: 'umd',
33
- corejs: 3
34
- }
35
- ],
36
- '@babel/preset-react'
37
- ],
38
- plugins: []
39
- }
40
- }
41
- }
42
- ]
43
- },
44
- plugins: [
45
- new webpack.DefinePlugin({
46
- 'process.env.NODE_ENV': JSON.stringify(
47
- process.env.NODE_ENV || 'development'
48
- )
49
- })
50
- ]
51
- }
52
-
53
- if (isDev) {
54
- config.cache = true
55
- config.devtool = 'source-map'
56
- }
57
-
58
- export default config