-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
151b83c
commit caa3a36
Showing
21 changed files
with
293 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@import '~codemirror/lib/codemirror.css'; | ||
|
||
.CodeMirror { | ||
font: 13px/1.5 SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Ubuntu Mono", "Courier New", monospace; | ||
height: auto; | ||
min-height: 45px; | ||
} | ||
|
||
.CodeMirror-wrap { | ||
box-shadow: 0 0 0 1px rgba(43, 45, 80, .16), 0 0 0 1px rgba(6, 122, 184, 0), 0 0 0 2px rgba(6, 122, 184, 0), 0 1px 1px rgba(0, 0, 0, .08);; | ||
border-radius: var(--border-radius); | ||
} | ||
|
||
.CodeMirror-gutters { | ||
background: var(--gray-100); | ||
} | ||
|
||
.CodeMirror-linenumber { | ||
color: var(--text-muted); | ||
} | ||
|
||
.CodeMirror-lines { | ||
padding-bottom: 5px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require('../css/form-type-code-editor.css'); | ||
|
||
import CodeMirror from 'codemirror'; | ||
|
||
import 'codemirror/mode/css/css'; | ||
import 'codemirror/mode/dockerfile/dockerfile'; | ||
import 'codemirror/mode/javascript/javascript'; | ||
import 'codemirror/mode/markdown/markdown'; | ||
import 'codemirror/mode/nginx/nginx'; | ||
import 'codemirror/mode/php/php'; | ||
import 'codemirror/mode/shell/shell'; | ||
import 'codemirror/mode/sql/sql'; | ||
import 'codemirror/mode/twig/twig'; | ||
import 'codemirror/mode/xml/xml'; | ||
import 'codemirror/mode/yaml-frontmatter/yaml-frontmatter'; | ||
import 'codemirror/mode/yaml/yaml'; | ||
|
||
document.querySelectorAll('[data-easyadmin-code-editor]').forEach(function(codeBlock) { | ||
CodeMirror.fromTextArea(codeBlock, { | ||
autocapitalize: false, | ||
autocorrect: false, | ||
indentWithTabs: codeBlock.dataset.indentWithTabs, | ||
lineNumbers: true, | ||
lineWrapping: true, | ||
mode: codeBlock.dataset.language, | ||
scrollbarStyle: 'native', | ||
spellcheck: false, | ||
tabSize: codeBlock.dataset.tabSize, | ||
theme: 'default', | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Form\Type; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\FormView; | ||
use Symfony\Component\OptionsResolver\Options; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Yonel Ceruto <yonelceruto@gmail.com> | ||
*/ | ||
class CodeEditorType extends AbstractType | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildView(FormView $view, FormInterface $form, array $options): void | ||
{ | ||
$view->vars['height'] = $options['height']; | ||
$view->vars['tabSize'] = $options['tab_size']; | ||
$view->vars['indentWithTabs'] = $options['indent_with_tabs']; | ||
$view->vars['language'] = $options['language']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefaults([ | ||
'height' => null, | ||
'tab_size' => 4, | ||
'indent_with_tabs' => false, | ||
// the code editor can't autodetect the language, so 'markdown' is used when | ||
// no language is selected explicitly (because it's the most similar to regular text) | ||
'language' => 'markdown', | ||
]); | ||
$resolver->setAllowedTypes('height', ['null', 'int']); | ||
$resolver->setAllowedTypes('tab_size', 'int'); | ||
$resolver->setAllowedTypes('indent_with_tabs', 'bool'); | ||
$resolver->setAllowedTypes('language', 'string'); | ||
$resolver->setAllowedValues('language', ['css', 'dockerfile', 'js', 'javascript', 'markdown', 'nginx', 'php', 'shell', 'sql', 'twig', 'xml', 'yaml-frontmatter', 'yaml']); | ||
|
||
// define some programming language shortcuts for better UX (e.g. 'js' === 'javascript') | ||
$resolver->setNormalizer('language', static function (Options $options, $language) { | ||
if ('js' === $language) { | ||
$language = 'javascript'; | ||
} | ||
|
||
return $language; | ||
}); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getParent(): string | ||
{ | ||
return TextareaType::class; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getBlockPrefix(): string | ||
{ | ||
return 'easyadmin_code_editor'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Form\Type\Configurator; | ||
|
||
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\CodeEditorType; | ||
use Symfony\Component\Form\FormConfigInterface; | ||
|
||
/** | ||
* This configurator is applied to any form field of type 'code_editor'. | ||
* | ||
* @author Javier Eguiluz <javier.eguiluz@gmail.com> | ||
*/ | ||
class CodeEditorTypeConfigurator implements TypeConfiguratorInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configure($name, array $options, array $metadata, FormConfigInterface $parentConfig): array | ||
{ | ||
if (isset($metadata['height'])) { | ||
$options['height'] = $metadata['height']; | ||
} | ||
if (isset($metadata['tab_size'])) { | ||
$options['tab_size'] = $metadata['tab_size']; | ||
} | ||
if (isset($metadata['indent_with_tabs'])) { | ||
$options['indent_with_tabs'] = $metadata['indent_with_tabs']; | ||
} | ||
if (isset($metadata['language'])) { | ||
$options['language'] = $metadata['language']; | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($type, array $options, array $metadata): bool | ||
{ | ||
return \in_array($type, ['code_editor', CodeEditorType::class], true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.