Skip to content

Commit

Permalink
Merge branch '3.x' into patch-for-2300
Browse files Browse the repository at this point in the history
  • Loading branch information
mikerockett authored Aug 28, 2023
2 parents 1d9d673 + 35d0bbc commit a4bfc69
Show file tree
Hide file tree
Showing 24 changed files with 112 additions and 50 deletions.
8 changes: 4 additions & 4 deletions docs/content/1_docs/13_custom-cms-pages/1_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ return [
- Add a controller to handle the request

```php
// file: app/Http/Controllers/Admin/CustomPageController.php
// file: app/Http/Controllers/Twill/CustomPageController.php

namespace App\Http\Controllers\Admin;
namespace App\Http\Controllers\Twill;

use A17\Twill\Http\Controllers\Admin\Controller;

class CustomPageController extends Controller
{
public function show()
{
return view('admin.customPage');
return view('twill.customPage');
}
}
```

- And create the view

```php
// file: resources/views/admin/customPage.blade.php
// file: resources/views/twill/customPage.blade.php

@extends('twill::layouts.free')

Expand Down
4 changes: 2 additions & 2 deletions docs/content/1_docs/3_modules/12_nested-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ use A17\Twill\Services\Breadcrumbs\NestedBreadcrumbs;

class IssueArticleController extends BaseModuleController
{
protected $moduleName = 'issues.articles';
protected $modelName = 'IssueArticle';

protected function setUpController(): void
{
$this->setModuleName('issues.articles');
if (request('issue')) {
$this->setBreadcrumbs(
NestedBreadcrumbs::make()
->forParent(
parentModule: 'issues',
module: $this->modelName,
module: $this->moduleName,
activeParentId: request('issue'),
repository: \App\Repositories\IssueRepository::class
)
Expand Down
4 changes: 2 additions & 2 deletions docs/content/1_docs/3_modules/6_table-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ unpublished.

##### NestedData

`NestedData::make()`
`NestedData::make()->...`

This field requires no additional methods, it shows information about the nested models.
Renders the `field` using the relationship of the same name. It shows information and a link about the nested model.

##### Languages

Expand Down
15 changes: 14 additions & 1 deletion docs/content/1_docs/4_form-fields/01_input.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Input::make()
type="textarea"
:rows="3"
:translated="true"
direction="ltr"
/>
```

Expand All @@ -62,7 +63,8 @@ Input::make()
'note' => 'Hint message goes here',
'placeholder' => 'Placeholder goes here',
'type' => 'textarea',
'rows' => 3
'rows' => 3,
'direction' => 'ltr'
])
```

Expand All @@ -85,6 +87,7 @@ Input::make()
| readonly | Sets the field as readonly | boolean | false |
| default | Sets a default value if empty | string | |
| mask | Set a mask using the alpinejs mask plugin | string | |
| direction | Set custom input direction <small>(from `v3.1.0`)</small> | ltr<br/>rtl<br>auto | auto |

Specific options for the "number" type:

Expand Down Expand Up @@ -122,3 +125,13 @@ Schema::table('articles', function (Blueprint $table) {
```

When used in a [block](../5_block-editor), no migration is needed, as data contained in blocks, including componentBlocks, is stored in a separate table from the model, which is managed by Twill for you.

## Manually setting input direction

Introduced in `v3.1.0`

For certain types of input it maybe useful to manually set the direction to left-to-right (`ltr`) or right-to-left (`rtl`) depending upon the expected text input.

For example, maybe you have an Arabic translated page and need URL which mixes Arabic with an `ltr` domain name and TLD. In this case content entry maybe proving difficult for your CMS users with a `rtl` input; in which case you may find setting the direction to `ltr` beneficial.

You may also simply just need a single Hebrew text entry in an otherwise `ltr` form.
35 changes: 21 additions & 14 deletions docs/content/1_docs/4_form-fields/02_wysiwyg.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,21 @@ $wysiwygOptions = [
```


| Option | Description | Type/values | Default value |
|:---------------|:-------------------------------------------------------------------------------------------------------------------------|:-----------------|:--------------|
| name | Name of the field | string | |
| label | Label of the field | string | |
| type | Type of wysiwyg field | quill<br/>tiptap | tiptap |
| toolbarOptions | Array of options/tools that will be displayed in the editor | | See above |
| editSource | Displays a button to view source code | boolean | false |
| hideCounter | Hide the character counter displayed at the bottom | boolean | false |
| limitHeight | Limit the editor height from growing beyond the viewport | boolean | false |
| translated | Defines if the field is translatable | boolean | false |
| maxlength | Max character count of the field | integer | |
| note | Hint message displayed above the field | string | |
| placeholder | Text displayed as a placeholder in the field | string | |
| required | Displays an indicator that this field is required<br/>A backend validation rule is required to prevent users from saving | boolean | false |
| Option | Description | Type/values | Default value |
|:---------------|:-------------------------------------------------------------------------------------------------------------------------|:--------------------|:--------------|
| name | Name of the field | string | |
| label | Label of the field | string | |
| type | Type of wysiwyg field | quill<br/>tiptap | tiptap |
| toolbarOptions | Array of options/tools that will be displayed in the editor | | See above |
| editSource | Displays a button to view source code | boolean | false |
| hideCounter | Hide the character counter displayed at the bottom | boolean | false |
| limitHeight | Limit the editor height from growing beyond the viewport | boolean | false |
| translated | Defines if the field is translatable | boolean | false |
| maxlength | Max character count of the field | integer | |
| note | Hint message displayed above the field | string | |
| placeholder | Text displayed as a placeholder in the field | string | |
| required | Displays an indicator that this field is required<br/>A backend validation rule is required to prevent users from saving | boolean | false |
| direction | Set custom input direction <small>(from `v3.1.0`)</small> | ltr<br/>rtl<br>auto | auto |

Note that Quill outputs CSS classes in the HTML for certain toolbar modules (indent, font, align, etc.), and that the image module is not integrated with Twill's media library. It outputs the base64 representation of the uploaded image.
It is not a recommended way of using and storing images, prefer using one or multiple `medias` form fields or blocks fields for flexible content. This will give you greater control over your frontend output.
Expand Down Expand Up @@ -171,3 +172,9 @@ For regular fields on models you will have to manually call `parseInternalLinks`
```blade
{{ \A17\Twill\Facades\TwillUtil::parseInternalLinks($item->description) }}
```

## Manually setting input direction

Introduced in `v3.1.0`

For certain types of input it maybe useful to manually set the direction to left-to-right (`ltr`) or right-to-left (`rtl`) depending upon the expected text input; for example you may need a single Hebrew text entry in an otherwise `ltr` form.
8 changes: 5 additions & 3 deletions frontend/js/components/Previewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@
components: {
'a17-iframe': A17PreviewerFrame
},
props: ['breakpointsConfig'],
data: function () {
return {
loadedCurrent: false,
slipScreen: false,
activeBreakpoint: 1280,
lastActiveBreakpoint: 1280,
scrollPosition: 0,
breakpoints: [
breakpoints: this.breakpointsConfig || [
{
size: 1280,
name: 'preview-desktop'
Expand Down Expand Up @@ -115,11 +116,12 @@
methods: {
open: function (previewId = 0) {
const self = this
const desktopWidth = this.breakpoints.find(item => item.name === 'preview-desktop').size
// reset previewer state
this.loadedCurrent = false
this.activeBreakpoint = 1280
this.lastActiveBreakpoint = 1280
this.activeBreakpoint = desktopWidth || 1280
this.lastActiveBreakpoint = desktopWidth || 1280
function initPreview () {
if (self.$refs.overlay) self.$refs.overlay.open()
Expand Down
8 changes: 7 additions & 1 deletion frontend/js/components/dashboard/shortcutCreator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,19 @@
border-bottom: 1px solid $color__border;
}
.shortcutCreator .wrapper--reverse {
@include breakpoint('medium+') {
flex-flow: row-reverse;
}
}
.shortcutCreator__listing {
display: flex;
flex-grow: 1;
flex-flow: column nowrap;
@include breakpoint('small+') {
flex-flow: row nowrap;
flex-flow: row wrap;
}
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/js/mixins/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default {
type: String,
default: ''
},
direction: {
type: String,
default: 'auto'
},
name: {
default: ''
},
Expand Down
3 changes: 3 additions & 0 deletions frontend/js/mixins/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export default {
else return false
},
dirLocale: function () {
if (this.direction && this.direction !== 'auto') {
return this.direction;
}
return (this.isLocaleRTL ? 'rtl' : 'auto')
},
displayedLocale: function () {
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Models/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function input(string $name): mixed
return $this->content[$name] ?? null;
}

public function translatedInput(string $name, bool $forceLocale = null): mixed
public function translatedInput(string $name, string $forceLocale = null): mixed
{
$value = $this->content[$name] ?? null;

Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/Behaviors/HandleFieldsGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function handleFieldsGroups($fields)
$fields[$group] = null;
}

Arr::forget($fields, $groupFields);
$fields = array_filter($fields, fn($key) => !in_array($key, $groupFields), ARRAY_FILTER_USE_KEY);
}

return $fields;
Expand Down
1 change: 1 addition & 0 deletions src/Repositories/Behaviors/HandleMedias.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public function afterDuplicateHandleMedias(TwillModelContract $original, TwillMo
'crop_x' => $media->pivot->crop_x,
'crop_y' => $media->pivot->crop_y,
'metadatas' => $media->pivot->metadatas,
'locale' => $media->pivot->locale,
];

$newObject->medias()->attach($media->id, $newPushData);
Expand Down
11 changes: 7 additions & 4 deletions src/Services/Breadcrumbs/NestedBreadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class NestedBreadcrumbs extends Breadcrumbs
private int $activeParentId;
private string $titleKey;
private string $label;
private string $routePrefix = '';

public function parentLabel(string $parentLabel): self
{
Expand All @@ -26,13 +27,15 @@ public function forParent(
string $module,
int $activeParentId,
string $repository,
?string $titleKey = 'title'
?string $titleKey = 'title',
?string $routePrefix = '',
): self {
$this->module = $module;
$this->parentModule = $parentModule;
$this->parentRepository = $repository;
$this->activeParentId = $activeParentId;
$this->titleKey = $titleKey;
$this->routePrefix = $routePrefix;

if (!$this->parentLabel) {
$this->parentLabel(Str::title($parentModule));
Expand Down Expand Up @@ -61,16 +64,16 @@ public function toArray(): array
BreadcrumbItem::make()->label($this->parentLabel)
->displayOnForm()
->displayOnListing()
->url(moduleRoute($this->parentModule, '', 'index')),
->url(moduleRoute($this->parentModule, $this->routePrefix, 'index')),
BreadcrumbItem::make()->label($this->getActiveParentTitle())
->displayOnForm()
->displayOnListing()
->url(moduleRoute($this->parentModule, '', 'edit', $this->activeParentId)),
->url(moduleRoute($this->parentModule, $this->routePrefix, 'edit', $this->activeParentId)),
BreadcrumbItem::make()->label($this->label)
->displayOnListing(),
BreadcrumbItem::make()->label($this->label)
->displayOnForm()
->url(moduleRoute($this->module, '', 'index')),
->url(moduleRoute($this->module, $this->routePrefix, 'index')),
BreadcrumbItem::make()->label('Edit')
->displayOnForm(),
];
Expand Down
2 changes: 2 additions & 0 deletions src/Services/Forms/Fields/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use A17\Twill\Services\Forms\Fields\Traits\HasMin;
use A17\Twill\Services\Forms\Fields\Traits\HasOnChange;
use A17\Twill\Services\Forms\Fields\Traits\HasPlaceholder;
use A17\Twill\Services\Forms\Fields\Traits\HasDirection;
use A17\Twill\Services\Forms\Fields\Traits\IsTranslatable;

/**
Expand All @@ -19,6 +20,7 @@ class Input extends BaseFormField
use HasMax;
use HasMaxlength;
use HasPlaceholder;
use HasDirection;
use HasOnChange;

/**
Expand Down
18 changes: 18 additions & 0 deletions src/Services/Forms/Fields/Traits/HasDirection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace A17\Twill\Services\Forms\Fields\Traits;

trait HasDirection
{
protected ?string $direction = null;

/**
* Sets the direction of the field.
*/
public function direction(string $direction): static
{
$this->direction = $direction === 'ltr' || $direction === 'rtl' ? $direction : 'auto';

return $this;
}
}
2 changes: 2 additions & 0 deletions src/Services/Forms/Fields/Wysiwyg.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
use A17\Twill\Services\Forms\Fields\Traits\HasMaxlength;
use A17\Twill\Services\Forms\Fields\Traits\HasOnChange;
use A17\Twill\Services\Forms\Fields\Traits\HasPlaceholder;
use A17\Twill\Services\Forms\Fields\Traits\HasDirection;
use A17\Twill\Services\Forms\Fields\Traits\IsTranslatable;

class Wysiwyg extends BaseFormField
{
use IsTranslatable;
use HasMaxlength;
use HasPlaceholder;
use HasDirection;
use HasOnChange;

public bool $hideCounter = false;
Expand Down
7 changes: 0 additions & 7 deletions src/Services/Listings/Columns/NestedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@

class NestedData extends TableColumn
{
public static function make(): static
{
$item = parent::make();
$item->field('children');
return $item;
}

public function sortable(bool $sortable = true): static
{
if ($sortable && $this->sortFunction === null) {
Expand Down
1 change: 1 addition & 0 deletions src/View/Components/Fields/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function __construct(
// Component specific
public string $type = 'text',
public ?string $placeholder = '',
public ?string $direction = 'auto',
public ?int $maxlength = null,
public ?int $rows = null,
public ?string $ref = null,
Expand Down
1 change: 1 addition & 0 deletions src/View/Components/Fields/Wysiwyg.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function __construct(
// Component specific
public bool $hideCounter = false,
public ?string $placeholder = null,
public ?string $direction = 'auto',
public bool $editSource = false,
public ?array $toolbarOptions = null,
public ?int $maxlength = null,
Expand Down
Loading

0 comments on commit a4bfc69

Please sign in to comment.