Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElementEditor-powered Live Preview #15112

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 23 additions & 4 deletions src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class ElementsController extends Controller
private bool $_addAnother;
private array $_visibleLayoutElements;
private ?string $_selectedTab = null;
private bool $_applyParams;
private bool $_prevalidate;

/**
Expand Down Expand Up @@ -125,6 +126,7 @@ public function beforeAction($action): bool
$this->_addAnother = (bool)$this->_param('addAnother');
$this->_visibleLayoutElements = $this->_param('visibleLayoutElements') ?? [];
$this->_selectedTab = $this->_param('selectedTab');
$this->_applyParams = (bool)$this->_param('applyParams', true);
$this->_prevalidate = (bool)$this->_param('prevalidate');

unset($this->_attributes['failMessage']);
Expand Down Expand Up @@ -967,11 +969,24 @@ private function _prepareEditor(
$behavior->contentHtml($contentHtml);
$behavior->metaSidebarHtml($sidebarHtml);

$this->view->registerJsWithVars(fn($settingsJs) => <<<JS
new Craft.ElementEditor($('#$containerId'), $settingsJs);
$settings = $jsSettingsFn($form);

$isSlideout = Craft::$app->getRequest()->getHeaders()->has('X-Craft-Container-Id');
if ($isSlideout) {
$this->view->registerJsWithVars(fn($settings) => <<<JS
$('#$containerId').data('elementEditorSettings', $settings);
JS, [
$jsSettingsFn($form),
]);
$settings,
]);
} else {
$this->view->registerJsWithVars(fn($settings) => <<<JS
new Craft.ElementEditor($('#$containerId'), $settings);
JS, [
$settings,
]);
}



// Give the element a chance to do things here too
$element->prepareEditScreen($response, $containerId);
Expand Down Expand Up @@ -2226,6 +2241,10 @@ private function _validateElementType(string $elementType): void
*/
private function _applyParamsToElement(ElementInterface $element): void
{
if (!$this->_applyParams) {
return;
}

if (isset($this->_enabledForSite)) {
if (is_array($this->_enabledForSite)) {
// Make sure they are allowed to edit all of the posted site IDs
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/web/assets/cp/src/css/_cp.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,7 @@ li.breadcrumb-toggle-wrapper {
#content :not(.meta) > .flex-fields,
#content > .flex-fields,
.so-content .flex-fields,
.lp-content .flex-fields,
.draghelper .flex-fields {
--row-gap: var(--xl);
display: flex;
Expand Down Expand Up @@ -1757,6 +1758,7 @@ li.breadcrumb-toggle-wrapper {
}

.so-content .flex-fields,
.lp-content .flex-fields,
.draghelper.drag-in-slideout .flex-fields {
& > :not(h2):not(hr):not(.line-break) {
&,
Expand Down
56 changes: 56 additions & 0 deletions src/web/assets/cp/src/css/_preview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
box-sizing: border-box;
position: relative;
z-index: 1;
height: 44px;

@supports (backdrop-filter: blur(10px)) {
& {
Expand All @@ -38,6 +39,49 @@
.checkmark-icon {
margin-bottom: 0;
}

.btn[data-icon='xmark'] {
@include margin-left(-12px);
&:not(:hover):not(:active):not([aria-expanded='true']) {
background-color: transparent;
}
}

.lp-toolbar {
min-width: 0;

.pane-tabs {
margin-left: 0 !important;
margin-right: 0 !important;

[role='tablist'] {
padding: 0 12px;

&.scrollable {
mask-image: linear-gradient(
to right,
rgba(0, 0, 0, 0),
rgba(0, 0, 0) 12px,
rgba(0, 0, 0) calc(100% - 12px),
rgba(0, 0, 0, 0) 100%
);
}

[role='tab'] {
background-color: transparent;
}
}

.menubtn:not(.action-btn) {
margin-left: 0;
margin-right: 0;

&:not(:empty):not(.btn-empty)::after {
@include margin-left(0px);
}
}
}
}
}
}

Expand All @@ -50,6 +94,7 @@
padding: 24px;
overflow: auto;
box-sizing: border-box;
position: relative;

& > .field {
&:last-child {
Expand All @@ -61,6 +106,17 @@
}
}

&:not(.loading) > .spinner {
display: none;
}

&.loading > .spinner {
position: absolute;
top: calc(50% - 17px);
left: calc(50% - 12px);
color: var(--ui-control-color);
}

.matrixblock > .fields > .flex-fields > .field > .status-badge {
@include left(calc(var(--m) * -1));
}
Expand Down
Loading
Loading