import { Alignment, BlockQuote, Bold, ClassicEditor, ClipboardPipeline, Essentials, FontBackgroundColor, FontColor, FontFamily, FontSize, Heading, HorizontalLine, Indent, IndentBlock, Italic, InputTextView, Plugin, Paragraph, Strikethrough, Subscript, Superscript, Underline } from '/assets/js/vendor/ckeditor5/ckeditor5.js'; import { createTemplateSelectorLockController } from '/assets/js/slides/slide-form-template-lock.js'; (function () { var DEFAULT_FONT_SIZE = 32; var dataElement = document.getElementById('slide-editor-data'); if (!dataElement) { return; } var slideEditorData = {}; try { slideEditorData = JSON.parse(dataElement.getAttribute('data-json') || dataElement.textContent || '{}') || {}; } catch (_error) { slideEditorData = {}; } var templates = Array.isArray(slideEditorData.templates) ? slideEditorData.templates : []; var rssFeeds = Array.isArray(slideEditorData.rssFeeds) ? slideEditorData.rssFeeds : []; var apiSources = Array.isArray(slideEditorData.apiSources) ? slideEditorData.apiSources : []; var existingTemplateId = slideEditorData.existingTemplateId !== undefined ? slideEditorData.existingTemplateId : null; var existingContent = slideEditorData.existingContent || {}; var templateSelect = document.getElementById('template-select'); var templateFields = document.getElementById('template-fields'); var slideForm = document.getElementById('slide-form'); var slideEditorShell = document.querySelector('.slide-editor-shell'); var slideEditorSidebar = document.querySelector('.slide-editor-sidebar'); var slidePreviewMeta = document.getElementById('slide-preview-meta'); var slidePreviewStage = document.getElementById('slide-preview-stage'); var slidePreviewCanvas = document.getElementById('slide-preview-canvas'); var slidePreviewBackground = document.getElementById('slide-preview-background'); var slidePreviewEmpty = document.getElementById('slide-preview-empty'); var slidePreviewOverlay = document.getElementById('slide-preview-overlay'); var openPreviewPopupButton = document.getElementById('open-preview-popup'); var editorInstances = new Map(); var submitting = false; var previewRenderFrame = 0; var previewPopupWindow = null; var previewPopupRenderFrame = 0; var currentPreviewCanvasWidth = 0; var currentPreviewCanvasHeight = 0; var sidebarSyncFrame = 0; var sidebarTopOffset = 16; var templateSelectorLock = createTemplateSelectorLockController(templateSelect); class FontSizeInputUI extends Plugin { static get pluginName() { return 'FontSizeInputUI'; } init() { var editor = this.editor; var fontSizeCommand = editor.commands.get('fontSize'); var plugin = this; if (!fontSizeCommand) { return; } editor.ui.componentFactory.add('fontSizeInput', function (locale) { var view = new InputTextView(locale); view.extendTemplate({ attributes: { class: ['ck-font-size-input'] } }); view.set({ placeholder: 'Font size', ariaLabel: 'Font size' }); function getCurrentFontSizeValue() { var value = fontSizeCommand.value; if (value === null || value === undefined || value === '') { return String(DEFAULT_FONT_SIZE); } var parsed = Math.round(Number(String(value).replace(/[^0-9.]/g, ''))); return Number.isFinite(parsed) && parsed > 0 ? String(parsed) : ''; } function syncValue() { if (view.element && document.activeElement === view.element) { return; } view.value = getCurrentFontSizeValue(); } view.on('render', function () { if (!view.element) { return; } view.element.type = 'text'; view.element.inputMode = 'numeric'; view.element.autocomplete = 'off'; view.element.spellcheck = false; view.element.style.width = '3.5em'; syncValue(); }); function applyValue() { if (!view.element) { return; } var size = Math.max(1, Math.round(Number(view.element.value || 0))); if (!size) { return; } editor.execute('fontSize', { value: size + 'px' }); } view.on('input', applyValue); view.on('blur', applyValue); view.on('keydown', function (_eventInfo, domEvent) { if (domEvent.key === 'Enter') { domEvent.preventDefault(); if (view.element) { view.element.blur(); } } }); plugin.listenTo(editor.model.document.selection, 'change:range', syncValue); plugin.listenTo(fontSizeCommand, 'change:value', syncValue); syncValue(); return view; }); } } class ForcePlainTextPaste extends Plugin { static get pluginName() { return 'ForcePlainTextPaste'; } static get requires() { return [ClipboardPipeline]; } init() { var editor = this.editor; var clipboardPipeline = editor.plugins.get(ClipboardPipeline); this.listenTo(clipboardPipeline, 'inputTransformation', function (_event, data) { var plainText = data.dataTransfer.getData('text/plain'); data.content = editor.data.processor.toView(plainTextToHtml(plainText)); }, { priority: 'high' }); } } function escapeHtml(value) { return String(value ?? '') .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); } function plainTextToHtml(value) { var lines = String(value ?? '').replace(/\r\n?/g, '\n').split('\n'); var paragraphs = []; var currentParagraph = []; lines.forEach(function (line) { if (line === '') { if (currentParagraph.length) { paragraphs.push('
' + currentParagraph.join('
') + '
' + currentParagraph.join('
') + '