-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
425 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\actions; | ||
|
||
class GetIcons | ||
{ | ||
public function handle() | ||
{ | ||
$iconPath = \Craft::getAlias('@templates/icons/'); | ||
$icons = glob($iconPath.'*.svg'); | ||
|
||
return collect($icons) | ||
->map(fn ($path) => [ | ||
'path' => str_replace($iconPath, '', $path), | ||
'name' => ucfirst(pathinfo($path, PATHINFO_FILENAME)), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\actions; | ||
|
||
use craft\base\FieldInterface; | ||
use markhuot\keystone\base\InlineEditData; | ||
use markhuot\keystone\models\Component; | ||
|
||
class NormalizeFieldDataForComponent | ||
{ | ||
public function __construct( | ||
protected Component $component | ||
) { } | ||
|
||
public function handle(mixed $value, string $handle) | ||
{ | ||
// Get the field from the component type | ||
$field = $this->component->getType()->getField($handle); | ||
|
||
// $field may be null if the field has been deleted from the twig code | ||
// but still remains in the database. | ||
// If possible normalize the data so the DB stored ID gets turned in to | ||
// a Query object, for example. | ||
$value = $field?->normalizeValue($value) ?? $value; | ||
|
||
if ($field?->getBehavior('inlineEdit')) { | ||
if ($field->isEditableInPreview()) { | ||
return new InlineEditData($this->component, $handle, $value); | ||
} | ||
} | ||
|
||
// @TODO add in logic to return a custom class here | ||
// the custom class will be responsible for rendering the | ||
// value in normal situations or a live editor in | ||
// live preview situations. | ||
// We'll monkey patch on a behavior to the PlainText field | ||
// type to make this possible | ||
// if ($this->getType()->getHandle() === 'site/components/tab' && $handle === 'description') { | ||
// return 'foo'; | ||
// } | ||
|
||
return $value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\attributes; | ||
|
||
use Illuminate\Support\Collection; | ||
use markhuot\keystone\base\Attribute; | ||
|
||
class Alignment extends Attribute | ||
{ | ||
public function __construct( | ||
protected ?array $value = [] | ||
) { | ||
} | ||
|
||
public function getInputHtml(): string | ||
{ | ||
return \Craft::$app->getView()->renderTemplate('keystone/styles/alignment', [ | ||
'name' => get_class($this), | ||
'value' => $this->value, | ||
]); | ||
} | ||
|
||
public function getCssRules(): Collection | ||
{ | ||
return collect($this->value) | ||
|
||
// re-map everything to proper CSS rules | ||
->mapWithKeys(fn ($value, $key) => match ($key) { | ||
default => [$key => $value], | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\attributes; | ||
|
||
use Illuminate\Support\Collection; | ||
use markhuot\keystone\base\Attribute; | ||
|
||
class Grid extends Attribute | ||
{ | ||
public function __construct( | ||
protected ?array $value = [] | ||
) { | ||
} | ||
|
||
public function getInputHtml(): string | ||
{ | ||
return \Craft::$app->getView()->renderTemplate('keystone/styles/grid', [ | ||
'name' => get_class($this), | ||
'value' => $this->value, | ||
]); | ||
} | ||
|
||
public function getCssRules(): Collection | ||
{ | ||
return collect($this->value) | ||
->mapWithKeys(fn ($value, $key) => match($key) { | ||
'grid-template-columns' => [$key => 'repeat(' . $value . ', minmax(0, 1fr))'], | ||
default => [$key => $value], | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\base; | ||
|
||
use craft\web\View; | ||
use markhuot\keystone\models\Component; | ||
|
||
class InlineEditData | ||
{ | ||
public function __construct( | ||
protected Component $component, | ||
protected string $handle, | ||
protected string $value | ||
) { } | ||
|
||
public function __toString() | ||
{ | ||
return \Craft::$app->getView()->renderTemplate('keystone/inline-edit', [ | ||
'component' => $this->component, | ||
'handle' => $this->handle, | ||
'value' => $this->value, | ||
], View::TEMPLATE_MODE_CP); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\behaviors; | ||
|
||
use yii\base\Behavior; | ||
|
||
class InlineEditBehavior extends Behavior | ||
{ | ||
protected bool $editableInPreview = false; | ||
|
||
public function setEditableInPreview(bool $editable=true) | ||
{ | ||
$this->editableInPreview = $editable; | ||
} | ||
|
||
public function isEditableInPreview() | ||
{ | ||
return $this->editableInPreview; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\listeners; | ||
|
||
use craft\events\DefineBehaviorsEvent; | ||
use markhuot\keystone\behaviors\InlineEditBehavior; | ||
|
||
class AttachInlineEditBehavior | ||
{ | ||
public function handle(DefineBehaviorsEvent $event): void | ||
{ | ||
$event->behaviors['inlineEdit'] = InlineEditBehavior::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace markhuot\keystone\listeners; | ||
|
||
use Craft; | ||
use markhuot\keystone\behaviors\BodyParamObjectBehavior; | ||
use markhuot\keystone\behaviors\CssRuleBehavior; | ||
|
||
class AttachPerRequestBehaviors | ||
{ | ||
public function handle(): void | ||
{ | ||
Craft::$app->getRequest()->attachBehaviors(['bodyParamObject' => BodyParamObjectBehavior::class]); | ||
|
||
Craft::$app->getView()->attachBehaviors(['cssRules' => CssRuleBehavior::class]); | ||
Craft::$app->getView()->clearCssRules(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.