cms-renderer 0.6.10 → 0.6.12
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/block-renderer.d.ts +27 -8
- package/dist/lib/block-renderer.js +445 -109
- package/dist/lib/block-renderer.js.map +1 -1
- package/dist/lib/block-toolbar.js +18 -4
- package/dist/lib/block-toolbar.js.map +1 -1
- package/dist/lib/client-editable-block.d.ts +5 -2
- package/dist/lib/client-editable-block.js +71 -15
- package/dist/lib/client-editable-block.js.map +1 -1
- package/dist/lib/custom-schemas.js.map +1 -1
- package/dist/lib/markdown-utils.js +19 -2
- package/dist/lib/markdown-utils.js.map +1 -1
- package/dist/lib/parametric-route.d.ts +7 -3
- package/dist/lib/parametric-route.js +447 -135
- package/dist/lib/parametric-route.js.map +1 -1
- package/dist/lib/renderer.js +447 -135
- package/dist/lib/renderer.js.map +1 -1
- package/package.json +3 -2
package/dist/lib/renderer.js
CHANGED
|
@@ -453,7 +453,427 @@ var LanguageSchema = z9.object({
|
|
|
453
453
|
|
|
454
454
|
// lib/block-renderer.tsx
|
|
455
455
|
import React from "react";
|
|
456
|
-
|
|
456
|
+
|
|
457
|
+
// lib/cms-overlay-script.ts
|
|
458
|
+
function generateCmsOverlayScript(cmsParentOrigin) {
|
|
459
|
+
return `
|
|
460
|
+
(function() {
|
|
461
|
+
if (window.__cmsOverlayInitialized) return;
|
|
462
|
+
window.__cmsOverlayInitialized = true;
|
|
463
|
+
|
|
464
|
+
var CMS_PARENT_ORIGIN = ${JSON.stringify(cmsParentOrigin)};
|
|
465
|
+
|
|
466
|
+
var style = document.createElement('style');
|
|
467
|
+
style.setAttribute('data-cms-overlay', '');
|
|
468
|
+
style.textContent = \`
|
|
469
|
+
[data-cms-block],
|
|
470
|
+
[data-cms-editable] {
|
|
471
|
+
cursor: pointer;
|
|
472
|
+
}
|
|
473
|
+
[data-cms-editable] {
|
|
474
|
+
border-radius: 2px;
|
|
475
|
+
}
|
|
476
|
+
[data-cms-editable]:not([data-cms-block]):hover {
|
|
477
|
+
outline: 2px solid #3b82f6;
|
|
478
|
+
outline-offset: 2px;
|
|
479
|
+
}
|
|
480
|
+
#cms-overlay-root {
|
|
481
|
+
position: fixed;
|
|
482
|
+
top: 0;
|
|
483
|
+
left: 0;
|
|
484
|
+
width: 0;
|
|
485
|
+
height: 0;
|
|
486
|
+
pointer-events: none;
|
|
487
|
+
z-index: 99998;
|
|
488
|
+
}
|
|
489
|
+
#cms-overlay-root > * {
|
|
490
|
+
pointer-events: none;
|
|
491
|
+
}
|
|
492
|
+
.cms-block-outline {
|
|
493
|
+
position: fixed;
|
|
494
|
+
border: 2px solid #3b82f6;
|
|
495
|
+
border-radius: 4px;
|
|
496
|
+
pointer-events: none;
|
|
497
|
+
z-index: 99997;
|
|
498
|
+
transition: all 0.15s ease;
|
|
499
|
+
}
|
|
500
|
+
.cms-block-outline.cms-outline-selected {
|
|
501
|
+
border-color: #2563eb;
|
|
502
|
+
border-width: 3px;
|
|
503
|
+
}
|
|
504
|
+
.cms-block-cursor {
|
|
505
|
+
position: fixed;
|
|
506
|
+
width: 22px;
|
|
507
|
+
height: 22px;
|
|
508
|
+
background: radial-gradient(circle, #fff 5px, #000 5px);
|
|
509
|
+
border-radius: 50%;
|
|
510
|
+
pointer-events: none;
|
|
511
|
+
z-index: 99999;
|
|
512
|
+
transform: translate(-50%, -50%);
|
|
513
|
+
opacity: 0;
|
|
514
|
+
transition: opacity 0.1s ease;
|
|
515
|
+
}
|
|
516
|
+
.cms-block-cursor.cms-cursor-visible {
|
|
517
|
+
opacity: 1;
|
|
518
|
+
}
|
|
519
|
+
.cms-block-toolbar {
|
|
520
|
+
position: fixed;
|
|
521
|
+
display: flex;
|
|
522
|
+
gap: 4px;
|
|
523
|
+
background: #1f2937;
|
|
524
|
+
border-radius: 6px;
|
|
525
|
+
padding: 4px;
|
|
526
|
+
box-shadow: 0 4px 12px rgba(0,0,0,0.25);
|
|
527
|
+
z-index: 99999;
|
|
528
|
+
pointer-events: none;
|
|
529
|
+
opacity: 0;
|
|
530
|
+
transform: scale(0.9) translateY(4px);
|
|
531
|
+
transition: opacity 0.15s ease, transform 0.15s ease;
|
|
532
|
+
}
|
|
533
|
+
.cms-block-toolbar.cms-toolbar-visible {
|
|
534
|
+
opacity: 1;
|
|
535
|
+
transform: scale(1) translateY(0);
|
|
536
|
+
pointer-events: auto;
|
|
537
|
+
}
|
|
538
|
+
.cms-block-toolbar button {
|
|
539
|
+
display: flex;
|
|
540
|
+
align-items: center;
|
|
541
|
+
justify-content: center;
|
|
542
|
+
width: 28px;
|
|
543
|
+
height: 28px;
|
|
544
|
+
border: none;
|
|
545
|
+
background: transparent;
|
|
546
|
+
color: #9ca3af;
|
|
547
|
+
border-radius: 4px;
|
|
548
|
+
cursor: pointer;
|
|
549
|
+
transition: background 0.15s ease, color 0.15s ease;
|
|
550
|
+
}
|
|
551
|
+
.cms-block-toolbar button:hover {
|
|
552
|
+
background: #374151;
|
|
553
|
+
color: #fff;
|
|
554
|
+
}
|
|
555
|
+
.cms-block-toolbar button.delete:hover {
|
|
556
|
+
background: #dc2626;
|
|
557
|
+
color: #fff;
|
|
558
|
+
}
|
|
559
|
+
.cms-block-toolbar button:disabled {
|
|
560
|
+
opacity: 0.4;
|
|
561
|
+
cursor: not-allowed;
|
|
562
|
+
}
|
|
563
|
+
.cms-block-toolbar button:disabled:hover {
|
|
564
|
+
background: transparent;
|
|
565
|
+
color: #9ca3af;
|
|
566
|
+
}
|
|
567
|
+
.cms-block-toolbar svg {
|
|
568
|
+
width: 16px;
|
|
569
|
+
height: 16px;
|
|
570
|
+
}
|
|
571
|
+
\`;
|
|
572
|
+
document.head.appendChild(style);
|
|
573
|
+
|
|
574
|
+
function stampBlockElements() {
|
|
575
|
+
var sentinels = document.querySelectorAll('[data-cms-sentinel]');
|
|
576
|
+
sentinels.forEach(function(sentinel) {
|
|
577
|
+
var blockEl = sentinel.nextElementSibling;
|
|
578
|
+
if (!blockEl) return;
|
|
579
|
+
|
|
580
|
+
var blockId = sentinel.getAttribute('data-block-id');
|
|
581
|
+
var blockType = sentinel.getAttribute('data-block-type');
|
|
582
|
+
|
|
583
|
+
blockEl.setAttribute('data-cms-block', '');
|
|
584
|
+
blockEl.setAttribute('data-block-id', blockId);
|
|
585
|
+
blockEl.setAttribute('data-block-type', blockType);
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
stampBlockElements();
|
|
590
|
+
|
|
591
|
+
var stampObserver = new MutationObserver(function(mutations) {
|
|
592
|
+
var needsStamp = mutations.some(function(m) {
|
|
593
|
+
return m.addedNodes.length > 0;
|
|
594
|
+
});
|
|
595
|
+
if (needsStamp) stampBlockElements();
|
|
596
|
+
});
|
|
597
|
+
stampObserver.observe(document.body, { childList: true, subtree: true });
|
|
598
|
+
|
|
599
|
+
var overlayRoot = document.createElement('div');
|
|
600
|
+
overlayRoot.id = 'cms-overlay-root';
|
|
601
|
+
document.body.appendChild(overlayRoot);
|
|
602
|
+
|
|
603
|
+
var cursor = document.createElement('div');
|
|
604
|
+
cursor.className = 'cms-block-cursor';
|
|
605
|
+
overlayRoot.appendChild(cursor);
|
|
606
|
+
|
|
607
|
+
var outline = document.createElement('div');
|
|
608
|
+
outline.className = 'cms-block-outline';
|
|
609
|
+
outline.style.display = 'none';
|
|
610
|
+
overlayRoot.appendChild(outline);
|
|
611
|
+
|
|
612
|
+
var selectedOutline = document.createElement('div');
|
|
613
|
+
selectedOutline.className = 'cms-block-outline cms-outline-selected';
|
|
614
|
+
selectedOutline.style.display = 'none';
|
|
615
|
+
overlayRoot.appendChild(selectedOutline);
|
|
616
|
+
|
|
617
|
+
var toolbar = document.createElement('div');
|
|
618
|
+
toolbar.className = 'cms-block-toolbar';
|
|
619
|
+
toolbar.setAttribute('data-cms-toolbar', '');
|
|
620
|
+
toolbar.innerHTML = \`
|
|
621
|
+
<button class="move-up" title="Move up">
|
|
622
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
623
|
+
<path d="M18 15l-6-6-6 6"/>
|
|
624
|
+
</svg>
|
|
625
|
+
</button>
|
|
626
|
+
<button class="move-down" title="Move down">
|
|
627
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
628
|
+
<path d="M6 9l6 6 6-6"/>
|
|
629
|
+
</svg>
|
|
630
|
+
</button>
|
|
631
|
+
<button class="delete" title="Delete">
|
|
632
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
633
|
+
<path d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
|
|
634
|
+
</svg>
|
|
635
|
+
</button>
|
|
636
|
+
\`;
|
|
637
|
+
overlayRoot.appendChild(toolbar);
|
|
638
|
+
|
|
639
|
+
var currentBlockId = null;
|
|
640
|
+
var toolbarVisible = false;
|
|
641
|
+
var selectedBlockId = null;
|
|
642
|
+
|
|
643
|
+
function decoratePreviewUrl(rawHref) {
|
|
644
|
+
if (!rawHref) return rawHref;
|
|
645
|
+
try {
|
|
646
|
+
var url = new URL(rawHref, window.location.href);
|
|
647
|
+
if (url.origin !== window.location.origin) return rawHref;
|
|
648
|
+
url.searchParams.set('edit_mode', 'true');
|
|
649
|
+
if (CMS_PARENT_ORIGIN) {
|
|
650
|
+
url.searchParams.set('cms_parent_origin', CMS_PARENT_ORIGIN);
|
|
651
|
+
}
|
|
652
|
+
return url.toString();
|
|
653
|
+
} catch (_) {
|
|
654
|
+
return rawHref;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function preserveEditParamsOnNavigation(e) {
|
|
659
|
+
if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
var anchor = e.target.closest('a[href]');
|
|
664
|
+
if (!anchor || (anchor.target && anchor.target !== '_self') || anchor.hasAttribute('download')) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
var href = anchor.getAttribute('href');
|
|
669
|
+
var decorated = decoratePreviewUrl(href);
|
|
670
|
+
if (decorated && decorated !== href) {
|
|
671
|
+
anchor.setAttribute('href', decorated);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
function postToParent(message) {
|
|
676
|
+
if (!CMS_PARENT_ORIGIN || !window.parent || window.parent === window) {
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
window.parent.postMessage(message, CMS_PARENT_ORIGIN);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function sendReadySignal() {
|
|
683
|
+
postToParent({ type: 'cms-preview-ready' });
|
|
684
|
+
}
|
|
685
|
+
sendReadySignal();
|
|
686
|
+
// The preview iframe can execute before the admin listener is attached.
|
|
687
|
+
setTimeout(sendReadySignal, 500);
|
|
688
|
+
setTimeout(sendReadySignal, 1500);
|
|
689
|
+
|
|
690
|
+
function getBlockElement(blockId) {
|
|
691
|
+
return document.querySelector('[data-block-id="' + blockId + '"]');
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function getAllBlocks() {
|
|
695
|
+
return Array.from(document.querySelectorAll('[data-cms-block]'));
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function getBlockIndex(blockId) {
|
|
699
|
+
var blocks = getAllBlocks();
|
|
700
|
+
for (var i = 0; i < blocks.length; i++) {
|
|
701
|
+
if (blocks[i].getAttribute('data-block-id') === blockId) return i;
|
|
702
|
+
}
|
|
703
|
+
return -1;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
function updateOutline(el, outlineEl) {
|
|
707
|
+
if (!el) {
|
|
708
|
+
outlineEl.style.display = 'none';
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
var rect = el.getBoundingClientRect();
|
|
712
|
+
outlineEl.style.display = 'block';
|
|
713
|
+
outlineEl.style.top = rect.top + 'px';
|
|
714
|
+
outlineEl.style.left = rect.left + 'px';
|
|
715
|
+
outlineEl.style.width = rect.width + 'px';
|
|
716
|
+
outlineEl.style.height = rect.height + 'px';
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
function positionToolbar(x, y) {
|
|
720
|
+
var rect = toolbar.getBoundingClientRect();
|
|
721
|
+
var top = Math.max(4, y - rect.height - 12);
|
|
722
|
+
var left = Math.max(4, Math.min(x - rect.width / 2, window.innerWidth - rect.width - 4));
|
|
723
|
+
toolbar.style.top = top + 'px';
|
|
724
|
+
toolbar.style.left = left + 'px';
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function showToolbar(x, y, blockId) {
|
|
728
|
+
currentBlockId = blockId;
|
|
729
|
+
toolbarVisible = true;
|
|
730
|
+
positionToolbar(x, y);
|
|
731
|
+
toolbar.classList.add('cms-toolbar-visible');
|
|
732
|
+
|
|
733
|
+
var index = getBlockIndex(blockId);
|
|
734
|
+
var total = getAllBlocks().length;
|
|
735
|
+
toolbar.querySelector('.move-up').disabled = index <= 0;
|
|
736
|
+
toolbar.querySelector('.move-down').disabled = index >= total - 1;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function hideToolbar() {
|
|
740
|
+
toolbarVisible = false;
|
|
741
|
+
toolbar.classList.remove('cms-toolbar-visible');
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function showCursor(x, y) {
|
|
745
|
+
cursor.style.top = y + 'px';
|
|
746
|
+
cursor.style.left = x + 'px';
|
|
747
|
+
cursor.classList.add('cms-cursor-visible');
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function hideCursor() {
|
|
751
|
+
cursor.classList.remove('cms-cursor-visible');
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
document.addEventListener('mouseover', function(e) {
|
|
755
|
+
if (toolbarVisible) return;
|
|
756
|
+
var block = e.target.closest('[data-cms-block]');
|
|
757
|
+
if (block) {
|
|
758
|
+
updateOutline(block, outline);
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
document.addEventListener('mouseout', function(e) {
|
|
763
|
+
var block = e.target.closest('[data-cms-block]');
|
|
764
|
+
var related = e.relatedTarget ? e.relatedTarget.closest('[data-cms-block]') : null;
|
|
765
|
+
if (block && block !== related) {
|
|
766
|
+
outline.style.display = 'none';
|
|
767
|
+
hideCursor();
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
|
|
771
|
+
document.addEventListener('mousemove', function(e) {
|
|
772
|
+
if (toolbarVisible) return;
|
|
773
|
+
var block = e.target.closest('[data-cms-block]');
|
|
774
|
+
if (block) {
|
|
775
|
+
showCursor(e.clientX, e.clientY);
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
document.addEventListener('contextmenu', function(e) {
|
|
780
|
+
if (e.target.closest('[data-cms-toolbar]')) return;
|
|
781
|
+
var block = e.target.closest('[data-cms-block]');
|
|
782
|
+
if (block) {
|
|
783
|
+
if (toolbarVisible) return;
|
|
784
|
+
e.preventDefault();
|
|
785
|
+
hideCursor();
|
|
786
|
+
outline.style.display = 'none';
|
|
787
|
+
var blockId = block.getAttribute('data-block-id');
|
|
788
|
+
showToolbar(e.clientX, e.clientY, blockId);
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
|
|
792
|
+
document.addEventListener('click', function(e) {
|
|
793
|
+
preserveEditParamsOnNavigation(e);
|
|
794
|
+
|
|
795
|
+
if (toolbarVisible && !e.target.closest('[data-cms-toolbar]')) {
|
|
796
|
+
var block = e.target.closest('[data-cms-block]');
|
|
797
|
+
if (!block || block.getAttribute('data-block-id') !== currentBlockId) {
|
|
798
|
+
hideToolbar();
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
if (e.target.closest('[data-cms-toolbar]')) return;
|
|
803
|
+
|
|
804
|
+
var editable = e.target.closest('[data-cms-editable]');
|
|
805
|
+
if (editable) {
|
|
806
|
+
postToParent({
|
|
807
|
+
type: 'cms-editable-click',
|
|
808
|
+
blockId: editable.getAttribute('data-block-id'),
|
|
809
|
+
blockType: editable.getAttribute('data-block-type'),
|
|
810
|
+
contentPath: editable.getAttribute('data-content-path')
|
|
811
|
+
});
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
var block = e.target.closest('[data-cms-block]');
|
|
816
|
+
if (block) {
|
|
817
|
+
postToParent({
|
|
818
|
+
type: 'cms-editable-click',
|
|
819
|
+
blockId: block.getAttribute('data-block-id'),
|
|
820
|
+
blockType: block.getAttribute('data-block-type'),
|
|
821
|
+
contentPath: null
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
}, true);
|
|
825
|
+
|
|
826
|
+
toolbar.querySelector('.move-up').addEventListener('click', function() {
|
|
827
|
+
if (!currentBlockId) return;
|
|
828
|
+
postToParent({ type: 'cms-block-action', action: 'move-up', blockId: currentBlockId });
|
|
829
|
+
hideToolbar();
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
toolbar.querySelector('.move-down').addEventListener('click', function() {
|
|
833
|
+
if (!currentBlockId) return;
|
|
834
|
+
postToParent({ type: 'cms-block-action', action: 'move-down', blockId: currentBlockId });
|
|
835
|
+
hideToolbar();
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
toolbar.querySelector('.delete').addEventListener('click', function() {
|
|
839
|
+
if (!currentBlockId) return;
|
|
840
|
+
postToParent({ type: 'cms-block-action', action: 'delete', blockId: currentBlockId });
|
|
841
|
+
hideToolbar();
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
window.addEventListener('scroll', function() {
|
|
845
|
+
hideCursor();
|
|
846
|
+
hideToolbar();
|
|
847
|
+
if (selectedBlockId) {
|
|
848
|
+
var el = getBlockElement(selectedBlockId);
|
|
849
|
+
updateOutline(el, selectedOutline);
|
|
850
|
+
}
|
|
851
|
+
}, { passive: true, capture: true });
|
|
852
|
+
|
|
853
|
+
window.addEventListener('resize', function() {
|
|
854
|
+
if (selectedBlockId) {
|
|
855
|
+
var el = getBlockElement(selectedBlockId);
|
|
856
|
+
updateOutline(el, selectedOutline);
|
|
857
|
+
}
|
|
858
|
+
}, { passive: true });
|
|
859
|
+
|
|
860
|
+
window.addEventListener('message', function(e) {
|
|
861
|
+
if (CMS_PARENT_ORIGIN && e.origin !== CMS_PARENT_ORIGIN) return;
|
|
862
|
+
if (e.source !== window.parent) return;
|
|
863
|
+
|
|
864
|
+
if (e.data && e.data.type === 'cms-select-block') {
|
|
865
|
+
selectedBlockId = e.data.blockId || null;
|
|
866
|
+
if (selectedBlockId) {
|
|
867
|
+
var el = getBlockElement(selectedBlockId);
|
|
868
|
+
updateOutline(el, selectedOutline);
|
|
869
|
+
} else {
|
|
870
|
+
selectedOutline.style.display = 'none';
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
})();
|
|
875
|
+
`;
|
|
876
|
+
}
|
|
457
877
|
|
|
458
878
|
// lib/cms-post-message.ts
|
|
459
879
|
var CMS_PARENT_ORIGIN_PARAM = "cms_parent_origin";
|
|
@@ -511,137 +931,19 @@ function getCmsParentTargetOrigin(preferredCmsUrl, explicitParentOrigin) {
|
|
|
511
931
|
|
|
512
932
|
// lib/block-renderer.tsx
|
|
513
933
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
514
|
-
function extractContentValues(content, basePath = []) {
|
|
515
|
-
const map = /* @__PURE__ */ new Map();
|
|
516
|
-
function walk(obj, path) {
|
|
517
|
-
if (typeof obj === "string" && obj.trim() !== "") {
|
|
518
|
-
const contentPath = path.join(".");
|
|
519
|
-
const existing = map.get(obj) || [];
|
|
520
|
-
existing.push({ contentPath, value: obj });
|
|
521
|
-
map.set(obj, existing);
|
|
522
|
-
} else if (Array.isArray(obj)) {
|
|
523
|
-
for (let index = 0; index < obj.length; index++) {
|
|
524
|
-
walk(obj[index], [...path, String(index)]);
|
|
525
|
-
}
|
|
526
|
-
} else if (obj && typeof obj === "object") {
|
|
527
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
528
|
-
walk(value, [...path, key]);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
walk(content, basePath);
|
|
533
|
-
return map;
|
|
534
|
-
}
|
|
535
934
|
function CmsEditableInit({
|
|
536
935
|
cmsUrl,
|
|
537
936
|
cmsParentOrigin
|
|
538
937
|
}) {
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
cursor: pointer;
|
|
546
|
-
border-radius: 2px;
|
|
547
|
-
}
|
|
548
|
-
[data-cms-editable]:hover {
|
|
549
|
-
outline: 2px solid #3b82f6;
|
|
550
|
-
outline-offset: 2px;
|
|
551
|
-
}
|
|
552
|
-
.cms-block-toolbar {
|
|
553
|
-
position: fixed;
|
|
554
|
-
display: flex;
|
|
555
|
-
gap: 4px;
|
|
556
|
-
background: #1f2937;
|
|
557
|
-
border-radius: 6px;
|
|
558
|
-
padding: 4px;
|
|
559
|
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
|
560
|
-
transition: opacity 0.15s ease;
|
|
561
|
-
z-index: 99999;
|
|
562
|
-
pointer-events: auto;
|
|
563
|
-
}
|
|
564
|
-
.cms-block-toolbar button {
|
|
565
|
-
display: flex;
|
|
566
|
-
align-items: center;
|
|
567
|
-
justify-content: center;
|
|
568
|
-
width: 28px;
|
|
569
|
-
height: 28px;
|
|
570
|
-
border: none;
|
|
571
|
-
background: transparent;
|
|
572
|
-
color: #9ca3af;
|
|
573
|
-
border-radius: 4px;
|
|
574
|
-
cursor: pointer;
|
|
575
|
-
transition: background 0.15s ease, color 0.15s ease;
|
|
576
|
-
}
|
|
577
|
-
.cms-block-toolbar button:hover {
|
|
578
|
-
background: #374151;
|
|
579
|
-
color: #fff;
|
|
580
|
-
}
|
|
581
|
-
.cms-block-toolbar button.delete:hover {
|
|
582
|
-
background: #dc2626;
|
|
583
|
-
color: #fff;
|
|
584
|
-
}
|
|
585
|
-
.cms-block-toolbar button:disabled {
|
|
586
|
-
opacity: 0.4;
|
|
587
|
-
cursor: not-allowed;
|
|
588
|
-
}
|
|
589
|
-
.cms-block-toolbar button:disabled:hover {
|
|
590
|
-
background: transparent;
|
|
591
|
-
color: #9ca3af;
|
|
592
|
-
}
|
|
593
|
-
.cms-block-toolbar svg {
|
|
594
|
-
width: 16px;
|
|
595
|
-
height: 16px;
|
|
596
|
-
}
|
|
597
|
-
` }),
|
|
598
|
-
/* @__PURE__ */ jsx(
|
|
599
|
-
"script",
|
|
600
|
-
{
|
|
601
|
-
dangerouslySetInnerHTML: {
|
|
602
|
-
__html: `
|
|
603
|
-
(function() {
|
|
604
|
-
var cmsParentOrigin = ${cmsParentOriginJson};
|
|
605
|
-
if (!window.__cmsEditableInitialized) {
|
|
606
|
-
window.__cmsEditableInitialized = true;
|
|
607
|
-
|
|
608
|
-
document.addEventListener('click', function(e) {
|
|
609
|
-
if (e.target.closest('.cms-block-toolbar')) return;
|
|
610
|
-
|
|
611
|
-
var editableTarget = e.target.closest('[data-cms-editable]');
|
|
612
|
-
if (editableTarget) {
|
|
613
|
-
var message = {
|
|
614
|
-
type: 'cms-editable-click',
|
|
615
|
-
blockId: editableTarget.getAttribute('data-block-id'),
|
|
616
|
-
blockType: editableTarget.getAttribute('data-block-type'),
|
|
617
|
-
contentPath: editableTarget.getAttribute('data-content-path')
|
|
618
|
-
};
|
|
619
|
-
if (cmsParentOrigin && window.parent && window.parent !== window) {
|
|
620
|
-
window.parent.postMessage(message, cmsParentOrigin);
|
|
621
|
-
}
|
|
622
|
-
return;
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
var blockTarget = e.target.closest('[data-cms-block]');
|
|
626
|
-
if (blockTarget) {
|
|
627
|
-
var message = {
|
|
628
|
-
type: 'cms-editable-click',
|
|
629
|
-
blockId: blockTarget.getAttribute('data-block-id'),
|
|
630
|
-
blockType: blockTarget.getAttribute('data-block-type'),
|
|
631
|
-
contentPath: null
|
|
632
|
-
};
|
|
633
|
-
if (cmsParentOrigin && window.parent && window.parent !== window) {
|
|
634
|
-
window.parent.postMessage(message, cmsParentOrigin);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
})();
|
|
640
|
-
`
|
|
641
|
-
}
|
|
938
|
+
const targetOrigin = getCmsParentTargetOrigin(cmsUrl, cmsParentOrigin) ?? "";
|
|
939
|
+
return /* @__PURE__ */ jsx(
|
|
940
|
+
"script",
|
|
941
|
+
{
|
|
942
|
+
dangerouslySetInnerHTML: {
|
|
943
|
+
__html: generateCmsOverlayScript(targetOrigin)
|
|
642
944
|
}
|
|
643
|
-
|
|
644
|
-
|
|
945
|
+
}
|
|
946
|
+
);
|
|
645
947
|
}
|
|
646
948
|
function pathMatchesPattern(path, pattern) {
|
|
647
949
|
const pathSegs = path.split("/").filter(Boolean);
|
|
@@ -692,9 +994,19 @@ function BlockRenderer({
|
|
|
692
994
|
if (disableEditable) {
|
|
693
995
|
return component;
|
|
694
996
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
997
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
998
|
+
/* @__PURE__ */ jsx(
|
|
999
|
+
"span",
|
|
1000
|
+
{
|
|
1001
|
+
"data-cms-sentinel": "",
|
|
1002
|
+
"data-block-id": block.id,
|
|
1003
|
+
"data-block-type": block.type,
|
|
1004
|
+
style: { display: "none" },
|
|
1005
|
+
"aria-hidden": "true"
|
|
1006
|
+
}
|
|
1007
|
+
),
|
|
1008
|
+
component
|
|
1009
|
+
] });
|
|
698
1010
|
}
|
|
699
1011
|
|
|
700
1012
|
// lib/parametric-route.tsx
|
|
@@ -724,11 +1036,11 @@ async function renderParametricRoute({
|
|
|
724
1036
|
websiteId: providedWebsiteId
|
|
725
1037
|
}) {
|
|
726
1038
|
const websiteId = getWebsiteId(providedWebsiteId);
|
|
727
|
-
const { slug } = await params;
|
|
728
|
-
const resolvedSearchParams = await searchParams;
|
|
1039
|
+
const { slug } = "then" in params ? await params : params;
|
|
1040
|
+
const resolvedSearchParams = searchParams && "then" in searchParams ? await searchParams : searchParams;
|
|
729
1041
|
let aiPreviewIndex = null;
|
|
730
1042
|
const aiPreviewParam = resolvedSearchParams?.ai_preview;
|
|
731
|
-
if (aiPreviewParam) {
|
|
1043
|
+
if (aiPreviewParam && typeof aiPreviewParam !== "boolean") {
|
|
732
1044
|
const paramValue = Array.isArray(aiPreviewParam) ? aiPreviewParam[0] : aiPreviewParam;
|
|
733
1045
|
if (paramValue) {
|
|
734
1046
|
const parsed = parseInt(paramValue, 10);
|
|
@@ -738,9 +1050,9 @@ async function renderParametricRoute({
|
|
|
738
1050
|
}
|
|
739
1051
|
}
|
|
740
1052
|
const editModeParam = resolvedSearchParams?.edit_mode;
|
|
741
|
-
const editMode = editModeParam === "true" || editModeParam === "1";
|
|
1053
|
+
const editMode = editModeParam === true || editModeParam === "true" || editModeParam === "1";
|
|
742
1054
|
const cmsParentOriginParam = resolvedSearchParams?.cms_parent_origin;
|
|
743
|
-
const cmsParentOrigin = Array.isArray(cmsParentOriginParam) ? cmsParentOriginParam[0] : cmsParentOriginParam;
|
|
1055
|
+
const cmsParentOrigin = typeof cmsParentOriginParam === "boolean" ? void 0 : Array.isArray(cmsParentOriginParam) ? cmsParentOriginParam[0] : cmsParentOriginParam;
|
|
744
1056
|
const rawPath = `/${slug.join("/")}`;
|
|
745
1057
|
const path = normalizePath(rawPath);
|
|
746
1058
|
if (/\.[a-zA-Z0-9]+$/.test(path)) {
|