Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
223 lines
7.6 KiB
JavaScript
223 lines
7.6 KiB
JavaScript
import { once } from 'alpinejs/src/utils/once'
|
|
|
|
export default (Alpine) => {
|
|
Alpine.data('notificationComponent', ({ notification }) => ({
|
|
isShown: false,
|
|
|
|
computedStyle: null,
|
|
|
|
transitionDuration: null,
|
|
|
|
transitionEasing: null,
|
|
|
|
closeTimeout: null,
|
|
|
|
durationTimeout: null,
|
|
|
|
unsubscribeLivewireHook: null,
|
|
|
|
init() {
|
|
this.computedStyle = window.getComputedStyle(this.$el)
|
|
|
|
this.transitionDuration =
|
|
parseFloat(this.computedStyle.transitionDuration) * 1000
|
|
|
|
this.transitionEasing = this.computedStyle.transitionTimingFunction
|
|
|
|
this.configureTransitions()
|
|
this.configureAnimations()
|
|
|
|
if (
|
|
notification.duration &&
|
|
notification.duration !== 'persistent'
|
|
) {
|
|
this.durationTimeout = setTimeout(() => {
|
|
if (!this.$el.matches(':hover')) {
|
|
this.close()
|
|
|
|
return
|
|
}
|
|
|
|
this.$el.addEventListener('mouseleave', () => this.close())
|
|
}, notification.duration)
|
|
}
|
|
|
|
this.isShown = true
|
|
},
|
|
|
|
configureTransitions() {
|
|
const display = this.computedStyle.display
|
|
|
|
const show = () => {
|
|
Alpine.mutateDom(() => {
|
|
this.$el.style.setProperty('display', display)
|
|
this.$el.style.setProperty('visibility', 'visible')
|
|
})
|
|
this.$el._x_isShown = true
|
|
}
|
|
|
|
const hide = () => {
|
|
Alpine.mutateDom(() => {
|
|
this.$el._x_isShown
|
|
? this.$el.style.setProperty('visibility', 'hidden')
|
|
: this.$el.style.setProperty('display', 'none')
|
|
})
|
|
}
|
|
|
|
const toggle = once(
|
|
(value) => (value ? show() : hide()),
|
|
(value) => {
|
|
this.$el._x_toggleAndCascadeWithTransitions(
|
|
this.$el,
|
|
value,
|
|
show,
|
|
hide,
|
|
)
|
|
},
|
|
)
|
|
|
|
Alpine.effect(() => toggle(this.isShown))
|
|
},
|
|
|
|
configureAnimations() {
|
|
// Inline notifications, such as those in the database
|
|
// notifications modal, are removed instantly, without animation.
|
|
if (this.$el.classList.contains('fi-inline')) {
|
|
return
|
|
}
|
|
|
|
this.unsubscribeLivewireHook = Livewire.interceptMessage(
|
|
({ message, onSuccess }) => {
|
|
if (
|
|
!message.component.snapshot.data
|
|
.isFilamentNotificationsComponent
|
|
) {
|
|
return
|
|
}
|
|
|
|
// Calling `el.getBoundingClientRect()` from outside `requestAnimationFrame()` can
|
|
// occasionally cause the page to scroll to the top.
|
|
requestAnimationFrame(() => {
|
|
const getTop = () =>
|
|
this.$el.getBoundingClientRect().top
|
|
const oldTop = getTop()
|
|
|
|
onSuccess(({ onRender }) => {
|
|
// `onRender` runs once the DOM has been morphed, inside a
|
|
// `requestAnimationFrame()` before the browser paints, so the
|
|
// new position can be measured and the animation started
|
|
// without the notification flashing in its final position.
|
|
onRender(() => {
|
|
if (!this.isShown) {
|
|
return
|
|
}
|
|
|
|
// Finish any running animations so they do not distort
|
|
// the measurement of the new position.
|
|
this.$el
|
|
.getAnimations()
|
|
.forEach((animation) => animation.finish())
|
|
|
|
const newTop = getTop()
|
|
|
|
if (oldTop === newTop) {
|
|
return
|
|
}
|
|
|
|
// Honor `prefers-reduced-motion`: `element.animate()`
|
|
// (the Web Animations API) is not covered by the CSS
|
|
// reduced-motion reset, so skip the FLIP reposition
|
|
// entirely — the element is already at its final
|
|
// position after the morph.
|
|
if (
|
|
window.matchMedia(
|
|
'(prefers-reduced-motion: reduce)',
|
|
).matches
|
|
) {
|
|
return
|
|
}
|
|
|
|
this.$el.animate(
|
|
[
|
|
{
|
|
transform: `translateY(${oldTop - newTop}px)`,
|
|
},
|
|
{ transform: 'translateY(0px)' },
|
|
],
|
|
{
|
|
duration: this.transitionDuration,
|
|
easing: this.transitionEasing,
|
|
},
|
|
)
|
|
})
|
|
})
|
|
})
|
|
},
|
|
)
|
|
},
|
|
|
|
close(isImmediate = false) {
|
|
clearTimeout(this.closeTimeout)
|
|
clearTimeout(this.durationTimeout)
|
|
|
|
const dispatchClosedEvent = () =>
|
|
window.dispatchEvent(
|
|
new CustomEvent('notificationClosed', {
|
|
detail: {
|
|
id: notification.id,
|
|
},
|
|
}),
|
|
)
|
|
|
|
if (isImmediate === true) {
|
|
this.isShown = false
|
|
|
|
dispatchClosedEvent()
|
|
|
|
return
|
|
}
|
|
|
|
// Inline notifications, such as those in the database
|
|
// notifications modal, are part of a list, so they are removed
|
|
// from it as soon as possible instead of fading out first.
|
|
if (this.$root.classList.contains('fi-inline')) {
|
|
dispatchClosedEvent()
|
|
|
|
return
|
|
}
|
|
|
|
this.isShown = false
|
|
|
|
this.closeTimeout = setTimeout(
|
|
dispatchClosedEvent,
|
|
this.transitionDuration,
|
|
)
|
|
},
|
|
|
|
markAsRead() {
|
|
window.dispatchEvent(
|
|
new CustomEvent('markedNotificationAsRead', {
|
|
detail: {
|
|
id: notification.id,
|
|
},
|
|
}),
|
|
)
|
|
},
|
|
|
|
markAsUnread() {
|
|
window.dispatchEvent(
|
|
new CustomEvent('markedNotificationAsUnread', {
|
|
detail: {
|
|
id: notification.id,
|
|
},
|
|
}),
|
|
)
|
|
},
|
|
|
|
destroy() {
|
|
clearTimeout(this.closeTimeout)
|
|
clearTimeout(this.durationTimeout)
|
|
this.unsubscribeLivewireHook?.()
|
|
},
|
|
}))
|
|
}
|