Skip to content

Commit

Permalink
Merge branch '4.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
jasonvarga committed May 8, 2024
2 parents a32c923 + 7c060b2 commit adfb667
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 10 deletions.
30 changes: 27 additions & 3 deletions resources/css/components/fieldtypes/button-group.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
/* Inside a Grid field
/* Vertical alignment of btn groups when overflowing
========================================================================== */

.grid-table td.button_group-fieldtype {
width: 1%;
.btn-group:not(.btn-vertical) {
@apply flex-wrap;
}
.btn-group.btn-vertical {
@apply flex-col items-stretch justify-start p-0 h-auto;

button {
@apply border-b border-t-0 rounded-none border-l border-r ;
height: 2.375rem; /* 38px */
}

:is(.btn-group button:not(:last-child):not(.active)) {
@apply border-r border-l;
}

button.active+button {
@apply border-l border-r;
}

button:first-child {
@apply rounded-t rounded-b-none border-t;
}

button:last-child {
@apply rounded-t-none rounded-b border-b;
}
}
4 changes: 4 additions & 0 deletions resources/js/components/blueprints/Section.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ export default {
},
editConfirmed() {
if (! this.editingSection.handle) {
this.editingSection.handle = this.$slugify(this.editingSection.display, '_');
}
this.$emit('updated', {...this.section, ...this.editingSection});
this.editingSection = false;
},
Expand Down
5 changes: 5 additions & 0 deletions resources/js/components/blueprints/Tab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,18 @@ export default {
},
editConfirmed() {
if (! this.handle) {
this.handle = this.$slugify(this.display, '_');
}
this.$emit('updated', {
...this.tab,
handle: this.handle,
display: this.display,
instructions: this.instructions,
icon: this.icon,
});
this.editing = false;
},
Expand Down
36 changes: 35 additions & 1 deletion resources/js/components/fieldtypes/ButtonGroupFieldtype.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="button-group-fieldtype-wrapper" :class="{'inline-mode': config.inline}">
<div class="btn-group">
<div class="btn-group" ref="buttonGroup">
<button class="btn px-4"
v-for="(option, $index) in options"
:key="$index"
Expand All @@ -18,10 +18,25 @@

<script>
import HasInputOptions from './HasInputOptions.js'
import ResizeObserver from 'resize-observer-polyfill';
export default {
mixins: [Fieldtype, HasInputOptions],
data() {
return {
resizeObserver: null,
}
},
mounted() {
this.setupResizeObserver();
},
beforeDestroy() {
this.resizeObserver.disconnect();
},
computed: {
options() {
return this.normalizeInputOptions(this.config.options);
Expand All @@ -37,6 +52,25 @@ export default {
methods: {
setupResizeObserver() {
this.resizeObserver = new ResizeObserver(() => {
this.handleWrappingOfNode(this.$refs.buttonGroup);
});
this.resizeObserver.observe(this.$refs.buttonGroup);
},
handleWrappingOfNode(node) {
const lastEl = node.lastChild;
if (!lastEl) return;
node.classList.remove('btn-vertical');
if(lastEl.offsetTop > node.clientTop) {
node.classList.add('btn-vertical');
}
},
focus() {
this.$refs.button[0].focus();
}
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/fieldtypes/GroupFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

<style>
.group-fieldtype-button-wrapper {
@apply flex justify-end absolute top-5 sm:top-7 rtl:left-0 ltr:right-0 @md:right-4 @lg:right-6;
@apply flex rtl:left-6 ltr:right-6 absolute top-5 sm:top-7;
}
.replicator-set .group-fieldtype-button-wrapper {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/fieldtypes/date/RangePopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@focus="$emit('focus', $event.target)"
@blur="$emit('blur')"
/>
<button @click="clear" type="button" title="Clear" aria-label="Clear" class="cursor-pointer px-2 hover:text-blue-500">
<button v-if="!isReadOnly" @click="clear" type="button" title="Clear" aria-label="Clear" class="cursor-pointer px-2 hover:text-blue-500">
<span>×</span>
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/fieldtypes/date/SinglePopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@focus="$emit('focus', $event.target)"
@blur="$emit('blur')"
/>
<button @click="clear" type="button" title="Clear" aria-label="Clear" class="cursor-pointer px-2 hover:text-blue-500">
<button v-if="!isReadOnly" @click="clear" type="button" title="Clear" aria-label="Clear" class="cursor-pointer px-2 hover:text-blue-500">
<span>×</span>
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
":count set|:count sets": ":count jeu|:count jeux",
":count word|:count words": ":count mot|:count mots",
":count\/:max selected": ":count sélectionnés \/:max",
":count\/:total characters": "count caractères \/:total",
":count\/:total characters": "count caractères :count\/:total",
":file uploaded": ":file téléchargé",
":start-:end of :total": ":start-:end sur :total",
":title Field": "Champ :title",
Expand Down
2 changes: 1 addition & 1 deletion src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ public function defaultAugmentedArrayKeys()

public function shallowAugmentedArrayKeys()
{
return ['id', 'url', 'permalink', 'api_url'];
return ['id', 'url', 'permalink', 'api_url', 'alt'];
}

protected function defaultAugmentedRelations()
Expand Down
3 changes: 2 additions & 1 deletion src/Facades/Parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace Statamic\Facades;

use Illuminate\Support\Facades\Facade;
use Statamic\View\Antlers\AntlersString;

/**
* @method static string template($str, $variables = [], $context = [], $php = false)
* @method static AntlersString template($str, $variables = [], $context = [], $php = false)
* @method static string templateLoop($content, $data, $supplement = true, $context = [], $php = false)
* @method static array YAML($str)
* @method static mixed env($val)
Expand Down
17 changes: 17 additions & 0 deletions src/Http/Middleware/CP/AddVaryHeaderToResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Statamic\Http\Middleware\CP;

use Closure;

class AddVaryHeaderToResponse
{
public function handle($request, Closure $next)
{
$response = $next($request);

$response->headers->set('Vary', 'X-Requested-With');

return $response;
}
}
1 change: 1 addition & 0 deletions src/Providers/CpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ protected function registerMiddlewareGroups()
\Statamic\Http\Middleware\CP\BootPreferences::class,
\Statamic\Http\Middleware\CP\BootUtilities::class,
\Statamic\Http\Middleware\CP\CountUsers::class,
\Statamic\Http\Middleware\CP\AddVaryHeaderToResponse::class,
\Statamic\Http\Middleware\DeleteTemporaryFileUploads::class,
]);
}
Expand Down
18 changes: 18 additions & 0 deletions src/Tags/Vite.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ public function asset()
->asset($src);
}

/**
* The {{ vite:content }} tag.
*
* @return string
*/
public function content()
{
if (! $src = $this->params->get('src')) {
throw new \Exception('Please provide a source file.');
}

$directory = $this->params->get('directory', 'build');

return $this->vite()
->useBuildDirectory($directory)
->content($src);
}

private function vite()
{
return clone app(LaravelVite::class);
Expand Down
24 changes: 24 additions & 0 deletions tests/Fieldtypes/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ public function it_augments_to_a_single_asset_when_max_files_is_one()
/** @test */
public function it_shallow_augments_to_a_collection_of_assets()
{
AssetContainer::find('test')
->queryAssets()
->where('path', 'foo/one.txt')
->first()
->set('alt', 'Alt text for one')
->save();

AssetContainer::find('test')
->queryAssets()
->where('path', 'bar/two.txt')
->first()
->set('alt', 'Alt text for two')
->save();

$augmented = $this->fieldtype()->shallowAugment(['foo/one.txt', 'bar/two.txt', 'unknown.txt']);

$this->assertInstanceOf(Collection::class, $augmented);
Expand All @@ -79,19 +93,28 @@ public function it_shallow_augments_to_a_collection_of_assets()
'url' => '/assets/foo/one.txt',
'permalink' => 'http://localhost/assets/foo/one.txt',
'api_url' => 'http://localhost/api/assets/test/foo/one.txt',
'alt' => 'Alt text for one',
],
[
'id' => 'test::bar/two.txt',
'url' => '/assets/bar/two.txt',
'permalink' => 'http://localhost/assets/bar/two.txt',
'api_url' => 'http://localhost/api/assets/test/bar/two.txt',
'alt' => 'Alt text for two',
],
], $augmented->toArray());
}

/** @test */
public function it_shallow_augments_to_a_single_asset_when_max_files_is_one()
{
AssetContainer::find('test')
->queryAssets()
->where('path', 'foo/one.txt')
->first()
->set('alt', 'Alt text for one')
->save();

$augmented = $this->fieldtype(['max_files' => 1])->shallowAugment(['foo/one.txt']);

$this->assertInstanceOf(AugmentedCollection::class, $augmented);
Expand All @@ -100,6 +123,7 @@ public function it_shallow_augments_to_a_single_asset_when_max_files_is_one()
'url' => '/assets/foo/one.txt',
'permalink' => 'http://localhost/assets/foo/one.txt',
'api_url' => 'http://localhost/api/assets/test/foo/one.txt',
'alt' => 'Alt text for one',
], $augmented->toArray());
}

Expand Down

0 comments on commit adfb667

Please sign in to comment.