From 34616a1ce1f6bc7469121b8bdb03e666ccf887d1 Mon Sep 17 00:00:00 2001 From: Thomas Skerbis Date: Fri, 3 Jul 2026 15:05:11 +0200 Subject: [PATCH 01/16] 9.2.5 --- CHANGELOG.md | 12 +++++++ docs/05_wrapper.md | 18 ++++++++++- fragments/mform/mform_wrapper.php | 9 +++++- .../MFormFlexRepeaterRenderer.php | 32 ++++++++++++++++--- lib/MForm/Parser/MFormParser.php | 12 +++++++ package.yml | 2 +- 6 files changed, 77 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e1e7247..ed1eced2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # MForm - REDAXO Addon für Modul-Input-Formulare +## Version 9.2.5 + +### Behoben + +- **Row/Column-Grundverhalten vereinheitlicht (klassischer Parser + Flex-Repeater)** - `addColumnElement()` wird jetzt in allen relevanten Renderpfaden konsistent in `row`-Gruppen geführt. Damit ist kein manueller HTML-Workaround mit `addHtml('
')` mehr nötig. +- **Modal-Wrapper auf Bootstrap-Row ausgerichtet** - Der Modal-Button-Wrapper rendert jetzt konsistent als `row form-group` (klassischer Parser und Flex-Repeater), damit `col-*`-Spalten erwartungsgemäß funktionieren. + +### Neu + +- **Optionale Row-Klassen für Auto-Column-Gruppen** - Für automatisch erzeugte Column-Row-Wrapper können jetzt zusätzliche Klassen per `data-group-column-row-class` (Alias: `data-group-row-class`) gesetzt werden. +- **Optionale Row-Klassen für Modal-Wrapper** - Zusätzliche Klassen für den Modal-Row-Wrapper sind jetzt per `data-modal-row-class` (Alias: `data-group-row-class`) möglich. + ## Version 9.2.4 ### Entfernt diff --git a/docs/05_wrapper.md b/docs/05_wrapper.md index b690e335..13134ac1 100644 --- a/docs/05_wrapper.md +++ b/docs/05_wrapper.md @@ -165,6 +165,17 @@ $mform = MForm::factory() echo $mform->show(); ``` +Hinweis zur Kompatibilität: + +- `addColumnElement()` wird auch im Flex-Repeater-Kontext automatisch zu einer `row`-Gruppe zusammengefasst. Ein zusätzlicher manueller HTML-Workaround mit `addHtml('
')` ist nicht nötig. +- Optional kann die Row-Klasse für die automatisch erzeugte Spaltengruppe pro Column-Element erweitert werden: + +```php +->addColumnElement(6, $field, ['data-group-column-row-class' => 'g-5']) +``` + +Alias (gleiches Verhalten): `data-group-row-class`. + ## Inline-Elemente Stellt Inline-Elemente dar, die sich in einer Zeile nebeneinander anordnen. @@ -255,6 +266,11 @@ Hinweise: | `$align` | `string` | `'left'` | Button-Ausrichtung: `'left'`, `'center'` oder `'right'` | | `$attributes` | `array` | `[]` | Zusätzliche HTML-Attribute für den Button-Wrapper | +Zusätzliche optionale Attribute für den Modal-Button-Wrapper: + +- `data-modal-row-class`: Zusätzliche Klassen für den äußeren `row form-group`-Wrapper. +- `data-group-row-class`: Alias zu `data-modal-row-class`. + ```php 'Klein', 'py-4' => 'Mittel', ], ['label' => 'Abstand']) - , 'btn-default', 'center') + , 'btn-default', 'center', ['data-modal-row-class' => 'g-5']) // Hilfe-Dialog rechts, btn-info ->addModalElement('Hilfe', MForm::factory() diff --git a/fragments/mform/mform_wrapper.php b/fragments/mform/mform_wrapper.php index ecf09906..b2d9ef6a 100644 --- a/fragments/mform/mform_wrapper.php +++ b/fragments/mform/mform_wrapper.php @@ -83,15 +83,22 @@ $btnClass = 'btn ' . ($this->getVar('class') ?: 'btn-default'); // extract alignment from rendered attributes string (data-modal-align="left|center|right") $modalAlignRaw = ''; + $modalRowClass = ''; if (preg_match('/data-modal-align="([^"]*?)"/', (string) $this->getVar('attributes'), $_alignM)) { $modalAlignRaw = $_alignM[1]; } + if (preg_match('/data-modal-row-class="([^"]*?)"/', (string) $this->getVar('attributes'), $_rowM)) { + $modalRowClass = trim((string) $_rowM[1]); + } + if (preg_match('/data-group-row-class="([^"]*?)"/', (string) $this->getVar('attributes'), $_groupRowM)) { + $modalRowClass = trim($modalRowClass . ' ' . (string) $_groupRowM[1]); + } $modalAlignClass = match ($modalAlignRaw) { 'center' => 'text-center', 'right' => 'text-right', default => 'text-left', }; - echo '
'; + echo '
'; echo ''; diff --git a/lib/MForm/FlexRepeater/MFormFlexRepeaterRenderer.php b/lib/MForm/FlexRepeater/MFormFlexRepeaterRenderer.php index 17973750..fdde9a39 100644 --- a/lib/MForm/FlexRepeater/MFormFlexRepeaterRenderer.php +++ b/lib/MForm/FlexRepeater/MFormFlexRepeaterRenderer.php @@ -24,6 +24,10 @@ class MFormFlexRepeaterRenderer public static function renderTemplate(MForm $form, int $level = 1): string { $items = array_values($form->getItems()); + + // Keep the same auto-group behavior as the classic parser path. + // This ensures addColumnElement() also creates a row wrapper in Flex-Repeater templates. + $items = array_values(MFormGroupExtensionHelper::addColumnGroupExtensionItems($items)); if (self::needsTabAutoGrouping($items)) { $items = array_values(MFormGroupExtensionHelper::addTabGroupExtensionItems($items)); } @@ -75,6 +79,13 @@ public static function renderTemplate(MForm $form, int $level = 1): string $attrs = $item->getAttributes(); $btnClass = 'btn ' . (isset($attrs['data-modal-btn-class']) ? htmlspecialchars($attrs['data-modal-btn-class'], ENT_QUOTES) : 'btn-default'); $align = $attrs['data-modal-align'] ?? 'left'; + $rowClass = ''; + if (isset($attrs['data-modal-row-class']) && is_string($attrs['data-modal-row-class'])) { + $rowClass = trim($attrs['data-modal-row-class']); + } + if (isset($attrs['data-group-row-class']) && is_string($attrs['data-group-row-class'])) { + $rowClass = trim($rowClass . ' ' . $attrs['data-group-row-class']); + } $innerHtml = ''; ++$i; while ($i < count($items)) { @@ -90,7 +101,7 @@ public static function renderTemplate(MForm $form, int $level = 1): string } ++$i; } - $html .= self::renderModalBlock($modalLabel, $btnClass, $align, $innerHtml); + $html .= self::renderModalBlock($modalLabel, $btnClass, $align, $innerHtml, $rowClass); continue; } @@ -171,8 +182,19 @@ public static function renderTemplate(MForm $form, int $level = 1): string // COLUMN-GROUP: Bootstrap-3 row + col-* divs if ('start-group-column' === $type) { - $cls = trim('row ' . $item->getClass()); - $html .= sprintf('
', htmlspecialchars($cls, ENT_QUOTES), self::renderAttributes($item->getAttributes())); + $attrs = $item->getAttributes(); + $rowExtraClass = ''; + if (isset($attrs['data-group-column-row-class']) && is_string($attrs['data-group-column-row-class'])) { + $rowExtraClass = trim($attrs['data-group-column-row-class']); + unset($attrs['data-group-column-row-class']); + } + if (isset($attrs['data-group-row-class']) && is_string($attrs['data-group-row-class'])) { + $rowExtraClass = trim($rowExtraClass . ' ' . $attrs['data-group-row-class']); + unset($attrs['data-group-row-class']); + } + + $cls = trim('row ' . $rowExtraClass . ' ' . $item->getClass()); + $html .= sprintf('
', htmlspecialchars($cls, ENT_QUOTES), self::renderAttributes($attrs)); ++$i; continue; } @@ -522,7 +544,7 @@ private static function renderField(MFormItem $item): string } } - private static function renderModalBlock(string $label, string $btnClass, string $align, string $innerHtml): string + private static function renderModalBlock(string $label, string $btnClass, string $align, string $innerHtml, string $rowClass = ''): string { $alignClass = match ($align) { 'center' => 'text-center', @@ -530,7 +552,7 @@ private static function renderModalBlock(string $label, string $btnClass, string default => 'text-left', }; // __MFRID__ is replaced by a unique ID in JS (_renderItem) when the template is cloned - return '
' . + return '
' . '
' . '', + htmlspecialchars(rex_i18n::msg('mform_flex_repeater_paste_start'), ENT_QUOTES), + htmlspecialchars(rex_i18n::msg('mform_flex_repeater_paste_label'), ENT_QUOTES), + ) : ''; + + $pasteButtonBottom = $copyPaste ? sprintf( '', htmlspecialchars(rex_i18n::msg('mform_flex_repeater_paste'), ENT_QUOTES), - htmlspecialchars(rex_i18n::msg('mform_flex_repeater_paste'), ENT_QUOTES), + htmlspecialchars(rex_i18n::msg('mform_flex_repeater_paste_label'), ENT_QUOTES), + ) : ''; + + $clearClipboardButton = $copyPaste ? sprintf( + '', + htmlspecialchars(rex_i18n::msg('mform_flex_repeater_clipboard_clear'), ENT_QUOTES), ) : ''; $toggleAllButton = sprintf( @@ -202,9 +213,10 @@ private function openFlexRepeaterElement(MFormItem $item, int|string $key, array htmlspecialchars($btnClass, ENT_QUOTES), htmlspecialchars($btnText, ENT_QUOTES), ); - $toolbarGroup = '
' . $toolbarToggle . $toolbarAdd . $pasteButton . '
'; + $toolbarGroupTop = '
' . $toolbarToggle . $toolbarAdd . $pasteButtonTop . $clearClipboardButton . '
'; + $toolbarGroupBottom = '
' . $toolbarToggle . $toolbarAdd . $pasteButtonBottom . $clearClipboardButton . '
'; - $this->elements[] = '
' . $toolbarGroup . '
'; + $this->elements[] = '
' . $toolbarGroupTop . '
'; $this->elements[] = '
'; @@ -220,7 +232,7 @@ private function openFlexRepeaterElement(MFormItem $item, int|string $key, array $templateHtml, ); - $this->elements[] = '
' . $toolbarGroup . '
'; + $this->elements[] = '
' . $toolbarGroupBottom . '
'; if ($this->debug) { $this->elements[] = sprintf( From b4c8a28c8ebbff2ae8018a04231920a92b4d4bb2 Mon Sep 17 00:00:00 2001 From: Thomas Skerbis Date: Tue, 7 Jul 2026 14:00:13 +0200 Subject: [PATCH 14/16] clipboard fix --- CHANGELOG.md | 1 + assets/js/flex-repeater.js | 70 +++++++++++++++++++++++++++++++++----- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dec7dc8..0ee85273 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - **Tabs in beiden Pfaden generell angeglichen** - Active-/Pull-Right-Auswertung, Nav-Klassenbildung, Layout-/Style-Flags (`vertical`/`modern`) sowie die Bereinigung tab-spezifischer Meta-Attribute sind jetzt in Parser und Flex-Repeater konsistent umgesetzt (inkl. robuster Truthy-Auswertung für `true`/`1`). - **Selectpicker in Repeatern stabilisiert** - Wenn bei `.selectpicker` kein explizites `data-container` gesetzt ist, wird beim Initialisieren standardmäßig `body` verwendet. Das verhindert falsch angedockte Dropdowns in verschachtelten Wrappern/Reapeatern. - **Copy/Paste-UX im Repeater entkoppelt und bereinigt** - Das Kopieren ist jetzt eine klare Aktion ohne klebrigen Toggle-Zustand. Die Einfügen-Buttons folgen konsequent dem Clipboard-Status und bleiben nicht mehr unbeabsichtigt sichtbar. +- **Clipboard auf Modultyp + Repeater begrenzt** - Ein kopiertes Item kann jetzt nur noch in Blöcken desselben Modultyps und im selben Repeater eingefügt werden. Dadurch erscheinen Einfügen-Aktionen nicht mehr in fachfremden Bereichen. - **Toolbar-Einfügen semantisch aufgeteilt** - Oben wird jetzt am Anfang eingefügt, unten am Ende. Beide Buttons bleiben kompakt mit dem Label „Einfügen“, die genaue Position wird über den Title vermittelt. - **Kopieren beenden kompakt und eindeutig** - Für den aktiven Clipboard-Zustand gibt es ein eigenes Symbol (Copy mit X-Overlay) inklusive Tooltip-Titel „Kopieren beenden“, damit der Exit aus dem Copy-Modus sofort erkennbar ist. - **Einfache Feldparität im Flex-Repeater erweitert** - `datetime` wird im Repeater-Template jetzt direkt gerendert, Textfelder unterstützen Datalist-Optionen analog zum Parser, und `markitup` wird bewusst als normale `textarea`-Fallback-Ausgabe behandelt. diff --git a/assets/js/flex-repeater.js b/assets/js/flex-repeater.js index 03dfb74c..d4d9358c 100644 --- a/assets/js/flex-repeater.js +++ b/assets/js/flex-repeater.js @@ -1231,23 +1231,77 @@ _setClipboardSnapshot(snapshot) { if (!snapshot || typeof snapshot !== 'object') return; + const payload = { + mfrClipboardVersion: 2, + scopeKey: this._getClipboardScopeKey(), + data: snapshot + }; try { - sessionStorage.setItem('mfr_clipboard', JSON.stringify(snapshot)); + sessionStorage.setItem('mfr_clipboard', JSON.stringify(payload)); } catch (e) { /* ignore */ } - window._mfrClipboard = snapshot; + window._mfrClipboard = payload; document.dispatchEvent(new CustomEvent('mfr:clipboard-updated')); } - _getClipboardSnapshot() { - let snapshot = null; + _getClipboardScopeKey() { + const form = this.container.closest('form'); + let moduleId = ''; + + if (form) { + const field = form.querySelector('[name="module_id"]'); + if (field && field.value !== undefined && String(field.value) !== '') { + moduleId = String(field.value); + } + + if (!moduleId) { + try { + const action = form.getAttribute('action') || window.location.href; + const url = new URL(action, window.location.origin); + moduleId = url.searchParams.get('module_id') || ''; + } catch (e) { /* ignore */ } + } + } + + if (!moduleId) { + try { + moduleId = new URL(window.location.href).searchParams.get('module_id') || ''; + } catch (e) { /* ignore */ } + } + + const moduleScope = moduleId ? ('module_id=' + moduleId) : ('path=' + window.location.pathname); + return moduleScope + '::' + String(this.fieldName || 'unknown-repeater'); + } + + _readClipboardPayload() { + let payload = null; try { const raw = sessionStorage.getItem('mfr_clipboard'); - if (raw) snapshot = JSON.parse(raw); + if (raw) payload = JSON.parse(raw); } catch (e) { /* ignore */ } - if (!snapshot && window._mfrClipboard) { - snapshot = window._mfrClipboard; + + if (!payload && window._mfrClipboard) { + payload = window._mfrClipboard; + } + + return payload; + } + + _getClipboardSnapshot() { + const payload = this._readClipboardPayload(); + if (!payload || typeof payload !== 'object') { + return null; } - return snapshot; + + if (payload.mfrClipboardVersion !== 2 || !payload.scopeKey || !payload.data || typeof payload.data !== 'object') { + // Legacy/invalid payload is ignored to prevent cross-repeater leakage. + return null; + } + + if (payload.scopeKey !== this._getClipboardScopeKey()) { + return null; + } + + return payload.data; } _clearClipboard() { From 57447f6315d91276af929a3dac4023256515a742 Mon Sep 17 00:00:00 2001 From: Thomas Skerbis Date: Tue, 7 Jul 2026 15:48:35 +0200 Subject: [PATCH 15/16] css fixes --- CHANGELOG.md | 1 + assets/css/flex-repeater.css | 169 ++++++++++++++++++++++++++++++++--- assets/js/flex-repeater.js | 23 +++-- 3 files changed, 170 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ee85273..5d68264a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - **Clipboard auf Modultyp + Repeater begrenzt** - Ein kopiertes Item kann jetzt nur noch in Blöcken desselben Modultyps und im selben Repeater eingefügt werden. Dadurch erscheinen Einfügen-Aktionen nicht mehr in fachfremden Bereichen. - **Toolbar-Einfügen semantisch aufgeteilt** - Oben wird jetzt am Anfang eingefügt, unten am Ende. Beide Buttons bleiben kompakt mit dem Label „Einfügen“, die genaue Position wird über den Title vermittelt. - **Kopieren beenden kompakt und eindeutig** - Für den aktiven Clipboard-Zustand gibt es ein eigenes Symbol (Copy mit X-Overlay) inklusive Tooltip-Titel „Kopieren beenden“, damit der Exit aus dem Copy-Modus sofort erkennbar ist. +- **Style-Fixes für Repeater-Aktionsbuttons** - Die Buttonflächen und Hover-Zustände im Flex-Repeater wurden für Light- und Dark-Mode vereinheitlicht. Der Plus-Button bleibt grün, der Delete-Button wieder klar als weißer Danger-Button mit rotem Icon erkennbar, und die Icon-Kontraste bleiben in beiden Dark-Modi sauber lesbar. - **Einfache Feldparität im Flex-Repeater erweitert** - `datetime` wird im Repeater-Template jetzt direkt gerendert, Textfelder unterstützen Datalist-Optionen analog zum Parser, und `markitup` wird bewusst als normale `textarea`-Fallback-Ausgabe behandelt. - **Password-Input in beiden Renderpfaden angeglichen** - `password` wird jetzt wie andere einfache Input-Typen sowohl im klassischen Parser als auch im Flex-Repeater konsistent als Eingabefeld gerendert. - **Gemeinsamer Feldtyp-Core für einfache Felder** - Die Typ-Klassifikation und Normalisierung für einfache Inputs (`text`, `datetime`, `password`, `text-readonly`, …) sowie Textarea-Typen (`textarea`, `markitup`, `textarea-readonly`) ist jetzt zentralisiert und wird von Parser und Flex-Repeater gemeinsam genutzt. diff --git a/assets/css/flex-repeater.css b/assets/css/flex-repeater.css index 31ac026c..6c3ce1c8 100644 --- a/assets/css/flex-repeater.css +++ b/assets/css/flex-repeater.css @@ -306,7 +306,104 @@ body.rex-theme-dark { font-size: 12px; line-height: 1; border-radius: 4px; - transition: opacity var(--mfr-transition); + background: #f8fafc; + border-color: #d8e0e8; + transition: opacity var(--mfr-transition), background-color var(--mfr-transition), border-color var(--mfr-transition), color var(--mfr-transition); +} + +.mfr-nested-actions .btn { + background: #f8fafc; + border-color: #d8e0e8; +} + +.mfr-item-actions .btn.btn-danger, +.mfr-nested-actions .btn.btn-danger { + background: #f8fafc; + border-color: #d8e0e8; + color: #d9534f; +} + +.mfr-item-actions .btn.btn-danger:hover, +.mfr-item-actions .btn.btn-danger:focus, +.mfr-nested-actions .btn.btn-danger:hover, +.mfr-nested-actions .btn.btn-danger:focus { + background: #fff5f5; + border-color: #e3b5b3; + color: #c9302c; +} + +.mfr-item-actions .btn:not(.btn-danger):hover, +.mfr-item-actions .btn:not(.btn-danger):focus, +.mfr-nested-actions .btn:not(.btn-danger):hover, +.mfr-nested-actions .btn:not(.btn-danger):focus { + background: #eef3f7; + border-color: #ccd6e2; +} + +body.rex-theme-dark .mfr-item-actions .btn:not(.btn-danger), +body.rex-theme-dark .mfr-nested-actions .btn:not(.btn-danger) { + background: #202b35; + border-color: #151c22; + color: rgba(255, 255, 255, 0.82); +} + +body.rex-theme-dark .mfr-item-actions .btn.btn-danger, +body.rex-theme-dark .mfr-nested-actions .btn.btn-danger { + background: #202b35; + border-color: #151c22; + color: #f08a8a; +} + +body.rex-theme-dark .mfr-item-actions .btn.btn-danger:hover, +body.rex-theme-dark .mfr-item-actions .btn.btn-danger:focus, +body.rex-theme-dark .mfr-nested-actions .btn.btn-danger:hover, +body.rex-theme-dark .mfr-nested-actions .btn.btn-danger:focus { + background: #27323d; + border-color: #344150; + color: #ffb3b3; +} + +body.rex-theme-dark .mfr-item-actions .btn:not(.btn-danger):hover, +body.rex-theme-dark .mfr-item-actions .btn:not(.btn-danger):focus, +body.rex-theme-dark .mfr-nested-actions .btn:not(.btn-danger):hover, +body.rex-theme-dark .mfr-nested-actions .btn:not(.btn-danger):focus { + background: #27323d; + border-color: #344150; + color: #ffffff; +} + +@media (prefers-color-scheme: dark) { + body.rex-has-theme:not(.rex-theme-light) .mfr-item-actions .btn:not(.btn-danger), + body.rex-has-theme:not(.rex-theme-light) .mfr-nested-actions .btn:not(.btn-danger) { + background: #202b35; + border-color: #151c22; + color: rgba(255, 255, 255, 0.82); + } + + body.rex-has-theme:not(.rex-theme-light) .mfr-item-actions .btn:not(.btn-danger):hover, + body.rex-has-theme:not(.rex-theme-light) .mfr-item-actions .btn:not(.btn-danger):focus, + body.rex-has-theme:not(.rex-theme-light) .mfr-nested-actions .btn:not(.btn-danger):hover, + body.rex-has-theme:not(.rex-theme-light) .mfr-nested-actions .btn:not(.btn-danger):focus { + background: #27323d; + border-color: #344150; + color: #ffffff; + } + + body.rex-has-theme:not(.rex-theme-light) .mfr-item-actions .btn.btn-danger, + body.rex-has-theme:not(.rex-theme-light) .mfr-nested-actions .btn.btn-danger { + background: #202b35; + border-color: #151c22; + color: #f08a8a; + } + + body.rex-has-theme:not(.rex-theme-light) .mfr-item-actions .btn.btn-danger:hover, + body.rex-has-theme:not(.rex-theme-light) .mfr-item-actions .btn.btn-danger:focus, + body.rex-has-theme:not(.rex-theme-light) .mfr-nested-actions .btn.btn-danger:hover, + body.rex-has-theme:not(.rex-theme-light) .mfr-nested-actions .btn.btn-danger:focus { + background: #27323d; + border-color: #344150; + color: #ffb3b3; + } } /* --- Body --- */ @@ -430,32 +527,46 @@ body.rex-theme-dark { margin-top: .4rem; } -.mfr-btn-add-after, -.mfr-btn-nested-add-after { +.mfr-container .mfr-btn-add-after, +.mfr-container .mfr-btn-nested-add-after { color: #2a7f45; } -.mfr-btn-add-after:hover, -.mfr-btn-nested-add-after:hover { +.mfr-container .mfr-btn-add-after:hover, +.mfr-container .mfr-btn-nested-add-after:hover { color: #1f6135; } +body.rex-theme-dark .mfr-item-actions .mfr-btn-add-after, +body.rex-theme-dark .mfr-item-actions .mfr-btn-nested-add-after, +body.rex-theme-dark .mfr-nested-actions .mfr-btn-add-after, +body.rex-theme-dark .mfr-nested-actions .mfr-btn-nested-add-after { + color: #63dd88; +} + +body.rex-theme-dark .mfr-item-actions .mfr-btn-add-after:hover, +body.rex-theme-dark .mfr-item-actions .mfr-btn-nested-add-after:hover, +body.rex-theme-dark .mfr-nested-actions .mfr-btn-add-after:hover, +body.rex-theme-dark .mfr-nested-actions .mfr-btn-nested-add-after:hover { + color: #8ef0ad; +} + /* Copy button */ -.mfr-btn-copy { +.mfr-container .mfr-btn-copy { color: #5b8fc7; } -.mfr-btn-copy:hover { +.mfr-container .mfr-btn-copy:hover { color: #3a6ea8; } -.mfr-btn-copy-active { +.mfr-container .mfr-btn-copy-active { color: #fff !important; background-color: #5b8fc7 !important; border-color: #3a6ea8 !important; } -.mfr-btn-clipboard-clear { +.mfr-container .mfr-btn-clipboard-clear { color: #a94442; } @@ -472,29 +583,59 @@ body.rex-theme-dark { font-size: 10px; } -.mfr-btn-clipboard-clear:hover { +.mfr-container .mfr-btn-clipboard-clear:hover { color: #843534; } /* Paste button in toolbar – margin handled by btn-group */ /* Dark mode copy button */ -body.rex-theme-dark .mfr-btn-copy { +body.rex-theme-dark .mfr-container .mfr-btn-copy { color: #7fb3e8; } +body.rex-theme-dark .mfr-container .mfr-btn-copy:hover { + color: #a9d6ff; +} + +body.rex-theme-dark .mfr-container .mfr-btn-clipboard-clear:hover { + color: #ffb3b3; +} + @media (prefers-color-scheme: dark) { - body.rex-has-theme:not(.rex-theme-light) .mfr-btn-copy { + body.rex-has-theme:not(.rex-theme-light) .mfr-item-actions .mfr-btn-add-after, + body.rex-has-theme:not(.rex-theme-light) .mfr-item-actions .mfr-btn-nested-add-after, + body.rex-has-theme:not(.rex-theme-light) .mfr-nested-actions .mfr-btn-add-after, + body.rex-has-theme:not(.rex-theme-light) .mfr-nested-actions .mfr-btn-nested-add-after { + color: #63dd88; + } + + body.rex-has-theme:not(.rex-theme-light) .mfr-item-actions .mfr-btn-add-after:hover, + body.rex-has-theme:not(.rex-theme-light) .mfr-item-actions .mfr-btn-nested-add-after:hover, + body.rex-has-theme:not(.rex-theme-light) .mfr-nested-actions .mfr-btn-add-after:hover, + body.rex-has-theme:not(.rex-theme-light) .mfr-nested-actions .mfr-btn-nested-add-after:hover { + color: #8ef0ad; + } + + body.rex-has-theme:not(.rex-theme-light) .mfr-container .mfr-btn-copy:hover { + color: #a9d6ff; + } + + body.rex-has-theme:not(.rex-theme-light) .mfr-container .mfr-btn-clipboard-clear:hover { + color: #ffb3b3; + } + + body.rex-has-theme:not(.rex-theme-light) .mfr-container .mfr-btn-copy { color: #7fb3e8; } } -body.rex-theme-dark .mfr-btn-clipboard-clear { +body.rex-theme-dark .mfr-container .mfr-btn-clipboard-clear { color: #f08a8a; } @media (prefers-color-scheme: dark) { - body.rex-has-theme:not(.rex-theme-light) .mfr-btn-clipboard-clear { + body.rex-has-theme:not(.rex-theme-light) .mfr-container .mfr-btn-clipboard-clear { color: #f08a8a; } } diff --git a/assets/js/flex-repeater.js b/assets/js/flex-repeater.js index d4d9358c..4c6fb2c4 100644 --- a/assets/js/flex-repeater.js +++ b/assets/js/flex-repeater.js @@ -502,8 +502,10 @@ const insertedEl = this._renderItem(d, insertIndex); if (insertedEl) { const children = Array.from(this.itemsList.children); - const ref = children[insertIndex + 1]; - if (ref) ref.before(insertedEl); + const ref = children[insertIndex]; + if (ref && ref !== insertedEl) { + ref.before(insertedEl); + } this._focusNewItem(insertedEl, true); } @@ -866,14 +868,15 @@ const d = data || this._emptyData(); const insertIndex = index + 1; + const nextSibling = this.itemsList ? (this.itemsList.children[insertIndex] || null) : null; this.data.splice(insertIndex, 0, d); this._log('insertItemAfter', { index: index, insertIndex: insertIndex, data: d }); const insertedEl = this._renderItem(d, insertIndex); if (insertedEl) { - const children = Array.from(this.itemsList.children); - const ref = children[insertIndex + 1]; - if (ref) ref.before(insertedEl); + if (nextSibling && nextSibling !== insertedEl) { + nextSibling.before(insertedEl); + } this._focusNewItem(insertedEl, true); } @@ -1130,9 +1133,10 @@ delete snapshot[MFR_ITEM_DISABLED_KEY]; this._setClipboardSnapshot(snapshot); this._updateClipboardUi(); - // Visual feedback + copyBtn.classList.remove('mfr-btn-copy-active'); + void copyBtn.offsetWidth; copyBtn.classList.add('mfr-btn-copy-active'); - window.setTimeout(function () { copyBtn.classList.remove('mfr-btn-copy-active'); }, 800); + window.setTimeout(function () { copyBtn.classList.remove('mfr-btn-copy-active'); }, 650); this._log('copyItem', { idx: idx, snapshot: snapshot }); }); } @@ -1202,10 +1206,11 @@ if (this.max > 0 && this.data.length >= this.max) return; + const firstSibling = this.itemsList ? this.itemsList.firstElementChild : null; this.data.unshift(data); const insertedEl = this._renderItem(data, 0); - if (insertedEl && this.itemsList && this.itemsList.firstElementChild && this.itemsList.firstElementChild !== insertedEl) { - this.itemsList.firstElementChild.before(insertedEl); + if (insertedEl && firstSibling && firstSibling !== insertedEl) { + firstSibling.before(insertedEl); } this._reindex(); From 3a4225ae9aaebfb2498bad09f4a826d576b088f8 Mon Sep 17 00:00:00 2001 From: Thomas Skerbis Date: Tue, 7 Jul 2026 16:04:49 +0200 Subject: [PATCH 16/16] reviews fixed --- assets/js/flex-repeater.js | 22 ++++++++++++++++++++-- lib/MForm/Template/MFormLayoutCore.php | 17 +++++++---------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/assets/js/flex-repeater.js b/assets/js/flex-repeater.js index 4c6fb2c4..0cfb7843 100644 --- a/assets/js/flex-repeater.js +++ b/assets/js/flex-repeater.js @@ -17,6 +17,8 @@ const MFR_LOG_PREFIX = '[MFR]'; const MFR_ITEM_DISABLED_KEY = '__disabled'; + const _clipboardUiInstances = new Set(); + let _clipboardUiListenerRegistered = false; function isGlobalDebugEnabled() { return window.MFR_DEBUG === true; @@ -34,6 +36,23 @@ console.log.apply(console, [MFR_LOG_PREFIX + ' ' + label].concat(args)); } + function registerClipboardUiInstance(instance) { + if (!instance) return; + _clipboardUiInstances.add(instance); + + if (_clipboardUiListenerRegistered) { + return; + } + + document.addEventListener('mfr:clipboard-updated', function () { + _clipboardUiInstances.forEach(function (registeredInstance) { + registeredInstance._updateClipboardUi(); + }); + }); + + _clipboardUiListenerRegistered = true; + } + // ------------------------------------------------------------------------- // Hilfsfunktionen // ------------------------------------------------------------------------- @@ -713,8 +732,7 @@ this.data = []; this._suppressSync = false; this._isBootstrapping = false; - this._onClipboardUpdated = () => this._updateClipboardUi(); - document.addEventListener('mfr:clipboard-updated', this._onClipboardUpdated); + registerClipboardUiInstance(this); this._log('constructor', { fieldName: this.fieldName, diff --git a/lib/MForm/Template/MFormLayoutCore.php b/lib/MForm/Template/MFormLayoutCore.php index cf721b19..fc4aed19 100644 --- a/lib/MForm/Template/MFormLayoutCore.php +++ b/lib/MForm/Template/MFormLayoutCore.php @@ -29,8 +29,7 @@ public static function consumeModalRowClass(array &$attributes): string */ public static function isCollapseOpen(array $attributes): bool { - return isset($attributes['data-group-open-collapse']) - && (1 === (int) $attributes['data-group-open-collapse'] || true === $attributes['data-group-open-collapse']); + return isset($attributes['data-group-open-collapse']) && self::isTruthyFlag($attributes['data-group-open-collapse']); } /** @@ -38,7 +37,7 @@ public static function isCollapseOpen(array $attributes): bool */ public static function isCollapseAccordion(array $attributes): bool { - return isset($attributes['data-group-accordion']) && 1 === (int) $attributes['data-group-accordion']; + return isset($attributes['data-group-accordion']) && self::isTruthyFlag($attributes['data-group-accordion']); } /** @@ -48,7 +47,7 @@ public static function shouldHideCollapseToggle(array $attributes, bool $hasLabe { return !$hasLabel || (array_key_exists('data-group-hide-toggle-links', $attributes) - && 'true' === (string) $attributes['data-group-hide-toggle-links']); + && self::isTruthyFlag($attributes['data-group-hide-toggle-links'])); } /** @@ -67,6 +66,7 @@ public static function consumeCollapseWrapperAttributes(array &$attributes): voi * Ensures selectpicker fields have a stable default container. * * @param array $attributes + * @param string $itemClass */ public static function ensureSelectpickerContainer(array &$attributes, string $itemClass = ''): void { @@ -102,17 +102,11 @@ public static function isTabActive(array $attributes): bool return isset($attributes['data-group-open-tab']) && self::isTruthyFlag($attributes['data-group-open-tab']); } - /** - * @param array $attributes - */ public static function isTabPullRight(array $attributes): bool { return isset($attributes['pull-right']) && self::isTruthyFlag($attributes['pull-right']); } - /** - * @param array $attributes - */ public static function buildTabNavClass(array $attributes): string { $class = ''; @@ -174,6 +168,9 @@ private static function consumeClassAttributes(array &$attributes, array $keys): return $class; } + /** + * Returns true for boolean true, numeric 1 and string values like "1" or "true". + */ private static function isTruthyFlag(mixed $value): bool { if (true === $value) {