Skip to content

Commit 7aba923

Browse files
committed
feat: improve icon style injection and enhance line break conversion logic
1 parent da5ca9a commit 7aba923

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed

resources/dist/filament-markdown-editor-extended.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/index.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,15 @@ function patchComponent(component) {
215215
component.init = async function (...args) {
216216
await originalInit(...args);
217217

218-
applyPreviewSyntaxNormalizer(component);
218+
ensureIconStylesInjected(this);
219+
applyPreviewSyntaxNormalizer(this);
219220
};
220221

221222
component.__markdownEditorExtendedInitPatched = true;
223+
} else {
224+
ensureIconStylesInjected(component);
222225
}
223226

224-
ensureIconStylesInjected(component);
225-
226227
const originalGetToolbarButton = component.getToolbarButton.bind(component);
227228

228229
component.getToolbarButton = function (name) {
@@ -481,24 +482,17 @@ function convertLineBreaksToParagraphs(component) {
481482
let endPos;
482483

483484
if (hasSelection) {
484-
// Only convert selected text
485485
text = doc.getSelection();
486486
startPos = doc.getCursor('from');
487487
endPos = doc.getCursor('to');
488488
} else {
489-
// Convert entire document
490489
text = doc.getValue();
491490
startPos = { line: 0, ch: 0 };
492491
endPos = { line: doc.lineCount() - 1, ch: doc.getLine(doc.lineCount() - 1).length };
493492
}
494493

495-
// Convert single newlines to double newlines (paragraphs)
496-
// But preserve existing double newlines (already paragraphs)
497-
// And preserve markdown elements like headers, lists, code blocks, etc.
498494
const converted = text
499-
// First, normalize: replace 3+ newlines with exactly 2
500495
.replace(/\n{3,}/g, '\n\n')
501-
// Then convert single newlines to double (but not inside code blocks or after special chars)
502496
.replace(/([^\n])\n(?!\n)(?![-*+#>\d`|])/g, '$1\n\n');
503497

504498
if (hasSelection) {
@@ -544,9 +538,6 @@ if (! patchAlpineData()) {
544538
}
545539

546540
function openCuratorPanel(component) {
547-
// component is the Alpine data object (markdownEditorFormComponent instance)
548-
// It has: editor, state, $wire, $root, $refs, etc.
549-
550541
const $wire = component.$wire;
551542
const $root = component.$root;
552543

@@ -560,8 +551,6 @@ function openCuratorPanel(component) {
560551
return;
561552
}
562553

563-
// The key is the id attribute of the $root element (set in the blade template)
564-
// Format: typically something like "data.content"
565554
const key = $root.id;
566555

567556
if (!key) {
@@ -575,24 +564,17 @@ function openCuratorPanel(component) {
575564
}));
576565
}
577566

578-
// Listen for our custom markdown-curator-insert event
579567
document.addEventListener('markdown-curator-insert', (event) => {
580-
// Handle both wrapped and unwrapped event detail (Livewire can wrap in array)
581568
let detail = event.detail;
582569
if (Array.isArray(detail)) {
583570
detail = detail[0];
584571
}
585572

586573
const { key } = detail || {};
587574

588-
// The media structure from Curator is deeply nested:
589-
// detail.media = [{ statePath: '...', media: [actual items] }]
590-
// We need to extract the actual media items
591575
let media = detail?.media;
592576

593-
// Unwrap the nested structure
594577
if (Array.isArray(media) && media.length > 0) {
595-
// Check if it's the Curator structure with statePath and media
596578
if (media[0]?.media && Array.isArray(media[0].media)) {
597579
media = media[0].media;
598580
}
@@ -613,7 +595,6 @@ document.addEventListener('markdown-curator-insert', (event) => {
613595
return;
614596
}
615597

616-
// The key matches the id attribute of the markdown editor element
617598
const editorElement = document.getElementById(key);
618599

619600
if (!editorElement) {

0 commit comments

Comments
 (0)