Skip to content

Commit

Permalink
Fix publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
murdercode committed Apr 28, 2022
0 parents commit 98d14dd
Show file tree
Hide file tree
Showing 17 changed files with 311 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.idea
/vendor
/node_modules
package-lock.json
composer.phar
composer.lock
phpunit.xml
.phpunit.result.cache
.DS_Store
Thumbs.db
29 changes: 29 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 22 additions & 0 deletions config/nova-tinymce-editor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

return [
'init' => [
'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', ''),
];
1 change: 1 addition & 0 deletions dist/css/field.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions dist/js/field.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions dist/js/field.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!
* vuex v4.0.2
* (c) 2021 Evan You
* @license MIT
*/
4 changes: 4 additions & 0 deletions dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"/js/field.js": "/js/field.js",
"/css/field.css": "/css/field.css"
}
40 changes: 40 additions & 0 deletions nova.mix.js
Original file line number Diff line number Diff line change
@@ -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())
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"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",
"nova:install": "npm --prefix='../../vendor/laravel/nova' ci"
},
"devDependencies": {
"@vue/compiler-sfc": "^3.2.33",
"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",
"vuex": "^4.0.2"
}
}
1 change: 1 addition & 0 deletions resources/css/field.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Nova Field CSS */
19 changes: 19 additions & 0 deletions resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<PanelItem :index="index" :field="field">
<template #value>
<excerpt :content="field.value" :should-show="field.shouldShow" />
</template>
</PanelItem>
</template>

<script>
export default {
props: ['index', 'resource', 'resourceName', 'resourceId', 'field'],
data() {
return {
content: 'Hidden content',
}
}
}
</script>
46 changes: 46 additions & 0 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<template>
<DefaultField :field="field" :errors="errors" :show-help-text="showHelpText">
<template #field>
<editor
:id="field.attribute"
v-model="value"
:api-key="field.options.apiKey"
:init="field.options.init"
:plugins="field.options.plugins"
:toolbar="field.options.toolbar"
:placeholder="field.name"
/>
</template>
</DefaultField>
</template>

<script>
import { FormField, HandlesValidationErrors } from "laravel-nova";
import Editor from "@tinymce/tinymce-vue";
export default {
mixins: [FormField, HandlesValidationErrors],
props: ["resourceName", "resourceId", "field", "options"],
components: {
editor: Editor,
},
methods: {
/*
* Set the initial, internal value for the field.
*/
setInitialValue() {
this.value = this.field.value || "";
},
/**
* Fill the given FormData object with the field's internal value.
*/
fill(formData) {
formData.append(this.field.attribute, this.value || "");
},
},
};
</script>
9 changes: 9 additions & 0 deletions resources/js/components/IndexField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<span>{{ field.value }}</span>
</template>

<script>
export default {
props: ['resourceName', 'field'],
}
</script>
9 changes: 9 additions & 0 deletions resources/js/field.js
Original file line number Diff line number Diff line change
@@ -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)
})
37 changes: 37 additions & 0 deletions src/FieldServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Murdercode\TinymceEditor;

use Illuminate\Support\ServiceProvider;
use Laravel\Nova\Events\ServingNova;
use Laravel\Nova\Nova;

class FieldServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Nova::serving(function (ServingNova $event) {
Nova::script('tinymce-editor', __DIR__ . '/../dist/js/field.js');
Nova::style('tinymce-editor', __DIR__ . '/../dist/css/field.css');
});

$this->publishes([
__DIR__ . '/../config/nova-tinymce-editor.php' => config_path('nova-tinymce-editor.php'),
], 'config');
}

/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
41 changes: 41 additions & 0 deletions src/TinymceEditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Murdercode\TinymceEditor;

use Laravel\Nova\Fields\Field;

class TinymceEditor extends Field
{
/**
* The field's component.
*
* @var string
*/
public $component = 'tinymce-editor';

/**
* Indicates if the element should be shown on the index view.
*
* @var bool
*/
public $showOnIndex = false;

public function __construct(string $name, $attribute = null, callable $resolveCallback = null)
{
parent::__construct($name, $attribute);
$this->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),
]);
}
}
11 changes: 11 additions & 0 deletions webpack.mix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let mix = require('laravel-mix')
let path = require('path')

require('./nova.mix')

mix
.setPublicPath('dist')
.js('resources/js/field.js', 'js')
.vue({ version: 3 })
.css('resources/css/field.css', 'css')
.nova('murdercode/nova4-tinymce-editor')

0 comments on commit 98d14dd

Please sign in to comment.