feat: add custom CSS save system with dual-editor interface
All checks were successful
Deploy / Build and Deploy to Production (push) Successful in 16s

Implement complete custom CSS management system:
- Separate base CSS (readonly) and custom CSS (editable)
- Save custom CSS to Kirby backend per narrative
- Visual save button with state indicators (dirty/saving/success/error)
- CSRF-protected API endpoint for CSS operations
- Dual-editor StylesheetViewer (base + custom with edit mode toggle)
- Auto-format custom CSS with Prettier on edit mode exit

Backend changes:
- Add web2print Kirby plugin with POST/GET routes
- Add customCss field to narrative blueprint
- Add CSRF token meta tag in header
- Include customCss and modified timestamps in JSON template
- Install code-editor plugin for Kirby panel

Frontend changes:
- Refactor stylesheet store with baseCss/customCss refs
- Make content a computed property (baseCss + customCss)
- Add helper methods: replaceBlock, replaceInCustomCss, setCustomCss
- Update all components to use new store API
- Create SaveButton component with FAB design
- Redesign StylesheetViewer with collapsable sections
- Initialize store from narrative data on app mount

File changes:
- Rename stylesheet.css → stylesheet.print.css
- Update all references to new filename

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
isUnknown 2026-01-09 13:39:25 +01:00
parent 4d1183d1af
commit 0f46618066
32 changed files with 1207 additions and 89 deletions

37
src/utils/kirby-auth.js Normal file
View file

@ -0,0 +1,37 @@
/**
* Kirby Authentication Utilities
*
* Helper functions for authentication and CSRF token management
*/
/**
* Get CSRF token from meta tag
* @returns {string|null} CSRF token or null if not found
*/
export function getCsrfToken() {
// Check for meta tag (added by header.php when user is logged in)
const metaTag = document.querySelector('meta[name="csrf"]');
if (metaTag) {
return metaTag.getAttribute('content');
}
// Alternatively, could be in a cookie
const cookies = document.cookie.split(';');
for (let cookie of cookies) {
const [name, value] = cookie.trim().split('=');
if (name === 'kirby_csrf') {
return decodeURIComponent(value);
}
}
return null;
}
/**
* Check if user is authenticated (has Kirby session)
* @returns {boolean} True if authenticated, false otherwise
*/
export function isAuthenticated() {
// Check for kirby session cookie
return document.cookie.includes('kirby_session');
}