@rmdes/indiekit-endpoint-homepage 1.0.23 → 1.0.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-homepage",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "Homepage builder endpoint for Indiekit. Configure layout, sections, and sidebar widgets from the admin UI.",
5
5
  "keywords": [
6
6
  "indiekit",
@@ -532,10 +532,12 @@
532
532
  // Create a list item element for a section/widget/footer item
533
533
  function createItemElement(item, labels, removeFn, editFn) {
534
534
  var isCustom = (item.type === 'custom-html');
535
+ var isRecentPosts = (item.type === 'recent-posts');
536
+ var isEditable = isCustom || isRecentPosts;
535
537
  var container = document.createDocumentFragment();
536
538
 
537
539
  var li = document.createElement('li');
538
- li.className = 'hp-section-item' + (isCustom ? ' hp-section-item--has-edit' : '');
540
+ li.className = 'hp-section-item' + (isEditable ? ' hp-section-item--has-edit' : '');
539
541
  li.dataset.key = item._key;
540
542
  li.dataset.type = item.type;
541
543
 
@@ -564,12 +566,27 @@
564
566
  info.appendChild(preview);
565
567
  }
566
568
 
569
+ // Show config preview for recent-posts
570
+ if (isRecentPosts && item.config) {
571
+ var rpPreview = document.createElement('div');
572
+ rpPreview.className = 'hp-section-item__preview';
573
+ var parts = [];
574
+ if (item.config.maxItems) parts.push(item.config.maxItems + ' items');
575
+ if (item.config.excludeTypes && item.config.excludeTypes.length) {
576
+ parts.push('excluding: ' + item.config.excludeTypes.join(', '));
577
+ }
578
+ if (parts.length) {
579
+ rpPreview.textContent = parts.join(' · ');
580
+ info.appendChild(rpPreview);
581
+ }
582
+ }
583
+
567
584
  li.appendChild(info);
568
585
 
569
586
  var actions = document.createElement('div');
570
587
  actions.className = 'hp-section-item__actions';
571
588
 
572
- if (isCustom) {
589
+ if (isEditable) {
573
590
  var editBtn = document.createElement('button');
574
591
  editBtn.type = 'button';
575
592
  editBtn.className = 'button button--small';
@@ -657,6 +674,95 @@
657
674
  container.appendChild(details);
658
675
  }
659
676
 
677
+ // Edit panel for recent-posts
678
+ if (isRecentPosts) {
679
+ var rpDetails = document.createElement('details');
680
+ rpDetails.className = 'hp-edit-panel';
681
+ rpDetails.appendChild(document.createElement('summary'));
682
+
683
+ // Max items field
684
+ var maxField = document.createElement('div');
685
+ maxField.className = 'field';
686
+ var maxLabel = document.createElement('label');
687
+ maxLabel.className = 'field__label';
688
+ maxLabel.textContent = 'Max items';
689
+ var maxInput = document.createElement('input');
690
+ maxInput.className = 'field__input';
691
+ maxInput.type = 'number';
692
+ maxInput.min = '1';
693
+ maxInput.max = '50';
694
+ maxInput.value = (item.config && item.config.maxItems) || 5;
695
+ maxField.appendChild(maxLabel);
696
+ maxField.appendChild(maxInput);
697
+ rpDetails.appendChild(maxField);
698
+
699
+ // Exclude types checkboxes
700
+ var excludeField = document.createElement('div');
701
+ excludeField.className = 'field';
702
+ var excludeLabel = document.createElement('label');
703
+ excludeLabel.className = 'field__label';
704
+ excludeLabel.textContent = 'Exclude post types';
705
+ excludeField.appendChild(excludeLabel);
706
+
707
+ var currentExclude = (item.config && item.config.excludeTypes) || [];
708
+ var postTypes = [
709
+ { value: 'reply', label: 'Replies' },
710
+ { value: 'like', label: 'Likes' },
711
+ { value: 'bookmark', label: 'Bookmarks' },
712
+ { value: 'repost', label: 'Reposts' },
713
+ { value: 'photo', label: 'Photos' },
714
+ { value: 'article', label: 'Articles' },
715
+ { value: 'note', label: 'Notes' }
716
+ ];
717
+
718
+ var checkboxes = [];
719
+ postTypes.forEach(function(pt) {
720
+ var wrapper = document.createElement('label');
721
+ wrapper.style.cssText = 'display:inline-flex;align-items:center;gap:0.25rem;margin-right:0.75rem;font-size:0.875rem;';
722
+ var cb = document.createElement('input');
723
+ cb.type = 'checkbox';
724
+ cb.value = pt.value;
725
+ cb.checked = currentExclude.indexOf(pt.value) !== -1;
726
+ checkboxes.push(cb);
727
+ wrapper.appendChild(cb);
728
+ wrapper.appendChild(document.createTextNode(pt.label));
729
+ excludeField.appendChild(wrapper);
730
+ });
731
+ rpDetails.appendChild(excludeField);
732
+
733
+ // Save / Cancel buttons
734
+ var rpButtons = document.createElement('div');
735
+ rpButtons.className = 'hp-edit-panel__buttons';
736
+
737
+ var rpSaveBtn = document.createElement('button');
738
+ rpSaveBtn.type = 'button';
739
+ rpSaveBtn.className = 'button button--primary button--small';
740
+ rpSaveBtn.textContent = 'Apply';
741
+ rpSaveBtn.addEventListener('click', function() {
742
+ var excluded = [];
743
+ checkboxes.forEach(function(cb) {
744
+ if (cb.checked) excluded.push(cb.value);
745
+ });
746
+ editFn(item._key, Object.assign({}, item.config, {
747
+ maxItems: parseInt(maxInput.value, 10) || 5,
748
+ excludeTypes: excluded
749
+ }));
750
+ rpDetails.open = false;
751
+ });
752
+
753
+ var rpCancelBtn = document.createElement('button');
754
+ rpCancelBtn.type = 'button';
755
+ rpCancelBtn.className = 'button button--small button--secondary';
756
+ rpCancelBtn.textContent = 'Cancel';
757
+ rpCancelBtn.addEventListener('click', function() { rpDetails.open = false; });
758
+
759
+ rpButtons.appendChild(rpSaveBtn);
760
+ rpButtons.appendChild(rpCancelBtn);
761
+ rpDetails.appendChild(rpButtons);
762
+
763
+ container.appendChild(rpDetails);
764
+ }
765
+
660
766
  return container;
661
767
  }
662
768