Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## [Unreleased](https://github.com/Refactor-Circus/Atrium/compare/v0.1.0...main)

### Added

- `slide-over` component, with `slide-over-link`: a panel that slides in from the right over the page, opened and closed by its URL's query string, so a row can open its record in place and the link can be shared.
- An account menu in the top bar: the signed-in user's initials, name and email, and Sign out, which posts to the app's logout route (`atrium.logout_route`, default `logout`). Hidden for guests, and when that route is null or not defined.

### Fixed

- Search sources run in child processes returned no results on Laravel 13.40 and later, whose `invoke-serialized-closure` command frames its result in a signed envelope. `atrium:search-source` now unwraps it, and still reads the bare JSON earlier versions write.

## [v0.1.0](https://github.com/Refactor-Circus/Atrium/commits/v0.1.0) - 2026-10-30

### Breaking
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ Available components:

**Layout and content**: `card`, `section`, `page-header`, `empty-state`, `stat`, `table` (with `table.row` and `table.cell`), `description-list` (with `description-list.item`), `pagination`, `breadcrumbs`, `guest` (a standalone page outside the shell)

**Controls**: `button`, `icon-button`, `icon`, `badge`, `status-dot`, `chip`, `kbd`, `avatar`, `toggle`, `tooltip`, `dropdown`, `modal`, `tabs`, `tab-panel`, `search-input`
**Controls**: `button`, `icon-button`, `icon`, `badge`, `status-dot`, `chip`, `kbd`, `avatar`, `toggle`, `tooltip`, `dropdown`, `modal`, `slide-over` (with `slide-over-link`), `tabs`, `tab-panel`, `search-input`

**Feedback**: `alert`, `flash` (the session status and first error), `banner` (with `banner.button`), `progress`, `spinner`, `skeleton`

Expand Down
13 changes: 13 additions & 0 deletions config/atrium.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@

'gate' => 'viewAtrium',

/*
|--------------------------------------------------------------------------
| Sign Out
|--------------------------------------------------------------------------
|
| The name of the app's logout route (a POST route, as Laravel's starter
| kits define it). The top bar's account menu signs out through it. Null,
| or a route the app does not define, hides the menu.
|
*/

'logout_route' => 'logout',

/*
|--------------------------------------------------------------------------
| Policies
Expand Down
2 changes: 2 additions & 0 deletions lang/en/atrium.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
'collapse_sidebar' => 'Collapse sidebar',
'expand_sidebar' => 'Expand sidebar',
'appearance' => 'Appearance',
'account' => 'Account',
'sign_out' => 'Sign out',
'theme_light' => 'Light',
'theme_dark' => 'Dark',
'theme_system' => 'System',
Expand Down
2 changes: 1 addition & 1 deletion public/atrium.css

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions resources/css/atrium.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
@source '../views/components/search-input.blade.php';
@source '../views/components/section.blade.php';
@source '../views/components/skeleton.blade.php';
@source '../views/components/slide-over-link.blade.php';
@source '../views/components/slide-over.blade.php';
@source '../views/components/spinner.blade.php';
@source '../views/components/stat.blade.php';
@source '../views/components/status-dot.blade.php';
Expand All @@ -99,6 +101,7 @@
@source '../views/partials/theme-switcher.blade.php';
@source '../views/partials/theme.blade.php';
@source '../views/partials/top-navigation.blade.php';
@source '../views/partials/user-menu.blade.php';
@source '../views/settings/index.blade.php';
@source '../views/settings/show.blade.php';

Expand Down
15 changes: 15 additions & 0 deletions resources/views/components/slide-over-link.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{--
A link that opens its `href` in the named slide-over without leaving the
page. A plain link still works: without JavaScript, or opened in a new tab,
it loads the page with the panel open.

<x-atrium::slide-over-link name="orders" :href="$url">SO-1</x-atrium::slide-over-link>
--}}
@props(['name', 'href'])

<a
href="{{ $href }}"
{{ $attributes->class('font-medium text-primary hover:underline dark:text-primary-dark') }}
x-data
x-on:click="if (! ($event.metaKey || $event.ctrlKey || $event.shiftKey || $event.button === 1)) { $event.preventDefault(); $dispatch('atrium-slide-over-load', { name: @js($name), url: $el.href }); }"
>{{ $slot }}</a>
129 changes: 129 additions & 0 deletions resources/views/components/slide-over.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{{--
A panel that slides in from the right over the page, for viewing one
record without leaving the list behind it.

Server-rendered: pass `open` when the request already names the record
(a `?record=` link), and the panel renders open and slides in on load.
`close-url` is where closing goes back to (the list without the record),
as an absolute URL; without it, closing only hides the panel.

Client-side: a `slide-over-link` (or an `atrium-slide-over-load` event,
`{ name, url }`) fetches `url`, takes this panel's content from the page
it returns, swaps it in and slides the panel open, updating the address
so the record stays linkable. `atrium-slide-over-open` / `-close` with the
name open and close it as the modal's events do.

<x-atrium::slide-over name="orders" title="SO-1" :open="$selected !== null" :close-url="$listUrl">
...the record...
</x-atrium::slide-over>
--}}
@props([
'name',
'title' => null,
'open' => false,
'closeUrl' => null,
'size' => 'lg',
])

@php
$sizes = [
'md' => 'max-w-lg',
'lg' => 'max-w-2xl',
'xl' => 'max-w-4xl',
];
@endphp

<div
x-data="{
open: false,
loading: false,
failed: false,
title: @js($title),
closeUrl: @js($closeUrl),
init() {
if (@js((bool) $open)) {
this.$nextTick(() => this.open = true);
}
},
async load(url) {
this.open = true;
this.loading = true;
this.failed = false;

try {
const response = await fetch(url, { headers: { 'X-Requested-With': 'XMLHttpRequest' } });

if (! response.ok) {
throw new Error(response.statusText);
}

const page = new DOMParser().parseFromString(await response.text(), 'text/html');
const content = page.querySelector('[data-slide-over-content=' + JSON.stringify(@js($name)) + ']');

if (! content) {
throw new Error('No slide-over content on the page.');
}

this.$refs.content.innerHTML = content.innerHTML;
this.title = content.dataset.slideOverTitle || this.title;
window.history.pushState({ atriumSlideOver: @js($name) }, '', url);
} catch (error) {
this.failed = true;
} finally {
this.loading = false;
}
},
close() {
this.open = false;

if (this.closeUrl && window.location.href !== this.closeUrl) {
window.history.pushState({}, '', this.closeUrl);
}
},
}"
x-on:atrium-slide-over-load.window="if ($event.detail.name === @js($name)) load($event.detail.url)"
x-on:atrium-slide-over-open.window="if ($event.detail === @js($name)) open = true"
x-on:atrium-slide-over-close.window="if ($event.detail === @js($name)) close()"
x-on:keydown.escape.window="if (open) close()"
x-on:popstate.window="if (open && closeUrl && window.location.href === closeUrl) open = false"
data-slide-over="{{ $name }}"
>
<div class="fixed inset-0 z-40 bg-zinc-950/40 backdrop-blur-sm" x-show="open" x-cloak x-transition.opacity x-on:click="close()"></div>

<aside
{{ $attributes->class('fixed inset-y-0 right-0 z-50 flex w-full flex-col border-l border-outline bg-surface text-on-surface shadow-2xl dark:border-outline-dark dark:bg-surface-dark dark:text-on-surface-dark '.($sizes[$size] ?? $sizes['lg'])) }}
x-show="open"
x-cloak
x-transition:enter="transform transition duration-200 ease-out"
x-transition:enter-start="translate-x-full"
x-transition:enter-end="translate-x-0"
x-transition:leave="transform transition duration-150 ease-in"
x-transition:leave-start="translate-x-0"
x-transition:leave-end="translate-x-full"
role="dialog"
aria-modal="true"
x-bind:aria-busy="loading"
>
<div class="flex items-center justify-between gap-3 border-b border-outline px-5 py-3 dark:border-outline-dark">
<h2 class="truncate text-base font-semibold text-on-surface-strong dark:text-on-surface-dark-strong" x-text="title">{{ $title }}</h2>

<button type="button" class="grid size-8 shrink-0 cursor-pointer place-items-center rounded-md text-on-surface transition-colors hover:bg-on-surface-strong/5 hover:text-on-surface-strong dark:text-on-surface-dark dark:hover:bg-white/5 dark:hover:text-on-surface-dark-strong" x-on:click="close()" aria-label="Close">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="size-5" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" />
</svg>
</button>
</div>

<div class="relative flex-1 overflow-y-auto">
<div class="absolute inset-0 grid place-items-center bg-surface/60 dark:bg-surface-dark/60" x-show="loading" x-cloak>
<x-atrium::spinner />
</div>

<div class="p-5" x-show="failed" x-cloak>
<x-atrium::alert variant="danger">{{ __('This record could not be loaded.') }}</x-atrium::alert>
</div>

<div class="p-5" x-ref="content" x-show="! failed" data-slide-over-content="{{ $name }}" data-slide-over-title="{{ $title }}">{{ $slot }}</div>
</div>
</aside>
</div>
1 change: 1 addition & 0 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class="block rounded-md px-2 py-1.5 text-sm text-on-surface transition-colors ho
<div class="ml-auto flex items-center gap-1.5">
@include('atrium::partials.theme-switcher')
@include('atrium::partials.appearance')
@include('atrium::partials.user-menu')

@if (! empty($topbarEnd))
{{ $topbarEnd }}
Expand Down
45 changes: 45 additions & 0 deletions resources/views/partials/user-menu.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{--
The signed-in user and a way out: who they are, and Sign out, which posts
to the app's logout route (`atrium.logout_route`). Hidden for guests, and
when that route is off (null) or not defined.
--}}
@php
$atriumUser = auth()->user();
$atriumLogout = config('atrium.logout_route', 'logout');
$atriumLogout = is_string($atriumLogout) && $atriumLogout !== '' && \Illuminate\Support\Facades\Route::has($atriumLogout) ? route($atriumLogout) : null;
$atriumUserName = $atriumUser ? (string) ($atriumUser->name ?? $atriumUser->email ?? '') : '';
$atriumUserEmail = $atriumUser ? (string) ($atriumUser->email ?? '') : '';
$atriumInitials = mb_strtoupper(collect(preg_split('/\s+/', trim($atriumUserName)) ?: [])->filter()->take(2)->map(fn (string $word): string => mb_substr($word, 0, 1))->implode('')) ?: '?';
@endphp

@if ($atriumUser && $atriumLogout)
<x-atrium::dropdown align="right" data-testid="user-menu">
<x-slot:trigger>
<button type="button" data-testid="user-menu-toggle"
class="grid size-9 cursor-pointer place-items-center rounded-radius text-on-surface transition-colors hover:bg-on-surface-strong/5 hover:text-on-surface-strong dark:text-on-surface-dark dark:hover:bg-white/5 dark:hover:text-on-surface-dark-strong"
aria-label="{{ __('atrium::atrium.account') }}" title="{{ $atriumUserName }}">
<x-atrium::avatar :initials="$atriumInitials" :alt="$atriumUserName" size="sm" />
</button>
</x-slot:trigger>

<div class="min-w-36" role="menu" aria-label="{{ __('atrium::atrium.account') }}">
<div class="px-2 py-1.5 text-sm">
<div class="truncate font-medium text-on-surface-strong dark:text-on-surface-dark-strong">{{ $atriumUserName }}</div>
@if ($atriumUserEmail !== '' && $atriumUserEmail !== $atriumUserName)
<div class="truncate text-xs">{{ $atriumUserEmail }}</div>
@endif
</div>

<form method="POST" action="{{ $atriumLogout }}">
@csrf
<button type="submit" role="menuitem" data-testid="sign-out"
class="flex w-full cursor-pointer items-center gap-2.5 rounded-md px-2 py-1.5 text-sm text-on-surface transition-colors hover:bg-on-surface-strong/5 hover:text-on-surface-strong dark:text-on-surface-dark dark:hover:bg-white/5 dark:hover:text-on-surface-dark-strong">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" class="size-4 shrink-0" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 9V5.25A2.25 2.25 0 0 0 13.5 3h-6a2.25 2.25 0 0 0-2.25 2.25v13.5A2.25 2.25 0 0 0 7.5 21h6a2.25 2.25 0 0 0 2.25-2.25V15m3 0 3-3m0 0-3-3m3 3H9" />
</svg>
<span class="flex-1 text-left">{{ __('atrium::atrium.sign_out') }}</span>
</button>
</form>
</div>
</x-atrium::dropdown>
@endif
35 changes: 34 additions & 1 deletion src/Domains/Search/Console/InvokeSearchSourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@
* closure the parent sent, in this process. That closure hands its rows back
* through the container under RESULTS, so the framework's serialized return
* value is never read: only JSON leaves this process.
*
* From Laravel 13.40 the framework command frames its JSON in a signed
* envelope (`@@LARAVEL-CONCURRENCY-V1@@{base64}@@{hmac}@@`), keyed by
* LARAVEL_CONCURRENCY_HMAC_KEY. This command sets that key for the call and
* unwraps the envelope; earlier versions write the JSON bare.
*/
class InvokeSearchSourceCommand extends Command
{
/** The container key the closure binds its rows under. */
public const string RESULTS = SearchRegistry::class.'@results';

/** The environment variable the framework signs its result envelope with. */
private const string ENVELOPE_KEY = 'LARAVEL_CONCURRENCY_HMAC_KEY';

protected $signature = 'atrium:search-source';

protected $description = 'Run a search source sent by Atrium and write its results as JSON.';
Expand All @@ -35,6 +43,10 @@ public function handle(): int
$this->laravel->forgetInstance(self::RESULTS);

$buffer = new BufferedOutput;
$key = bin2hex(random_bytes(32));

$_SERVER[self::ENVELOPE_KEY] = $_ENV[self::ENVELOPE_KEY] = $key;
putenv(self::ENVELOPE_KEY.'='.$key);

// Whatever the source prints would land on stdout beside the envelope.
ob_start();
Expand All @@ -43,13 +55,34 @@ public function handle(): int
Artisan::call('invoke-serialized-closure', [], $buffer);
} finally {
ob_end_clean();

unset($_SERVER[self::ENVELOPE_KEY], $_ENV[self::ENVELOPE_KEY]);
putenv(self::ENVELOPE_KEY);
}

$this->output->write($this->encode($this->envelope($buffer->fetch())), false, OutputInterface::OUTPUT_RAW);
$this->output->write($this->encode($this->envelope($this->unframe($buffer->fetch(), $key))), false, OutputInterface::OUTPUT_RAW);

return self::SUCCESS;
}

/**
* The framework's JSON: the payload of its signed envelope when it framed
* one, else the output as written (before Laravel 13.40). An envelope
* whose signature does not match reads as no result.
*/
private function unframe(string $output, string $key): string
{
if (preg_match('/@@LARAVEL-CONCURRENCY-V1@@([A-Za-z0-9+\/=]*)@@([a-f0-9]{64})@@/', $output, $frame) !== 1) {
return $output;
}

if (! hash_equals(hash_hmac('sha256', $frame[1], $key), $frame[2])) {
return '';
}

return (string) base64_decode($frame[1], true);
}

/**
* @return array{successful: true, results: array<array-key, mixed>}|array{successful: false, message: string}
*/
Expand Down
26 changes: 26 additions & 0 deletions tests/Feature/ComponentLibraryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,29 @@ function render(string $template, array $data = []): string
->toContain('Works')
->not->toContain('<aside');
});

it('renders a slide-over closed by default, with its content marked for loading', function (): void {
$html = render('<x-atrium::slide-over name="orders" title="SO-1">Order body</x-atrium::slide-over>');

expect($html)->toContain('data-slide-over="orders"')
->toContain('data-slide-over-content="orders"')
->toContain('data-slide-over-title="SO-1"')
->toContain('Order body')
->toContain('role="dialog"')
->toContain('if (false)');
});

it('renders a slide-over open, with where closing goes back to', function (): void {
$html = render('<x-atrium::slide-over name="orders" :open="true" close-url="https://app.test/orders">Order body</x-atrium::slide-over>');

expect($html)->toContain('if (true)')
->toContain("closeUrl: 'https:\\/\\/app.test\\/orders'");
});

it('renders a slide-over link that loads its href into the named panel', function (): void {
$html = render('<x-atrium::slide-over-link name="orders" href="/orders?record=SO-1">SO-1</x-atrium::slide-over-link>');

expect($html)->toContain('href="/orders?record=SO-1"')
->toContain('atrium-slide-over-load')
->toContain('SO-1');
});
Loading
Loading