Skip to content

Commit b1e8893

Browse files
authored
Inspector and Toolbar refactoring (#247)
* feat: add local fallback for Alpine.js * fix: replaced hardcoded RGBA values with corresponding CSS variables * refactor: format CSS variable definitions for improved readability * refactor: update Alpine.js loading mechanism and adjust CSS variable values * refactor: update Alpine.js loading verification to use local fallback * refactor: streamline Alpine.js URL encoding for improved readability
1 parent 8c70652 commit b1e8893

17 files changed

Lines changed: 3304 additions & 194 deletions

File tree

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
/infection.json5 export-ignore
2020
/.gitignore export-ignore
2121
/.gitattributes export-ignore
22+
23+
# Vendored/minified frontend libraries: treat as binary to keep diffs readable
24+
src/view/frontend/web/js/lib/alpine.min.js binary

.github/workflows/functional-tests.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ jobs:
200200
201201
# Verify Alpine.js auto-loading in template
202202
echo "Verifying Alpine.js auto-loading for non-Hyvä themes:"
203-
if grep -q "jsdelivr.net/npm/alpinejs" "$INSPECTOR_TPL"; then
204-
echo "✓ Template includes Alpine.js CDN loading"
203+
if grep -q "getAlpineJsUrl" "$INSPECTOR_TPL"; then
204+
echo "✓ Template includes local Alpine.js fallback loading"
205205
else
206-
echo "✗ Template missing Alpine.js auto-loading"
206+
echo "✗ Template missing local Alpine.js fallback loading"
207207
exit 1
208208
fi
209209
@@ -214,6 +214,13 @@ jobs:
214214
exit 1
215215
fi
216216
217+
if grep -q "jsdelivr.net/npm/alpinejs" "$INSPECTOR_TPL"; then
218+
echo "✗ Template still references external Alpine.js CDN"
219+
exit 1
220+
else
221+
echo "✓ Template no longer relies on external Alpine.js CDN"
222+
fi
223+
217224
# Test Luma theme (non-Hyvä)
218225
echo "Testing Inspector with Luma theme (non-Hyvä):"
219226
bin/magento config:set design/theme/theme_id 4 # Luma theme ID

src/Block/Inspector.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ public function getToolbarJsUrl(): string
101101
return $this->getViewFileUrl('OpenForgeProject_MageForge::js/toolbar.js');
102102
}
103103

104+
/**
105+
* Get local Alpine.js fallback URL
106+
*
107+
* @return string
108+
*/
109+
public function getAlpineJsUrl(): string
110+
{
111+
return $this->getViewFileUrl('OpenForgeProject_MageForge::js/lib/alpine.min.js');
112+
}
113+
104114
/**
105115
* Whether button labels should be displayed in the toolbar
106116
*

src/etc/frontend/csp_whitelist.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/view/frontend/templates/inspector.phtml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ declare(strict_types=1);
88
* Initializes the Alpine.js inspector component.
99
* The floating button and info badge are created dynamically via JavaScript.
1010
*
11-
* Note: Loads Alpine.js from CDN if not already available (for non-Hyvä themes like Luma)
11+
* Note: Loads bundled Alpine.js locally as fallback if not already available
12+
* (e.g. for non-Hyvä themes like Luma). No external CDN is used.
1213
*
1314
* @var \OpenForgeProject\MageForge\Block\Inspector $block
1415
*/
@@ -17,47 +18,46 @@ declare(strict_types=1);
1718
<link rel="stylesheet" type="text/css" href="<?= $escaper->escapeUrl($block->getToolbarCssUrl()) ?>" />
1819
<link rel="stylesheet" type="text/css" href="<?= $escaper->escapeUrl($block->getCssUrl()) ?>" />
1920

20-
<!-- Alpine.js Bootstrap (load only if not already present) -->
21+
<!-- Alpine.js Bootstrap (load local fallback only if not already present) -->
2122
<?php
2223

24+
$alpineJsUrl = json_encode($block->getAlpineJsUrl(), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
2325
$alpineBootstrap = <<<JS
2426
(function() {
2527
'use strict';
2628
27-
function loadAlpineFromCDN() {
29+
function loadAlpineLocally() {
2830
// Check if Alpine.js is already loaded (Hyvä themes) to avoid conflicts
2931
if (typeof Alpine !== 'undefined') {
3032
console.log('[MageForge Inspector] Alpine.js already loaded');
3133
return;
3234
}
3335
34-
console.log('[MageForge Inspector] Loading Alpine.js from CDN');
36+
console.log('[MageForge Inspector] Loading bundled Alpine.js');
3537
3638
var alpineScript = document.createElement('script');
37-
alpineScript.src = 'https://cdn.jsdelivr.net/npm/alpinejs@3.15.11/dist/cdn.min.js';
38-
alpineScript.integrity = 'sha256-vuumPQiVb2T6Bg9rainIejQb8Gn7lslFnCIsb9QuWK4=';
39-
alpineScript.crossOrigin = 'anonymous';
39+
alpineScript.src = {$alpineJsUrl};
4040
alpineScript.onload = function() {
4141
console.log('[MageForge Inspector] Alpine.js loaded successfully');
4242
};
4343
alpineScript.onerror = function() {
44-
console.error('[MageForge Inspector] Failed to load Alpine.js');
44+
console.error('[MageForge Inspector] Failed to load bundled Alpine.js');
4545
};
4646
4747
document.head.appendChild(alpineScript);
4848
}
4949
5050
// Use a short microtask delay after DOMContentLoaded so that all deferred
5151
// and module scripts (including Hyvä's Alpine bundle) have had a chance to
52-
// run before we decide to load Alpine from CDN.
52+
// run before we decide to load the local Alpine fallback.
5353
if (document.readyState === 'loading') {
5454
document.addEventListener('DOMContentLoaded', function() {
5555
// setTimeout(0) yields to the script queue, giving defer/module
56-
// scripts priority over this CDN fallback.
57-
setTimeout(loadAlpineFromCDN, 0);
56+
// scripts priority over this local fallback.
57+
setTimeout(loadAlpineLocally, 0);
5858
});
5959
} else {
60-
setTimeout(loadAlpineFromCDN, 0);
60+
setTimeout(loadAlpineLocally, 0);
6161
}
6262
})();
6363
JS;

src/view/frontend/web/css/audits/tab-order.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
align-items: center;
5353
justify-content: center;
5454
transform: translate(-50%, -50%);
55-
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
55+
box-shadow: 0 1px 4px rgba(var(--mageforge-color-black-rgb), 0.4);
5656
}
5757

5858
.mageforge-tab-order-badge--negative {

0 commit comments

Comments
 (0)