diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d918156 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +/dist +/.idea +/vendor +/node_modules +package-lock.json +composer.phar +composer.lock +phpunit.xml +.phpunit.result.cache +.DS_Store +Thumbs.db diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5f988aa --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Alfonso Bribiesca + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fef4dd8 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# Nova Trumbowyg editor field +Laravel Nova Trumbowyg Editor field. + +## Installation + +Just install the package in to a Laravel app that uses Nova via composer: + +``` +composer require alfonsobries/nova-trumbowyg +``` + + +## Simple Usage: +```php +NovaTrumbowyg::make('Field Name') +``` + +## Advanced Usage: +You can pass any existing Trumbowyg option. Consult the [Trumbowyg documentation](https://alex-d.github.io/Trumbowyg/documentation/#basic-options) to view the list of all the available options. + +```php +NovaFroalaEditor::make('Description') + ->options(['btns' => [['bold', 'italic'], ['link']]]) +``` + +## Screenshot +![Froala editor](./docs/sh1.png) + +## License +The MIT License (MIT). Please see [License File](LICENSE) for more information. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..3244d18 --- /dev/null +++ b/composer.json @@ -0,0 +1,30 @@ +{ + "name": "alfonsobries/nova-trumbowyg", + "description": "A Laravel Trumbowyg Nova field.", + "keywords": [ + "laravel", + "nova", + "trumbowyg" + ], + "license": "MIT", + "require": { + "php": ">=7.1.0" + }, + "autoload": { + "psr-4": { + "Alfonsobries\\NovaTrumbowyg\\": "src/" + } + }, + "extra": { + "laravel": { + "providers": [ + "Alfonsobries\\NovaTrumbowyg\\FieldServiceProvider" + ] + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/docs/sh1.png b/docs/sh1.png new file mode 100644 index 0000000..2d7dd4d Binary files /dev/null and b/docs/sh1.png differ diff --git a/fonts/vendor/trumbowyg/dist/ui/icons.svg b/fonts/vendor/trumbowyg/dist/ui/icons.svg new file mode 100644 index 0000000..269c8df --- /dev/null +++ b/fonts/vendor/trumbowyg/dist/ui/icons.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mix-manifest.json b/mix-manifest.json new file mode 100644 index 0000000..b64e53f --- /dev/null +++ b/mix-manifest.json @@ -0,0 +1,5 @@ +{ + "/dist/js/field.js": "/dist/js/field.js", + "/dist/css/field.css": "/dist/css/field.css", + "/dist/img/icons.svg": "/dist/img/icons.svg" +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..14e417e --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "private": true, + "scripts": { + "dev": "npm run development", + "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", + "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", + "watch-poll": "npm run watch -- --watch-poll", + "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", + "prod": "npm run production", + "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" + }, + "devDependencies": { + "cross-env": "^5.0.0", + "laravel-mix": "^1.0", + "laravel-nova": "^1.0" + }, + "dependencies": { + "vue": "^2.5.0", + "vue-trumbowyg": "^3.4.0" + } +} diff --git a/resources/js/components/DetailField.vue b/resources/js/components/DetailField.vue new file mode 100644 index 0000000..51baf10 --- /dev/null +++ b/resources/js/components/DetailField.vue @@ -0,0 +1,19 @@ + + + diff --git a/resources/js/components/Excerpt.vue b/resources/js/components/Excerpt.vue new file mode 100755 index 0000000..cf10556 --- /dev/null +++ b/resources/js/components/Excerpt.vue @@ -0,0 +1,33 @@ + + + diff --git a/resources/js/components/FormField.vue b/resources/js/components/FormField.vue new file mode 100644 index 0000000..9bb36a7 --- /dev/null +++ b/resources/js/components/FormField.vue @@ -0,0 +1,71 @@ + + + diff --git a/resources/js/components/IndexField.vue b/resources/js/components/IndexField.vue new file mode 100644 index 0000000..fe750d1 --- /dev/null +++ b/resources/js/components/IndexField.vue @@ -0,0 +1,23 @@ + + + diff --git a/resources/js/field.js b/resources/js/field.js new file mode 100644 index 0000000..4332733 --- /dev/null +++ b/resources/js/field.js @@ -0,0 +1,5 @@ +Nova.booting((Vue, router) => { + Vue.component('index-nova-trumbowyg', require('./components/IndexField')); + Vue.component('detail-nova-trumbowyg', require('./components/DetailField')); + Vue.component('form-nova-trumbowyg', require('./components/FormField')); +}) diff --git a/resources/sass/field.scss b/resources/sass/field.scss new file mode 100644 index 0000000..f85ad40 --- /dev/null +++ b/resources/sass/field.scss @@ -0,0 +1 @@ +// Nova Tool CSS diff --git a/src/FieldServiceProvider.php b/src/FieldServiceProvider.php new file mode 100644 index 0000000..11d313e --- /dev/null +++ b/src/FieldServiceProvider.php @@ -0,0 +1,34 @@ +withMeta([ + 'options' => [ + 'btns' => [ + ['bold', 'italic'], + ['unorderedList', 'orderedList'], + ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'], + ['link', 'insertImage'], + ], + ] + ]); + } + + /** + * Allow to pass any existing Trumbowyg option to the editor. + * Consult the Trumbowyg documentation [https://alex-d.github.io/Trumbowyg/documentation/#basic-options] + * to view the list of all the available options. + * + * @param array $options + * @return self + */ + public function options(array $options) + { + $currentOptions = $this->meta['options']; + + return $this->withMeta([ + 'options' => array_merge($currentOptions, $options) + ]); + } +} diff --git a/webpack.mix.js b/webpack.mix.js new file mode 100644 index 0000000..b3b055c --- /dev/null +++ b/webpack.mix.js @@ -0,0 +1,18 @@ +let webpack = require('webpack') +let mix = require('laravel-mix') + +mix.js('resources/js/field.js', 'dist/js') + .sass('resources/sass/field.scss', 'dist/css') + .copy('node_modules/trumbowyg/dist/ui/icons.svg', 'dist/img') + .webpackConfig({ + resolve: { + symlinks: false + }, + plugins: [ + // Jquery loader plugin. + new webpack.ProvidePlugin({ + $: "jquery", + jQuery: "jquery" + }) + ] + })