From 4657c3df82bc6ac7919ce7460d0a8ac37f04dd72 Mon Sep 17 00:00:00 2001 From: z-song Date: Wed, 12 Sep 2018 01:20:09 +0800 Subject: [PATCH] update --- README.md | 7 +++++++ src/Editor.php | 33 ++++++++++++++++++--------------- src/JsEditorServiceProvider.php | 4 ++++ src/Json.php | 14 ++++++++++++++ src/Jsond.php | 14 ++++++++++++++ src/Typescript.php | 14 ++++++++++++++ 6 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 src/Json.php create mode 100644 src/Jsond.php create mode 100644 src/Typescript.php diff --git a/README.md b/README.md index 6ce6c7d..cbd588a 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,14 @@ php artisan vendor:publish --tag=laravel-admin-code-mirror ```php $form->js('code'); +// alias of `js` method $form->javascript('code'); + +$form->json('code'); + +$form->jsond('code'); + +$form->typescript('code'); ``` 设置高度 diff --git a/src/Editor.php b/src/Editor.php index 507014b..3a2d1d6 100644 --- a/src/Editor.php +++ b/src/Editor.php @@ -3,9 +3,20 @@ namespace Encore\JsEditor; use Encore\Admin\Form\Field; +use Jxlwqq\CodeMirror\CodeMirror; class Editor extends Field { + protected $options = [ + 'mode' => 'javascript', + 'lineNumbers' => true, + 'matchBrackets' => true, + 'continueComments' => true, + 'extraKeys' => [ + 'Ctrl-Q' => 'toggleComment', + ], + ]; + /** * {@inheritdoc} */ @@ -15,18 +26,18 @@ class Editor extends Field * {@inheritdoc} */ protected static $css = [ - 'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/lib/codemirror.css', + CodeMirror::ASSETS_PATH.'lib/codemirror.css', ]; /** * {@inheritdoc} */ protected static $js = [ - 'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/lib/codemirror.js', - 'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/addon/edit/matchbrackets.js', - 'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/addon/comment/continuecomment.js', - 'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/addon/comment/comment.js', - 'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/mode/javascript/javascript.js', + CodeMirror::ASSETS_PATH.'lib/codemirror.js', + CodeMirror::ASSETS_PATH.'addon/edit/matchbrackets.js', + CodeMirror::ASSETS_PATH.'addon/comment/continuecomment.js', + CodeMirror::ASSETS_PATH.'addon/comment/comment.js', + CodeMirror::ASSETS_PATH.'mode/javascript/javascript.js', ]; /** @@ -46,15 +57,7 @@ public function height($height = 10) public function render() { $options = array_merge( - [ - 'mode' => 'javascript', - 'lineNumbers' => true, - 'matchBrackets' => true, - 'continueComments' => true, - 'extraKeys' => [ - 'Ctrl-Q' => 'toggleComment', - ], - ], + $this->options, JsEditor::config('config', []) ); diff --git a/src/JsEditorServiceProvider.php b/src/JsEditorServiceProvider.php index 867b68b..94f692d 100644 --- a/src/JsEditorServiceProvider.php +++ b/src/JsEditorServiceProvider.php @@ -20,6 +20,10 @@ public function boot(JsEditor $extension) Admin::booting(function () { Form::extend('js', Editor::class); Form::alias('js', 'javascript'); + + Form::extend('json', Json::class); + Form::extend('jsond', Jsond::class); + Form::extend('typescript', Typescript::class); }); } } \ No newline at end of file diff --git a/src/Json.php b/src/Json.php new file mode 100644 index 0000000..a5f4ece --- /dev/null +++ b/src/Json.php @@ -0,0 +1,14 @@ + true, + 'autoCloseBrackets' => true, + 'lineNumbers' => true, + 'mode' => 'application/json', + 'lineWrapping' => true, + ]; +} \ No newline at end of file diff --git a/src/Jsond.php b/src/Jsond.php new file mode 100644 index 0000000..bf4cf7e --- /dev/null +++ b/src/Jsond.php @@ -0,0 +1,14 @@ + true, + 'autoCloseBrackets' => true, + 'lineNumbers' => true, + 'mode' => 'application/ld+json', + 'lineWrapping' => true, + ]; +} \ No newline at end of file diff --git a/src/Typescript.php b/src/Typescript.php new file mode 100644 index 0000000..4bfac71 --- /dev/null +++ b/src/Typescript.php @@ -0,0 +1,14 @@ + true, + 'autoCloseBrackets' => true, + 'lineNumbers' => true, + 'mode' => 'text/typescript', + 'lineWrapping' => true, + ]; +} \ No newline at end of file