Download the PHP package povly/moonshine-flexible-layouts without Composer

On this page you can find all versions of the php package povly/moonshine-flexible-layouts. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package moonshine-flexible-layouts

MoonShine Flexible Layouts

Flexible content blocks field for MoonShine 4. Build page builder-style layouts with unlimited nesting, drag-to-reorder, and AJAX-powered block management.

Language: Русский


English

Flexible content blocks field for MoonShine 4. Build page builder-style layouts with unlimited nesting, drag-to-reorder, and AJAX-powered block management.

Features

Requirements

Installation

Publish assets:

Optionally publish the config and translations:

Register the cast on your model:

Quick Start

Usage

Block Registration

The block() method accepts:

Parameter Type Description
$name string Snake_case key stored in JSON as _type
$title string Human-readable label shown in tabs and picker
$fields iterable MoonShine fields (can include nested FlexibleLayouts)
$limit ?int Max instances of this block type (default: unlimited)
$category ?string Grouping label in the picker modal
$description ?string Short description shown in the picker card
$icon ?string MoonShine icon name, emoji, or SVG string

Basic usage:

Registration is validated: duplicate names (compared after squish()->snake() normalization) and limit < 1 throw an InvalidArgumentException — pass null for unlimited.

With category, description, and icon (use named args):

Icons

The icon parameter accepts three types:

Type Example Renders as
MoonShine icon name 'photo' SVG from moonshine::icons.photo
Emoji '📷' Raw text
Raw SVG '<svg>...</svg>' Pass-through HTML

MoonShine includes 301 Heroicons (stroke-based, 24×24). Browse them in vendor/moonshine/moonshine/src/UI/resources/views/icons/. Common examples: users, photo, document-text, rectangle-stack, bars-3, cog-6-tooth, star, bolt, globe-alt, bookmark.

Icons appear in both the tab label and the picker card.

⚠️ Security: icon is rendered as raw HTML and must only receive developer-trusted values — never user input.

Blocks without a category are shown in an ungrouped section. When all blocks lack categories, the category pills row is hidden automatically.

Block Picker Modal

Clicking Add block opens a Gutenberg-style modal with:

Press Esc or click outside the modal to close.

z-index / compatibility

The picker overlay lives on the MoonShine core modal layer — z-index: var(--z-modal, 1100). It stays below core menus (--z-menu: 1200) and toasts (--z-toast: 1300), and packages with dedicated elevated layers (e.g. moonshine-media-manager dialogs at 1150/1250) always stack above it. Do not raise the overlay above the core scale — that was the original 9999 bug.

Nested Flexible Layouts

You can put a FlexibleLayouts field inside any block. Nested layouts support the same features (drag, add, remove, reindex):

Disabling Features

Custom Buttons

Duplicating Blocks

Every block header includes a duplicate button right after the remove button. It fetches a fresh server-rendered instance of the same block type (so field ids/names stay unique and per-type limits are enforced server-side), copies all field values from the source block, and inserts the copy directly after it. File fields cannot be copied (browser limitation) — they start empty in the duplicate. A flexible-layouts:block-duplicated DOM event is dispatched after each duplication. Additions and removals dispatch flexible-layouts:block-added and flexible-layouts:block-removed respectively — all events bubble on document with {name, column} in detail.

Custom Labels per Field

By default, all Flexible Layouts fields share the same UI labels from messages.php. Use ->transKey() to give a specific field its own set of labels — useful for nested layouts with different content types:

Create lang/vendor/flexible-layouts/en/refs.php:

Labels resolve in order: flexible-layouts::refs.{key} → if missing → flexible-layouts::messages.{key}. An example file ships in lang/en/refs.php and lang/ru/refs.php.

Multi-column Layouts

Use MoonShine's native Flex and Column components inside blocks for side-by-side fields:

columnSpan(6) = half width (out of 12-column grid). Use columnSpan(4) for three columns, columnSpan(3) for four, etc.

Configuration

Publish the config file:

The package route is registered inside Route::moonshine() and inherits core auth/web/CSRF middleware — no middleware key exists or is needed.

Translations

The package ships with English and Russian translations. The UI adapts to the app locale automatically.

Available keys:

Key EN RU
add_block Add block Добавить блок
search_blocks Search blocks... Поиск блоков...
no_blocks_found No blocks found Блоки не найдены
all_categories All Все
duplicate_block Duplicate Дублировать

Publish translations to customize or add new languages:

To add a language, copy any file to a new locale folder:

Data Format

The field stores data as a flat JSON array. Each entry has a _type key and the block's field values:

Unknown _type handling

Block types removed from code but still present in stored JSON are not lost:

Entry state Render Save Field callbacks
Known _type rendered fields applied run
Unknown string _type skipped (+ warning if logging on) preserved verbatim (+ warning if logging on) skipped
No _type skipped dropped skipped

This makes block-type migrations safe: unrecognized entries keep round-tripping through save → load until you re-register or explicitly remove them. The cast caps JSON nesting depth at 64 (DoS protection).

Development

Assets are built to dist/ and published to public/vendor/flexible-layouts/. See docs/development.md for build internals and debugging.


Русский

Поле гибких контентных блоков для MoonShine 4. Стройте макеты в стиле конструктора страниц: неограниченная вложенность, drag-сортировка и AJAX-управление блоками.

Возможности

Требования

Установка

Опубликуйте собранные ассеты:

Опционально — конфиг и переводы:

Зарегистрируйте каст на модели:

Быстрый старт

Использование

Регистрация блоков

Метод block() принимает:

Параметр Тип Описание
$name string Ключ snake_case, сохраняется в JSON как _type
$title string Человекочитаемый заголовок (табы, пикер)
$fields iterable Поля MoonShine (в т.ч. вложенные FlexibleLayouts)
$limit ?int Максимум инстансов этого типа (по умолчанию — без ограничений)
$category ?string Группировка в пикере
$description ?string Короткое описание в карточке пикера
$icon ?string Имя иконки MoonShine, emoji или SVG-строка

Базовое использование:

Регистрация валидируется: дубликаты имён (сравнение после нормализации squish()->snake()) и limit < 1 бросают InvalidArgumentException — для неограниченного количества передайте null.

С категорией, описанием и иконкой (именованные аргументы):

Иконки

Параметр icon принимает три типа значений:

Тип Пример Рендерится как
Имя иконки MoonShine 'photo' SVG из moonshine::icons.photo
Emoji '📷' Как есть
Сырой SVG '<svg>...</svg>' Pass-through HTML

MoonShine включает 301 Heroicons (stroke, 24×24). Список — в vendor/moonshine/moonshine/src/UI/resources/views/icons/. Часто используемые: users, photo, document-text, rectangle-stack, bars-3, cog-6-tooth, star, bolt, globe-alt, bookmark.

Иконка отображается и на табе, и в карточке пикера.

⚠️ Безопасность: значение icon рендерится как сырой HTML — допускаются только developer-trusted значения, никогда пользовательский ввод.

Блоки без категории попадают в группу «без группировки». Если категорий нет ни у одного блока — ряд пилюль категорий скрывается автоматически.

Модальный пикер

Клик по «Добавить блок» открывает модал в стиле Gutenberg:

Esc или клик вне модала — закрытие.

z-index / совместимость

Оверлей пикера живёт на слое модалов ядра MoonShine — z-index: var(--z-modal, 1100). Он остаётся ниже меню ядра (--z-menu: 1200) и тостов (--z-toast: 1300); пакеты с собственными elevated-слоями (например, диалоги moonshine-media-manager на 1150/1250) всегда лежат выше. Не поднимайте оверлей выше шкалы ядра — это вернёт исходный баг с 9999.

Вложенные Flexible Layouts

FlexibleLayouts можно положить внутрь полей любого блока. Вложенные макеты поддерживают те же возможности (drag, add, remove, reindex):

Отключение возможностей

Кастомные кнопки

Дублирование блоков

В хедере каждого блока, сразу после кнопки удаления, есть кнопка дублирования. Она запрашивает свежий серверный рендер того же типа блока (id/name полей остаются уникальными, лимиты типов проверяются на сервере), копирует все значения полей исходного блока и вставляет копию сразу после него. Файловые поля скопировать нельзя (ограничение браузера) — в дубле они пусты. После дублирования диспатчится DOM-событие flexible-layouts:block-duplicated. Добавление и удаление диспатчат flexible-layouts:block-added и flexible-layouts:block-removed соответственно — все события всплывают на document с {name, column} в detail.

Персональные подписи поля

По умолчанию все поля FlexibleLayouts берут подписи UI из messages.php. Метод ->transKey() даёт конкретному полю свой набор лейблов — полезно для вложенных макетов с другим типом контента:

Создайте lang/vendor/flexible-layouts/ru/refs.php:

Порядок разрешения: flexible-layouts::refs.{key} → при отсутствии → flexible-layouts::messages.{key}. Пример файла идёт в комплекте: lang/en/refs.php и lang/ru/refs.php.

Мультиколоночные раскладки

Внутри блоков работают нативные компоненты Flex и Column:

columnSpan(6) — половина ширины (сетка из 12 колонок). columnSpan(4) — три колонки, columnSpan(3) — четыре, и т.д.

Конфигурация

Опубликуйте конфиг:

Роут пакета регистрируется внутри Route::moonshine() и наследует auth/web/CSRF middleware ядра — ключа middleware в конфиге нет и он не нужен.

Переводы

Пакет поставляется с английской и русской локализацией. UI автоматически подстраивается под локаль приложения.

Ключи:

Ключ EN RU
add_block Add block Добавить блок
search_blocks Search blocks... Поиск блоков...
no_blocks_found No blocks found Блоки не найдены
all_categories All Все
duplicate_block Duplicate Дублировать

Публикация переводов (для кастомизации или новых языков):

Добавление языка — скопируйте файл в новый каталог локали:

Формат данных

Поле хранит данные как плоский JSON-массив. Каждый элемент содержит ключ _type и значения полей блока:

Обработка неизвестных _type

Типы блоков, удалённые из кода, но оставшиеся в JSON, не теряются:

Состояние записи Рендер Сохранение Колбэки полей
_type зарегистрирован блок рендерится поля применяются выполняются
_type неизвестен пропуск (+ warning при включённом logging) сохраняется verbatim (+ warning) пропускаются
Нет _type пропуск отбрасывается пропускаются

Это делает миграции набора блоков безопасными: нераспознанные записи продолжают round-trip через save → load, пока вы не перерегистрируете или явно не удалите их. Каст ограничивает глубину JSON 64 уровнями (защита от DoS).

Разработка

Ассеты собираются в dist/ и публикуются в public/vendor/flexible-layouts/. Подробности сборки и отладки — в docs/development.md.


Documentation

Detailed guides (in Russian) live in the docs/ directory:

Guide Description
Getting Started Installation, publishing, model cast, verification
Block Types block(), icons, limits, categories, picker, z-index
Nested Layouts Nesting, Flex/Column, transKey()
Data Format JSON, _type, cast, unknown-type passthrough
Configuration route_prefix, logging, env vars
Translations Keys, locales, adding new languages
Development Bun/Vite build, debugging

License

MIT


All versions of moonshine-flexible-layouts with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
moonshine/moonshine Version ^4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package povly/moonshine-flexible-layouts contains the following files

Loading the files please wait ...