Download the PHP package awcodes/mason without Composer
On this page you can find all versions of the php package awcodes/mason. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download awcodes/mason
More information about awcodes/mason
Files in awcodes/mason
Package mason
Short Description A simple block based drag and drop page / document builder field for Filament.
License MIT
Homepage https://github.com/awcodes/mason
Informations about the package mason
Mason
A simple block-based drag and drop page / document builder field for Filament.
Compatibility
| Package Version | Filament Version |
|---|---|
| 0.x | 3.x |
| 1.x | 4.x |
| 2.x | 5.x |
| 3.x | 4.x, 5.x |
Installation
You can install the package via composer:
In an effort to align with Filament's theming methodology, you will need to use a custom theme to use this plugin.
[!IMPORTANT] If you have not set up a custom theme and are using Filament Panels, follow the instructions in the Filament Docs first. The following applies to both the Panels Package and the standalone Forms package.
After setting up a custom theme, add the plugin's CSS to your theme CSS file or your app's CSS file if using the standalone forms package.
Configuration
You can publish the config file with:
These are the contents of the published config file:
Auth Guards
By default, Mason uses the web and auth middleware for its routes internally. If you are using a different guard or have multiple guards, you can customize the middleware used by updating the routes.middleware configuration option in the published config file.
Usage
[!IMPORTANT] Mason uses JSON to store its data in the database, so it is important that you cast the field to either 'array' or 'json' on your model, and it's recommended to store the content as a
longTextcolumn in the database.
Form Field
In your Filament forms you should use the Mason component. The Mason component accepts a name prop which should be the name of the field in your model, and requires an array 'bricks' available to the editor.
Field Preview Layout
Since Mason uses an iframe to render in the editor, you should set the preview layout for the field to a view in your application that includes your app's styles. This will ensure that the content in the editor looks similar to how it will look on the front end of your site. If all Mason fields in your forms use the same layout, you can set a default in the config file. Otherwise, you can set it per field like so:
Then in your layout file you can include the necessary styles and includes to render the content correctly.
If the blue color used in the editor doesn't work with your design, you can customize it with CSS in your app's CSS file.
Double-Clicking Bricks to Edit
By default, Mason requires you to click the edit button on each brick to edit its content. If you would like to enable double-clicking on bricks to open the edit modal, you can chain the doubleClickToEdit method on the field.
Infolist Entry
In your Filament infolists you should use the MasonEntry component. The MasonEntry component accepts a name prop which should be the name of the field in your model, and requires an array of 'bricks' available to the entry.
Entry Preview Layout
Since Mason uses an iframe to render in the infolist, you should set the preview layout for the field to a view in your application that includes your app's styles. This will ensure that the content in the editor looks similar to how it will look on the front end of your site. If all Mason fields in your forms use the same layout, you can set a default in the config file. Otherwise, you can set it per field like so:
Then in your layout file you can include the necessary styles and includes to render the content correctly.
Tips & Tricks
Custom Height
If you find that the default height of the Mason editor or entry is not enough for your use case, you can customize using Filament's default ->extraInputAttrbutes() method on both the Mason field and the MasonEntry component.
Brick Collections
To keep from having to repeat yourself when assigning bricks to the editor and the entry, it would help to create sets of bricks that make sense for their use case. Then you can use that in the bricks method.
Sidebar Position
By default, the Mason editor sidebar is positioned on the right side of the editor. If you would like to position it on the left side, you can chain the sidebarPosition method on the field and assign it the new position.
Displaying Brick Actions as a Grid
By default, the Mason editor displays the brick actions in a list. If you would like to display them in a grid format, you can chain the displayActionsAsGrid method on the field.
Sorting Bricks
By default, bricks are sorted in the order they are defined in the bricks array. If you would like to allow users to sort the bricks in the editor, you can chain the sortBricks method on the field.
Static Bricks without data or forms
If you would like to create a brick that does not require any data or forms, you can return the view in the toHtml method and set the action to have a hidden modal in the configureBrickAction method in your brick class. Now, when inserting the brick, it will simply add the brick without any configuration.
Light / Dark Mode
If your application supports light and dark mode, you can optionally add support for it in the Mason editor by using the colorModeToggle method on the field. This will add a toggle button to the editor sidebar that allows users to switch between light and dark mode. You can also use the defaultColorMode method to set the default color mode for the editor. One thing to note is that defaultColorMode only sets the initial mode when the editor is loaded. If the user switches modes, their preference will be saved in local storage for future visits.
In order for this to work properly, you will need to ensure that your application's CSS supports manually setting light and dark mode according to the Tailwind CSS documentation on manually controlling color mode.
Creating Bricks
Bricks are nothing more than classes that have an associated view that is rendered in the editor with its data.
To help you get started, there is a make:mason-brick command that will create a new brick for you with the necessary class and blade template in the paths specified in the config file.
This will create a new brick in the App\Mason namespace with the class Section and a preview and index blade template in the resources/views/mason directory. Bricks follow the same conventions as Filament RichEditor custom blocks.
Rendering Content
You are free to render the content however you see fit. The data is stored in the database as JSON, so you can use the data however you see fit. But the plugin offers a helper method for converting the data to HTML should you choose to use it.
Similar to the form field and entry components, the helper needs to know what bricks are available. You can pass the bricks to the helper as the second argument. See, above about creating a collection of bricks. This will help keep your code DRY.
There is also a dedicated Render that can be used if you need more control over the rendering process.
Faking Content
When testing, you may want to fake some Mason content. There is a helper method for that as well.
Testing
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Adam Weston
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of mason with dependencies
filament/filament Version ^4.0|^5.0
spatie/laravel-package-tools Version ^1.15.0