1/** 2 * @file 3 * Auto-enables header row on newly inserted CKEditor 5 tables. 4 * 5 * Intercepts editor.execute('insertTable') to inject headingRows: 1, 6 * so every new table starts with a header row (<thead>/<th>). 7 */ 8(function () { 9 'use strict'; 10 11 // Track editors we've already patched to avoid double-patching. 12 const patched = new WeakSet(); 13 14 function patchEditor(editor) { 15 if (patched.has(editor)) { 16 return; 17 } 18 patched.add(editor); 19 20 const originalExecute = editor.execute.bind(editor); 21 editor.execute = function (commandName, ...args) { 22 if (commandName === 'insertTable') { 23 const options = args[0] || {}; 24 if (options.headingRows === undefined) { 25 options.headingRows = 1; 26 } 27 args[0] = options; 28 } 29 return originalExecute(commandName, ...args); 30 }; 31 } 32 33 // Use a MutationObserver to detect when CKEditor editables appear in the DOM 34 // and patch them as soon as their ckeditorInstance is available. 35 const observer = new MutationObserver(() => { 36 document.querySelectorAll('.ck-editor__editable').forEach((editable) => { 37 if (editable.ckeditorInstance) { 38 patchEditor(editable.ckeditorInstance); 39 } 40 }); 41 }); 42 43 observer.observe(document.body, { childList: true, subtree: true }); 44 45 // Also patch any editors already present. 46 document.querySelectorAll('.ck-editor__editable').forEach((editable) => { 47 if (editable.ckeditorInstance) { 48 patchEditor(editable.ckeditorInstance); 49 } 50 }); 51})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.