@elliemae/ds-codeeditor 2.3.0-alpha.9 → 2.3.0-next.3

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.
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _jsx = require('@babel/runtime/helpers/jsx');
6
+ require('core-js/modules/web.dom-collections.iterator.js');
7
+ var React = require('react');
8
+ var reactDesc = require('react-desc');
9
+ var DSModal = require('@elliemae/ds-modal');
10
+ var AceEditor = require('react-ace');
11
+ var DSCodeEditorForm = require('./components/DSCodeEditorForm.js');
12
+ require('brace/mode/javascript.js');
13
+ require('brace/theme/tomorrow.js');
14
+ var jsxRuntime = require('react/jsx-runtime');
15
+
16
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
+
18
+ var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
19
+ var DSModal__default = /*#__PURE__*/_interopDefaultLegacy(DSModal);
20
+ var AceEditor__default = /*#__PURE__*/_interopDefaultLegacy(AceEditor);
21
+
22
+ const DSCodeEditor = _ref => {
23
+ let {
24
+ containerProps = {},
25
+ value: defaultValue = '',
26
+ onSave = () => null,
27
+ onClose = () => null,
28
+ onReject = () => null,
29
+ onChange = () => null,
30
+ isOpen = false,
31
+ fileName = '',
32
+ confirmLabel = 'Save',
33
+ maxLines = 20,
34
+ minLines = 20,
35
+ modalTitle = 'Javascript Editor',
36
+ modalType = 'confirm',
37
+ rejectLabel = 'Close',
38
+ size = 'large',
39
+ style = {},
40
+ useModal = true,
41
+ showHeader = true,
42
+ showSyntaxChecks = true
43
+ } = _ref;
44
+ const [{
45
+ value,
46
+ errors
47
+ }, setState] = React.useState({
48
+ value: defaultValue,
49
+ errors: []
50
+ });
51
+ const reactAceComponent = React.useRef();
52
+
53
+ const editor = /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
54
+ children: [showHeader && /*#__PURE__*/_jsx__default["default"](DSCodeEditorForm, {
55
+ fileName: fileName,
56
+ reactAceComponent: reactAceComponent
57
+ }), /*#__PURE__*/jsxRuntime.jsx(AceEditor__default["default"], {
58
+ ref: reactAceComponent,
59
+ editorProps: {
60
+ $blockScrolling: true
61
+ },
62
+ maxLines: maxLines,
63
+ minLines: minLines,
64
+ mode: "javascript",
65
+ name: "ace-code-edior",
66
+ onChange: val => {
67
+ setState({
68
+ errors,
69
+ value: val
70
+ });
71
+ onChange(val, errors);
72
+ },
73
+ onValidate: annotations => setState({
74
+ value,
75
+ errors: annotations
76
+ }),
77
+ theme: "tomorrow",
78
+ setOptions: {
79
+ useWorker: showSyntaxChecks
80
+ },
81
+ value: value
82
+ })]
83
+ });
84
+
85
+ if (!useModal) return editor;
86
+ return /*#__PURE__*/_jsx__default["default"](DSModal__default["default"], {
87
+ centered: false,
88
+ confirmLabel: confirmLabel,
89
+ containerProps: containerProps,
90
+ isOpen: isOpen,
91
+ modalTitle: modalTitle,
92
+ modalType: modalType,
93
+ onClose: () => onClose(value, fileName, errors),
94
+ onConfirm: () => onSave(value, fileName, errors),
95
+ onReject: () => onReject(value, fileName, errors),
96
+ rejectLabel: rejectLabel,
97
+ size: size,
98
+ style: style
99
+ }, void 0, editor);
100
+ };
101
+
102
+ const codeEditorProps = {
103
+ containerProps: reactDesc.PropTypes.object.description('Set of Properties attached to the main container'),
104
+ value: reactDesc.PropTypes.string.description('editors content').isRequired,
105
+ onSave: reactDesc.PropTypes.func.description('function called when the user press save'),
106
+ onClose: reactDesc.PropTypes.func.description('function called when the user closes the modal'),
107
+ onReject: reactDesc.PropTypes.func.description('function called when is rejected'),
108
+ onChange: reactDesc.PropTypes.func.description('function executed when code editor value changes').isRequired,
109
+ isOpen: reactDesc.PropTypes.bool.description('Whether the modal is opened or not').defaultValue(false),
110
+ fileName: reactDesc.PropTypes.string.description('File name to open in the editor'),
111
+ maxLines: reactDesc.PropTypes.number.description('Max lines in the editor content').defaultValue(20),
112
+ minLines: reactDesc.PropTypes.number.description('Min lines in the editor content').defaultValue(20),
113
+ modalTitle: reactDesc.PropTypes.string.description('Modal title').defaultValue('Javascript Editor'),
114
+ confirmLabel: reactDesc.PropTypes.string.description('Customize modal confirm label').defaultValue('Save'),
115
+ rejectLabel: reactDesc.PropTypes.string.description('Customize modal rejection label').defaultValue('Close'),
116
+ modalType: reactDesc.PropTypes.oneOf(DSModal.modalTypes).description('Modal type').defaultValue('confirm'),
117
+ size: reactDesc.PropTypes.oneOf(['xsmall', 'small', 'medium', 'large', 'xlarge']).description('modal size').defaultValue('large'),
118
+ style: reactDesc.PropTypes.object.description('css inline style'),
119
+ useModal: reactDesc.PropTypes.bool.description('whether to use code editor inside modal or not').defaultValue(true),
120
+ showHeader: reactDesc.PropTypes.bool.description('show editors header').defaultValue(true),
121
+ showSyntaxChecks: reactDesc.PropTypes.bool.description('show syntax warnings and checks').defaultValue(true)
122
+ };
123
+ const CodeEditorWithSchema = reactDesc.describe(DSCodeEditor);
124
+ CodeEditorWithSchema.propTypes = codeEditorProps;
125
+
126
+ exports.CodeEditorWithSchema = CodeEditorWithSchema;
127
+ exports["default"] = DSCodeEditor;
@@ -0,0 +1,189 @@
1
+ 'use strict';
2
+
3
+ var _jsx = require('@babel/runtime/helpers/jsx');
4
+ require('core-js/modules/esnext.async-iterator.find.js');
5
+ require('core-js/modules/esnext.iterator.constructor.js');
6
+ require('core-js/modules/esnext.iterator.find.js');
7
+ require('core-js/modules/es.string.replace.js');
8
+ require('core-js/modules/es.string.replace-all.js');
9
+ var React = require('react');
10
+ var DSButton = require('@elliemae/ds-button');
11
+ var dsForm = require('@elliemae/ds-form');
12
+ var dsClassnames = require('@elliemae/ds-classnames');
13
+ var dsIcons = require('@elliemae/ds-icons');
14
+
15
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
+
17
+ var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
18
+ var DSButton__default = /*#__PURE__*/_interopDefaultLegacy(DSButton);
19
+
20
+ var _DSButton, _ChevronSmallRight;
21
+ const blockName = 'code-editor';
22
+ const {
23
+ cssClassName,
24
+ classNameBlock
25
+ } = dsClassnames.convertPropToCssClassName(blockName);
26
+ const CheckOptionsGroup = dsClassnames.aggregatedClasses('div')("".concat(blockName, "-options-group"));
27
+
28
+ class DSCodeEditorForm extends React.Component {
29
+ constructor(props) {
30
+ super(props);
31
+ this.state = {
32
+ find: false,
33
+ replace: false,
34
+ isCaseSensitive: false,
35
+ isWholeWord: false,
36
+ filteredText: '',
37
+ replaceText: ''
38
+ };
39
+ }
40
+
41
+ searchWord(isReplace, all) {
42
+ const {
43
+ reactAceComponent: {
44
+ current: {
45
+ editor
46
+ }
47
+ }
48
+ } = this.props;
49
+ const {
50
+ isCaseSensitive,
51
+ isWholeWord,
52
+ filteredText,
53
+ replaceText
54
+ } = this.state;
55
+ const options = {
56
+ backwards: false,
57
+ wrap: true,
58
+ caseSensitive: isCaseSensitive,
59
+ wholeWord: isWholeWord,
60
+ regExp: true
61
+ };
62
+ editor.find(filteredText, options);
63
+ const selectedContent = editor.getSelectedText();
64
+
65
+ if (isReplace && replaceText && selectedContent) {
66
+ if (all) {
67
+ editor.findAll(filteredText, options);
68
+ editor.replaceAll(replaceText);
69
+ } else {
70
+ const range = editor.selection.getRange();
71
+ editor.session.replace(range, replaceText);
72
+ }
73
+ }
74
+ }
75
+
76
+ render() {
77
+ const {
78
+ fileName
79
+ } = this.props;
80
+ const {
81
+ find,
82
+ replace,
83
+ isCaseSensitive,
84
+ isWholeWord,
85
+ filteredText,
86
+ replaceText
87
+ } = this.state;
88
+ return /*#__PURE__*/_jsx__default["default"]("div", {
89
+ className: "".concat(cssClassName)
90
+ }, void 0, fileName ? /*#__PURE__*/_jsx__default["default"]("div", {
91
+ className: classNameBlock('file-name')
92
+ }, void 0, "File Name: ", /*#__PURE__*/_jsx__default["default"]("span", {}, void 0, " ", fileName, " ")) : null, /*#__PURE__*/_jsx__default["default"]("div", {
93
+ className: classNameBlock('find-replace-btn')
94
+ }, void 0, !find && !replace ? /*#__PURE__*/_jsx__default["default"](DSButton__default["default"], {
95
+ buttonType: "secondary",
96
+ labelText: "Find",
97
+ onClick: () => this.setState({
98
+ find: true
99
+ }),
100
+ size: "m"
101
+ }) : null, !replace ? /*#__PURE__*/_jsx__default["default"](DSButton__default["default"], {
102
+ buttonType: "secondary",
103
+ labelText: "Find & Replace",
104
+ onClick: () => this.setState({
105
+ replace: true
106
+ }),
107
+ size: "m"
108
+ }) : null), find || replace ? /*#__PURE__*/_jsx__default["default"](dsForm.DSInputGroup, {
109
+ className: classNameBlock('find')
110
+ }, void 0, /*#__PURE__*/_jsx__default["default"](dsForm.DSTextBox, {
111
+ className: "find-word",
112
+ fluidWidth: false,
113
+ id: "find-textbox",
114
+ onChange: e => this.setState({
115
+ filteredText: e.currentTarget.value
116
+ }),
117
+ placeholder: "Find",
118
+ rightComponent: /*#__PURE__*/_jsx__default["default"]("div", {
119
+ className: classNameBlock('next-back-btn')
120
+ }, void 0, _DSButton || (_DSButton = /*#__PURE__*/_jsx__default["default"](DSButton__default["default"], {
121
+ icon: /*#__PURE__*/_jsx__default["default"](dsIcons.ChevronSmallLeft, {}),
122
+ size: "m"
123
+ })), /*#__PURE__*/_jsx__default["default"](DSButton__default["default"], {
124
+ icon: _ChevronSmallRight || (_ChevronSmallRight = /*#__PURE__*/_jsx__default["default"](dsIcons.ChevronSmallRight, {})),
125
+ onClick: () => this.searchWord(),
126
+ size: "m"
127
+ })),
128
+ value: filteredText
129
+ }), /*#__PURE__*/_jsx__default["default"](CheckOptionsGroup, {}, void 0, /*#__PURE__*/_jsx__default["default"](dsForm.DSCheckbox, {
130
+ checked: isCaseSensitive,
131
+ id: "case-sensitive-check",
132
+ labelText: "Case Sensitive",
133
+ name: "case-sensitive-check",
134
+ onChange: () => this.setState({
135
+ isCaseSensitive: !isCaseSensitive
136
+ })
137
+ }), /*#__PURE__*/_jsx__default["default"](dsForm.DSCheckbox, {
138
+ checked: isWholeWord,
139
+ id: "whole-word-check",
140
+ labelText: "Whole Word",
141
+ name: "whole-word-check",
142
+ onChange: () => this.setState({
143
+ isWholeWord: !isWholeWord
144
+ })
145
+ }), /*#__PURE__*/_jsx__default["default"](dsForm.DSCheckbox, {
146
+ checked: replace,
147
+ id: "replace-check",
148
+ labelText: "Replace",
149
+ name: "replace-check",
150
+ onChange: () => this.setState({
151
+ replace: !replace
152
+ })
153
+ })), /*#__PURE__*/_jsx__default["default"](DSButton__default["default"], {
154
+ buttonType: "secondary",
155
+ labelText: "Done",
156
+ onClick: () => this.setState({
157
+ replace: false,
158
+ find: false
159
+ }),
160
+ size: "m"
161
+ })) : null, replace ? /*#__PURE__*/_jsx__default["default"]("div", {
162
+ className: classNameBlock('replace')
163
+ }, void 0, /*#__PURE__*/_jsx__default["default"](dsForm.DSTextBox, {
164
+ className: "find-word",
165
+ fluidWidth: false,
166
+ id: "replace-textbox",
167
+ onChange: e => this.setState({
168
+ replaceText: e.currentTarget.value
169
+ }),
170
+ placeholder: "Replace",
171
+ value: replaceText
172
+ }), /*#__PURE__*/_jsx__default["default"]("div", {
173
+ className: classNameBlock('replace-btns')
174
+ }, void 0, /*#__PURE__*/_jsx__default["default"](DSButton__default["default"], {
175
+ buttonType: "secondary",
176
+ labelText: "Replace",
177
+ onClick: () => this.searchWord(true, false),
178
+ size: "m"
179
+ }), /*#__PURE__*/_jsx__default["default"](DSButton__default["default"], {
180
+ buttonType: "secondary",
181
+ labelText: "Replace All",
182
+ onClick: () => this.searchWord(true, true),
183
+ size: "m"
184
+ }))) : null);
185
+ }
186
+
187
+ }
188
+
189
+ module.exports = DSCodeEditorForm;
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ var _jsx = require('@babel/runtime/helpers/jsx');
4
+ var React = require('react');
5
+ var AceEditor = require('react-ace');
6
+ var DSModal = require('@elliemae/ds-modal');
7
+ var DSCodeEditorForm = require('./DSCodeEditorForm.js');
8
+ require('brace/mode/javascript.js');
9
+ require('brace/theme/tomorrow.js');
10
+ var jsxRuntime = require('react/jsx-runtime');
11
+
12
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+
14
+ var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
15
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
16
+ var AceEditor__default = /*#__PURE__*/_interopDefaultLegacy(AceEditor);
17
+ var DSModal__default = /*#__PURE__*/_interopDefaultLegacy(DSModal);
18
+
19
+ class DSCodeEditorImpl extends React.Component {
20
+ constructor(props) {
21
+ super(props);
22
+ this.state = {
23
+ value: props.value,
24
+ errors: []
25
+ };
26
+ this.reactAceComponent = /*#__PURE__*/React__default["default"].createRef();
27
+ }
28
+
29
+ render() {
30
+ const {
31
+ onSave,
32
+ onClose,
33
+ onReject,
34
+ isOpen,
35
+ fileName,
36
+ confirmLabel,
37
+ maxLines,
38
+ minLines,
39
+ modalTitle,
40
+ modalType,
41
+ rejectLabel,
42
+ size,
43
+ style,
44
+ containerProps
45
+ } = this.props;
46
+ const {
47
+ value,
48
+ errors
49
+ } = this.state;
50
+ return /*#__PURE__*/_jsx__default["default"](DSModal__default["default"], {
51
+ centered: false,
52
+ confirmLabel: confirmLabel,
53
+ containerProps: containerProps,
54
+ isOpen: isOpen,
55
+ modalTitle: modalTitle,
56
+ modalType: modalType,
57
+ onClose: () => onClose(value, fileName, errors),
58
+ onConfirm: () => onSave(value, fileName, errors),
59
+ onReject: () => onReject(value, fileName, errors),
60
+ rejectLabel: rejectLabel,
61
+ size: size,
62
+ style: style
63
+ }, void 0, /*#__PURE__*/_jsx__default["default"](DSCodeEditorForm, {
64
+ fileName: fileName,
65
+ reactAceComponent: this.reactAceComponent
66
+ }), /*#__PURE__*/jsxRuntime.jsx(AceEditor__default["default"], {
67
+ ref: this.reactAceComponent,
68
+ editorProps: {
69
+ $blockScrolling: true
70
+ },
71
+ maxLines: maxLines,
72
+ minLines: minLines,
73
+ mode: "javascript",
74
+ name: "ace-code-edior",
75
+ onChange: val => this.setState({
76
+ value: val
77
+ }),
78
+ onValidate: annotations => this.setState({
79
+ errors: annotations
80
+ }),
81
+ theme: "tomorrow",
82
+ value: value
83
+ }));
84
+ }
85
+
86
+ }
87
+
88
+ module.exports = DSCodeEditorImpl;
package/cjs/index.js ADDED
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var DSCodeEditor = require('./DSCodeEditor.js');
6
+
7
+
8
+
9
+ exports.CodeEditorWithSchema = DSCodeEditor.CodeEditorWithSchema;
10
+ exports["default"] = DSCodeEditor["default"];
@@ -0,0 +1,116 @@
1
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
2
+ import 'core-js/modules/web.dom-collections.iterator.js';
3
+ import { useState, useRef } from 'react';
4
+ import { PropTypes, describe } from 'react-desc';
5
+ import DSModal, { modalTypes } from '@elliemae/ds-modal';
6
+ import AceEditor from 'react-ace';
7
+ import DSCodeEditorForm from './components/DSCodeEditorForm.js';
8
+ import 'brace/mode/javascript.js';
9
+ import 'brace/theme/tomorrow.js';
10
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
11
+
12
+ const DSCodeEditor = _ref => {
13
+ let {
14
+ containerProps = {},
15
+ value: defaultValue = '',
16
+ onSave = () => null,
17
+ onClose = () => null,
18
+ onReject = () => null,
19
+ onChange = () => null,
20
+ isOpen = false,
21
+ fileName = '',
22
+ confirmLabel = 'Save',
23
+ maxLines = 20,
24
+ minLines = 20,
25
+ modalTitle = 'Javascript Editor',
26
+ modalType = 'confirm',
27
+ rejectLabel = 'Close',
28
+ size = 'large',
29
+ style = {},
30
+ useModal = true,
31
+ showHeader = true,
32
+ showSyntaxChecks = true
33
+ } = _ref;
34
+ const [{
35
+ value,
36
+ errors
37
+ }, setState] = useState({
38
+ value: defaultValue,
39
+ errors: []
40
+ });
41
+ const reactAceComponent = useRef();
42
+
43
+ const editor = /*#__PURE__*/jsxs(Fragment, {
44
+ children: [showHeader && /*#__PURE__*/_jsx(DSCodeEditorForm, {
45
+ fileName: fileName,
46
+ reactAceComponent: reactAceComponent
47
+ }), /*#__PURE__*/jsx(AceEditor, {
48
+ ref: reactAceComponent,
49
+ editorProps: {
50
+ $blockScrolling: true
51
+ },
52
+ maxLines: maxLines,
53
+ minLines: minLines,
54
+ mode: "javascript",
55
+ name: "ace-code-edior",
56
+ onChange: val => {
57
+ setState({
58
+ errors,
59
+ value: val
60
+ });
61
+ onChange(val, errors);
62
+ },
63
+ onValidate: annotations => setState({
64
+ value,
65
+ errors: annotations
66
+ }),
67
+ theme: "tomorrow",
68
+ setOptions: {
69
+ useWorker: showSyntaxChecks
70
+ },
71
+ value: value
72
+ })]
73
+ });
74
+
75
+ if (!useModal) return editor;
76
+ return /*#__PURE__*/_jsx(DSModal, {
77
+ centered: false,
78
+ confirmLabel: confirmLabel,
79
+ containerProps: containerProps,
80
+ isOpen: isOpen,
81
+ modalTitle: modalTitle,
82
+ modalType: modalType,
83
+ onClose: () => onClose(value, fileName, errors),
84
+ onConfirm: () => onSave(value, fileName, errors),
85
+ onReject: () => onReject(value, fileName, errors),
86
+ rejectLabel: rejectLabel,
87
+ size: size,
88
+ style: style
89
+ }, void 0, editor);
90
+ };
91
+
92
+ const codeEditorProps = {
93
+ containerProps: PropTypes.object.description('Set of Properties attached to the main container'),
94
+ value: PropTypes.string.description('editors content').isRequired,
95
+ onSave: PropTypes.func.description('function called when the user press save'),
96
+ onClose: PropTypes.func.description('function called when the user closes the modal'),
97
+ onReject: PropTypes.func.description('function called when is rejected'),
98
+ onChange: PropTypes.func.description('function executed when code editor value changes').isRequired,
99
+ isOpen: PropTypes.bool.description('Whether the modal is opened or not').defaultValue(false),
100
+ fileName: PropTypes.string.description('File name to open in the editor'),
101
+ maxLines: PropTypes.number.description('Max lines in the editor content').defaultValue(20),
102
+ minLines: PropTypes.number.description('Min lines in the editor content').defaultValue(20),
103
+ modalTitle: PropTypes.string.description('Modal title').defaultValue('Javascript Editor'),
104
+ confirmLabel: PropTypes.string.description('Customize modal confirm label').defaultValue('Save'),
105
+ rejectLabel: PropTypes.string.description('Customize modal rejection label').defaultValue('Close'),
106
+ modalType: PropTypes.oneOf(modalTypes).description('Modal type').defaultValue('confirm'),
107
+ size: PropTypes.oneOf(['xsmall', 'small', 'medium', 'large', 'xlarge']).description('modal size').defaultValue('large'),
108
+ style: PropTypes.object.description('css inline style'),
109
+ useModal: PropTypes.bool.description('whether to use code editor inside modal or not').defaultValue(true),
110
+ showHeader: PropTypes.bool.description('show editors header').defaultValue(true),
111
+ showSyntaxChecks: PropTypes.bool.description('show syntax warnings and checks').defaultValue(true)
112
+ };
113
+ const CodeEditorWithSchema = describe(DSCodeEditor);
114
+ CodeEditorWithSchema.propTypes = codeEditorProps;
115
+
116
+ export { CodeEditorWithSchema, DSCodeEditor as default };