Basic features done

This commit is contained in:
2026-04-24 00:00:19 -06:00
parent b8edbcb403
commit 193391d837
19 changed files with 2226 additions and 294 deletions
+1
View File
File diff suppressed because one or more lines are too long
+290
View File
@@ -0,0 +1,290 @@
/*
Server Sent Events Extension
============================
This extension adds support for Server Sent Events to htmx. See /www/extensions/sse.md for usage instructions.
*/
(function () {
/** @type {import("../htmx").HtmxInternalApi} */
var api
htmx.defineExtension('sse', {
/**
* Init saves the provided reference to the internal HTMX API.
*
* @param {import("../htmx").HtmxInternalApi} api
* @returns void
*/
init: function (apiRef) {
// store a reference to the internal API.
api = apiRef
// set a function in the public API for creating new EventSource objects
if (htmx.createEventSource == undefined) {
htmx.createEventSource = createEventSource
}
},
getSelectors: function () {
return ['[sse-connect]', '[data-sse-connect]', '[sse-swap]', '[data-sse-swap]']
},
/**
* onEvent handles all events passed to this extension.
*
* @param {string} name
* @param {Event} evt
* @returns void
*/
onEvent: function (name, evt) {
var parent = evt.target || evt.detail.elt
switch (name) {
case 'htmx:beforeCleanupElement':
var internalData = api.getInternalData(parent)
// Try to remove remove an EventSource when elements are removed
var source = internalData.sseEventSource
if (source) {
api.triggerEvent(parent, 'htmx:sseClose', {
source,
type: 'nodeReplaced',
})
internalData.sseEventSource.close()
}
return
// Try to create EventSources when elements are processed
case 'htmx:afterProcessNode':
ensureEventSourceOnElement(parent)
}
}
})
/// ////////////////////////////////////////////
// HELPER FUNCTIONS
/// ////////////////////////////////////////////
/**
* createEventSource is the default method for creating new EventSource objects.
* it is hoisted into htmx.config.createEventSource to be overridden by the user, if needed.
*
* @param {string} url
* @returns EventSource
*/
function createEventSource(url) {
return new EventSource(url, { withCredentials: true })
}
/**
* registerSSE looks for attributes that can contain sse events, right
* now hx-trigger and sse-swap and adds listeners based on these attributes too
* the closest event source
*
* @param {HTMLElement} elt
*/
function registerSSE(elt) {
// Add message handlers for every `sse-swap` attribute
if (api.getAttributeValue(elt, 'sse-swap')) {
// Find closest existing event source
var sourceElement = api.getClosestMatch(elt, hasEventSource)
if (sourceElement == null) {
// api.triggerErrorEvent(elt, "htmx:noSSESourceError")
return null // no eventsource in parentage, orphaned element
}
// Set internalData and source
var internalData = api.getInternalData(sourceElement)
var source = internalData.sseEventSource
var sseSwapAttr = api.getAttributeValue(elt, 'sse-swap')
var sseEventNames = sseSwapAttr.split(',')
for (var i = 0; i < sseEventNames.length; i++) {
const sseEventName = sseEventNames[i].trim()
const listener = function (event) {
// If the source is missing then close SSE
if (maybeCloseSSESource(sourceElement)) {
return
}
// If the body no longer contains the element, remove the listener
if (!api.bodyContains(elt)) {
source.removeEventListener(sseEventName, listener)
return
}
// swap the response into the DOM and trigger a notification
if (!api.triggerEvent(elt, 'htmx:sseBeforeMessage', event)) {
return
}
swap(elt, event.data)
api.triggerEvent(elt, 'htmx:sseMessage', event)
}
// Register the new listener
api.getInternalData(elt).sseEventListener = listener
source.addEventListener(sseEventName, listener)
}
}
// Add message handlers for every `hx-trigger="sse:*"` attribute
if (api.getAttributeValue(elt, 'hx-trigger')) {
// Find closest existing event source
var sourceElement = api.getClosestMatch(elt, hasEventSource)
if (sourceElement == null) {
// api.triggerErrorEvent(elt, "htmx:noSSESourceError")
return null // no eventsource in parentage, orphaned element
}
// Set internalData and source
var internalData = api.getInternalData(sourceElement)
var source = internalData.sseEventSource
var triggerSpecs = api.getTriggerSpecs(elt)
triggerSpecs.forEach(function (ts) {
if (ts.trigger.slice(0, 4) !== 'sse:') {
return
}
var listener = function (event) {
if (maybeCloseSSESource(sourceElement)) {
return
}
if (!api.bodyContains(elt)) {
source.removeEventListener(ts.trigger.slice(4), listener)
}
// Trigger events to be handled by the rest of htmx
htmx.trigger(elt, ts.trigger, event)
htmx.trigger(elt, 'htmx:sseMessage', event)
}
// Register the new listener
api.getInternalData(elt).sseEventListener = listener
source.addEventListener(ts.trigger.slice(4), listener)
})
}
}
/**
* ensureEventSourceOnElement creates a new EventSource connection on the provided element.
* If a usable EventSource already exists, then it is returned. If not, then a new EventSource
* is created and stored in the element's internalData.
* @param {HTMLElement} elt
* @param {number} retryCount
* @returns {EventSource | null}
*/
function ensureEventSourceOnElement(elt, retryCount) {
if (elt == null) {
return null
}
// handle extension source creation attribute
if (api.getAttributeValue(elt, 'sse-connect')) {
var sseURL = api.getAttributeValue(elt, 'sse-connect')
if (sseURL == null) {
return
}
ensureEventSource(elt, sseURL, retryCount)
}
registerSSE(elt)
}
function ensureEventSource(elt, url, retryCount) {
var source = htmx.createEventSource(url)
source.onerror = function (err) {
// Log an error event
api.triggerErrorEvent(elt, 'htmx:sseError', { error: err, source })
// If parent no longer exists in the document, then clean up this EventSource
if (maybeCloseSSESource(elt)) {
return
}
// Otherwise, try to reconnect the EventSource
if (source.readyState === EventSource.CLOSED) {
retryCount = retryCount || 0
retryCount = Math.max(Math.min(retryCount * 2, 128), 1)
var timeout = retryCount * 500
window.setTimeout(function () {
ensureEventSourceOnElement(elt, retryCount)
}, timeout)
}
}
source.onopen = function (evt) {
api.triggerEvent(elt, 'htmx:sseOpen', { source })
if (retryCount && retryCount > 0) {
const childrenToFix = elt.querySelectorAll("[sse-swap], [data-sse-swap], [hx-trigger], [data-hx-trigger]")
for (let i = 0; i < childrenToFix.length; i++) {
registerSSE(childrenToFix[i])
}
// We want to increase the reconnection delay for consecutive failed attempts only
retryCount = 0
}
}
api.getInternalData(elt).sseEventSource = source
var closeAttribute = api.getAttributeValue(elt, "sse-close");
if (closeAttribute) {
// close eventsource when this message is received
source.addEventListener(closeAttribute, function () {
api.triggerEvent(elt, 'htmx:sseClose', {
source,
type: 'message',
})
source.close()
});
}
}
/**
* maybeCloseSSESource confirms that the parent element still exists.
* If not, then any associated SSE source is closed and the function returns true.
*
* @param {HTMLElement} elt
* @returns boolean
*/
function maybeCloseSSESource(elt) {
if (!api.bodyContains(elt)) {
var source = api.getInternalData(elt).sseEventSource
if (source != undefined) {
api.triggerEvent(elt, 'htmx:sseClose', {
source,
type: 'nodeMissing',
})
source.close()
// source = null
return true
}
}
return false
}
/**
* @param {HTMLElement} elt
* @param {string} content
*/
function swap(elt, content) {
api.withExtensions(elt, function (extension) {
content = extension.transformResponse(content, null, elt)
})
var swapSpec = api.getSwapSpecification(elt)
var target = api.getTarget(elt)
api.swap(target, content, swapSpec)
}
function hasEventSource(node) {
return api.getInternalData(node).sseEventSource != null
}
})()
+484 -15
View File
@@ -838,33 +838,502 @@ footer a:hover {
color: var(--text-primary);
}
/* rooms grid */
.rooms-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 1rem;
}
.room-card {
display: block;
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
padding: 1.25rem 1.5rem;
text-decoration: none;
transition: all 0.15s;
position: relative;
}
.room-card:hover {
background: var(--bg-surface-hover);
border-color: var(--border-accent);
transform: translateY(-2px);
}
.room-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 0.75rem;
}
.room-name {
font-size: 1.1rem;
font-weight: 600;
color: var(--text-primary);
}
.room-code {
font-family: var(--font-mono);
font-size: 0.75rem;
color: var(--accent);
background: rgba(139, 92, 246, 0.12);
padding: 0.2rem 0.5rem;
border-radius: var(--radius-sm);
}
.room-meta {
display: flex;
gap: 1rem;
font-size: 0.8rem;
color: var(--text-secondary);
}
.room-owner-badge {
position: absolute;
top: 1rem;
right: 1rem;
font-size: 0.65rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.05em;
color: var(--accent);
background: rgba(139, 92, 246, 0.15);
padding: 0.2rem 0.5rem;
border-radius: var(--radius-sm);
}
.empty-state {
text-align: center;
padding: 3rem;
color: var(--text-secondary);
}
/* modal */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.7);
display: flex;
align-items: center;
justify-content: center;
z-index: 100;
backdrop-filter: blur(4px);
}
.modal {
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
padding: 2rem;
max-width: 420px;
width: 90%;
box-shadow: var(--shadow-card);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
}
.modal-header h2 {
font-size: 1.25rem;
font-weight: 600;
color: var(--text-primary);
}
.modal-close {
background: none;
border: none;
color: var(--text-secondary);
font-size: 1.5rem;
cursor: pointer;
padding: 0.25rem;
line-height: 1;
}
.modal-close:hover {
color: var(--text-primary);
}
/* room detail */
.back-btn {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
border-radius: var(--radius-md);
background: var(--bg-surface);
border: 1px solid var(--border);
color: var(--text-secondary);
text-decoration: none;
transition: all 0.15s;
}
.back-btn:hover {
background: var(--bg-surface-hover);
color: var(--text-primary);
}
.room-code-badge {
font-family: var(--font-mono);
font-size: 0.8rem;
color: var(--accent);
background: rgba(139, 92, 246, 0.12);
padding: 0.25rem 0.75rem;
border-radius: var(--radius-md);
}
.scale-badge {
font-size: 0.75rem;
color: var(--text-secondary);
background: var(--bg-surface);
padding: 0.25rem 0.75rem;
border-radius: var(--radius-md);
border: 1px solid var(--border);
}
.room-layout {
display: grid;
grid-template-columns: 1fr 240px;
gap: 1.5rem;
min-height: 400px;
}
.stories-panel,
.members-panel {
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
padding: 1.25rem;
}
.panel-title {
font-size: 0.8rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--text-muted);
margin-bottom: 1rem;
}
.stories-list,
.members-list {
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.story-card {
background: rgba(255, 255, 255, 0.03);
border: 1px solid var(--border);
border-radius: var(--radius-md);
padding: 1rem;
transition: all 0.15s;
}
.story-card:hover {
border-color: var(--border-accent);
}
.story-revealed {
border-color: rgba(139, 92, 246, 0.3);
background: rgba(139, 92, 246, 0.05);
}
.story-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 0.75rem;
margin-bottom: 0.75rem;
}
.story-title {
font-size: 0.95rem;
font-weight: 500;
color: var(--text-primary);
flex: 1 1 auto;
word-break: break-word;
margin-top: 0.15rem; /* align text baseline with buttons */
}
.story-actions {
display: flex;
gap: 0.4rem;
align-items: center;
flex-wrap: wrap;
flex: 0 0 auto;
}
.story-btn {
display: inline-flex;
align-items: center;
justify-content: center;
height: 26px;
padding: 0 0.6rem;
font-size: 0.75rem;
font-weight: 500;
border-radius: var(--radius-sm);
cursor: pointer;
transition: all 0.15s;
border: 1px solid transparent;
}
.story-btn-primary {
background: var(--accent);
color: white;
border-color: var(--accent);
}
.story-btn-primary:hover {
background: var(--accent-hover);
border-color: var(--accent-hover);
}
.story-btn-secondary {
background: transparent;
color: var(--text-secondary);
border-color: var(--border);
}
.story-btn-secondary:hover {
background: var(--bg-surface-hover);
color: var(--text-primary);
}
.story-badge {
display: inline-flex;
align-items: center;
justify-content: center;
height: 26px;
padding: 0 0.6rem;
font-size: 0.75rem;
font-weight: 500;
border-radius: var(--radius-sm);
}
.story-badge-active {
color: var(--success-text);
border: 1px solid var(--success-border);
background: var(--success-bg);
}
.story-badge-revealed {
color: var(--accent);
border: 1px solid rgba(139, 92, 246, 0.4);
background: rgba(139, 92, 246, 0.1);
}
.story-points {
font-family: var(--font-mono);
font-size: 1rem;
font-weight: 700;
color: var(--accent);
background: rgba(139, 92, 246, 0.15);
padding: 0.25rem 0.75rem;
border-radius: var(--radius-md);
}
.vote-form {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
.vote-option {
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius-md);
padding: 0.4rem 0.75rem;
font-family: var(--font-mono);
font-size: 0.85rem;
color: var(--text-secondary);
cursor: pointer;
transition: all 0.15s;
}
.vote-option:hover {
background: var(--bg-surface-hover);
border-color: var(--accent);
color: var(--text-primary);
}
.vote-option.vote-selected {
border-color: var(--accent);
background: rgba(139, 92, 246, 0.12);
color: var(--text-primary);
}
.story-active {
border-color: var(--success-border);
background: var(--success-bg);
}
.story-action-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 26px;
height: 26px;
padding: 0;
border-radius: var(--radius-sm);
background: transparent;
border: 1px solid var(--border);
color: var(--text-muted);
cursor: pointer;
transition: all 0.15s;
flex-shrink: 0;
}
.story-action-btn:hover {
background: var(--bg-surface-hover);
color: var(--text-primary);
border-color: var(--border-accent);
}
.story-action-btn.story-action-delete:hover {
border-color: rgba(239, 68, 68, 0.4);
color: #f87171;
background: rgba(239, 68, 68, 0.06);
}
.revealed-votes {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
margin-top: 0.75rem;
padding-top: 0.75rem;
border-top: 1px solid var(--border);
}
.revealed-vote {
display: flex;
align-items: center;
gap: 0.4rem;
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius-md);
padding: 0.3rem 0.6rem;
}
.revealed-vote-user {
font-size: 0.8rem;
color: var(--text-secondary);
}
.revealed-vote-value {
font-family: var(--font-mono);
font-size: 0.85rem;
font-weight: 700;
color: var(--accent);
background: rgba(139, 92, 246, 0.15);
padding: 0.1rem 0.4rem;
border-radius: var(--radius-sm);
}
.member-row {
display: flex;
align-items: center;
gap: 0.65rem;
padding: 0.5rem;
border-radius: var(--radius-md);
}
.member-name {
font-size: 0.9rem;
color: var(--text-secondary);
}
/* SSE indicator */
.sse-indicator {
display: inline-flex;
align-items: center;
gap: 0.375rem;
font-size: 0.75rem;
font-weight: 500;
color: var(--success-text);
padding: 0.25rem 0.5rem;
border-radius: var(--radius-full);
background: var(--success-bg);
border: 1px solid var(--success-border);
}
.mobile-menu-btn {
display: none;
background: transparent;
border: none;
color: var(--text-secondary);
cursor: pointer;
padding: 0.25rem;
border-radius: var(--radius-sm);
transition: all 0.2s ease;
}
.mobile-menu-btn:hover {
color: var(--text-primary);
background: var(--bg-surface-hover);
}
.sse-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--success-text);
animation: pulse 2s ease infinite;
}
/* ============================================================
RESPONSIVE
============================================================ */
.sidebar-backdrop {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(4px);
z-index: 90;
opacity: 0;
transition: opacity 0.3s ease;
}
@media (max-width: 768px) {
.app-shell {
grid-template-columns: 1fr;
grid-template-rows: auto 1fr;
height: auto;
min-height: 100vh;
overflow-y: auto;
}
.mobile-menu-btn {
display: block;
}
.sidebar-backdrop.open {
display: block;
opacity: 1;
}
.sidebar {
border-right: none;
border-bottom: 1px solid var(--border);
padding: 1rem;
position: fixed;
top: 0;
left: 0;
bottom: 0;
width: 280px;
z-index: 100;
transform: translateX(-100%);
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
background: var(--bg); /* Opaque background for mobile menu */
border-right: 1px solid var(--border);
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
.sidebar-nav {
flex-direction: row;
flex-wrap: wrap;
gap: 0.25rem;
}
.main-content {
overflow-y: unset;
.sidebar.open {
transform: translateX(0);
}
.dashboard-grid {