From 124a9c708da91c457a358bdbfd44cb86f5c0d263 Mon Sep 17 00:00:00 2001 From: Stefano Novelli Date: Wed, 20 Apr 2022 18:33:24 +0200 Subject: [PATCH 1/4] Initial commit --- .gitignore | 10 ++++++ composer.json | 29 +++++++++++++++++ config/nova-tinymce-editor.php | 22 +++++++++++++ dist/mix-manifest.json | 1 + mix.js | 40 +++++++++++++++++++++++ package.json | 23 +++++++++++++ resources/css/field.css | 1 + resources/js/components/DetailField.vue | 19 +++++++++++ resources/js/components/FormField.vue | 43 +++++++++++++++++++++++++ resources/js/components/IndexField.vue | 9 ++++++ resources/js/field.js | 9 ++++++ src/FieldServiceProvider.php | 37 +++++++++++++++++++++ src/TinymceEditor.php | 41 +++++++++++++++++++++++ webpack.mix.js | 11 +++++++ 14 files changed, 295 insertions(+) create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 config/nova-tinymce-editor.php create mode 100644 dist/mix-manifest.json create mode 100644 mix.js create mode 100644 package.json create mode 100644 resources/css/field.css create mode 100644 resources/js/components/DetailField.vue create mode 100644 resources/js/components/FormField.vue create mode 100644 resources/js/components/IndexField.vue create mode 100644 resources/js/field.js create mode 100644 src/FieldServiceProvider.php create mode 100644 src/TinymceEditor.php create mode 100644 webpack.mix.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b817577 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +/.idea +/vendor +/node_modules +package-lock.json +composer.phar +composer.lock +phpunit.xml +.phpunit.result.cache +.DS_Store +Thumbs.db diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..6879569 --- /dev/null +++ b/composer.json @@ -0,0 +1,29 @@ +{ + "name": "murdercode/nova4-tinymce-editor", + "description": "A Laravel Nova field.", + "keywords": [ + "laravel", + "nova" + ], + "license": "MIT", + "require": { + "php": "^7.3|^8.0" + }, + "autoload": { + "psr-4": { + "Murdercode\\TinymceEditor\\": "src/" + } + }, + "extra": { + "laravel": { + "providers": [ + "Murdercode\\TinymceEditor\\FieldServiceProvider" + ] + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/config/nova-tinymce-editor.php b/config/nova-tinymce-editor.php new file mode 100644 index 0000000..61f45d7 --- /dev/null +++ b/config/nova-tinymce-editor.php @@ -0,0 +1,22 @@ + [ + 'menubar' => false, + 'autoresize_bottom_margin' => 40, + 'branding' => false, + 'image_caption' => true, + 'paste_as_text' => true, + 'paste_word_valid_elements' => 'b,strong,i,em,h1,h2', + ], + 'plugins' => [ + 'advlist autolink lists link image imagetools media', + 'paste code wordcount autoresize table', + ], + 'toolbar' => [ + 'undo redo | formatselect forecolor backcolor | + bold italic underline strikethrough blockquote removeformat | + align bullist numlist outdent indent | link table media insertmedialibrary | code', + ], + 'apiKey' => env('TINYMCE_API_KEY', ''), +]; \ No newline at end of file diff --git a/dist/mix-manifest.json b/dist/mix-manifest.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/dist/mix-manifest.json @@ -0,0 +1 @@ +{} diff --git a/mix.js b/mix.js new file mode 100644 index 0000000..c43ca88 --- /dev/null +++ b/mix.js @@ -0,0 +1,40 @@ +const mix = require('laravel-mix') +const webpack = require('webpack') +const path = require('path') + +class NovaExtension { + name() { + return 'nova-extension' + } + + register(name) { + this.name = name + } + + webpackPlugins() { + return new webpack.ProvidePlugin({ + _: 'lodash', + Errors: 'form-backend-validation', + }) + } + + webpackConfig(webpackConfig) { + webpackConfig.externals = { + vue: 'Vue', + } + + webpackConfig.resolve.alias = { + ...(webpackConfig.resolve.alias || {}), + 'laravel-nova': path.join( + __dirname, + '../../vendor/laravel/nova/resources/js/mixins/packages.js' + ), + } + + webpackConfig.output = { + uniqueName: this.name, + } + } +} + +mix.extend('nova', new NovaExtension()) diff --git a/package.json b/package.json new file mode 100644 index 0000000..0ee5aa7 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "private": true, + "scripts": { + "dev": "npm run development", + "development": "mix", + "watch": "mix watch", + "watch-poll": "mix watch -- --watch-options-poll=1000", + "hot": "mix watch --hot", + "prod": "npm run production", + "production": "mix --production" + }, + "devDependencies": { + "@vue/compiler-sfc": "^3.2.22", + "form-backend-validation": "^2.3.3", + "laravel-mix": "^6.0.41", + "lodash": "^4.17.21", + "postcss": "^8.3.11", + "vue-loader": "^16.8.3" + }, + "dependencies": { + "@tinymce/tinymce-vue": "^4.0.7" + } +} diff --git a/resources/css/field.css b/resources/css/field.css new file mode 100644 index 0000000..2a9d2e2 --- /dev/null +++ b/resources/css/field.css @@ -0,0 +1 @@ +/* Nova Field CSS */ diff --git a/resources/js/components/DetailField.vue b/resources/js/components/DetailField.vue new file mode 100644 index 0000000..29bcc26 --- /dev/null +++ b/resources/js/components/DetailField.vue @@ -0,0 +1,19 @@ + + + diff --git a/resources/js/components/FormField.vue b/resources/js/components/FormField.vue new file mode 100644 index 0000000..bca64f9 --- /dev/null +++ b/resources/js/components/FormField.vue @@ -0,0 +1,43 @@ + + + diff --git a/resources/js/components/IndexField.vue b/resources/js/components/IndexField.vue new file mode 100644 index 0000000..5a07928 --- /dev/null +++ b/resources/js/components/IndexField.vue @@ -0,0 +1,9 @@ + + + diff --git a/resources/js/field.js b/resources/js/field.js new file mode 100644 index 0000000..a6d8f6b --- /dev/null +++ b/resources/js/field.js @@ -0,0 +1,9 @@ +import IndexField from './components/IndexField' +import DetailField from './components/DetailField' +import FormField from './components/FormField' + +Nova.booting((app, store) => { + app.component('index-tinymce-editor', IndexField) + app.component('detail-tinymce-editor', DetailField) + app.component('form-tinymce-editor', FormField) +}) diff --git a/src/FieldServiceProvider.php b/src/FieldServiceProvider.php new file mode 100644 index 0000000..1962498 --- /dev/null +++ b/src/FieldServiceProvider.php @@ -0,0 +1,37 @@ +publishes([ + __DIR__ . '/../config/nova-tinymce-editor.php' => config_path('nova-tinymce-editor.php'), + ], 'config'); + } + + /** + * Register any application services. + * + * @return void + */ + public function register() + { + // + } +} diff --git a/src/TinymceEditor.php b/src/TinymceEditor.php new file mode 100644 index 0000000..80cddc4 --- /dev/null +++ b/src/TinymceEditor.php @@ -0,0 +1,41 @@ +resolveCallback = $resolveCallback; + + $this->withMeta([ + 'options' => config('nova-tinymce-editor', []), + ]); + } + + public function options($options) + { + $inlineOptions = $this->meta['options'] ?? []; + + return $this->withMeta([ + 'options' => array_merge($inlineOptions, $options), + ]); + } +} diff --git a/webpack.mix.js b/webpack.mix.js new file mode 100644 index 0000000..26597f4 --- /dev/null +++ b/webpack.mix.js @@ -0,0 +1,11 @@ +let mix = require('laravel-mix') +let path = require('path') + +require('./mix') + +mix + .setPublicPath('dist') + .js('resources/js/field.js', 'js') + .vue({ version: 3 }) + .css('resources/css/field.css', 'css') + .nova('murdercode/tinymce-editor') From b28e8768ba0f3eb07f2288a0ad924d5252e84a27 Mon Sep 17 00:00:00 2001 From: Stefano Novelli Date: Wed, 20 Apr 2022 19:03:18 +0200 Subject: [PATCH 2/4] Remove laravel-nova needs --- resources/js/components/FormField.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/js/components/FormField.vue b/resources/js/components/FormField.vue index bca64f9..0bc5a8c 100644 --- a/resources/js/components/FormField.vue +++ b/resources/js/components/FormField.vue @@ -11,11 +11,11 @@