Implement professional smart formatting with toggle logic and whitespace preservation
This commit is contained in:
@@ -29,12 +29,11 @@ export class ApiClient {
|
||||
}
|
||||
|
||||
|
||||
async createContent(content, type, htmlMarkup) {
|
||||
async createContent(content, htmlMarkup) {
|
||||
try {
|
||||
const payload = {
|
||||
html_markup: htmlMarkup, // Always send HTML markup - server extracts ID or generates new one
|
||||
html_content: content,
|
||||
type: type,
|
||||
file_path: this.getCurrentFilePath() // Always include file path for consistent ID generation
|
||||
};
|
||||
|
||||
@@ -49,7 +48,7 @@ export class ApiClient {
|
||||
|
||||
if (response.ok) {
|
||||
const result = await response.json();
|
||||
console.log(`✅ Content created: ${result.id} (${result.type})`);
|
||||
console.log(`✅ Content created: ${result.id}`);
|
||||
return result;
|
||||
} else {
|
||||
console.warn(`⚠️ Create failed (${response.status}): server will generate ID`);
|
||||
|
||||
@@ -131,10 +131,8 @@ export class InsertrEditor {
|
||||
result = await this.apiClient.updateContent(meta.contentId, contentValue);
|
||||
} else {
|
||||
// Create new content - server handles ID extraction/generation from markup
|
||||
const contentType = this.determineContentType(meta.element);
|
||||
result = await this.apiClient.createContent(
|
||||
contentValue,
|
||||
contentType,
|
||||
meta.htmlMarkup // Always send HTML markup - server is smart about ID handling
|
||||
);
|
||||
}
|
||||
@@ -142,7 +140,6 @@ export class InsertrEditor {
|
||||
if (result) {
|
||||
// Store the backend-generated/confirmed ID in the element
|
||||
meta.element.setAttribute('data-content-id', result.id);
|
||||
meta.element.setAttribute('data-content-type', result.type);
|
||||
console.log(`✅ Content saved: ${result.id}`, contentValue);
|
||||
} else {
|
||||
console.error('❌ Failed to save content to server');
|
||||
@@ -157,16 +154,7 @@ export class InsertrEditor {
|
||||
}
|
||||
}
|
||||
|
||||
determineContentType(element) {
|
||||
const tagName = element.tagName.toLowerCase();
|
||||
|
||||
if (tagName === 'a' || tagName === 'button') {
|
||||
return 'link';
|
||||
}
|
||||
|
||||
// ALL text elements use text content type
|
||||
return 'text';
|
||||
}
|
||||
|
||||
|
||||
handleCancel(meta) {
|
||||
console.log('❌ Edit cancelled:', meta.contentId);
|
||||
|
||||
@@ -9,29 +9,23 @@ export class InsertrCore {
|
||||
...options
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Find all enhanced elements on the page
|
||||
// Note: Container expansion is handled at build-time by the backend enhancer
|
||||
// Frontend should only find elements that already have .insertr class
|
||||
findEnhancedElements() {
|
||||
return document.querySelectorAll('.insertr');
|
||||
}
|
||||
|
||||
// Note: All container expansion logic removed - handled by backend enhancer
|
||||
// Frontend only works with elements that already have .insertr class
|
||||
|
||||
|
||||
// Get element metadata
|
||||
getElementMetadata(element) {
|
||||
const existingId = element.getAttribute('data-content-id');
|
||||
|
||||
// HTML-first approach: no content type needed, just HTML markup for ID generation
|
||||
|
||||
return {
|
||||
contentId: existingId, // null if new content, existing ID if updating
|
||||
contentId: existingId,
|
||||
element: element,
|
||||
htmlMarkup: element.outerHTML // Server will generate ID from this
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Get current file path from URL for consistent ID generation
|
||||
getCurrentFilePath() {
|
||||
const path = window.location.pathname;
|
||||
@@ -41,11 +35,10 @@ export class InsertrCore {
|
||||
// Remove leading slash: "/about.html" → "about.html"
|
||||
return path.replace(/^\//, '');
|
||||
}
|
||||
|
||||
|
||||
// Get all elements with their metadata
|
||||
// Note: Container expansion handled by backend - frontend finds enhanced elements only
|
||||
getAllElements() {
|
||||
const elements = this.findEnhancedElements();
|
||||
return Array.from(elements).map(el => this.getElementMetadata(el));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user