-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d2b0127
Showing
16 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "codelabs/seo-title", | ||
"description": "A Laravel Nova field.", | ||
"keywords": [ | ||
"laravel", | ||
"nova" | ||
], | ||
"license": "MIT", | ||
"require": { | ||
"php": "^7.3|^8.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Codelabs\\SeoTitle\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Codelabs\\SeoTitle\\FieldServiceProvider" | ||
] | ||
} | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/*! | ||
* vuex v4.0.2 | ||
* (c) 2021 Evan You | ||
* @license MIT | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": { | ||
"vuex": "^4.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* Nova Field CSS */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<template> | ||
<PanelItem :index="index" :field="field" /> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: ['index', 'resource', 'resourceName', 'resourceId', 'field'], | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<template> | ||
<DefaultField :field="field" :errors="errors" :show-help-text="showHelpText"> | ||
<template #field> | ||
<input | ||
:id="field.attribute" | ||
@input="handleChange" | ||
type="text" | ||
class="w-full form-control form-input form-input-bordered" | ||
:class="errorClasses" | ||
:placeholder="field.name" | ||
v-model="value" | ||
/> | ||
<p | ||
class="mt-2 help-text" | ||
:class="isInRange ? 'text-green-600' : 'text-red-500'" | ||
>{{ isInRange ? 'This title is good for SEO. Great work!' : `You're out of ${overChars} characters. Please make a better title!` }}</p> | ||
</template> | ||
</DefaultField> | ||
</template> | ||
|
||
<script> | ||
import { FormField, HandlesValidationErrors } from 'laravel-nova' | ||
export default { | ||
mixins: [FormField, HandlesValidationErrors], | ||
props: ['resourceName', 'resourceId', 'field', 'min', 'max'], | ||
computed: { | ||
isInRange() { | ||
return this.value.length >= this.field.min && this.value.length <= this.field.max | ||
}, | ||
overChars() { | ||
if (this.value.length > this.field.max) { | ||
return this.value.length - this.field.max | ||
} else if (this.value.length < this.field.min) { | ||
return this.field.min - this.value.length; | ||
} | ||
} | ||
}, | ||
mounted() { | ||
//console.log(typeof (this.field.max)) | ||
}, | ||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<template> | ||
<span> | ||
<div | ||
class="inline-block w-2 h-2 rounded-full opacity-75" | ||
:class="isInRange ? 'bg-green-500' : 'bg-red-500'" | ||
:title="isInRange ? 'This title is good for SEO. Great work!' : `You're out of ${overChars} characters. Please make a better title!`" | ||
></div> | ||
{{ field.value }} | ||
</span> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: ['resourceName', 'field', 'min', 'max'], | ||
computed: { | ||
isInRange() { | ||
return this.field.value.length >= this.field.min && this.field.value.length <= this.field.max | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-seo-title', IndexField) | ||
app.component('detail-seo-title', DetailField) | ||
app.component('form-seo-title', FormField) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Codelabs\SeoTitle; | ||
|
||
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('seo-title', __DIR__.'/../dist/js/field.js'); | ||
Nova::style('seo-title', __DIR__.'/../dist/css/field.css'); | ||
}); | ||
} | ||
|
||
/** | ||
* Register any application services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Codelabs\SeoTitle; | ||
|
||
use Laravel\Nova\Fields\Field; | ||
|
||
class SeoTitle extends Field | ||
{ | ||
/** | ||
* The field's component. | ||
* | ||
* @var string | ||
*/ | ||
public $component = 'seo-title'; | ||
|
||
/** | ||
* Set the range of acceptable string length. | ||
* | ||
* @param int $min | ||
* @param int $max | ||
* @return $this | ||
*/ | ||
public function rangeLength(int $min = 30, int $max = 60) : self | ||
{ | ||
return $this->withMeta([ | ||
'min' => $min, | ||
'max' => $max, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('codelabs/seo-title') |