diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e1e7247..5d68264a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,33 @@ # MForm - REDAXO Addon für Modul-Input-Formulare +## Version 9.3.0 + +### 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. +- **`setTooltipInfo()` im Flex-Repeater funktionsgleich zum Parser** - Label- und Tooltip-Rendering laufen jetzt über einen gemeinsamen internen Renderer. Dadurch wird der Tooltip im Repeater nicht mehr ignoriert und die Label-Aufbereitung (inkl. Sprach-Array-Fallback) bleibt über beide Pfade konsistent. +- **Default-Tooltip-Icon angepasst** - Wenn bei `setTooltipInfo()` kein eigenes Icon übergeben wird, verwendet MForm jetzt standardmäßig `fa-info-circle` statt `fa-exclamation`. +- **Gemeinsamer Layout-Core für Wrapper-Row-Klassen** - Die Verarbeitung von `data-group-column-row-class` / `data-group-row-class` (Columns) sowie `data-modal-row-class` / `data-group-row-class` (Modal) wurde in einen gemeinsamen internen Core ausgelagert und wird jetzt von Parser und Flex-Repeater genutzt. +- **Label-Auflösung für Wrapper/Navigation vereinheitlicht** - Repeater-, Modal-, Collapse- und Tab-Labels verwenden jetzt in beiden Renderpfaden dieselbe locale-fähige Auflösung (statt „erstes Array-Element“). Das reduziert Drift bei mehrsprachigen Label-Arrays. +- **Gemeinsame Collapse-Kernlogik** - Entscheidungen zu `open`/`accordion`/`hide-toggle-links` und die Bereinigung der Collapse-Wrapper-Attribute laufen jetzt über einen gemeinsamen Layout-Core und werden in Parser sowie Flex-Repeater gleich genutzt. +- **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. +- **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. + +### Neu + +- **Renderer-Parität Demo/Smoke-Checks** - Neue Demo-Seite `demo_renderer_parity` zur Gegenprobe von Parser-HTML und Flex-Repeater-Template-HTML inkl. Marker-Checks für Tooltip, Row-/Modal-Klassen und Full-Layout. +- **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/assets/css/flex-repeater.css b/assets/css/flex-repeater.css index db4e801c..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,44 +527,119 @@ 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-container .mfr-btn-clipboard-clear { + color: #a94442; +} + +.mfr-copy-off-icon { + position: relative; + display: inline-block; + line-height: 1; +} + +.mfr-copy-off-icon .mfr-copy-off-x { + position: absolute; + right: -4px; + top: -4px; + font-size: 10px; +} + +.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-container .mfr-btn-clipboard-clear { + color: #f08a8a; +} + +@media (prefers-color-scheme: dark) { + body.rex-has-theme:not(.rex-theme-light) .mfr-container .mfr-btn-clipboard-clear { + color: #f08a8a; + } +} + /* Nested Drag-Feedback */ .mfr-nested-items .mfr-item-ghost { opacity: .35; diff --git a/assets/css/mform.css b/assets/css/mform.css index 9a2b792b..7d8579a0 100755 --- a/assets/css/mform.css +++ b/assets/css/mform.css @@ -2,6 +2,246 @@ margin: 0; } +.mform, +.mfr-container { + --mform-field-bg: #ffffff; + --mform-field-text: #1f2d3d; + --mform-field-border: #c7d0dc; + --mform-field-border-hover: #9aa8ba; + --mform-field-focus: #4f8ec5; + --mform-field-placeholder: #7b8795; + --mform-field-bg-disabled: #eef1f5; + --mform-field-border-disabled: #c1cad7; + --mform-field-radius: 6px; + --mform-field-shadow: inset 0 1px 1px rgba(0, 0, 0, .04); + --mform-field-shadow-focus: 0 0 0 2px rgba(79, 142, 197, .22); + + --mform-btn-white-bg: #ffffff; + --mform-btn-white-text: #333333; + --mform-btn-white-border: #e8e8e8; + --mform-btn-white-hover-bg: #4b9ad9; + --mform-btn-white-active-bg: #2a81c7; + --mform-btn-white-active-text: #ffffff; + --mform-btn-white-icon: #4b9ad9; + --mform-btn-white-icon-active: #ffffff; + --mform-btn-white-tabs-bg: #fafafa; + + --mform-custom-link-bg: #ffffff; + --mform-custom-link-border: #d8e0e8; + --mform-custom-link-empty-text: #7c8997; + --mform-custom-link-btn-bg: #f7f9fb; + --mform-custom-link-btn-border: #e3e8ee; + --mform-custom-link-btn-text: inherit; + --mform-custom-link-btn-hover-bg: #eaf1f8; + --mform-custom-link-btn-active-bg: #d0e8fa; + --mform-custom-link-btn-active-text: #1a6ca8; + --mform-custom-link-btn-active-border: #b0d0ef; + + --mform-cl-multi-bg: #f7f9fb; + --mform-cl-multi-border: #dde4ec; + --mform-cl-multi-handle: #aaaaaa; + --mform-cl-multi-remove: #c0392b; + + --mform-accent: #79af8a; + --mform-accent-bg: rgba(121, 175, 138, 0.12); + --mform-accent-ring: rgba(121, 175, 138, 0.4); + + --mform-grey-legend-bg: #d8d8d8; + --mform-grey-legend-tab-bg: #f3f3f3; + --mform-grey-legend-sort-bg: #ececec; + + --mform-cbg-border: rgba(94, 94, 94, 0.3); + --mform-cbg-border-hover: rgba(94, 94, 94, 0.55); + --mform-cbg-indicator-border: rgba(94, 94, 94, 0.45); + --mform-cbg-text: inherit; + --mform-cbg-text-active: inherit; + + --mform-cs-popup-bg: #ffffff; + --mform-cs-popup-border: rgba(0, 0, 0, 0.15); + --mform-cs-popup-text: inherit; + --mform-cs-preview-class-bg: #e0e0e0; + --mform-cs-preview-class-text: #333333; + --mform-cs-swatch-class-bg: #e0e0e0; + --mform-cs-swatch-class-text: #444444; +} + +body.rex-theme-dark .mform, +body.rex-theme-dark .mfr-container { + --mform-field-bg: #243140; + --mform-field-text: #edf3f9; + --mform-field-border: #415266; + --mform-field-border-hover: #5a6d83; + --mform-field-focus: #7fb3e8; + --mform-field-placeholder: #a6b5c4; + --mform-field-bg-disabled: #1e2935; + --mform-field-border-disabled: #39495d; + --mform-field-shadow: inset 0 1px 1px rgba(0, 0, 0, .28); + --mform-field-shadow-focus: 0 0 0 2px rgba(127, 179, 232, .28); + + --mform-btn-white-bg: #202b35; + --mform-btn-white-text: rgba(255, 255, 255, 0.75); + --mform-btn-white-border: #151c22; + --mform-btn-white-hover-bg: #0f4671; + --mform-btn-white-active-bg: #0f4671; + --mform-btn-white-active-text: rgba(255, 255, 255, 0.75); + --mform-btn-white-icon: rgba(255, 255, 255, 0.75); + --mform-btn-white-icon-active: #7abaec; + --mform-btn-white-tabs-bg: #202b35; + + --mform-custom-link-bg: #1f2830; + --mform-custom-link-border: #3a4753; + --mform-custom-link-empty-text: #9fb0c0; + --mform-custom-link-btn-bg: #27323d; + --mform-custom-link-btn-border: #344150; + --mform-custom-link-btn-text: #c9d4df; + --mform-custom-link-btn-hover-bg: #30404d; + --mform-custom-link-btn-active-bg: #1a3a55; + --mform-custom-link-btn-active-text: #7ec8f4; + --mform-custom-link-btn-active-border: #2a5070; + + --mform-cl-multi-bg: #1f2830; + --mform-cl-multi-border: #3a4753; + --mform-cl-multi-handle: #5a6a78; + --mform-cl-multi-remove: #e57373; + + --mform-accent: #79af8a; + --mform-accent-bg: rgba(121, 175, 138, 0.18); + --mform-accent-ring: rgba(121, 175, 138, 0.4); + + --mform-grey-legend-bg: #1a3332; + --mform-grey-legend-tab-bg: #f3f3f3; + --mform-grey-legend-sort-bg: #ececec; + + --mform-cbg-border: rgba(180, 180, 180, 0.25); + --mform-cbg-border-hover: rgba(180, 180, 180, 0.45); + --mform-cbg-indicator-border: rgba(180, 180, 180, 0.45); + --mform-cbg-text: rgba(220, 220, 220, 0.85); + --mform-cbg-text-active: #ffffff; + + --mform-cs-popup-bg: #1e2a35; + --mform-cs-popup-border: rgba(255, 255, 255, 0.12); + --mform-cs-popup-text: #ccd4dc; + --mform-cs-preview-class-bg: #2d3b48; + --mform-cs-preview-class-text: #cccccc; + --mform-cs-swatch-class-bg: #2d3b48; + --mform-cs-swatch-class-text: #cccccc; +} + +@media (prefers-color-scheme: dark) { + body.rex-has-theme:not(.rex-theme-light) .mform, + body.rex-has-theme:not(.rex-theme-light) .mfr-container { + --mform-field-bg: #243140; + --mform-field-text: #edf3f9; + --mform-field-border: #415266; + --mform-field-border-hover: #5a6d83; + --mform-field-focus: #7fb3e8; + --mform-field-placeholder: #a6b5c4; + --mform-field-bg-disabled: #1e2935; + --mform-field-border-disabled: #39495d; + --mform-field-shadow: inset 0 1px 1px rgba(0, 0, 0, .28); + --mform-field-shadow-focus: 0 0 0 2px rgba(127, 179, 232, .28); + + --mform-btn-white-bg: #202b35; + --mform-btn-white-text: rgba(255, 255, 255, 0.75); + --mform-btn-white-border: #151c22; + --mform-btn-white-hover-bg: #0f4671; + --mform-btn-white-active-bg: #0f4671; + --mform-btn-white-active-text: rgba(255, 255, 255, 0.75); + --mform-btn-white-icon: rgba(255, 255, 255, 0.75); + --mform-btn-white-icon-active: #7abaec; + --mform-btn-white-tabs-bg: #202b35; + + --mform-custom-link-bg: #1f2830; + --mform-custom-link-border: #3a4753; + --mform-custom-link-empty-text: #9fb0c0; + --mform-custom-link-btn-bg: #27323d; + --mform-custom-link-btn-border: #344150; + --mform-custom-link-btn-text: #c9d4df; + --mform-custom-link-btn-hover-bg: #30404d; + --mform-custom-link-btn-active-bg: #1a3a55; + --mform-custom-link-btn-active-text: #7ec8f4; + --mform-custom-link-btn-active-border: #2a5070; + + --mform-cl-multi-bg: #1f2830; + --mform-cl-multi-border: #3a4753; + --mform-cl-multi-handle: #5a6a78; + --mform-cl-multi-remove: #e57373; + + --mform-accent: #79af8a; + --mform-accent-bg: rgba(121, 175, 138, 0.18); + --mform-accent-ring: rgba(121, 175, 138, 0.4); + + --mform-grey-legend-bg: #1a3332; + --mform-grey-legend-tab-bg: #f3f3f3; + --mform-grey-legend-sort-bg: #ececec; + + --mform-cbg-border: rgba(180, 180, 180, 0.25); + --mform-cbg-border-hover: rgba(180, 180, 180, 0.45); + --mform-cbg-indicator-border: rgba(180, 180, 180, 0.45); + --mform-cbg-text: rgba(220, 220, 220, 0.85); + --mform-cbg-text-active: #ffffff; + + --mform-cs-popup-bg: #1e2a35; + --mform-cs-popup-border: rgba(255, 255, 255, 0.12); + --mform-cs-popup-text: #ccd4dc; + --mform-cs-preview-class-bg: #2d3b48; + --mform-cs-preview-class-text: #cccccc; + --mform-cs-swatch-class-bg: #2d3b48; + --mform-cs-swatch-class-text: #cccccc; + } +} + +.mform .form-control, +.mfr-item-body .form-control, +.mfr-nested-body .form-control, +.mform .custom-link.input-group, +.mfr-item-body .custom-link.input-group, +.mfr-nested-body .custom-link.input-group { + border-radius: var(--mform-field-radius); + border-color: var(--mform-field-border); + background-color: var(--mform-field-bg); + color: var(--mform-field-text); + box-shadow: var(--mform-field-shadow); + transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease; +} + +.mform .form-control:hover, +.mfr-item-body .form-control:hover, +.mfr-nested-body .form-control:hover, +.mform .custom-link.input-group:hover, +.mfr-item-body .custom-link.input-group:hover, +.mfr-nested-body .custom-link.input-group:hover { + border-color: var(--mform-field-border-hover); +} + +.mform .form-control:focus, +.mfr-item-body .form-control:focus, +.mfr-nested-body .form-control:focus, +.mform .custom-link.input-group:focus-within, +.mfr-item-body .custom-link.input-group:focus-within, +.mfr-nested-body .custom-link.input-group:focus-within { + border-color: var(--mform-field-focus); + box-shadow: var(--mform-field-shadow-focus); +} + +.mform .form-control::placeholder, +.mfr-item-body .form-control::placeholder, +.mfr-nested-body .form-control::placeholder { + color: var(--mform-field-placeholder); + opacity: 1; +} + +.mform .form-control[readonly], +.mform .form-control[disabled], +.mfr-item-body .form-control[readonly], +.mfr-item-body .form-control[disabled], +.mfr-nested-body .form-control[readonly], +.mfr-nested-body .form-control[disabled] { + background-color: var(--mform-field-bg-disabled); + border-color: var(--mform-field-border-disabled); + color: var(--mform-field-placeholder); +} + .mform select.form-control { height: 34px; } @@ -26,7 +266,7 @@ .mform .mform-tabs .tab-content { padding: 20px; - background: #fff; + background: var(--mform-tab-content-bg); } .mform .mform-tabs { @@ -152,7 +392,7 @@ .mform fieldset.grey-legend-background > legend { border-bottom: none; padding: 8px 10px; - background: #d8d8d8; + background: var(--mform-grey-legend-bg); font-size: 14px; font-weight: bold; } @@ -160,7 +400,7 @@ .mform .tab-content .mform-headline.grey-legend-background h3, .mform .tab-content fieldset.grey-legend-background > legend, .mform .tab-content fieldset.grey-legend-background > legend { - background: #f3f3f3; + background: var(--mform-grey-legend-tab-bg); } .sortitem .mform fieldset.grey-legend-background:first-child { @@ -169,7 +409,7 @@ .sortitem .mform .mform-headline.grey-legend-background h3, .sortitem .mform fieldset.grey-legend-background > legend { - background: #ececec; + background: var(--mform-grey-legend-sort-bg); } .tab-content .sortitem { @@ -181,44 +421,44 @@ } .mform .btn-white { - background-color: #fff; - color: #333; + background-color: var(--mform-btn-white-bg); + color: var(--mform-btn-white-text); border-radius: 0; text-align: left; font-size: 14px; height: 50px; line-height: 20px; padding: 15px; - border-top: 1px solid #e8e8e8; - border-bottom: 1px solid #e8e8e8; + border-top: 1px solid var(--mform-btn-white-border); + border-bottom: 1px solid var(--mform-btn-white-border); position: relative; margin-bottom: 1px; } .mform .btn-white[aria-expanded=true] { - background: #4b9ad9; - color: #fff; + background: var(--mform-btn-white-hover-bg); + color: var(--mform-btn-white-active-text); } .mform .btn-white:hover { - background-color: #4b9ad9; - color: #ffffff; + background-color: var(--mform-btn-white-hover-bg); + color: var(--mform-btn-white-active-text); } .mform .btn-white:focus, .mform .btn-white:active { - background-color: #2a81c7; + background-color: var(--mform-btn-white-active-bg); } .mform-tabs .btn-white { - background-color: #fafafa; + background-color: var(--mform-btn-white-tabs-bg); } .mform .btn-white:after { content: '\f067'; width: 10px; height: 10px; - color: #4b9ad9; + color: var(--mform-btn-white-icon); display: inline-block; margin-left: 15px; float: right; @@ -227,12 +467,12 @@ } .mform .btn-white:hover:after { - color: #FFF; + color: var(--mform-btn-white-icon-active); } .mform .btn-white[aria-expanded="true"]:after { content: '\f068'; - color: #fff; + color: var(--mform-btn-white-icon-active); } .mform .collapse-wrapper { @@ -275,10 +515,6 @@ margin-top: 0; } -body.rex-theme-dark .mform .mform-tabs .nav-tabs { - /*background-color: rgba(0, 0, 0, 0.15);*/ -} - body.rex-theme-dark .mform .mform-tabs { --mform-tab-nav-bg: #19222d; --mform-tab-nav-border: #304050; @@ -290,75 +526,11 @@ body.rex-theme-dark .mform .mform-tabs { --mform-tab-link-hover-bg: #243342; } -body.rex-theme-dark .mform .mform-tabs .tab-content { - background-color: #202b35; -} - -body.rex-theme-dark .mform .mform-headline.grey-legend-background h3, -body.rex-theme-dark .sortitem .mform fieldset.grey-legend-background > legend, -body.rex-theme-dark .mform fieldset.grey-legend-background > legend { - background-color: #1a3332; -} - -body.rex-theme-dark .mform .tab-content .mform-headline.grey-legend-background h3, -body.rex-theme-dark .mform .tab-content fieldset.grey-legend-background > legend, -body.rex-theme-dark .mform .tab-content fieldset.grey-legend-background > legend { - background-color: #f3f3f3; -} - -body.rex-theme-dark .sortitem .mform .mform-headline.grey-legend-background h3, -body.rex-theme-dark .sortitem .mform fieldset.grey-legend-background > legend { - background-color: #ececec; -} - -body.rex-theme-dark .mform .btn-white { - background-color: #202b35; - color: rgba(255, 255, 255, 0.75); - border-top-color: #151c22; - border-bottom-color: #151c22; -} - -body.rex-theme-dark .mform .btn-white[aria-expanded=true] { - background-color: #0f4671; - color: rgba(255, 255, 255, 0.75); -} - -body.rex-theme-dark .mform .btn-white:hover { - background-color: #0f4671; - color: rgba(255, 255, 255, 0.75); -} - -body.rex-theme-dark .mform .btn-white:focus, -body.rex-theme-dark .mform .btn-white:active { - background-color: #0f4671; -} - -body.rex-theme-dark .mform-tabs .btn-white { - background-color: #202b35; -} - -body.rex-theme-dark .mform .btn-white:after { - color: rgba(255, 255, 255, 0.75); -} - -body.rex-theme-dark .mform .btn-white:hover:after { - color: #7abaec; -} - -body.rex-theme-dark .mform .btn-white[aria-expanded="true"]:after { - color: #7abaec; -} - -body.rex-theme-dark .mform .collapse, -body.rex-theme-dark .mform .collapsing { - -} - .mform .custom-link.input-group { - border: 1px solid #d8e0e8; + border: 1px solid var(--mform-custom-link-border); border-radius: 6px; overflow: visible; - background: #fff; + background: var(--mform-custom-link-bg); } .mform .custom-link.input-group input.form-control[readonly] { @@ -374,8 +546,9 @@ body.rex-theme-dark .mform .collapsing { .mform .custom-link.input-group .btn.btn-popup { border: 0; - border-left: 1px solid #e3e8ee; - background: #f7f9fb; + border-left: 1px solid var(--mform-custom-link-btn-border); + background: var(--mform-custom-link-btn-bg); + color: var(--mform-custom-link-btn-text); min-width: 34px; min-height: 36px; } @@ -386,47 +559,17 @@ body.rex-theme-dark .mform .collapsing { .mform .custom-link.input-group .btn.btn-popup:hover, .mform .custom-link.input-group .btn.btn-popup:focus { - background: #eaf1f8; + background: var(--mform-custom-link-btn-hover-bg); } .mform .custom-link.input-group .btn.btn-popup.active { - background: #d0e8fa; - color: #1a6ca8; - border-left-color: #b0d0ef; + background: var(--mform-custom-link-btn-active-bg); + color: var(--mform-custom-link-btn-active-text); + border-left-color: var(--mform-custom-link-btn-active-border); } .mform .custom-link.input-group.is-empty input.form-control[readonly] { - color: #7c8997; -} - -body.rex-theme-dark .mform .custom-link.input-group { - border-color: #3a4753; - background: #1f2830; -} - -body.rex-theme-dark .mform .custom-link.input-group .btn.btn-popup { - border-left-color: #344150; - background: #27323d; - color: #c9d4df; -} - -body.rex-theme-dark .mform .custom-link.input-group .btn.btn-popup.media_preview_link--leading { - margin-right: 8px; -} - -body.rex-theme-dark .mform .custom-link.input-group .btn.btn-popup:hover, -body.rex-theme-dark .mform .custom-link.input-group .btn.btn-popup:focus { - background: #30404d; -} - -body.rex-theme-dark .mform .custom-link.input-group .btn.btn-popup.active { - background: #1a3a55; - color: #7ec8f4; - border-left-color: #2a5070; -} - -body.rex-theme-dark .mform .custom-link.input-group.is-empty input.form-control[readonly] { - color: #9fb0c0; + color: var(--mform-custom-link-empty-text); } @media (prefers-color-scheme: dark) { @@ -441,115 +584,41 @@ body.rex-theme-dark .mform .custom-link.input-group.is-empty input.form-control[ --mform-tab-link-hover-bg: #243342; } - body.rex-has-theme:not(.rex-theme-light) .mform .mform-tabs .nav-tabs { - /*background-color: rgba(0, 0, 0, 0.15);*/ - } - - - body.rex-has-theme:not(.rex-theme-light) .mform .mform-tabs .tab-content { - background-color: #202b35; - } - - body.rex-has-theme:not(.rex-theme-light) .mform .mform-headline.grey-legend-background h3, - body.rex-has-theme:not(.rex-theme-light) .sortitem .mform fieldset.grey-legend-background > legend, - body.rex-has-theme:not(.rex-theme-light) .mform fieldset.grey-legend-background > legend { - background-color: #1a3332; - } - - body.rex-has-theme:not(.rex-theme-light) .mform .tab-content .mform-headline.grey-legend-background h3, - body.rex-has-theme:not(.rex-theme-light) .mform .tab-content fieldset.grey-legend-background > legend, - body.rex-has-theme:not(.rex-theme-light) .mform .tab-content fieldset.grey-legend-background > legend { - background-color: #f3f3f3; - } - - body.rex-has-theme:not(.rex-theme-light) .sortitem .mform .mform-headline.grey-legend-background h3, - body.rex-has-theme:not(.rex-theme-light) .sortitem .mform fieldset.grey-legend-background > legend { - background-color: #ececec; - } - - body.rex-has-theme:not(.rex-theme-light) .mform .custom-link.input-group { - border-color: #3a4753; - background: #1f2830; - } - - body.rex-has-theme:not(.rex-theme-light) .mform .custom-link.input-group .btn.btn-popup { - border-left-color: #344150; - background: #27323d; - color: #c9d4df; - } - - body.rex-has-theme:not(.rex-theme-light) .mform .custom-link.input-group .btn.btn-popup.media_preview_link--leading { - margin-right: 8px; - } - - body.rex-has-theme:not(.rex-theme-light) .mform .custom-link.input-group .btn.btn-popup:hover, - body.rex-has-theme:not(.rex-theme-light) .mform .custom-link.input-group .btn.btn-popup:focus { - background: #30404d; - } - - body.rex-has-theme:not(.rex-theme-light) .mform .custom-link.input-group .btn.btn-popup.active { - background: #1a3a55; - color: #7ec8f4; - border-left-color: #2a5070; - } - - body.rex-has-theme:not(.rex-theme-light) .mform .custom-link.input-group.is-empty input.form-control[readonly] { - color: #9fb0c0; - } - - body.rex-has-theme:not(.rex-theme-light) .mform .btn-white { - background-color: #202b35; - color: rgba(255, 255, 255, 0.75); - border-top-color: #151c22; - border-bottom-color: #151c22; - } - - body.rex-has-theme:not(.rex-theme-light) .mform .btn-white[aria-expanded=true] { - background-color: #1867a6; - color: rgba(255, 255, 255, 0.75); - } - - body.rex-has-theme:not(.rex-theme-light) .mform .btn-white:hover { - background-color: #1867a6; - color: rgba(255, 255, 255, 0.75); - } - - body.rex-has-theme:not(.rex-theme-light) .mform .btn-white:focus, - body.rex-has-theme:not(.rex-theme-light) .mform .btn-white:active { - background-color: #1867a6; - } - - body.rex-has-theme:not(.rex-theme-light) .mform-tabs .btn-white { - background-color: #202b35; - } - - body.rex-has-theme:not(.rex-theme-light) .mform .btn-white:after { - color: rgba(255, 255, 255, 0.75); - } +} - body.rex-has-theme:not(.rex-theme-light) .mform .btn-white:hover:after { - color: #7abaec; - } +section.repeater { + --mform-repeater-group-border: rgba(100, 100, 100, 0.2); + --mform-repeater-group-bg: rgba(255, 255, 255, 0.09); + --mform-repeater-group-shadow: 0 5px 15px rgba(0, 0, 0, .08); + --mform-repeater-group-shadow-hover: 0 5px 15px rgba(0, 0, 0, .22); + --mform-repeater-group-accent: rgba(0, 0, 0, 0.3); +} - body.rex-has-theme:not(.rex-theme-light) .mform .btn-white[aria-expanded="true"]:after { - color: #7abaec; - } +body.rex-theme-dark section.repeater { + --mform-repeater-group-border: rgba(17, 17, 17, 0.1); + --mform-repeater-group-bg: rgba(17, 17, 17, 0.15); + --mform-repeater-group-shadow: 0 5px 15px rgba(0, 0, 0, .08); + --mform-repeater-group-shadow-hover: 0 5px 15px rgba(0, 0, 0, .22); + --mform-repeater-group-accent: rgba(255, 255, 255, 0.3); +} - body.rex-has-theme:not(.rex-theme-light) .mform .collapse, - body.rex-has-theme:not(.rex-theme-light) .mform .collapsing { +@media (prefers-color-scheme: dark) { + body.rex-has-theme:not(.rex-theme-light) section.repeater { + --mform-repeater-group-border: rgba(17, 17, 17, 0.1); + --mform-repeater-group-bg: rgba(17, 17, 17, 0.15); + --mform-repeater-group-shadow: 0 5px 15px rgba(0, 0, 0, .08); + --mform-repeater-group-shadow-hover: 0 5px 15px rgba(0, 0, 0, .22); + --mform-repeater-group-accent: rgba(255, 255, 255, 0.3); } } - -.rex-theme-light section.repeater .repeater-group, section.repeater .repeater-group { padding: 0.5rem 1.25rem 1.25rem 1.25rem; margin-bottom: 0.5rem; transition: box-shadow 0.3s ease-in-out; - - border: 1px solid rgba(100, 100, 100, 0.20); - background: rgba(255, 255, 255, 0.09); - box-shadow: 0 5px 15px rgba(0, 0, 0, .08); + border: 1px solid var(--mform-repeater-group-border); + background: var(--mform-repeater-group-bg); + box-shadow: var(--mform-repeater-group-shadow); position: relative; } @@ -562,55 +631,23 @@ section.repeater .repeater-group:before { width: 0; content: ''; display: block; - background-color: rgba(0, 0, 0, 0.3); + background-color: var(--mform-repeater-group-accent); transition: width 0.25s ease-in-out; } -.rex-theme-light section.repeater .repeater-group:hover::before, section.repeater .repeater-group:hover::before { - background-color: rgba(0, 0, 0, 0.3); + background-color: var(--mform-repeater-group-accent); width: 3px; } -.rex-theme-light section.repeater .repeater-group:hover, section.repeater .repeater-group:hover { - box-shadow: 0 5px 15px rgba(0, 0, 0, .22); -} - -.rex-theme-dark section.repeater .repeater-group { - border: 1px solid rgba(17, 17, 17, 0.1); - background: rgba(17, 17, 17, 0.15); - box-shadow: 0 5px 15px rgba(0, 0, 0, .08); -} - -.rex-theme-dark section.repeater .repeater-group:hover::before { - background-color: rgba(255, 255, 255, 0.3); -} - -.rex-theme-dark section.repeater .repeater-group:hover { - box-shadow: 0 5px 15px rgba(0, 0, 0, .22); + box-shadow: var(--mform-repeater-group-shadow-hover); } section.repeater .repeater-group:last-child { margin-bottom: 0; } -@media (prefers-color-scheme: dark) { - section.repeater .repeater-group { - border: 1px solid rgba(17, 17, 17, 0.1); - background: rgba(17, 17, 17, 0.15); - box-shadow: 0 5px 15px rgba(0, 0, 0, .08); - } - - section.repeater .repeater-group:hover::before { - background-color: rgba(255, 255, 255, 0.3); - } - - section.repeater .repeater-group:hover { - box-shadow: 0 5px 15px rgba(0, 0, 0, .22); - } -} - section.repeater .repeater-group header > div { display: block; position: absolute; @@ -705,7 +742,7 @@ section.repeater .repeater-group header + .mform > .mform-tabs .tab-content { } .mform-inline-img-radios label.active img { - border: 4px solid #79af8a; + border: 4px solid var(--mform-accent); box-shadow: 0 0 5px 5px rgba(0, 0, 0, .03); opacity: 0.97; } @@ -757,7 +794,7 @@ section.repeater .repeater-group header + .mform > .mform-tabs .tab-content { .mform-icon-radios label.active, .mform-inline-icon-radios label.active { - border: 4px solid #79af8a; + border: 4px solid var(--mform-accent); box-shadow: 0 0 5px 5px rgba(0, 0, 0, .03); opacity: 0.97; } @@ -812,7 +849,7 @@ section.repeater .repeater-group header + .mform > .mform-tabs .tab-content { .mform-inline-color-radios.form-group .radio input[type=radio]:checked + span { transform: scale(1.25); - border: 2px solid #79af8a; + border: 2px solid var(--mform-accent); } .mform .checkbox .mform-toggle { @@ -841,7 +878,7 @@ section.repeater .repeater-group header + .mform > .mform-tabs .tab-content { align-items: center; gap: 6px; padding: 5px 12px; - border: 2px solid rgba(94, 94, 94, 0.3); + border: 2px solid var(--mform-cbg-border); border-radius: 4px; cursor: pointer; font-weight: normal; @@ -852,14 +889,14 @@ section.repeater .repeater-group header + .mform > .mform-tabs .tab-content { } .mform-cbg-option:hover { - border-color: rgba(94, 94, 94, 0.55); + border-color: var(--mform-cbg-border-hover); opacity: 0.9; } .mform-cbg-option.active { - border-color: #79af8a; - background-color: rgba(121, 175, 138, 0.12); - color: inherit; + border-color: var(--mform-accent); + background-color: var(--mform-accent-bg); + color: var(--mform-cbg-text-active); opacity: 1; } @@ -867,7 +904,7 @@ section.repeater .repeater-group header + .mform > .mform-tabs .tab-content { display: inline-block; width: 14px; height: 14px; - border: 2px solid rgba(94, 94, 94, 0.45); + border: 2px solid var(--mform-cbg-indicator-border); border-radius: 3px; background: transparent; flex-shrink: 0; @@ -876,8 +913,8 @@ section.repeater .repeater-group header + .mform > .mform-tabs .tab-content { } .mform-cbg-option.active .mform-cbg-indicator { - border-color: #79af8a; - background-color: #79af8a; + border-color: var(--mform-accent); + background-color: var(--mform-accent); } .mform-cbg-option.active .mform-cbg-indicator::after { @@ -909,41 +946,6 @@ section.repeater .repeater-group header + .mform > .mform-tabs .tab-content { transform: none; } -/* Dark mode */ -body.rex-theme-dark .mform-cbg-option { - border-color: rgba(180, 180, 180, 0.25); - color: rgba(220, 220, 220, 0.85); -} - -body.rex-theme-dark .mform-cbg-option:hover { - border-color: rgba(180, 180, 180, 0.45); -} - -body.rex-theme-dark .mform-cbg-option.active { - border-color: #79af8a; - background-color: rgba(121, 175, 138, 0.18); - color: #fff; -} - -@media (prefers-color-scheme: dark) { - body.rex-has-theme:not(.rex-theme-light) .mform-cbg-option { - border-color: rgba(180, 180, 180, 0.25); - color: rgba(220, 220, 220, 0.85); - } - - body.rex-has-theme:not(.rex-theme-light) .mform-cbg-option:hover { - border-color: rgba(180, 180, 180, 0.45); - } - - body.rex-has-theme:not(.rex-theme-light) .mform-cbg-option.active { - border-color: #79af8a; - background-color: rgba(121, 175, 138, 0.18); - color: #fff; - } -} - - - .collapse-group > .collapse > .form-group { margin-bottom: 15px !important; } @@ -974,8 +976,8 @@ body.rex-theme-dark .mform-cbg-option.active { align-items: center; gap: 4px; margin-bottom: 4px; - background: #f7f9fb; - border: 1px solid #dde4ec; + background: var(--mform-cl-multi-bg); + border: 1px solid var(--mform-cl-multi-border); border-radius: 4px; padding: 4px 6px; } @@ -994,7 +996,7 @@ body.rex-theme-dark .mform-cbg-option.active { .mform-cl-multi-handle { cursor: grab; - color: #aaa; + color: var(--mform-cl-multi-handle); padding: 0 4px; flex-shrink: 0; } @@ -1016,7 +1018,7 @@ body.rex-theme-dark .mform-cbg-option.active { flex-shrink: 0; border: 0 !important; background: transparent !important; - color: #c0392b !important; + color: var(--mform-cl-multi-remove) !important; padding: 2px 6px; } @@ -1028,35 +1030,6 @@ body.rex-theme-dark .mform-cbg-option.active { margin-top: 2px; } -/* Dark mode */ -body.rex-theme-dark .mform-cl-multi-item { - background: #1f2830; - border-color: #3a4753; -} - -body.rex-theme-dark .mform-cl-multi-handle { - color: #5a6a78; -} - -body.rex-theme-dark .mform-cl-multi-remove { - color: #e57373 !important; -} - -@media (prefers-color-scheme: dark) { - body.rex-has-theme:not(.rex-theme-light) .mform-cl-multi-item { - background: #1f2830; - border-color: #3a4753; - } - - body.rex-has-theme:not(.rex-theme-light) .mform-cl-multi-handle { - color: #5a6a78; - } - - body.rex-has-theme:not(.rex-theme-light) .mform-cl-multi-remove { - color: #e57373 !important; - } -} - /* ------------------------------------------------------- * Color Swatch Field (.mform-color-swatch) * ------------------------------------------------------- */ @@ -1081,8 +1054,8 @@ body.rex-theme-dark .mform-cl-multi-remove { font-size: 9px; line-height: 20px; text-align: center; - color: #333; - background: #e0e0e0 !important; + color: var(--mform-cs-preview-class-text); + background: var(--mform-cs-preview-class-bg) !important; font-weight: bold; letter-spacing: -0.5px; } @@ -1131,8 +1104,9 @@ body.rex-theme-dark .mform-cl-multi-remove { top: 100%; left: 0; margin-top: 4px; - background: #fff; - border: 1px solid rgba(0, 0, 0, 0.15); + background: var(--mform-cs-popup-bg); + border: 1px solid var(--mform-cs-popup-border); + color: var(--mform-cs-popup-text); border-radius: 6px; padding: 10px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); @@ -1163,15 +1137,15 @@ body.rex-theme-dark .mform-cl-multi-remove { } .mform-cs-swatch.mform-cs-active { - border-color: #79af8a; - box-shadow: 0 0 0 2px rgba(121, 175, 138, 0.4); + border-color: var(--mform-accent); + box-shadow: 0 0 0 2px var(--mform-accent-ring); } .mform-cs-swatch--class { - background: #e0e0e0; + background: var(--mform-cs-swatch-class-bg); font-size: 8px; font-weight: bold; - color: #444; + color: var(--mform-cs-swatch-class-text); line-height: 24px; text-align: center; overflow: hidden; @@ -1179,37 +1153,3 @@ body.rex-theme-dark .mform-cl-multi-remove { text-overflow: clip; } -/* Dark mode */ -body.rex-theme-dark .mform-cs-popup { - background: #1e2a35; - border-color: rgba(255, 255, 255, 0.12); - color: #ccd4dc; -} - -body.rex-theme-dark .mform-cs-preview--class { - background: #2d3b48 !important; - color: #ccc; -} - -body.rex-theme-dark .mform-cs-swatch--class { - background: #2d3b48; - color: #ccc; -} - -@media (prefers-color-scheme: dark) { - body.rex-has-theme:not(.rex-theme-light) .mform-cs-popup { - background: #1e2a35; - border-color: rgba(255, 255, 255, 0.12); - color: #ccd4dc; - } - - body.rex-has-theme:not(.rex-theme-light) .mform-cs-preview--class { - background: #2d3b48 !important; - color: #ccc; - } - - body.rex-has-theme:not(.rex-theme-light) .mform-cs-swatch--class { - background: #2d3b48; - color: #ccc; - } -} \ No newline at end of file diff --git a/assets/js/flex-repeater.js b/assets/js/flex-repeater.js index 7b48c540..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 // ------------------------------------------------------------------------- @@ -502,8 +521,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); } @@ -711,6 +732,7 @@ this.data = []; this._suppressSync = false; this._isBootstrapping = false; + registerClipboardUiInstance(this); this._log('constructor', { fieldName: this.fieldName, @@ -791,6 +813,15 @@ e.preventDefault(); this._log('toggle all clicked (delegated)'); this._toggleAll(); + return; + } + + // Paste button in top toolbar → insert at start + const pasteStartBtn = e.target.closest('.mfr-btn-paste-start'); + if (pasteStartBtn && pasteStartBtn.closest('.mfr-container') === this.container) { + e.preventDefault(); + this._pasteItemAtStart(); + return; } // Paste button in toolbar → append at end @@ -798,6 +829,15 @@ if (pasteBtn && pasteBtn.closest('.mfr-container') === this.container) { e.preventDefault(); this._pasteItem(); + return; + } + + // Clear clipboard button in toolbar + const clearClipboardBtn = e.target.closest('.mfr-btn-clipboard-clear'); + if (clearClipboardBtn && clearClipboardBtn.closest('.mfr-container') === this.container) { + e.preventDefault(); + this._clearClipboard(); + return; } // Paste button on item → insert after that item @@ -807,6 +847,7 @@ const itemEl = pasteAfterBtn.closest('.mfr-item'); const idx = itemEl ? Array.from(this.itemsList.children).indexOf(itemEl) : -1; this._pasteItemAfter(idx); + return; } }); @@ -816,16 +857,7 @@ this._sortableInitialized = false; this._initSortable(); - // Show paste buttons if clipboard is already filled - if (this.copyPaste) { - try { - if (sessionStorage.getItem('mfr_clipboard')) { - this.container.querySelectorAll('.mfr-btn-paste, .mfr-btn-paste-after, .mfr-btn-paste-after').forEach(function (btn) { - btn.style.display = ''; - }); - } - } catch (e) { /* ignore */ } - } + this._updateClipboardUi(); // Formular-Submit wird über den globalen Handler in initRepeaters abgewickelt } @@ -854,14 +886,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); } @@ -997,6 +1030,8 @@ }); setTimeout(() => initWidgets(itemEl), 20); + this._updateClipboardUi(); + return itemEl; } @@ -1114,18 +1149,12 @@ const snapshot = JSON.parse(JSON.stringify(this.data[idx] || {})); // Remove disabled marker so paste produces an enabled item delete snapshot[MFR_ITEM_DISABLED_KEY]; - try { - sessionStorage.setItem('mfr_clipboard', JSON.stringify(snapshot)); - } catch (e2) { - window._mfrClipboard = snapshot; - } - // Show all paste buttons in this container - this.container.querySelectorAll('.mfr-btn-paste, .mfr-btn-paste-after').forEach(function (btn) { - btn.style.display = ''; - }); - // Visual feedback + this._setClipboardSnapshot(snapshot); + this._updateClipboardUi(); + 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 }); }); } @@ -1179,29 +1208,39 @@ } _pasteItem() { - let snapshot = null; - try { - const raw = sessionStorage.getItem('mfr_clipboard'); - if (raw) snapshot = JSON.parse(raw); - } catch (e) { /* ignore */ } - if (!snapshot && window._mfrClipboard) { - snapshot = window._mfrClipboard; - } + const snapshot = this._getClipboardSnapshot(); if (!snapshot) return; const data = JSON.parse(JSON.stringify(snapshot)); this._log('pasteItem', { data: data }); this.addItem(data); + this._updateClipboardUi(); } - _pasteItemAfter(idx) { - let snapshot = null; - try { - const raw = sessionStorage.getItem('mfr_clipboard'); - if (raw) snapshot = JSON.parse(raw); - } catch (e) { /* ignore */ } - if (!snapshot && window._mfrClipboard) { - snapshot = window._mfrClipboard; + _pasteItemAtStart() { + const snapshot = this._getClipboardSnapshot(); + if (!snapshot) return; + const data = JSON.parse(JSON.stringify(snapshot)); + this._log('pasteItemAtStart', { data: data }); + + 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 && firstSibling && firstSibling !== insertedEl) { + firstSibling.before(insertedEl); } + + this._reindex(); + this._updateAddBtn(); + this._updateToggleAllButton(); + this.syncValue(); + this._focusNewItem(insertedEl, true); + this._updateClipboardUi(); + } + + _pasteItemAfter(idx) { + const snapshot = this._getClipboardSnapshot(); if (!snapshot) return; const data = JSON.parse(JSON.stringify(snapshot)); this._log('pasteItemAfter', { idx: idx, data: data }); @@ -1210,6 +1249,116 @@ } else { this.addItem(data); } + this._updateClipboardUi(); + } + + _setClipboardSnapshot(snapshot) { + if (!snapshot || typeof snapshot !== 'object') return; + const payload = { + mfrClipboardVersion: 2, + scopeKey: this._getClipboardScopeKey(), + data: snapshot + }; + try { + sessionStorage.setItem('mfr_clipboard', JSON.stringify(payload)); + } catch (e) { /* ignore */ } + window._mfrClipboard = payload; + document.dispatchEvent(new CustomEvent('mfr:clipboard-updated')); + } + + _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) payload = JSON.parse(raw); + } catch (e) { /* ignore */ } + + if (!payload && window._mfrClipboard) { + payload = window._mfrClipboard; + } + + return payload; + } + + _getClipboardSnapshot() { + const payload = this._readClipboardPayload(); + if (!payload || typeof payload !== 'object') { + return null; + } + + 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() { + try { + sessionStorage.removeItem('mfr_clipboard'); + } catch (e) { /* ignore */ } + window._mfrClipboard = null; + document.dispatchEvent(new CustomEvent('mfr:clipboard-updated')); + } + + _updateClipboardUi() { + if (!this.copyPaste) return; + const hasClipboard = !!this._getClipboardSnapshot(); + + this.container.querySelectorAll('.mfr-btn-paste, .mfr-btn-paste-start, .mfr-btn-paste-after').forEach(function (btn) { + btn.style.display = hasClipboard ? '' : 'none'; + }); + + this.container.querySelectorAll('.mfr-btn-clipboard-clear').forEach(function (btn) { + btn.style.display = hasClipboard ? '' : 'none'; + const title = btn.getAttribute('title') || 'Kopieren beenden'; + if (!btn.getAttribute('title')) { + btn.setAttribute('title', title); + } + if (!btn.getAttribute('aria-label')) { + btn.setAttribute('aria-label', title); + } + if (!btn.getAttribute('data-toggle')) { + btn.setAttribute('data-toggle', 'tooltip'); + } + if (!btn.getAttribute('data-placement')) { + btn.setAttribute('data-placement', 'top'); + } + }); } _moveItem(fromIdx, toIdx) { diff --git a/assets/mform.js b/assets/mform.js index 3491d333..f409ec45 100644 --- a/assets/mform.js +++ b/assets/mform.js @@ -177,9 +177,10 @@ function initMFormSelectPicker(mform) { mform.find('.selectpicker').each(function () { // Stellen Sie sicher, dass der Wert '0' korrekt behandelt wird var selectedValue = $(this).attr('data-selected'); + var options = {}; $(this).selectpicker('destroy'); - $(this).selectpicker(); + $(this).selectpicker(options); // Wenn selectedValue '0' ist, manuell den ausgewählten Wert setzen if (selectedValue === '0' || selectedValue === 0) { diff --git a/docs/01_basics.md b/docs/01_basics.md index e644c8c5..35a32e19 100644 --- a/docs/01_basics.md +++ b/docs/01_basics.md @@ -195,6 +195,26 @@ $mform = MForm::factory() echo $mform->show(); ``` +### Tooltip-Icon: Default und Override + +Wenn bei `setTooltipInfo()` kein Icon gesetzt wird, nutzt MForm standardmäßig `fa-info-circle`. + +```php +addTextField(1.0, ['label' => 'Titel']) + // Default-Icon: fa-info-circle + ->setTooltipInfo('Standard-Hinweis ohne Icon-Override') + + ->addTextField(1.1, ['label' => 'Untertitel']) + // Eigenes Icon explizit gesetzt + ->setTooltipInfo('Hinweis mit Fragezeichen-Icon', 'fa-question-circle'); + +echo $mform->show(); +``` + ## Select- und Multiselect-Elemente Rendert ``-Elemente. 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/docs/13_api_reference.md b/docs/13_api_reference.md index afb46733..5221e4b3 100644 --- a/docs/13_api_reference.md +++ b/docs/13_api_reference.md @@ -702,6 +702,9 @@ setTooltipInfo(?string $value = null, string $icon = ''): MForm ``` Zeigt ein Info-Tooltip-Icon neben dem Label. +- Default ohne Icon-Parameter: `fa-info-circle` +- Eigenes Icon weiterhin möglich, z. B. `fa-question-circle` + --- ```php 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/lang/de_de.lang b/lang/de_de.lang index b5b7a816..95fe92b1 100755 --- a/lang/de_de.lang +++ b/lang/de_de.lang @@ -8,6 +8,7 @@ mform_demo_base = Basis Beispiele mform_demo_extended = Erweiterte Beispiele mform_demo_expert = Experten Beispiele mform_demo_layout_preview = Layout & SVG Vorschau +mform_demo_renderer_parity = Renderer-Parität mform_formbuilder = Form Builder mform_demo_community = FOS Beispiele mform_demo_wrapper = Wrapper Beispiele @@ -159,6 +160,9 @@ mform_example_description_community = Later mform_example_description_wrapper = Die "Wrapper Beispiele" zeigen auf, wie man mittels der MForm Wrapper-Elemente Input-Formulare sinnvoll layouten und interaktiv aufbereiten kann. mform_example_description_repeater = Durch die "Repeater Beispiele" wird demonstiert, wie einfach ein Repeater Element funktioniert, prinzipiell lässt es sich wie die anderen Wrapper Elemente anlegen. Das gewrappte Formular kann durch den Repeater beliebig oft oder mit einem min. oder max. Blocklimit (genauso wie bisher mit MBlock) repliziert werden. mform_example_description_layout_preview = Diese Seite zeigt die beiden Utility-Klassen HtmlToSvgConverter und LayoutPreviewBuilder aus dem MForm-Namespace FriendsOfRedaxo\MForm\Utils. LayoutPreviewBuilder erzeugt programmatisch SVG-Layout-Vorschauen aus Sections, Spalten und Platzhalterelementen – ideal als Modul-Vorschaubild im Backend. HtmlToSvgConverter verpackt SVG-Fragmente (rect, circle, line, path, text, g, image) zu einem vollständigen, eigenständigen SVG. Der "HTML"-Anteil bezieht sich dabei auf die unterstützten HTML-Style-Attribute (style="background:…; color:…; border: 1px solid red") auf diesen SVG-Tags – sie werden zu fill / stroke / stroke-width umgesetzt. +mform_demo_renderer_parity_description = Smoke-Checks für Parser und Flex-Repeater. Diese Seite vergleicht typische Wrapper-/Label-Szenarien und zeigt, ob beide Renderpfade die gleichen Kernmerkmale enthalten. +mform_demo_renderer_parity_checks = Renderer-Parität: Smoke-Checks +mform_demo_renderer_parity_html = Renderer-Parität: HTML-Vergleich mform_github = MForm bei FOR - go to github @@ -180,8 +184,11 @@ mform_flex_repeater_visibility = Aktiv / Inaktiv (Ausgabe) mform_flex_repeater_remove = Entfernen mform_flex_repeater_toggle = Aufklappen / Zuklappen mform_flex_repeater_copy = Kopieren +mform_flex_repeater_paste_label = Einfügen +mform_flex_repeater_paste_start = Einfügen (am Anfang) mform_flex_repeater_paste = Einfügen (am Ende) mform_flex_repeater_paste_after = Danach einfügen +mform_flex_repeater_clipboard_clear = Kopieren beenden mform_install = Install mform_update = Update diff --git a/lang/en_gb.lang b/lang/en_gb.lang index ea16bf59..3dc83941 100644 --- a/lang/en_gb.lang +++ b/lang/en_gb.lang @@ -8,6 +8,7 @@ mform_demo_base = Basic examples mform_demo_extended = Extended examples mform_demo_expert = Expert examples mform_demo_layout_preview = Layout & SVG preview +mform_demo_renderer_parity = Renderer parity mform_formbuilder = Form Builder mform_demo_community = FOS examples mform_demo_wrapper = Wrapper examples @@ -160,6 +161,9 @@ mform_example_description_community = Later mform_example_description_wrapper = The "Wrapper Examples" demonstrate how to effectively layout and enhance input forms using MForm wrapper elements. mform_example_description_repeater = The "Repeater Examples" illustrate how simple it is to use a repeater element. Essentially, it can be created like the other wrapper elements. The wrapped form can be replicated using the repeater as many times as needed, with minimum or maximum block limits (similar to MBlock as before). mform_example_description_layout_preview = This page demonstrates the two utility classes HtmlToSvgConverter and LayoutPreviewBuilder from the MForm namespace FriendsOfRedaxo\MForm\Utils. LayoutPreviewBuilder programmatically generates SVG layout previews from sections, columns and placeholder elements – ideal as a module preview image in the backend. HtmlToSvgConverter wraps SVG fragments (rect, circle, line, path, text, g, image) into a complete, standalone SVG. The "HTML" part refers to the supported HTML-style attributes (style="background:…; color:…; border: 1px solid red") on those SVG tags – they are translated to fill / stroke / stroke-width. +mform_demo_renderer_parity_description = Smoke checks for parser and flex repeater. This page compares common wrapper/label scenarios and shows whether both render paths contain the same core markers. +mform_demo_renderer_parity_checks = Renderer parity: Smoke checks +mform_demo_renderer_parity_html = Renderer parity: HTML comparison mform_github = MForm FOR – go to github @@ -178,8 +182,11 @@ mform_cl_multi_remove = Remove mform_cl_multi_move = Move mform_flex_repeater_toggle = Expand / Collapse mform_flex_repeater_copy = Copy +mform_flex_repeater_paste_label = Paste +mform_flex_repeater_paste_start = Paste (at start) mform_flex_repeater_paste = Paste (at end) mform_flex_repeater_paste_after = Paste after +mform_flex_repeater_clipboard_clear = End copy mode mform_repeater_remove_field_confirm_msg = Remove field? mform_list_widget_view_grid = Grid view mform_list_widget_view_list = List view diff --git a/lib/MForm/FlexRepeater/MFormFlexRepeaterRenderer.php b/lib/MForm/FlexRepeater/MFormFlexRepeaterRenderer.php index 17973750..3f2fecca 100644 --- a/lib/MForm/FlexRepeater/MFormFlexRepeaterRenderer.php +++ b/lib/MForm/FlexRepeater/MFormFlexRepeaterRenderer.php @@ -4,6 +4,9 @@ use FriendsOfRedaxo\MForm; use FriendsOfRedaxo\MForm\DTO\MFormItem; +use FriendsOfRedaxo\MForm\Template\MFormFieldTypeCore; +use FriendsOfRedaxo\MForm\Template\MFormLabelRenderer; +use FriendsOfRedaxo\MForm\Template\MFormLayoutCore; use FriendsOfRedaxo\MForm\Utils\MFormGroupExtensionHelper; use rex_var_custom_link; use rex_var_custom_link_multi; @@ -24,6 +27,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 +82,7 @@ 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 = MFormLayoutCore::consumeModalRowClass($attrs); $innerHtml = ''; ++$i; while ($i < count($items)) { @@ -90,7 +98,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; } @@ -124,20 +132,20 @@ public static function renderTemplate(MForm $form, int $level = 1): string if ('collapse' === $type) { $attrs = $item->getAttributes(); $labelStr = self::getLabelString($item->getLabel()); // Entwickler-HTML, nicht escapen - $hideToggleLinks = isset($attrs['data-group-hide-toggle-links']) && 'true' === (string) $attrs['data-group-hide-toggle-links']; - $openCollapse = isset($attrs['data-group-open-collapse']) && (1 === (int) $attrs['data-group-open-collapse'] || true === $attrs['data-group-open-collapse']); - $isAccordion = isset($attrs['data-group-accordion']) && 1 === (int) $attrs['data-group-accordion']; + $hideToggleLinks = MFormLayoutCore::shouldHideCollapseToggle($attrs, '' !== $labelStr); + $openCollapse = MFormLayoutCore::isCollapseOpen($attrs); + $isAccordion = MFormLayoutCore::isCollapseAccordion($attrs); $btnAttrs = ' data-toggle="collapse"'; if (!$isAccordion) { $btnAttrs .= ' data-collapse-open="' . ($openCollapse ? 1 : 0) . '"'; } $btnAttrs .= ' aria-expanded="' . ($openCollapse ? 'true' : 'false') . '"'; - $btnHidden = ('' === $labelStr || $hideToggleLinks) ? ' hidden' : ''; + $btnHidden = $hideToggleLinks ? ' hidden' : ''; $btnHtml = sprintf('%s', $btnHidden, $btnAttrs, $labelStr); // Wrapper-Attribute bereinigen wie im Fragment $wrapperAttrs = $attrs; - unset($wrapperAttrs['data-group-hide-toggle-links'], $wrapperAttrs['data-group-accordion'], $wrapperAttrs['data-group-open-collapse']); + MFormLayoutCore::consumeCollapseWrapperAttributes($wrapperAttrs); $cls = trim('collapse ' . $item->getClass() . ($openCollapse ? ' in' : '')); $wrapperAttrHtml = self::renderAttributes($wrapperAttrs); $html .= $btnHtml . sprintf('
', htmlspecialchars($cls, ENT_QUOTES), $wrapperAttrHtml); @@ -171,8 +179,11 @@ 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 = MFormLayoutCore::consumeColumnGroupRowClass($attrs); + + $cls = trim('row ' . $rowExtraClass . ' ' . $item->getClass()); + $html .= sprintf('
', htmlspecialchars($cls, ENT_QUOTES), self::renderAttributes($attrs)); ++$i; continue; } @@ -214,12 +225,8 @@ public static function renderTemplate(MForm $form, int $level = 1): string $navHtml = ''; foreach ($tabsMeta as $idx => $meta) { $tabIcon = isset($meta['attrs']['tab-icon']) ? ' ' : ''; - $isActive = isset($meta['attrs']['data-group-open-tab']) && true === $meta['attrs']['data-group-open-tab']; - $navClass = trim( - ((isset($meta['attrs']['nav-class'])) ? (string) $meta['attrs']['nav-class'] . ' ' : '') - . ((isset($meta['attrs']['pull-right']) && true === $meta['attrs']['pull-right']) ? 'pull-right ' : '') - . ($isActive ? 'active' : ''), - ); + $isActive = MFormLayoutCore::isTabActive($meta['attrs']); + $navClass = MFormLayoutCore::buildTabNavClass($meta['attrs']); $navHtml .= sprintf( '', htmlspecialchars($navClass, ENT_QUOTES), @@ -231,14 +238,12 @@ public static function renderTemplate(MForm $form, int $level = 1): string ); } $groupAttributes = $item->getAttributes(); - $layout = strtolower(trim((string) ($groupAttributes['data-group-tab-layout'] ?? ''))); - $style = strtolower(trim((string) ($groupAttributes['data-group-tab-style'] ?? ''))); $cls = trim('nav mform-tabs rex-page-nav ' . $item->getClass()); - if (in_array($layout, ['vertical', 'left', 'nav-left'], true)) { + if (MFormLayoutCore::isTabLayoutVertical($groupAttributes)) { $cls .= ' mform-tabs--vertical'; } - if ('modern' === $style) { + if (MFormLayoutCore::isTabStyleModern($groupAttributes)) { $cls .= ' mform-tabs--modern'; } @@ -254,7 +259,7 @@ public static function renderTemplate(MForm $form, int $level = 1): string if ('tab' === $type) { $tabIdx = self::tabIndexInGroup($items, $i); $attrs = $item->getAttributes(); - $isActive = isset($attrs['data-group-open-tab']) && true === $attrs['data-group-open-tab']; + $isActive = MFormLayoutCore::isTabActive($attrs); unset($attrs['tab-icon'], $attrs['nav-class'], $attrs['pull-right'], $attrs['data-group-open-tab'], $attrs['data-group-tab-layout'], $attrs['data-group-tab-style']); $cls = trim('tab-pane ' . $item->getClass() . ($isActive ? ' active' : '')); $html .= sprintf( @@ -406,37 +411,44 @@ private static function renderField(MFormItem $item): string if (count($toggleOptions) > 0 && in_array($type, ['select', 'multiselect'], true) && !isset($itemAttributes['data-toggle'])) { $itemAttributes = array_merge(['data-toggle' => 'collapse'], $itemAttributes); } + MFormLayoutCore::ensureSelectpickerContainer($itemAttributes, $item->getClass()); $attrs = self::renderAttributes($itemAttributes); $class = htmlspecialchars($item->getClass(), ENT_QUOTES); $key = htmlspecialchars($fieldKey, ENT_QUOTES); - switch ($type) { - case 'text': - case 'email': - case 'url': - case 'tel': - case 'number': - case 'color': - case 'date': - case 'time': - case 'datetime-local': - case 'month': - case 'week': - case 'search': - case 'range': - return self::wrapFormGroup( - $label, - sprintf('', htmlspecialchars($type, ENT_QUOTES), $class, $key, $attrs), - $item, - ); + $normalizedInputType = MFormFieldTypeCore::normalizeSimpleInputType($type); + if (null !== $normalizedInputType) { + return self::wrapFormGroup( + $label, + self::renderInputWithOptionalDatalist( + $normalizedInputType, + $class, + $key, + $attrs, + $item->getOptions(), + MFormFieldTypeCore::isReadonlySimpleInputType($type), + ), + $item, + ); + } - case 'textarea': - return self::wrapFormGroup( - $label, - sprintf('', $class, $key, $attrs), - $item, - ); + if (MFormFieldTypeCore::isTextareaLikeType($type)) { + $readonlyAttr = MFormFieldTypeCore::isReadonlyTextareaType($type) ? ' readonly' : ''; + + return self::wrapFormGroup( + $label, + sprintf( + '', + $class, + $key, + $attrs, + $readonlyAttr, + ), + $item, + ); + } + switch ($type) { case 'hidden': return sprintf('', $key); @@ -487,20 +499,6 @@ private static function renderField(MFormItem $item): string case 'linklist': return self::wrapFormGroup($label, self::renderListWidget('linklist', $key, $item), $item); - case 'text-readonly': - return self::wrapFormGroup( - $label, - sprintf('', $class, $key, $attrs), - $item, - ); - - case 'textarea-readonly': - return self::wrapFormGroup( - $label, - sprintf('', $class, $key, $attrs), - $item, - ); - case 'headline': $val = is_string($item->getValue()) ? $item->getValue() : ''; return sprintf('

%s

', htmlspecialchars($val, ENT_QUOTES)); @@ -522,7 +520,52 @@ private static function renderField(MFormItem $item): string } } - private static function renderModalBlock(string $label, string $btnClass, string $align, string $innerHtml): string + /** + * @param array $options + */ + private static function renderInputWithOptionalDatalist(string $type, string $class, string $fieldKeyEsc, string $attrs, array $options, bool $readonly = false): string + { + $datalistId = ''; + $datalistHtml = ''; + if (count($options) > 0) { + $datalistId = '__MFRID__-datalist-' . preg_replace('/[^a-z0-9\-_]/i', '-', html_entity_decode($fieldKeyEsc, ENT_QUOTES)); + $datalistHtml = sprintf('%s', htmlspecialchars($datalistId, ENT_QUOTES), self::renderDatalistOptions($options)); + } + + $listAttr = '' !== $datalistId ? ' list="' . htmlspecialchars($datalistId, ENT_QUOTES) . '"' : ''; + $readonlyAttr = $readonly ? ' readonly' : ''; + + return sprintf( + '%s', + htmlspecialchars($type, ENT_QUOTES), + $class, + $fieldKeyEsc, + $attrs, + $listAttr, + $readonlyAttr, + $datalistHtml, + ); + } + + /** + * @param array $options + */ + private static function renderDatalistOptions(array $options): string + { + $html = ''; + foreach ($options as $key => $value) { + if (is_array($value)) { + continue; + } + + $labelAttr = is_int($key) ? '' : ' label="' . htmlspecialchars((string) $key, ENT_QUOTES) . '"'; + $html .= ''; + } + + return $html; + } + + private static function renderModalBlock(string $label, string $btnClass, string $align, string $innerHtml, string $rowClass = ''): string { $alignClass = match ($align) { 'center' => 'text-center', @@ -530,7 +573,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( @@ -205,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[] = '
'; @@ -223,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( @@ -258,7 +267,7 @@ private function openWrapperElement(MFormItem $item, int|string $key, array $ite if ('modal' == $item->getType()) { $labelRaw = $item->getLabel(); if ('' !== $labelRaw && [] !== $labelRaw) { - $labelStr = is_array($labelRaw) ? (string) (array_values($labelRaw)[0] ?? '') : (string) $labelRaw; + $labelStr = MFormLabelRenderer::resolveLabelValue($labelRaw); $element->setLabel($labelStr); } $removeAttributes = ['data-modal-btn-class']; @@ -281,12 +290,16 @@ private function openWrapperElement(MFormItem $item, int|string $key, array $ite // COLLAPSE MANIPULATIONS if ('collapse' == $item->getType()) { $removeAttributes = ['data-group-hide-toggle-links', 'data-group-accordion', 'data-group-open-collapse']; + $openCollapse = MFormLayoutCore::isCollapseOpen($attributes); + $isAccordion = MFormLayoutCore::isCollapseAccordion($attributes); + $hideToggle = MFormLayoutCore::shouldHideCollapseToggle($attributes, '' !== MFormLabelRenderer::resolveLabelValue($item->getLabel())); + $buttonAttributes = [ 'data-toggle' => 'collapse', - 'data-collapse-open' => (int) $attributes['data-group-open-collapse'], - 'aria-expanded' => ((1 == (int) $attributes['data-group-open-collapse']) ? 'true' : 'false'), + 'data-collapse-open' => $openCollapse ? 1 : 0, + 'aria-expanded' => $openCollapse ? 'true' : 'false', ]; - if (isset($attributes['data-group-accordion']) && 1 == (int) $attributes['data-group-accordion']) { + if ($isAccordion) { unset($buttonAttributes['data-collapse-open']); } if ('true' == $buttonAttributes['aria-expanded']) { @@ -294,9 +307,9 @@ private function openWrapperElement(MFormItem $item, int|string $key, array $ite } $collapseButton = new MFormElement(); $collapseButton->setType('collapse-button') - ->setClass((('' === $item->getLabel() || [] === $item->getLabel()) || (array_key_exists('data-group-hide-toggle-links', $attributes) && 'true' == $attributes['data-group-hide-toggle-links'])) ? ' hidden' : '') + ->setClass($hideToggle ? ' hidden' : '') ->setAttributes($this->parseAttributes($buttonAttributes)) - ->setValue(is_array($item->getLabel()) ? (string) (array_values($item->getLabel())[0] ?? '') : (string) $item->getLabel()); + ->setValue(MFormLabelRenderer::resolveLabelValue($item->getLabel())); $element->setLabel($this->parseElement($collapseButton, 'wrapper')); // add parsed legend to collapse element } @@ -304,6 +317,14 @@ private function openWrapperElement(MFormItem $item, int|string $key, array $ite $removeAttributes = ['data-group-collapse-id']; } + // COLUMN GROUP MANIPULATIONS + if ('start-group-column' == $item->getType()) { + $rowClass = MFormLayoutCore::consumeColumnGroupRowClass($attributes); + if ('' !== $rowClass) { + $item->setClass(trim($item->getClass() . ' ' . $rowClass)); + } + } + // TAB MANIPULATIONS if ('start-group-tab' == $item->getType()) { $nav = []; @@ -313,34 +334,35 @@ private function openWrapperElement(MFormItem $item, int|string $key, array $ite $element = new MFormElement(); $element->setType('tabnavli') ->setValue($itm->getGroup() . $itm->getGroupCount() . '_' . (string) $item->getGroupKey()) - ->setLabel(((array_key_exists('tab-icon', $itm->getAttributes())) ? ' ' : '') . (is_array($itm->getLabel()) ? (string) (array_values($itm->getLabel())[0] ?? '') : (string) $itm->getLabel())) - ->setClass( - ((array_key_exists('nav-class', $itm->getAttributes())) ? $itm->getAttributes()['nav-class'] . ' ' : '') . - ((array_key_exists('pull-right', $itm->getAttributes()) && true === $itm->getAttributes()['pull-right']) ? ' pull-right' : '') . - ((array_key_exists('data-group-open-tab', $itm->getAttributes()) && true === $itm->getAttributes()['data-group-open-tab']) ? ' active' : ''), - ); + ->setLabel(((array_key_exists('tab-icon', $itm->getAttributes())) ? ' ' : '') . MFormLabelRenderer::resolveLabelValue($itm->getLabel())) + ->setClass(MFormLayoutCore::buildTabNavClass($itm->getAttributes())); $nav[] = $this->parseElement($element, 'wrapper'); } } $element->setElement(implode('', $nav)); - $tabLayout = strtolower(trim((string) ($attributes['data-group-tab-layout'] ?? ''))); - if (in_array($tabLayout, ['vertical', 'left', 'nav-left'], true)) { + if (MFormLayoutCore::isTabLayoutVertical($attributes)) { $item->setClass(trim($item->getClass() . ' mform-tabs--vertical')); } - $tabStyle = strtolower(trim((string) ($attributes['data-group-tab-style'] ?? ''))); - if ('modern' === $tabStyle) { + if (MFormLayoutCore::isTabStyleModern($attributes)) { $item->setClass(trim($item->getClass() . ' mform-tabs--modern')); } } if ('tab' == $item->getType()) { $attributes['data-tab-group-nav-tab-id'] = $item->getGroup() . $item->getGroupCount() . '_' . $item->getGroupKey(); - if (isset($attributes['data-group-open-tab']) && true === $attributes['data-group-open-tab']) { + if (MFormLayoutCore::isTabActive($attributes)) { $item->setClass(trim($item->getClass() . ' active')); } - unset($attributes['data-group-tab-layout'], $attributes['data-group-tab-style']); + unset( + $attributes['tab-icon'], + $attributes['nav-class'], + $attributes['pull-right'], + $attributes['data-group-open-tab'], + $attributes['data-group-tab-layout'], + $attributes['data-group-tab-style'], + ); } if (count($removeAttributes) > 0) { @@ -411,7 +433,7 @@ private function generateInputElement(MFormItem $item): void { $datalist = ''; - if ('text-readonly' == $item->getType()) { // is readonly + if (MFormFieldTypeCore::isReadonlySimpleInputType($item->getType())) { // is readonly MFormAttributeHandler::addAttribute($item, 'readonly', 'readonly'); // add attribute readonly } @@ -435,11 +457,12 @@ private function generateInputElement(MFormItem $item): void // create element $element = new MFormElement(); + $normalizedType = MFormFieldTypeCore::normalizeSimpleInputType($item->getType()) ?? $item->getType(); // add all replacement elements for template parsing $element->setId($item->getId()) ->setVarId($this->varIdStr($item)) ->setValue((string) ((is_array($item->getValue())) ? implode('', $item->getValue()) : $item->getValue())) - ->setType($item->getType()) + ->setType($normalizedType) ->setClass($item->getClass()) ->setDatalist($datalist) ->setAttributes($this->parseAttributes($item->getAttributes())); // parse attributes for use in templates @@ -460,9 +483,8 @@ private function generateInputElement(MFormItem $item): void */ private function generateAreaElement(MFormItem $item): void { - // set typ specific vars - if ('textarea-readonly' == $item->getType()) { - $item->setType('textarea'); // type is textarea + // set type specific vars + if (MFormFieldTypeCore::isReadonlyTextareaType($item->getType())) { MFormAttributeHandler::addAttribute($item, 'readonly', 'readonly'); // add attribute readonly } @@ -471,11 +493,12 @@ private function generateAreaElement(MFormItem $item): void // create element $element = new MFormElement(); + $normalizedType = MFormFieldTypeCore::normalizeTextareaType($item->getType()) ?? $item->getType(); // add all replacement elements for template parsing $element->setId($item->getId()) ->setVarId($this->varIdStr($item)) ->setValue((string) ((is_array($item->getValue())) ? implode('', $item->getValue()) : $item->getValue())) - ->setType($item->getType()) + ->setType($normalizedType) ->setClass($item->getClass()) ->setAttributes($this->parseAttributes($item->getAttributes())); @@ -501,6 +524,7 @@ private function generateOptionsElement(MFormItem $item): void // init option element string $optionElements = ''; $attributes = $item->getAttributes(); + MFormLayoutCore::ensureSelectpickerContainer($attributes, $item->getClass()); if (count($item->getToggleOptions()) > 0) { $attributes = array_merge(['data-toggle' => 'collapse'], $attributes); } @@ -1482,7 +1506,19 @@ private function parseFormFields(array $items): void $item = $mformItem; } - switch ($item->getType()) { + $itemType = $item->getType(); + + if (MFormFieldTypeCore::isSimpleInputType($itemType)) { + $this->generateInputElement($item); + continue; + } + + if (MFormFieldTypeCore::isTextareaLikeType($itemType)) { + $this->generateAreaElement($item); + continue; + } + + switch ($itemType) { // OPEN REPEATER case 'repeater': $this->openRepeaterElement($item, $key, $items, $skipKeys); @@ -1526,31 +1562,9 @@ private function parseFormFields(array $items): void case 'alert': $this->generateLineElement($item); break; - case 'color': - case 'email': - case 'url': - case 'tel': - case 'search': - case 'number': - case 'range': - case 'date': - case 'time': - case 'datetime': - case 'datetime-local': - case 'month': - case 'week': - case 'text': - case 'text-readonly': - $this->generateInputElement($item); - break; case 'hidden': $this->generateHiddenInputElement($item); break; - case 'markitup': - case 'textarea': - case 'textarea-readonly': - $this->generateAreaElement($item); - break; case 'select': case 'multiselect': $this->generateOptionsElement($item); @@ -1595,20 +1609,6 @@ private function parseFormFields(array $items): void private function createLabelElement(MFormItem $item): MFormElement { - $this->createTooltipElement($item); - - $labelString = $item->getLabel(); - if (is_array($item->getLabel())) { - foreach ($item->getLabel() as $key => $itemLabel) { - if (str_contains(rex_i18n::getLocale(), $key)) { - $labelString = $itemLabel; - } - } - if (is_array($labelString)) { - $labelString = array_values($labelString)[0]; - } - } - $label = new MFormElement(); $label->setId($item->getId()); @@ -1616,31 +1616,12 @@ private function createLabelElement(MFormItem $item): MFormElement $label->setId($item->getId() . '" :for="' . $item->getAttributes()[':id']); } - $label->setValue($labelString) + $label->setValue(MFormLabelRenderer::renderLabelHtml($item)) ->setType('label'); return $label; } - private function createTooltipElement(MFormItem $item): void - { - // set tooltip - if ($item->getInfoTooltip()) { - // parse tooltip - if ('' === (string) $item->getInfoTooltipIcon()) { - $item->setInfoTooltipIcon('fa-exclamation'); - } - - $tooltip = new MFormElement(); - $tooltip->setValue($item->getInfoTooltip()) - ->setInfoTooltipIcon($item->getInfoTooltipIcon()) - ->setType('tooltip-info'); - - $currentLabel = $item->getLabel(); - $item->setLabel((is_array($currentLabel) ? '' : (string) $currentLabel) . $this->parseElement($tooltip, 'base')); - } - } - /** * @param array $items */ @@ -1731,4 +1712,5 @@ private function parseAttributes(array $attributes): string } return $inlineAttributes; } + } diff --git a/lib/MForm/Template/MFormFieldTypeCore.php b/lib/MForm/Template/MFormFieldTypeCore.php new file mode 100644 index 00000000..7adef9ff --- /dev/null +++ b/lib/MForm/Template/MFormFieldTypeCore.php @@ -0,0 +1,70 @@ + + */ + private const SIMPLE_INPUT_TYPES = [ + 'text', + 'email', + 'url', + 'tel', + 'number', + 'color', + 'date', + 'datetime', + 'time', + 'datetime-local', + 'month', + 'week', + 'search', + 'password', + 'range', + 'text-readonly', + ]; + + public static function isSimpleInputType(string $type): bool + { + return in_array($type, self::SIMPLE_INPUT_TYPES, true); + } + + public static function normalizeSimpleInputType(string $type): ?string + { + if (!self::isSimpleInputType($type)) { + return null; + } + + if ('text-readonly' === $type) { + return 'text'; + } + + return $type; + } + + public static function isReadonlySimpleInputType(string $type): bool + { + return 'text-readonly' === $type; + } + + public static function isTextareaLikeType(string $type): bool + { + return in_array($type, ['textarea', 'textarea-readonly', 'markitup'], true); + } + + public static function normalizeTextareaType(string $type): ?string + { + if (!self::isTextareaLikeType($type)) { + return null; + } + + return 'textarea'; + } + + public static function isReadonlyTextareaType(string $type): bool + { + return 'textarea-readonly' === $type; + } +} diff --git a/lib/MForm/Template/MFormLabelRenderer.php b/lib/MForm/Template/MFormLabelRenderer.php new file mode 100644 index 00000000..2dd20d21 --- /dev/null +++ b/lib/MForm/Template/MFormLabelRenderer.php @@ -0,0 +1,54 @@ + $itemLabel) { + if (is_string($key) && str_contains(rex_i18n::getLocale(), $key)) { + return is_array($itemLabel) + ? (string) (array_values($itemLabel)[0] ?? '') + : (string) $itemLabel; + } + } + + $first = array_values($label)[0] ?? ''; + return is_array($first) ? (string) (array_values($first)[0] ?? '') : (string) $first; + } + + public static function resolveLabelString(MFormItem $item): string + { + return self::resolveLabelValue($item->getLabel()); + } + + public static function renderTooltipHtml(MFormItem $item): string + { + if ('' === $item->getInfoTooltip()) { + return ''; + } + + $icon = '' !== $item->getInfoTooltipIcon() ? $item->getInfoTooltipIcon() : 'fa-info-circle'; + $iconEsc = htmlspecialchars($icon, ENT_QUOTES); + $tooltipEsc = htmlspecialchars($item->getInfoTooltip(), ENT_QUOTES); + + return ''; + } + + public static function renderLabelHtml(MFormItem $item): string + { + return self::resolveLabelString($item) . self::renderTooltipHtml($item); + } +} diff --git a/lib/MForm/Template/MFormLayoutCore.php b/lib/MForm/Template/MFormLayoutCore.php new file mode 100644 index 00000000..fc4aed19 --- /dev/null +++ b/lib/MForm/Template/MFormLayoutCore.php @@ -0,0 +1,187 @@ + $attributes + */ + public static function consumeColumnGroupRowClass(array &$attributes): string + { + return self::consumeClassAttributes($attributes, ['data-group-column-row-class', 'data-group-row-class']); + } + + /** + * Consumes modal row-class attributes and returns merged class string. + * + * @param array $attributes + */ + public static function consumeModalRowClass(array &$attributes): string + { + return self::consumeClassAttributes($attributes, ['data-modal-row-class', 'data-group-row-class']); + } + + /** + * @param array $attributes + */ + public static function isCollapseOpen(array $attributes): bool + { + return isset($attributes['data-group-open-collapse']) && self::isTruthyFlag($attributes['data-group-open-collapse']); + } + + /** + * @param array $attributes + */ + public static function isCollapseAccordion(array $attributes): bool + { + return isset($attributes['data-group-accordion']) && self::isTruthyFlag($attributes['data-group-accordion']); + } + + /** + * @param array $attributes + */ + public static function shouldHideCollapseToggle(array $attributes, bool $hasLabel): bool + { + return !$hasLabel + || (array_key_exists('data-group-hide-toggle-links', $attributes) + && self::isTruthyFlag($attributes['data-group-hide-toggle-links'])); + } + + /** + * @param array $attributes + */ + public static function consumeCollapseWrapperAttributes(array &$attributes): void + { + unset( + $attributes['data-group-hide-toggle-links'], + $attributes['data-group-accordion'], + $attributes['data-group-open-collapse'], + ); + } + + /** + * Ensures selectpicker fields have a stable default container. + * + * @param array $attributes + * @param string $itemClass + */ + public static function ensureSelectpickerContainer(array &$attributes, string $itemClass = ''): void + { + $classParts = []; + if (isset($attributes['class'])) { + $classParts[] = trim((string) $attributes['class']); + } + if ('' !== trim($itemClass)) { + $classParts[] = trim($itemClass); + } + + $classAttr = trim(implode(' ', $classParts)); + if ('' === $classAttr) { + return; + } + + $classes = preg_split('/\s+/', $classAttr) ?: []; + if (!in_array('selectpicker', $classes, true)) { + return; + } + + $containerAttr = isset($attributes['data-container']) ? trim((string) $attributes['data-container']) : ''; + if ('' === $containerAttr) { + $attributes['data-container'] = 'body'; + } + } + + /** + * @param array $attributes + */ + public static function isTabActive(array $attributes): bool + { + return isset($attributes['data-group-open-tab']) && self::isTruthyFlag($attributes['data-group-open-tab']); + } + + public static function isTabPullRight(array $attributes): bool + { + return isset($attributes['pull-right']) && self::isTruthyFlag($attributes['pull-right']); + } + + public static function buildTabNavClass(array $attributes): string + { + $class = ''; + + if (array_key_exists('nav-class', $attributes) && is_string($attributes['nav-class']) && '' !== trim($attributes['nav-class'])) { + $class = trim($class . ' ' . $attributes['nav-class']); + } + + if (self::isTabPullRight($attributes)) { + $class = trim($class . ' pull-right'); + } + + if (self::isTabActive($attributes)) { + $class = trim($class . ' active'); + } + + return $class; + } + + /** + * @param array $attributes + */ + public static function isTabLayoutVertical(array $attributes): bool + { + $layout = strtolower(trim((string) ($attributes['data-group-tab-layout'] ?? ''))); + return in_array($layout, ['vertical', 'left', 'nav-left'], true); + } + + /** + * @param array $attributes + */ + public static function isTabStyleModern(array $attributes): bool + { + $style = strtolower(trim((string) ($attributes['data-group-tab-style'] ?? ''))); + return 'modern' === $style; + } + + /** + * @param array $attributes + * @param array $keys + */ + private static function consumeClassAttributes(array &$attributes, array $keys): string + { + $class = ''; + + foreach ($keys as $key) { + if (!array_key_exists($key, $attributes)) { + continue; + } + + $value = $attributes[$key]; + if (is_string($value) && '' !== trim($value)) { + $class = trim($class . ' ' . $value); + } + + unset($attributes[$key]); + } + + 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) { + return true; + } + + if (is_string($value)) { + $normalized = strtolower(trim($value)); + return '1' === $normalized || 'true' === $normalized; + } + + return 1 === (int) $value; + } +} diff --git a/package.yml b/package.yml index 63c20bdd..8a343459 100644 --- a/package.yml +++ b/package.yml @@ -1,5 +1,5 @@ package: mform -version: '9.2.4' +version: '9.3.0' name: MForm author: Friends Of REDAXO supportpage: https://github.com/FriendsOfREDAXO/mform @@ -22,6 +22,7 @@ page: demo_rexform: { title: 'translate:demo_rexform' } demo_expert: { title: 'translate:demo_expert' } demo_layout_preview: { title: 'translate:demo_layout_preview' } + demo_renderer_parity: { title: 'translate:demo_renderer_parity' } formbuilder: title: 'translate:formbuilder' diff --git a/pages/demo.demo_renderer_parity.php b/pages/demo.demo_renderer_parity.php new file mode 100644 index 00000000..cb75e73a --- /dev/null +++ b/pages/demo.demo_renderer_parity.php @@ -0,0 +1,196 @@ +setVar('title', rex_i18n::msg('mform_info'), false); +$fragment->setVar( + 'body', + '

' + . rex_i18n::msg('mform_demo_renderer_parity_description') + . '

', + false, +); +echo $fragment->parse('core/page/section.php'); + +$buildForm = static function (): MForm { + return MForm::factory() + ->addTextField(1.1, ['label' => 'Titel']) + ->setTooltipInfo('Tooltip-Test') + ->addColumnElement(6, MForm::factory()->addTextField(1.2, ['label' => 'Spalte A']), [ + 'data-group-column-row-class' => 'parity-column-row', + 'data-group-row-class' => 'parity-row', + ]) + ->addColumnElement(6, MForm::factory()->addTextField(1.3, ['label' => 'Spalte B'])) + ->addModalElement( + 'Modal-Konfiguration', + MForm::factory()->addTextField(1.4, ['label' => 'Im Modal']), + 'btn-info', + 'right', + [ + 'data-modal-row-class' => 'parity-modal-row', + 'data-group-row-class' => 'parity-modal-group-row', + ], + ) + ->addTextField(1.5, ['label' => 'Volle Breite']) + ->setFull() + ->addInputField('datetime', 1.8, ['label' => 'Datum/Zeit']) + ->addInputField('password', 1.11, ['label' => 'Passwort']) + ->addTextField(1.9, ['label' => 'Text mit Datalist']) + ->setOptions([ + 'Alpha', + 'Beta', + ]) + ->addInputField('markitup', 1.10, ['label' => 'Markitup Fallback']) + ->addTabElement( + 'Tab Inhalt', + MForm::factory()->addTextField(1.6, ['label' => 'Tab Feld A']), + true, + false, + [ + 'tab-icon' => 'fa-file-text-o', + 'nav-class' => 'parity-tab-nav', + 'data-group-tab-style' => 'modern', + 'data-group-tab-layout' => 'vertical', + ], + ) + ->addTabElement( + 'Tab Meta', + MForm::factory()->addTextField(1.7, ['label' => 'Tab Feld B']), + false, + true, + [ + 'tab-icon' => 'fa-cog', + ], + ); +}; + +$parserForm = $buildForm(); +$flexForm = $buildForm(); + +$parserHtml = $parserForm->show(); +$flexHtml = MFormFlexRepeaterRenderer::renderTemplate($flexForm, 1); + +$checks = [ + [ + 'label' => 'Tooltip-Icon gerendert', + 'needle' => 'mblock-info-tooltip', + ], + [ + 'label' => 'Tooltip-Default-Icon (info-circle) aktiv', + 'needle' => 'fa-info-circle', + ], + [ + 'label' => 'Column-Row-Klasse uebernommen', + 'needle' => 'parity-column-row', + ], + [ + 'label' => 'Generische Row-Klasse uebernommen', + 'needle' => 'parity-row', + ], + [ + 'label' => 'Modal-Row-Klasse uebernommen', + 'needle' => 'parity-modal-row', + ], + [ + 'label' => 'Modal-Group-Row-Klasse uebernommen', + 'needle' => 'parity-modal-group-row', + ], + [ + 'label' => 'Full-Layout-Klasse vorhanden', + 'needle' => 'col-sm-12', + ], + [ + 'label' => 'Tab-Nav Zusatzklasse uebernommen', + 'needle' => 'parity-tab-nav', + ], + [ + 'label' => 'Tab-Layout vertikal Klasse vorhanden', + 'needle' => 'mform-tabs--vertical', + ], + [ + 'label' => 'Tab-Style modern Klasse vorhanden', + 'needle' => 'mform-tabs--modern', + ], + [ + 'label' => 'Tab Pull-Right Klasse vorhanden', + 'needle' => 'pull-right', + ], + [ + 'label' => 'Tab Active-Markierung vorhanden', + 'needle' => ' active', + ], + [ + 'label' => 'Datetime-Feld gerendert', + 'needle' => 'type="datetime"', + ], + [ + 'label' => 'Password-Feld gerendert', + 'needle' => 'type="password"', + ], + [ + 'label' => 'Datalist am Input vorhanden', + 'needle' => ' 'Markitup-Feld vorhanden', + 'needle' => 'Markitup Fallback', + ], +]; + +$rows = ''; +foreach ($checks as $check) { + $needle = $check['needle']; + $parserOk = str_contains($parserHtml, $needle); + $flexOk = str_contains($flexHtml, $needle); + + $parserBadge = $parserOk + ? 'OK' + : 'Fehlt'; + $flexBadge = $flexOk + ? 'OK' + : 'Fehlt'; + + $rows .= '' + . '' . rex_escape($check['label']) . '' + . '' . rex_escape($needle) . '' + . '' . $parserBadge . '' + . '' . $flexBadge . '' + . ''; +} + +$checkBody = '
' + . '' + . '' + . '' . $rows . '' + . '
CheckNeedleParserFlex-Repeater
' + . '
'; + +$fragment = new rex_fragment(); +$fragment->setVar('title', rex_i18n::msg('mform_demo_renderer_parity_checks'), false); +$fragment->setVar('body', $checkBody, false); +echo $fragment->parse('core/page/section.php'); + +$htmlBody = '
' + . '
' + . '

Parser HTML

' + . '
' . rex_escape($parserHtml) . '
' + . '
' + . '
' + . '

Flex-Repeater Template HTML

' + . '
' . rex_escape($flexHtml) . '
' + . '
' + . '
'; + +$fragment = new rex_fragment(); +$fragment->setVar('title', rex_i18n::msg('mform_demo_renderer_parity_html'), false); +$fragment->setVar('body', $htmlBody, false); +echo $fragment->parse('core/page/section.php');