Browse Source

Editor: sync MD on publish

imwald
Nuša Pukšič 1 week ago
parent
commit
a545e55470
  1. 34
      assets/controllers/editor/layout_controller.js
  2. 6
      assets/controllers/nostr/nostr_publish_controller.js
  3. 4
      assets/styles/editor-layout.css

34
assets/controllers/editor/layout_controller.js

@ -43,9 +43,30 @@ export default class extends Controller {
this.updatePreview().then(r => console.log('Preview updated after content change', r)); this.updatePreview().then(r => console.log('Preview updated after content change', r));
}); });
// Auto-sync content when Quill editor loses focus
this.setupQuillBlurSync();
this.setupAuthModal(); this.setupAuthModal();
} }
setupQuillBlurSync() {
// Wait for Quill to be available and set up blur event
const setupBlurListener = () => {
if (window.appQuill && window.appQuill.root) {
this.quillBlurHandler = () => {
console.log('[Editor] Quill lost focus, auto-syncing content');
this.syncContentBeforePublish();
};
window.appQuill.root.addEventListener('blur', this.quillBlurHandler);
console.log('[Editor] Quill blur sync listener set up');
} else {
// Retry after a short delay if Quill isn't ready yet
setTimeout(setupBlurListener, 100);
}
};
setupBlurListener();
}
setupAuthModal() { setupAuthModal() {
this.authModal = document.getElementById('auth-choice-modal'); this.authModal = document.getElementById('auth-choice-modal');
this.signerBtn = document.getElementById('proceed-with-signer'); this.signerBtn = document.getElementById('proceed-with-signer');
@ -303,6 +324,10 @@ export default class extends Controller {
if (this.autoSaveTimer) { if (this.autoSaveTimer) {
clearTimeout(this.autoSaveTimer); clearTimeout(this.autoSaveTimer);
} }
// Clean up Quill blur listener
if (this.quillBlurHandler && window.appQuill && window.appQuill.root) {
window.appQuill.root.removeEventListener('blur', this.quillBlurHandler);
}
} }
// --- Content Update Handlers --- // --- Content Update Handlers ---
@ -320,6 +345,15 @@ export default class extends Controller {
} }
// --- Editor Sync Helpers --- // --- Editor Sync Helpers ---
syncContentBeforePublish() {
// If the active source is Quill, convert delta to markdown and update the form field
if (this.state.active_source === 'quill' && this.state.content_delta) {
this.state.content_NMD = this.deltaToNMD(this.state.content_delta);
this.updateMarkdownEditor();
console.log('[Editor] Synced Quill content to markdown');
}
}
updateMarkdownEditor() { updateMarkdownEditor() {
// Set Markdown editor value from state.content_NMD // Set Markdown editor value from state.content_NMD
const markdownInput = this.element.querySelector('textarea[name="editor[content]"]'); const markdownInput = this.element.querySelector('textarea[name="editor[content]"]');

6
assets/controllers/nostr/nostr_publish_controller.js

@ -265,12 +265,6 @@ export default class extends Controller {
} }
} }
// Placeholder for the actual signer logic
async signWithSigner(event) {
// TODO: Implement the actual signer logic here
throw new Error('Signer signing flow is not yet implemented.');
}
// If a user provided a partial or custom event, make sure required keys exist and supplement from form // If a user provided a partial or custom event, make sure required keys exist and supplement from form
applyEventDefaults(event, formData, options = {}) { applyEventDefaults(event, formData, options = {}) {
const now = Math.floor(Date.now() / 1000); const now = Math.floor(Date.now() / 1000);

4
assets/styles/editor-layout.css

@ -1,7 +1,5 @@
@import "../vendor/prismjs/themes/prism.min.css"; /* Editor IDE-like layout styles */
/* Main container - takes full viewport */ /* Main container - takes full viewport */
main[data-controller="editor--layout"] { main.editor-layout {
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;

Loading…
Cancel
Save