在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):VanOns/laraberg开源软件地址(OpenSource Url):https://github.com/VanOns/laraberg开源编程语言(OpenSource Language):PHP 90.6%开源软件介绍(OpenSource Introduction):Laraberg aims to provide an easy way to integrate the Gutenberg editor with your Laravel projects. It takes the Gutenberg editor and adds all the communication and data it needs function in a Laravel environment. Table of ContentsInstallationInstall package using composer: composer require van-ons/laraberg Add vendor files to your project (CSS, JS & Config): php artisan vendor:publish --provider="VanOns\Laraberg\LarabergServiceProvider" JavaScript and CSS filesThe package provides a JS and CSS file that should be present on the page you want to use the editor on: <link rel="stylesheet" href="{{asset('vendor/laraberg/css/laraberg.css')}}">
<script src="{{ asset('vendor/laraberg/js/laraberg.js') }}"></script> DependenciesThe Gutenberg editor expects React, ReactDOM, Moment and JQuery to be in the environment it runs in. An easy way to do this would be to add the following lines to your page: <script src="https://unpkg.com/[email protected]/umd/react.production.min.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js"></script> UpdatingWhen updating Laraberg you have to publish the vendor files again by running this command: php artisan vendor:publish --provider="VanOns\Laraberg\LarabergServiceProvider" --tag="public" --force UsageInitializing the EditorThe Gutenberg editor should replace an existing textarea in a form. On submit the raw content from the editor will be put in the 'value' attribute of this textarea. <textarea id="[id_here]" name="[name_here]" hidden></textarea> In order to edit content on an already existing model we have to set the value of the textarea to the raw content that the Gutenberg editor provided. <textarea id="[id_here]" name="[name_here]" hidden>{{ $model->content }}</textarea> To initialize the editor all we have to do is call the initialize function with the id of the textarea. You probably want to do this insde a DOMContentLoaded event. And that's it! The editor will replace the textarea in the DOM and on a form submit the editor content will be available in the textarea's value attribute. Laraberg.init('[id_here]') Configuration optionsThe const options = {}
Laraberg.init('[id_here]', options) The interface EditorSettings {
height?: string;
mediaUpload?: (upload: MediaUpload) => void;
fetchHandler?: FetchHandler;
disabledCoreBlocks?: string[];
alignWide?: boolean;
supportsLayout?: boolean;
maxWidth?: number;
imageEditing?: boolean;
colors?: Color[];
gradients?: Gradient[];
fontSizes?: FontSize[];
} ModelsIn order to add the editor content to a model Laraberg provides the 'RendersContent' trait. use VanOns\Laraberg\Traits\RendersContent;
class MyModel extends Model {
use RendersContent;
} This adds the use VanOns\Laraberg\Traits\RendersContent;
class MyModel extends Model {
use RendersContent;
protected $contentColumn = 'my_column';
} Or by passing the column name to the render method. $model->render('my_column'); Custom BlocksGutenberg allows developers to create custom blocks. For information on how to create a custom block you should read the Gutenberg documentation. Registering custom blocks is fairly easy. A Gutenberg block requires the properties const myBlock = {
title: 'My First Block!',
icon: 'universal-access-alt',
category: 'my-category',
edit() {
return <h1>Hello editor.</h1>
},
save() {
return <h1>Hello saved content.</h1>
}
}
Laraberg.registerBlockType('my-namespace/my-block', myBlock) Server-side blocksServer-side blocks can be registered in Laravel. You probably want to create a ServiceProvider and register your server-side blocks in it's class BlockServiceProvider extends ServiceProvider {
public function boot() {
Laraberg::registerBlockType(
'my-namespace/my-block',
[],
function ($attributes, $content) {
return view('blocks.my-block', compact('attributes', 'content'));
}
);
}
} WordPress exportsLaraberg uses the WordPress Gutenberg packages under the hood, a lot of those packages expose functionality that let's you customize the editor. You can find these packages in Javascript in the global
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论