|
1 |
| -# Nova HTML code Field |
| 1 | +# Nova HTML Code Field |
2 | 2 |
|
3 | 3 | [](https://packagist.org/packages/interaction-design-foundation/nova-html-code-field)
|
4 | 4 | [](https://packagist.org/packages/interaction-design-foundation/nova-html-code-field)
|
5 | 5 |
|
6 |
| - |
| 6 | +A Laravel Nova field that provides a powerful HTML code editor with real-time preview capabilities. |
| 7 | +Write raw HTML and see instant results, with the preview rendered in an isolated iframe to prevent style conflicts with Nova's UI. |
7 | 8 |
|
| 9 | + |
8 | 10 |
|
9 |
| -Sometimes you need an option to write a raw HTML and have a real-time preview for it. |
10 |
| -This package provides such ability. Under the hood this package uses iframe for HTML code your write, |
11 |
| -so Nova styles will not leak to the preview. Additionally, you can provide URLs to your custom CSS file |
12 |
| -and thus your HTML preview will be very close to the final result. |
13 |
| - |
14 |
| - |
| 11 | +## Features |
15 | 12 |
|
| 13 | +- Real-time HTML preview |
| 14 | +- Isolated preview environment using iframes |
| 15 | +- Custom CSS injection support |
| 16 | +- Customizable preview template |
| 17 | +- Compatible with Laravel Nova 4.x and 5.x |
16 | 18 |
|
17 | 19 | ## Installation
|
18 | 20 |
|
19 |
| -You can install the package in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer: |
| 21 | +You can install the package via composer: |
20 | 22 |
|
21 | 23 | ```bash
|
22 | 24 | composer require interaction-design-foundation/nova-html-code-field
|
23 | 25 | ```
|
24 | 26 |
|
| 27 | +The package will automatically register its service provider. |
| 28 | + |
25 | 29 | ## Usage
|
26 | 30 |
|
| 31 | +### Basic Usage |
| 32 | + |
27 | 33 | ```php
|
28 | 34 | use InteractionDesignFoundation\NovaHtmlCodeField\HtmlCode;
|
29 | 35 |
|
30 |
| -public function fields() |
| 36 | +public function fields(NovaRequest $request): array |
31 | 37 | {
|
32 | 38 | return [
|
33 |
| - HtmlCode::make('HTML content', 'content'), |
34 |
| - ]; |
| 39 | + HtmlCode::make('HTML Content', 'content'), |
| 40 | + ]; |
35 | 41 | }
|
36 | 42 | ```
|
37 | 43 |
|
| 44 | +### Advanced Usage |
38 | 45 |
|
39 |
| -### Options |
40 |
| - |
41 |
| -Full example: |
42 | 46 | ```php
|
43 |
| -HtmlCode::make('HTML content', 'content') |
44 |
| - ->styles([asset(mix('css/app.css'))]), // optional, you can inject your custom CSS files to have more realistic preview. |
45 |
| - ->previewTemplate('<section class="panel">%CODE%</section>') // optional, wrap editable code to have even better preview (good together with custom styles). |
46 |
| -``` |
| 47 | +use InteractionDesignFoundation\NovaHtmlCodeField\HtmlCode; |
47 | 48 |
|
| 49 | +public function fields(NovaRequest $request): array |
| 50 | +{ |
| 51 | + return [ |
| 52 | + HtmlCode::make('HTML Content', 'content') |
| 53 | + // Include stylesheets into iframe for more accurate preview |
| 54 | + ->styles([ |
| 55 | + asset('css/app.css'), // your custom |
| 56 | + 'https://cdn.example.com/custom.css', // from a CDN |
| 57 | + ]) |
| 58 | + // Wrap the HTML content in a template ("%CODE%" is required) |
| 59 | + ->previewTemplate('<section class="panel">%CODE%</section>'), |
| 60 | + ]; |
| 61 | +} |
| 62 | +``` |
48 | 63 |
|
49 |
| -### Changelog |
| 64 | +## Contributing |
50 | 65 |
|
51 |
| -Please see [Releases](https://github.com/InteractionDesignFoundation/nova-unlayer-field/releases) for more information on what has changed recently. |
| 66 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for details on how to contribute to this project. |
52 | 67 |
|
| 68 | +### Testing |
53 | 69 |
|
54 |
| -## Contributing |
| 70 | +```bash |
| 71 | +composer test |
| 72 | +``` |
55 | 73 |
|
56 |
| -Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 74 | +### Code Style |
57 | 75 |
|
| 76 | +```bash |
| 77 | +# Fix code style |
| 78 | +composer cs:fix |
| 79 | +``` |
58 | 80 |
|
59 |
| -## License |
| 81 | +## Security |
60 | 82 |
|
61 |
| -The MIT License (MIT). Please see [License File](LICENSE) for more information. |
| 83 | +If you discover any security-related issues, please email the maintainers instead of using the issue tracker. |
62 | 84 |
|
| 85 | +## Credits |
63 | 86 |
|
64 |
| -## ToDo |
| 87 | +- [Interaction Design Foundation](https://github.com/InteractionDesignFoundation) |
| 88 | +- [All Contributors](../../contributors) |
65 | 89 |
|
66 |
| -1. Add toolbar |
67 |
| -1. Add HTML validator (https://www.npmjs.com/package/html-validator) |
68 |
| -1. Optimize a preview: re-render only changed node |
| 90 | +## License |
69 | 91 |
|
| 92 | +The MIT License (MIT). Please see [License File](LICENSE) for more information. |
0 commit comments