Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
z-song committed Sep 11, 2018
1 parent bf7354f commit 4657c3d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 15 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```

设置高度
Expand Down
33 changes: 18 additions & 15 deletions src/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand All @@ -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',
];

/**
Expand All @@ -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', [])
);

Expand Down
4 changes: 4 additions & 0 deletions src/JsEditorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
14 changes: 14 additions & 0 deletions src/Json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Encore\JsEditor;

class Json extends Editor
{
protected $options = [
'matchBrackets' => true,
'autoCloseBrackets' => true,
'lineNumbers' => true,
'mode' => 'application/json',
'lineWrapping' => true,
];
}
14 changes: 14 additions & 0 deletions src/Jsond.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Encore\JsEditor;

class Jsond extends Editor
{
protected $options = [
'matchBrackets' => true,
'autoCloseBrackets' => true,
'lineNumbers' => true,
'mode' => 'application/ld+json',
'lineWrapping' => true,
];
}
14 changes: 14 additions & 0 deletions src/Typescript.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Encore\JsEditor;

class Typescript extends Editor
{
protected $options = [
'matchBrackets' => true,
'autoCloseBrackets' => true,
'lineNumbers' => true,
'mode' => 'text/typescript',
'lineWrapping' => true,
];
}

0 comments on commit 4657c3d

Please sign in to comment.