Replace Rose::CodeEditor with Hds::CodeEditor (#2679)
* chore: 🤖 replace Rose::CodeEditor with Hds::CodeEditor - Remove CodeEditor 5 dependency * chore: 🤖 Replace CodeMirror5 dep remove CodeMirror5 and replace existing editors with HDS::CodeEditor * chore: 🤖 deleting old codeeditor styles * feat: 🎸 changing code editor changing code editor ✅ Closes: 0 * removed unused export * pr cleanup * updating tests for new code editor * responding to PR feedback * added whitespace * fixing linting violations * chore: 🤖 self-review PR self-review PR in the course of switching to new HDS code editor * fix: 🐛 fix linting bug * fix: 🐛 unneeded dependency remove jslint dependency as this is handled in the new code editor from HDS * fix: 🐛 Fixing import bug Fix import bug caused by importing scss modules that no longer exist * Fix and refactor code editor acceptance test * Fix and refactor code editor acceptance test * chore: 🤖 remove codemirror dependency * refactor: 💡 fix merge conflict issues * test: 💍 update e2e test selectors * test: 💍 fix target spec click event * refactor: 💡 clean up test selectors for code editor * refactor: 💡 clean up storage bucket test selectors * chore: 🤖 remove code mirror modifiers --------- Co-authored-by: calcaide <ccorvo@hashicorp.com> Co-authored-by: cameronperera <cameron.perera@hashicorp.com>
This commit is contained in:
1 parent
fd1eba617b
commit
d469f305de
41 files changed
+354
-744
No files matched your search
@@ -1,11 +0,0 @@
|
||||
{{!
|
||||
Copyright IBM Corp. 2021, 2026
|
||||
SPDX-License-Identifier: BUSL-1.1
|
||||
}}
|
||||
|
||||
<div
|
||||
data-test-code-editor-field-editor
|
||||
...attributes
|
||||
class='rose-codemirror-container'
|
||||
{{code-mirror value=@value onInput=@onInput options=@options}}
|
||||
></div>
|
||||
@@ -1,13 +0,0 @@
|
||||
{{!
|
||||
Copyright IBM Corp. 2021, 2026
|
||||
SPDX-License-Identifier: BUSL-1.1
|
||||
}}
|
||||
|
||||
<div data-test-code-editor>
|
||||
{{yield
|
||||
(hash
|
||||
fieldEditor=(component 'rose/code-editor/field-editor' value=@codeValue)
|
||||
toolbar=(component 'rose/code-editor/toolbar' copyText=@codeValue)
|
||||
)
|
||||
}}
|
||||
</div>
|
||||
@@ -1,31 +0,0 @@
|
||||
{{!
|
||||
Copyright IBM Corp. 2021, 2026
|
||||
SPDX-License-Identifier: BUSL-1.1
|
||||
}}
|
||||
|
||||
<div class='rose-code-editor-toolbar' data-test-code-editor-toolbar>
|
||||
<div data-test-code-editor-toolbar-action class='code-editor-toolbar__action'>
|
||||
{{yield to='action'}}
|
||||
</div>
|
||||
|
||||
<div class='rose-code-editor-toolbar__right-aligned'>
|
||||
{{#if (has-block 'menu')}}
|
||||
<div
|
||||
data-test-code-editor-toolbar-menu
|
||||
class='rose-code-editor-toolbar__menu'
|
||||
>
|
||||
{{yield to='menu'}}
|
||||
</div>
|
||||
<div
|
||||
class='rose-code-editor-toolbar__menu-divider'
|
||||
data-test-code-editor-toolbar-menu-divider
|
||||
></div>
|
||||
{{/if}}
|
||||
<Hds::Copy::Button
|
||||
@text='Copy code'
|
||||
@textToCopy={{@copyText}}
|
||||
@onSuccess={{this.copied}}
|
||||
data-test-code-editor-toolbar-copy-button
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* Copyright IBM Corp. 2021, 2026
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
|
||||
export default class RoseCodeEditorToolbarComponent extends Component {
|
||||
@action
|
||||
copied() {
|
||||
this.args.onCopy?.();
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/**
|
||||
* Copyright IBM Corp. 2021, 2026
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import Modifier from 'ember-modifier';
|
||||
import codemirror from 'codemirror';
|
||||
|
||||
import '../utilities/register-codemirror-hcl';
|
||||
import 'codemirror/mode/go/go';
|
||||
import 'codemirror/mode/javascript/javascript';
|
||||
import 'codemirror/mode/shell/shell';
|
||||
import 'codemirror/addon/edit/matchbrackets';
|
||||
import 'codemirror/addon/edit/closebrackets';
|
||||
import 'codemirror/addon/selection/active-line';
|
||||
import 'codemirror/addon/display/autorefresh';
|
||||
import 'codemirror/addon/lint/lint';
|
||||
import 'codemirror/addon/lint/json-lint';
|
||||
|
||||
// Here we define default options for the editor.
|
||||
// These should follow the codemirror configuration types
|
||||
//
|
||||
const _PRESET_DEFAULTS = {
|
||||
theme: 'monokai',
|
||||
lineNumbers: true,
|
||||
cursorBlinkRate: 500,
|
||||
matchBrackets: true,
|
||||
autoCloseBrackets: true,
|
||||
styleActiveLine: true,
|
||||
mode: 'hcl',
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* `CodeMirror` implements a modifier that creates a CodeMirror instance on the provided element.
|
||||
*
|
||||
* The supported modes for the editor are currently: hcl, shell, go, javascript
|
||||
* The supported themes are: monokai
|
||||
*
|
||||
* Sample usage:
|
||||
* ```
|
||||
* <div
|
||||
* {{code-mirror value=@value onInput=@onInput options=@options}}
|
||||
* />
|
||||
* ```
|
||||
*
|
||||
* @class CodeMirror
|
||||
*
|
||||
*/
|
||||
export default class CodeMirrorModifier extends Modifier {
|
||||
_editor;
|
||||
didSetup = false;
|
||||
|
||||
modify(element, _, named) {
|
||||
if (!this.didSetup) {
|
||||
this._setup(element, named);
|
||||
this.didSetup = true;
|
||||
}
|
||||
|
||||
if (this._editor?.getValue() !== named.value) {
|
||||
this._editor?.setValue(named.value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when editor contents change.
|
||||
* @method CodeMirror#_onChange
|
||||
* See documentation for the CodeMirror editor events, specifically 'change' event here https://codemirror.net/doc/manual.html#events.
|
||||
*/
|
||||
_onChange(editor, named) {
|
||||
const { onInput } = named;
|
||||
const newVal = editor.getValue();
|
||||
|
||||
onInput && onInput(newVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the editor with default configuration merged with consumer-provided configuration.
|
||||
* Also registers a 'change' event on the editor.
|
||||
* @method CodeMirror#_setup
|
||||
*/
|
||||
_setup(element, named) {
|
||||
if (!element) {
|
||||
throw new Error('CodeMirror modifier has no element');
|
||||
}
|
||||
|
||||
const editor = codemirror(element, {
|
||||
..._PRESET_DEFAULTS,
|
||||
...(named.options || {}),
|
||||
value: named.value,
|
||||
});
|
||||
|
||||
editor.on('change', (editor) => {
|
||||
this._onChange(editor, named);
|
||||
});
|
||||
|
||||
this._editor = editor;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* Copyright IBM Corp. 2021, 2026
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import codemirror from 'codemirror';
|
||||
import 'codemirror/addon/mode/simple';
|
||||
|
||||
// This utility defines 'hcl' mode for a codemirror editor and enables correct syntax highlighting.
|
||||
// Importing this file in the codemirror modifier will allow 'hcl' to be selected as a mode:
|
||||
// import 'cloud-ui-core/utils/register-codemirror-hcl'
|
||||
codemirror.defineSimpleMode('hcl', {
|
||||
start: [
|
||||
{ regex: /"(?:[^\\]|\\.)*?(?:"|$)/, token: 'string' }, // strings
|
||||
{ regex: /(\w+)(\s+)(=)/, token: ['keyword', 'null', 'null'] }, // assignment of variables
|
||||
{
|
||||
regex: /(build|deploy|release|hook|registry|type|runner|url)( )({)/,
|
||||
token: ['keyword', 'null', 'null'],
|
||||
}, // top level keywords
|
||||
{ regex: /(variable)\b/, token: 'keyword' }, // input variable keyword
|
||||
{ regex: /true|false|null|undefined/, token: 'atom' }, // bool keywords
|
||||
{
|
||||
regex: /0x[a-f\d]+|[-+]?(?:\.\d+|\d+\.?\d*)(?:e[-+]?\d+)?/i,
|
||||
token: 'number',
|
||||
}, // numbers
|
||||
{ regex: /(#|\/\/)(\s*\S*)/, token: 'comment' }, // single line comments
|
||||
{ regex: /(path)(.)/, token: ['variable-2', 'null'] }, // path variables
|
||||
{ regex: /(workspace)(.)(\S*)/, token: ['string', 'null', 'string'] }, // workspace variables
|
||||
{ regex: /\/\*/, token: 'comment', next: 'comment' }, // multi-line comment
|
||||
{ regex: /[-+/*=<>!]+/, token: 'operator' }, // operators
|
||||
{ regex: /[{[(]/, indent: true }, // for auto indent
|
||||
{ regex: /[}\])]/, dedent: true },
|
||||
],
|
||||
// The multi-line comment state.
|
||||
comment: [
|
||||
{ regex: /.*?\*\//, token: 'comment', next: 'start' },
|
||||
{ regex: /.*/, token: 'comment' },
|
||||
],
|
||||
meta: {
|
||||
dontIndentStates: ['comment'],
|
||||
lineComment: '#',
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user