cms-renderer 0.6.13 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib/renderer.js
CHANGED
|
@@ -474,7 +474,7 @@ function generateCmsOverlayScript(cmsParentOrigin) {
|
|
|
474
474
|
border-radius: 2px;
|
|
475
475
|
}
|
|
476
476
|
[data-cms-editable]:not([data-cms-block]):hover {
|
|
477
|
-
outline: 2px solid #
|
|
477
|
+
outline: 2px solid var(--component-accent, #A78BFA);
|
|
478
478
|
outline-offset: 2px;
|
|
479
479
|
}
|
|
480
480
|
#cms-overlay-root {
|
|
@@ -491,15 +491,38 @@ function generateCmsOverlayScript(cmsParentOrigin) {
|
|
|
491
491
|
}
|
|
492
492
|
.cms-block-outline {
|
|
493
493
|
position: fixed;
|
|
494
|
-
|
|
494
|
+
box-sizing: border-box;
|
|
495
|
+
border: 4px solid var(--component-accent, #A78BFA);
|
|
495
496
|
border-radius: 4px;
|
|
496
497
|
pointer-events: none;
|
|
497
498
|
z-index: 99997;
|
|
498
499
|
transition: all 0.15s ease;
|
|
499
500
|
}
|
|
500
501
|
.cms-block-outline.cms-outline-selected {
|
|
501
|
-
border-color: #
|
|
502
|
-
border-width:
|
|
502
|
+
border-color: var(--component-accent, #A78BFA);
|
|
503
|
+
border-width: 4px;
|
|
504
|
+
}
|
|
505
|
+
.cms-block-label {
|
|
506
|
+
position: absolute;
|
|
507
|
+
top: 0;
|
|
508
|
+
left: 0;
|
|
509
|
+
display: none;
|
|
510
|
+
max-width: 240px;
|
|
511
|
+
padding: 2px 8px;
|
|
512
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
513
|
+
font-size: 12px;
|
|
514
|
+
font-weight: 600;
|
|
515
|
+
line-height: 1.4;
|
|
516
|
+
color: #fff;
|
|
517
|
+
background: var(--component-accent, #A78BFA);
|
|
518
|
+
border-radius: 4px 4px 4px 0;
|
|
519
|
+
white-space: nowrap;
|
|
520
|
+
overflow: hidden;
|
|
521
|
+
text-overflow: ellipsis;
|
|
522
|
+
pointer-events: none;
|
|
523
|
+
}
|
|
524
|
+
.cms-block-label.cms-label-visible {
|
|
525
|
+
display: block;
|
|
503
526
|
}
|
|
504
527
|
.cms-block-cursor {
|
|
505
528
|
position: fixed;
|
|
@@ -664,15 +687,19 @@ function generateCmsOverlayScript(cmsParentOrigin) {
|
|
|
664
687
|
cursor.className = 'cms-block-cursor';
|
|
665
688
|
overlayRoot.appendChild(cursor);
|
|
666
689
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
690
|
+
function createOutline(extraClass) {
|
|
691
|
+
var el = document.createElement('div');
|
|
692
|
+
el.className = 'cms-block-outline' + (extraClass ? ' ' + extraClass : '');
|
|
693
|
+
el.style.display = 'none';
|
|
694
|
+
var label = document.createElement('span');
|
|
695
|
+
label.className = 'cms-block-label';
|
|
696
|
+
el.appendChild(label);
|
|
697
|
+
overlayRoot.appendChild(el);
|
|
698
|
+
return el;
|
|
699
|
+
}
|
|
671
700
|
|
|
672
|
-
var
|
|
673
|
-
selectedOutline
|
|
674
|
-
selectedOutline.style.display = 'none';
|
|
675
|
-
overlayRoot.appendChild(selectedOutline);
|
|
701
|
+
var outline = createOutline();
|
|
702
|
+
var selectedOutline = createOutline('cms-outline-selected');
|
|
676
703
|
|
|
677
704
|
var toolbar = document.createElement('div');
|
|
678
705
|
toolbar.className = 'cms-block-toolbar';
|
|
@@ -700,35 +727,19 @@ function generateCmsOverlayScript(cmsParentOrigin) {
|
|
|
700
727
|
var toolbarVisible = false;
|
|
701
728
|
var selectedBlockId = null;
|
|
702
729
|
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
function preserveEditParamsOnNavigation(e) {
|
|
719
|
-
if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
var anchor = e.target.closest('a[href]');
|
|
724
|
-
if (!anchor || (anchor.target && anchor.target !== '_self') || anchor.hasAttribute('download')) {
|
|
725
|
-
return;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
var href = anchor.getAttribute('href');
|
|
729
|
-
var decorated = decoratePreviewUrl(href);
|
|
730
|
-
if (decorated && decorated !== href) {
|
|
731
|
-
anchor.setAttribute('href', decorated);
|
|
730
|
+
// In edit mode we hijack every link/button activation. Following a link or
|
|
731
|
+
// firing a button's own handler makes inline editing on that element
|
|
732
|
+
// impossible (the click navigates away or triggers an action instead of
|
|
733
|
+
// placing the caret). We block the default action and stop the event from
|
|
734
|
+
// reaching the element's own listeners, while still letting our selection /
|
|
735
|
+
// edit routing run below.
|
|
736
|
+
function blockInteractiveActivation(e) {
|
|
737
|
+
var interactive = e.target.closest(
|
|
738
|
+
'a[href], button, [role="button"], input[type="submit"], input[type="button"], input[type="reset"]'
|
|
739
|
+
);
|
|
740
|
+
if (interactive) {
|
|
741
|
+
e.preventDefault();
|
|
742
|
+
e.stopPropagation();
|
|
732
743
|
}
|
|
733
744
|
}
|
|
734
745
|
|
|
@@ -763,9 +774,18 @@ function generateCmsOverlayScript(cmsParentOrigin) {
|
|
|
763
774
|
return -1;
|
|
764
775
|
}
|
|
765
776
|
|
|
777
|
+
function formatBlockType(type) {
|
|
778
|
+
if (!type) return 'Block';
|
|
779
|
+
return type
|
|
780
|
+
.replace(/[-_]+/g, ' ')
|
|
781
|
+
.replace(/\\b\\w/g, function(c) { return c.toUpperCase(); });
|
|
782
|
+
}
|
|
783
|
+
|
|
766
784
|
function updateOutline(el, outlineEl) {
|
|
785
|
+
var label = outlineEl.querySelector('.cms-block-label');
|
|
767
786
|
if (!el) {
|
|
768
787
|
outlineEl.style.display = 'none';
|
|
788
|
+
if (label) label.classList.remove('cms-label-visible');
|
|
769
789
|
return;
|
|
770
790
|
}
|
|
771
791
|
var rect = el.getBoundingClientRect();
|
|
@@ -774,6 +794,10 @@ function generateCmsOverlayScript(cmsParentOrigin) {
|
|
|
774
794
|
outlineEl.style.left = rect.left + 'px';
|
|
775
795
|
outlineEl.style.width = rect.width + 'px';
|
|
776
796
|
outlineEl.style.height = rect.height + 'px';
|
|
797
|
+
if (label) {
|
|
798
|
+
label.textContent = formatBlockType(el.getAttribute('data-block-type'));
|
|
799
|
+
label.classList.add('cms-label-visible');
|
|
800
|
+
}
|
|
777
801
|
}
|
|
778
802
|
|
|
779
803
|
function positionToolbar(x, y) {
|
|
@@ -850,17 +874,19 @@ function generateCmsOverlayScript(cmsParentOrigin) {
|
|
|
850
874
|
});
|
|
851
875
|
|
|
852
876
|
document.addEventListener('click', function(e) {
|
|
853
|
-
|
|
877
|
+
// The floating toolbar is interactive (and its buttons are real <button>s);
|
|
878
|
+
// bail out before any blocking so its own handlers run.
|
|
879
|
+
if (e.target.closest('[data-cms-toolbar]')) return;
|
|
854
880
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
881
|
+
blockInteractiveActivation(e);
|
|
882
|
+
|
|
883
|
+
if (toolbarVisible) {
|
|
884
|
+
var activeBlock = e.target.closest('[data-cms-block]');
|
|
885
|
+
if (!activeBlock || activeBlock.getAttribute('data-block-id') !== currentBlockId) {
|
|
858
886
|
hideToolbar();
|
|
859
887
|
}
|
|
860
888
|
}
|
|
861
889
|
|
|
862
|
-
if (e.target.closest('[data-cms-toolbar]')) return;
|
|
863
|
-
|
|
864
890
|
var editable = e.target.closest('[data-cms-editable]');
|
|
865
891
|
if (editable) {
|
|
866
892
|
postToParent({
|