novadaemon/filament-pretty-json 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

novadaemon/filament-pretty-json

Composer 安装命令:

composer require novadaemon/filament-pretty-json

包简介

Read-only field to show pretty json in your filamentphp forms

README 文档

README

Read-only field to show pretty json in your filamentphp forms or infolists.

Screenshot

Installation

You can install the package via composer:

composer require novadaemon/filament-pretty-json

This package supports Filament 2.x, 3.x and 4.x.

Add to form

Simply use the component as you'd use any other Filament field. It's especially perfect for the resource view page where it blends right in.

use Novadaemon\FilamentPrettyJson\Form\PrettyJsonField;

class FormResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                PrettyJsonField::make('json')
            ]);
    }
}

Add to infolist

Use PrettyJsonEntry class instead.

use Novadaemon\FilamentPrettyJson\Infolist\PrettyJsonEntry;

class InfoResource extends Resource
{
    public static function infolist(Infolist $infolist): Form
    {
        return $infolist
            ->schema([
                PrettyJsonEntry::make('json')
            ]);
    }
}

The value of the field can be casting to string, json, array, object, AsArrayObject or object that implements Jsonable interface

/**
 * @var string[]
 */
protected $casts = [
    'card_info' => 'string',
    // OR 'card_info' => 'json',
    // OR 'card_info' => 'array',
    // OR 'card_info' => 'object',
    // OR 'card_info' => AsArrayObject::class,
    // OR 'card_info' => CustomCast::class,
];

Allowing the value to be copied to the clipboard

You may make the JSON copyable, such that clicking on the icon that appear in the top of the div when this option is enabled, the JSON value to the clipboard, and optionally specify a custom confirmation message and duration in milliseconds.

PrettyJsonEntry::make('card_info')
    ->copyable()
    ->copyMessage('Your JSON is copied to the clipboard')
    ->copyMessageDuration(1500)

Copyable

Customize

Add extra attributes

You can add additional attributes to the pre div using the extraAttributes() method.

PrettyJsonField::make('card')
->extraAttributes([
  'style' => 'max-height: 200px;',
]),

Global customization

Optionally, you can publish the views using

php artisan vendor:publish --tag="filament-pretty-json-views"

Also, you can overwrite the css rules in your stylesheets.

.prettyjson-container {
  position: relative;
  min-width: 0;
  flex: 1;
}

pre.prettyjson {
  color: black;
  background-color: rgba(0, 0, 0, 0);
  border: 1px solid rgb(229, 231, 235);
  border-radius: 0.5rem;
  padding: 10px 20px;
  overflow: auto;
  font-size: 12px;
}

:is(.dark) pre.prettyjson {
  opacity: 0.7;
  --tw-bg-opacity: 1;
  --tw-border-opacity: 1;
  border: 1px solid rgb(75 85 99 / var(--tw-border-opacity));
  color: rgb(209 213 219 / var(--tw-text-opacity));
}

:is(.dark) pre.prettyjson span.json-key {
  color: red !important;
}

:is(.dark) pre.prettyjson span.json-string {
  color: aquamarine !important;
}

:is(.dark) pre.prettyjson span.json-value {
  color: deepskyblue !important;
}

.copy-button {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 20px;
  height: 20px;
  text-align: center;
  line-height: 20px;
  cursor: pointer;
  color: rgb(156 163 175);
  border: none;
  outline: none;
  z-index: 50;
}

.copy-button:hover {
  color: rgb(75 85 99);
}

.copy-button:active,
.copy-button:focus {
  border: none;
  outline: none;
}

Contributing

Contributing is pretty chill and is highly appreciated! Just send a PR and/or create an issue!

Credits

License

The MIT License (MIT). Please see License File for more information.

novadaemon/filament-pretty-json 适用场景与选型建议

novadaemon/filament-pretty-json 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 480.01k 次下载、GitHub Stars 达 47, 最近一次更新时间为 2023 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「json」 「Forms」 「laravel」 「field」 「filament」 「novadaemon」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 novadaemon/filament-pretty-json 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 novadaemon/filament-pretty-json 我们能提供哪些服务?
定制开发 / 二次开发

基于 novadaemon/filament-pretty-json 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 480.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 47
  • 点击次数: 24
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 47
  • Watchers: 2
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-10