@rmdes/indiekit-endpoint-homepage 1.0.2 → 1.0.3

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.2",
3
+ "version": "1.0.3",
4
4
  "description": "Homepage builder endpoint for Indiekit. Configure layout, sections, and sidebar widgets from the admin UI.",
5
5
  "keywords": [
6
6
  "indiekit",
@@ -94,6 +94,27 @@
94
94
  gap: var(--space-2xs, 0.25rem);
95
95
  }
96
96
 
97
+ .hp-section-item__drag {
98
+ cursor: grab;
99
+ color: var(--color-on-offset, #999);
100
+ padding: 0 0.25rem;
101
+ display: flex;
102
+ align-items: center;
103
+ }
104
+
105
+ .hp-section-item__drag:active {
106
+ cursor: grabbing;
107
+ }
108
+
109
+ .hp-section-item.sortable-ghost {
110
+ opacity: 0.4;
111
+ background: var(--color-primary-container, #e6f0ff);
112
+ }
113
+
114
+ .hp-section-item.sortable-chosen {
115
+ box-shadow: 0 2px 8px rgba(0,0,0,0.15);
116
+ }
117
+
97
118
  .hp-section-picker {
98
119
  margin-block-start: var(--space-m, 1rem);
99
120
  padding: var(--space-s, 0.75rem);
@@ -301,6 +322,19 @@
301
322
  li.className = 'hp-section-item';
302
323
  li.dataset.type = type;
303
324
 
325
+ const drag = document.createElement('span');
326
+ drag.className = 'hp-section-item__drag drag-handle';
327
+ drag.title = 'Drag to reorder';
328
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
329
+ svg.setAttribute('width', '16');
330
+ svg.setAttribute('height', '16');
331
+ svg.setAttribute('viewBox', '0 0 24 24');
332
+ svg.setAttribute('fill', 'currentColor');
333
+ var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
334
+ path.setAttribute('d', 'M8 6a2 2 0 1 1 0-4 2 2 0 0 1 0 4zm0 8a2 2 0 1 1 0-4 2 2 0 0 1 0 4zm0 8a2 2 0 1 1 0-4 2 2 0 0 1 0 4zm8-16a2 2 0 1 1 0-4 2 2 0 0 1 0 4zm0 8a2 2 0 1 1 0-4 2 2 0 0 1 0 4zm0 8a2 2 0 1 1 0-4 2 2 0 0 1 0 4z');
335
+ svg.appendChild(path);
336
+ drag.appendChild(svg);
337
+
304
338
  const info = document.createElement('div');
305
339
  info.className = 'hp-section-item__info';
306
340
 
@@ -325,6 +359,7 @@
325
359
  btn.addEventListener('click', function() { removeFn(this); });
326
360
 
327
361
  actions.appendChild(btn);
362
+ li.appendChild(drag);
328
363
  li.appendChild(info);
329
364
  li.appendChild(actions);
330
365
 
@@ -364,6 +399,7 @@
364
399
  sections, sectionLabels, removeSection,
365
400
  '{{ __("homepage.sections.empty") }}'
366
401
  );
402
+ initSortable();
367
403
  }
368
404
 
369
405
  function addWidget(id, label) {
@@ -385,6 +421,7 @@
385
421
  sidebar, widgetLabels, removeWidget,
386
422
  '{{ __("homepage.sidebar.empty") }}'
387
423
  );
424
+ initSortable();
388
425
  }
389
426
 
390
427
  // Layout selection
@@ -408,5 +445,51 @@
408
445
 
409
446
  document.querySelectorAll('input[name^="hero["]').forEach(function(i) { i.name = ''; });
410
447
  });
448
+
449
+ // Sync data arrays from DOM order after drag
450
+ function syncSectionsFromDom() {
451
+ var items = document.getElementById('sections-list').querySelectorAll('.hp-section-item');
452
+ sections = [];
453
+ items.forEach(function(item) {
454
+ sections.push({ type: item.dataset.type, config: {} });
455
+ });
456
+ document.getElementById('sections-json').value = JSON.stringify(sections);
457
+ }
458
+
459
+ function syncSidebarFromDom() {
460
+ var items = document.getElementById('widgets-list').querySelectorAll('.hp-section-item');
461
+ sidebar = [];
462
+ items.forEach(function(item) {
463
+ sidebar.push({ type: item.dataset.type, config: {} });
464
+ });
465
+ document.getElementById('sidebar-json').value = JSON.stringify(sidebar);
466
+ }
467
+
468
+ // Initialize SortableJS when loaded
469
+ function initSortable() {
470
+ if (typeof Sortable === 'undefined') return;
471
+
472
+ new Sortable(document.getElementById('sections-list'), {
473
+ handle: '.drag-handle',
474
+ animation: 150,
475
+ ghostClass: 'sortable-ghost',
476
+ chosenClass: 'sortable-chosen',
477
+ onEnd: syncSectionsFromDom
478
+ });
479
+
480
+ new Sortable(document.getElementById('widgets-list'), {
481
+ handle: '.drag-handle',
482
+ animation: 150,
483
+ ghostClass: 'sortable-ghost',
484
+ chosenClass: 'sortable-chosen',
485
+ onEnd: syncSidebarFromDom
486
+ });
487
+ }
488
+
489
+ // Load SortableJS from CDN
490
+ var sortableScript = document.createElement('script');
491
+ sortableScript.src = 'https://cdn.jsdelivr.net/npm/sortablejs@1.15.6/Sortable.min.js';
492
+ sortableScript.onload = initSortable;
493
+ document.head.appendChild(sortableScript);
411
494
  </script>
412
495
  {% endblock %}