{"version":3,"file":"trix_extensions_controller-pMzVjZ1O.js","sources":["../../../app/javascript/controllers/admin/trix_extensions_controller.js"],"sourcesContent":["import { Controller } from '@hotwired/stimulus'\n\nexport default class extends Controller {\n static targets = ['editor']\n\n connect() {\n console.log('Trix extensions controller connected')\n\n // Configure Trix headings if not already configured\n this.configureTrixHeadings()\n\n // Wait for Trix to be fully loaded\n document.addEventListener(\n 'trix-initialize',\n this.setupHeadingButtons.bind(this)\n )\n }\n\n // Configure Trix to support heading block attributes\n configureTrixHeadings() {\n if (!window.Trix) {\n console.error('Trix not found. Make sure it is properly loaded.')\n return\n }\n\n // Define heading block attributes if they don't exist\n if (!Trix.config.blockAttributes.heading1) {\n Trix.config.blockAttributes.heading1 = {\n tagName: 'h1',\n terminal: true,\n breakOnReturn: true,\n group: false,\n }\n }\n\n if (!Trix.config.blockAttributes.heading2) {\n Trix.config.blockAttributes.heading2 = {\n tagName: 'h2',\n terminal: true,\n breakOnReturn: true,\n group: false,\n }\n }\n\n if (!Trix.config.blockAttributes.heading3) {\n Trix.config.blockAttributes.heading3 = {\n tagName: 'h3',\n terminal: true,\n breakOnReturn: true,\n group: false,\n }\n }\n\n if (!Trix.config.blockAttributes.heading4) {\n Trix.config.blockAttributes.heading4 = {\n tagName: 'h4',\n terminal: true,\n breakOnReturn: true,\n group: false,\n }\n }\n }\n\n setupHeadingButtons(event) {\n // Try to find the toolbar associated with our editor\n const editor = event.target\n\n if (!editor || !editor.toolbarElement) {\n console.error('Could not find Trix editor or toolbar')\n return\n }\n\n const toolbar = editor.toolbarElement\n\n // First, hide the default heading button if it exists\n const defaultHeadingButton = toolbar.querySelector(\n '[data-trix-attribute=\"heading1\"]'\n )\n if (defaultHeadingButton) {\n // Instead of just hiding it, let's remove it completely to avoid confusion\n defaultHeadingButton.remove()\n console.log('Removed default heading button')\n }\n\n // Find the button group for block tools where headings should be\n const blockToolsGroup = toolbar.querySelector(\n '[data-trix-button-group=\"block-tools\"]'\n )\n if (!blockToolsGroup) {\n console.error('Could not find block tools button group')\n return\n }\n\n // Check if our custom heading buttons are already there\n const existingHeading1 = blockToolsGroup.querySelector(\n '[data-trix-attribute=\"heading1\"][data-custom-heading=\"true\"]'\n )\n\n // If our custom heading buttons exist, we're done\n if (existingHeading1) {\n console.log('Custom heading buttons already exist')\n return\n }\n\n // Remove any existing heading buttons that might be there but don't have our custom attribute\n blockToolsGroup\n .querySelectorAll('[data-trix-attribute^=\"heading\"]')\n .forEach((button) => {\n button.remove()\n })\n\n // Headings don't exist, add all of them in the correct order at the beginning of the group\n const headingButtons = [\n this.createHeadingButton(1),\n this.createHeadingButton(2),\n this.createHeadingButton(3),\n this.createHeadingButton(4),\n ]\n\n // Insert at the beginning of the block tools group in the correct order\n const firstButton = blockToolsGroup.firstChild\n headingButtons.forEach((button) => {\n blockToolsGroup.insertBefore(button, firstButton)\n })\n\n console.log('Added heading buttons to toolbar in correct order')\n }\n\n // Helper to create a heading button with clearly visible label\n createHeadingButton(level) {\n const button = document.createElement('button')\n button.type = 'button'\n\n // Remove the icon class to prevent it from hiding the text\n button.className = `trix-button`\n button.dataset.trixAttribute = `heading${level}`\n button.dataset.customHeading = 'true' // Mark as our custom button\n button.title = `Heading ${level}`\n button.tabIndex = '-1'\n\n // Create a styled span for the text\n const textSpan = document.createElement('span')\n textSpan.textContent = `H${level}`\n textSpan.style.fontWeight = 'bold'\n textSpan.style.fontSize = `${20 - level * 2}px`\n textSpan.style.display = 'inline-block'\n textSpan.style.lineHeight = '1'\n textSpan.style.textAlign = 'center'\n textSpan.style.minWidth = '24px'\n\n // Add the span to the button\n button.appendChild(textSpan)\n\n // Style the button itself\n button.style.padding = '2px 8px'\n button.style.margin = '0 2px'\n button.style.backgroundColor = 'transparent'\n button.style.position = 'relative'\n button.style.verticalAlign = 'middle'\n\n return button\n }\n}\n"],"names":["TrixExtensionsController","Controller","event","editor","toolbar","defaultHeadingButton","blockToolsGroup","button","headingButtons","firstButton","level","textSpan","__publicField"],"mappings":"4MAEe,MA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