ReviewOS

also looking at this

loghqorg/loghq

Promote main to production: signed-out chrome and the subscriber tables

#17
Merged glennmichael123 wants to merge main into production
54 files +4252 -1353

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

config/crosswind.tsmodified+207-7
Changes to config/crosswind.ts
@@ -26,13 +26,24 @@ import type { CrosswindConfig, Theme } from '@cwcss/crosswind'
2626 * HTML, not over globs, so a content list means nothing here.
2727 * output OVERRIDDEN to "". The CSS is injected as a <style> tag.
2828 * minify OVERRIDDEN to false.
29 * preflights spread into the config and then NEVER EMITTED — toCSS()
30 * writes the built-in reset only. Verified by putting a probe
31 * token in a preflights entry and grepping the served page for
32 * it: zero occurrences, on both a marketing and an app route.
33 * This one matters: the obvious home for shared design tokens
34 * does not work, so they have to reach the document another
35 * way. See the token duplication noted in the styling work.
29 * preflights merged and EMITTED. This entry used to say the opposite,
30 * and it was true when it was written: the old dev-server
31 * merge read only `theme.extend`, `safelist` and `shortcuts`
32 * and dropped `preflights`, `darkMode`, `cssVariables`,
33 * `rules`, `blocklist` and `variants` outright. stacksjs/stx
34 * #1867 unified the two render paths onto one merge, and the
35 * installed 0.2.520 carries the fix — its own ts-css-config
36 * documents the old behaviour in the past tense.
37 *
38 * Re-verified here rather than taken from a changelog:
39 * mergeCssConfig() reports includePreflight true, carries the
40 * entries into `config`, and every rule below comes back out
41 * of toCSS(). The stale note mattered, because it is why this
42 * app's tokens went to public/app-chrome.css instead.
43 *
44 * One constraint is real: a single getCSS() returning several
45 * rules silently loses some of them. One entry per rule; see
46 * topLevelRules below.
3647 *
3748 * Anything not on the surviving list is decoration. This file used to carry
3849 * `content`, `minify`, and `preflight: true` — and that last one is not even a
@@ -43,7 +54,196 @@ import type { CrosswindConfig, Theme } from '@cwcss/crosswind'
4354 *
4455 * @see https://github.com/cwcss/crosswind
4556 */
57/*
58 * The date-range picker's stylesheet, lifted out of a <style> block in
59 * resources/views/analytics.stx (stx-standards rule 3).
60 *
61 * This is a RELOCATION and not a conversion to utilities, which is a weaker
62 * outcome than the rule wants, so here is why it is the honest one. Every
63 * state in this widget is a compound selector the client script toggles --
64 * .drp-day.is-range, .drp-preset.is-active, .drp-nav.is-hidden -- and a
65 * utility cannot express "this class AND that class". The spelling that could,
66 * an arbitrary-variant utility like [&.is-range]:bg-accent, emits nothing in
67 * this engine: the extractor rejects any class whose variant is an arbitrary
68 * selector (same defect as stacksjs/ts-css#37, fixed in ts-css 0.3.16 and not
69 * in @cwcss/crosswind). Splitting base rules into shortcuts and leaving the
70 * state rules here would be worse than either: the shortcuts are unlayered and
71 * a preflight lands in @layer cw-base, so every unlayered base would outrank
72 * its own layered active state and the selected range would stop painting.
73 *
74 * Moving it into the layer was checked for cascade damage rather than assumed.
75 * The picker's markup carries component classes only -- no utility co-occurs
76 * with .range-tool, .drp-* or .date-popover -- so nothing of equal specificity
77 * now wins where it used to lose. The one place a utility does meet these
78 * rules is the shared :focus-visible list: settings.stx puts
79 * focus:outline-none on seven inputs, and that already beat input:focus-visible
80 * on specificity (0,2,0 against 0,1,1) before this move. Those fields trade
81 * the ring for a border colour deliberately, and they behave the same either
82 * way.
83 */
84const DATE_RANGE_PICKER_CSS = `
85.range-tool {
86 display: inline-flex;
87 align-items: center;
88 justify-content: center;
89 gap: 0.4rem;
90 min-height: 2.25rem;
91 padding: 0 0.72rem;
92 border: 1px solid var(--border);
93 border-radius: 9px;
94 background: var(--panel);
95 color: var(--text-2);
96 font: 600 0.8125rem/1 var(--sans, ui-sans-serif);
97 text-decoration: none;
98 cursor: pointer;
99 transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
100}
101.range-tool:hover { color: var(--text); border-color: var(--accent); }
102.range-tool:active { transform: scale(0.98); }
103.range-tool:focus-visible,
104.range-link:focus-visible,
105.chrome-btn:focus-visible,
106.icon-btn:focus-visible,
107select.panel:focus-visible,
108input:focus-visible,
109textarea:focus-visible,
110summary:focus-visible {
111 outline: 2px solid var(--accent);
112 outline-offset: 2px;
113}
114.range-tool.is-active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
115.range-tool i { width: 1rem; height: 1rem; }
116.date-menu { position: relative; }
117.date-menu > summary { list-style: none; }
118.date-menu > summary::-webkit-details-marker { display: none; }
119.date-popover {
120 position: absolute;
121 right: 0;
122 top: calc(100% + 0.5rem);
123 z-index: 40;
124 width: min(44rem, calc(100vw - 2.5rem));
125 padding: 0.75rem;
126 border: 1px solid var(--border);
127 border-radius: 12px;
128 background: var(--panel);
129 box-shadow: 0 18px 50px color-mix(in srgb, var(--text) 10%, transparent);
130}
131/* Period picker: presets down the left, two months on the right. The range is
132 drawn flat with rounded ends, the way Fathom's is, on the --bar wash the KPI
133 bars already use so it reads as the same accent at the same strength. */
134.drp-backdrop { position: fixed; inset: 0; z-index: 39; background: transparent; cursor: default; }
135.drp { display: grid; grid-template-columns: 10.5rem minmax(0, 1fr); gap: 0.75rem; }
136.drp-presets { display: flex; flex-direction: column; gap: 0.15rem; padding-right: 0.75rem; border-right: 1px solid var(--border); }
137.drp-preset {
138 display: block;
139 width: 100%;
140 padding: 0.5rem 0.7rem;
141 border: 0;
142 border-radius: 8px;
143 background: transparent;
144 color: var(--text-2);
145 font: 500 0.8125rem/1.2 var(--sans, ui-sans-serif);
146 text-align: left;
147 cursor: pointer;
148}
149.drp-preset:hover { color: var(--text); background: color-mix(in srgb, var(--text) 6%, transparent); }
150.drp-preset.is-active { color: var(--accent-ink); background: var(--accent); }
151.drp-cals { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
152.drp-head { display: grid; grid-template-columns: 2rem minmax(0, 1fr) minmax(0, 1fr) 2rem; align-items: center; gap: 0.35rem; margin-bottom: 0.5rem; }
153.drp-nav {
154 display: inline-grid;
155 place-items: center;
156 width: 2rem;
157 height: 2rem;
158 padding: 0;
159 border: 1px solid transparent;
160 border-radius: 8px;
161 background: transparent;
162 color: var(--text-2);
163 cursor: pointer;
164}
165.drp-nav:hover { color: var(--text); border-color: var(--border); }
166.drp-nav svg { width: 1rem; height: 1rem; }
167.drp-nav.is-hidden { visibility: hidden; }
168.drp-sel {
169 min-width: 0;
170 height: 2rem;
171 padding: 0 0.5rem;
172 border: 1px solid var(--border);
173 border-radius: 8px;
174 background: var(--bg);
175 color: var(--text);
176 font: 600 0.8125rem/1 var(--sans, ui-sans-serif);
177}
178.drp-dow, .drp-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
179.drp-dow span { padding: 0.25rem 0; color: var(--text-3); font: 600 0.7rem/1.2 var(--sans, ui-sans-serif); text-align: center; }
180.drp-day {
181 height: 2.25rem;
182 padding: 0;
183 border: 0;
184 border-radius: 0;
185 background: transparent;
186 color: var(--text);
187 font: 500 0.8125rem/1 var(--mono, ui-monospace);
188 cursor: pointer;
189}
190.drp-day:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
191.drp-day.is-out { color: var(--text-3); }
192.drp-day.is-today { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
193.drp-day.is-range { background: var(--accent-soft); }
194.drp-day.is-edge { background: var(--accent); color: var(--accent-ink); border-radius: 8px; }
195.drp-day.is-disabled { color: var(--text-3); opacity: 0.45; cursor: default; }
196.drp-day.is-disabled:hover { background: transparent; }
197.drp-day:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 8px; }
198@media (max-width: 1023px) {
199 .date-menu { position: static; }
200 .date-popover { left: 0; right: auto; width: calc(100vw - 2rem); max-height: calc(100dvh - 6rem); overflow-y: auto; overscroll-behavior: contain; }
201 .drp { grid-template-columns: minmax(0, 1fr); }
202 .drp-presets { flex-direction: row; flex-wrap: wrap; gap: 0.35rem; padding: 0 0 0.6rem; border-right: 0; border-bottom: 1px solid var(--border); }
203 .drp-preset { width: auto; padding: 0.45rem 0.65rem; border: 1px solid var(--border); border-radius: 999px; }
204 .drp-cals { grid-template-columns: minmax(0, 1fr); }
205 .drp-cal.is-right { display: none; }
206 .drp-cal.is-left .drp-nav.is-hidden { visibility: visible; }
207 .drp-day { height: 2.5rem; }
208}
209`
210
211/**
212 * Split a stylesheet into its top-level rules, one per preflight entry.
213 *
214 * Not organisational taste: a getCSS() that returns several rules loses some of
215 * them. Measured on commshq, where ten rules in one string came back with h1-h3
216 * and the first half of a @keyframes block gone and its `transform:...}to{...`
217 * spliced into the preceding rule. Depth is tracked so an @media block stays a
218 * single rule, which means a comment in this stylesheet must not contain a
219 * brace.
220 */
221function topLevelRules(css: string): string[] {
222 const rules: string[] = []
223 let depth = 0
224 let current = ''
225 for (const ch of css) {
226 current += ch
227 if (ch === '{') {
228 depth++
229 }
230 else if (ch === '}') {
231 depth--
232 if (depth === 0) {
233 rules.push(current.trim())
234 current = ''
235 }
236 }
237 }
238 const tail = current.trim()
239 if (tail)
240 rules.push(tail)
241 // A trailing comment with no rule after it is not a rule.
242 return rules.filter(rule => rule.length > 0 && !/^\/\*[\s\S]*\*\/$/.test(rule))
243}
244
46245export default {
246 preflights: topLevelRules(DATE_RANGE_PICKER_CSS).map(css => ({ getCSS: () => css })),
47247 theme: {
48248 extend: {
49249 borderRadius: {
resources/views/analytics.stxmodified+0-129
Changes to resources/views/analytics.stx
@@ -240,135 +240,6 @@ onMounted(() => {
240240@section('content')
241241
242242
243{{-- Date-range picker styling. A loose <style> under a layout: stx sweeps it
244 into the page (loghq's default layout has no @stack('styles')). Self-contained
245 to the picker, themed on the app's tokens. --}}
246<style>
247.range-tool {
248 display: inline-flex;
249 align-items: center;
250 justify-content: center;
251 gap: 0.4rem;
252 min-height: 2.25rem;
253 padding: 0 0.72rem;
254 border: 1px solid var(--border);
255 border-radius: 9px;
256 background: var(--panel);
257 color: var(--text-2);
258 font: 600 0.8125rem/1 var(--sans, ui-sans-serif);
259 text-decoration: none;
260 cursor: pointer;
261 transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
262}
263.range-tool:hover { color: var(--text); border-color: var(--accent); }
264.range-tool:active { transform: scale(0.98); }
265.range-tool:focus-visible,
266.range-link:focus-visible,
267.chrome-btn:focus-visible,
268.icon-btn:focus-visible,
269select.panel:focus-visible,
270input:focus-visible,
271textarea:focus-visible,
272summary:focus-visible {
273 outline: 2px solid var(--accent);
274 outline-offset: 2px;
275}
276.range-tool.is-active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
277.range-tool i { width: 1rem; height: 1rem; }
278.date-menu { position: relative; }
279.date-menu > summary { list-style: none; }
280.date-menu > summary::-webkit-details-marker { display: none; }
281.date-popover {
282 position: absolute;
283 right: 0;
284 top: calc(100% + 0.5rem);
285 z-index: 40;
286 width: min(44rem, calc(100vw - 2.5rem));
287 padding: 0.75rem;
288 border: 1px solid var(--border);
289 border-radius: 12px;
290 background: var(--panel);
291 box-shadow: 0 18px 50px color-mix(in srgb, var(--text) 10%, transparent);
292}
293/* Period picker: presets down the left, two months on the right. The range is
294 drawn flat with rounded ends, the way Fathom's is, on the --bar wash the KPI
295 bars already use so it reads as the same accent at the same strength. */
296.drp-backdrop { position: fixed; inset: 0; z-index: 39; background: transparent; cursor: default; }
297.drp { display: grid; grid-template-columns: 10.5rem minmax(0, 1fr); gap: 0.75rem; }
298.drp-presets { display: flex; flex-direction: column; gap: 0.15rem; padding-right: 0.75rem; border-right: 1px solid var(--border); }
299.drp-preset {
300 display: block;
301 width: 100%;
302 padding: 0.5rem 0.7rem;
303 border: 0;
304 border-radius: 8px;
305 background: transparent;
306 color: var(--text-2);
307 font: 500 0.8125rem/1.2 var(--sans, ui-sans-serif);
308 text-align: left;
309 cursor: pointer;
310}
311.drp-preset:hover { color: var(--text); background: color-mix(in srgb, var(--text) 6%, transparent); }
312.drp-preset.is-active { color: var(--accent-ink); background: var(--accent); }
313.drp-cals { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
314.drp-head { display: grid; grid-template-columns: 2rem minmax(0, 1fr) minmax(0, 1fr) 2rem; align-items: center; gap: 0.35rem; margin-bottom: 0.5rem; }
315.drp-nav {
316 display: inline-grid;
317 place-items: center;
318 width: 2rem;
319 height: 2rem;
320 padding: 0;
321 border: 1px solid transparent;
322 border-radius: 8px;
323 background: transparent;
324 color: var(--text-2);
325 cursor: pointer;
326}
327.drp-nav:hover { color: var(--text); border-color: var(--border); }
328.drp-nav svg { width: 1rem; height: 1rem; }
329.drp-nav.is-hidden { visibility: hidden; }
330.drp-sel {
331 min-width: 0;
332 height: 2rem;
333 padding: 0 0.5rem;
334 border: 1px solid var(--border);
335 border-radius: 8px;
336 background: var(--bg);
337 color: var(--text);
338 font: 600 0.8125rem/1 var(--sans, ui-sans-serif);
339}
340.drp-dow, .drp-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
341.drp-dow span { padding: 0.25rem 0; color: var(--text-3); font: 600 0.7rem/1.2 var(--sans, ui-sans-serif); text-align: center; }
342.drp-day {
343 height: 2.25rem;
344 padding: 0;
345 border: 0;
346 border-radius: 0;
347 background: transparent;
348 color: var(--text);
349 font: 500 0.8125rem/1 var(--mono, ui-monospace);
350 cursor: pointer;
351}
352.drp-day:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
353.drp-day.is-out { color: var(--text-3); }
354.drp-day.is-today { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
355.drp-day.is-range { background: var(--accent-soft); }
356.drp-day.is-edge { background: var(--accent); color: var(--accent-ink); border-radius: 8px; }
357.drp-day.is-disabled { color: var(--text-3); opacity: 0.45; cursor: default; }
358.drp-day.is-disabled:hover { background: transparent; }
359.drp-day:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 8px; }
360@media (max-width: 1023px) {
361 .date-menu { position: static; }
362 .date-popover { left: 0; right: auto; width: calc(100vw - 2rem); max-height: calc(100dvh - 6rem); overflow-y: auto; overscroll-behavior: contain; }
363 .drp { grid-template-columns: minmax(0, 1fr); }
364 .drp-presets { flex-direction: row; flex-wrap: wrap; gap: 0.35rem; padding: 0 0 0.6rem; border-right: 0; border-bottom: 1px solid var(--border); }
365 .drp-preset { width: auto; padding: 0.45rem 0.65rem; border: 1px solid var(--border); border-radius: 999px; }
366 .drp-cals { grid-template-columns: minmax(0, 1fr); }
367 .drp-cal.is-right { display: none; }
368 .drp-cal.is-left .drp-nav.is-hidden { visibility: visible; }
369 .drp-day { height: 2.5rem; }
370}
371</style>
372243<div class="grain" aria-hidden="true"></div>
373244
374245<div class="px-5 py-10 md:px-10 min-h-[100dvh] page-dashboard">
tests/unit/date-range-picker-css.test.tsadded+116-0
Changes to tests/unit/date-range-picker-css.test.ts
@@ -0,0 +1,116 @@
1import { describe, expect, test } from 'bun:test'
2import { readdirSync, readFileSync, statSync } from 'node:fs'
3import { join } from 'node:path'
4import { CSSGenerator, defaultConfig } from '@cwcss/crosswind'
5// The installed stx package does not export this subpath by bare specifier.
6import { mergeCssConfig } from '../../node_modules/@stacksjs/stx/dist/ts-css-config.js'
7import theme from '../../config/crosswind'
8
9const ROOT = join(import.meta.dir, '../..')
10
11/*
12 * The picker's stylesheet moved out of a <style> block in analytics.stx and
13 * into config/crosswind.ts preflights (stx-standards rule 3). It is a
14 * relocation rather than a utility rewrite because every state in this widget
15 * is a compound selector the client script toggles, and no utility can say
16 * "this class AND that class" -- the arbitrary-variant spelling that could,
17 * [&.is-range]:…, emits nothing in this engine.
18 *
19 * That makes the rules below the fragile part: they are plain CSS in a config
20 * file now, reached through a merge, and nothing else would notice if they
21 * stopped arriving. The selected range would simply stop painting.
22 */
23const merged: any = mergeCssConfig(defaultConfig as any, theme as any)
24const generator = new CSSGenerator(merged.config)
25const sheet: string = generator.toCSS(merged.includePreflight, merged.minify)
26// stx pins minify false, so compare without whitespace or trailing semicolons.
27const appPreflights = (theme as any).preflights as { getCSS: () => string }[]
28const flat = sheet.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\s+/g, '').replace(/;\}/g, '}')
29
30function contains(rule: string): boolean {
31 return flat.includes(rule.replace(/\s+/g, '').replace(/;\}/g, '}'))
32}
33
34describe('date range picker CSS reaches the generated sheet', () => {
35 test('preflights are merged and emitted at all', () => {
36 // This app's config used to state the opposite, from a stx version where
37 // the dev-server merge dropped preflights outright (stacksjs/stx#1867).
38 // If that ever regresses, every rule in this file goes with it.
39 expect(merged.includePreflight).toBe(true)
40 // The app's own entries, one per rule, plus the engine's built-in reset.
41 expect(appPreflights.length).toBeGreaterThan(30)
42 expect(merged.config.preflights.length).toBeGreaterThan(appPreflights.length)
43 })
44
45 test('the JS-toggled state rules are present', () => {
46 expect(contains('.range-tool.is-active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }')).toBe(true)
47 expect(contains('.drp-preset.is-active { color: var(--accent-ink); background: var(--accent); }')).toBe(true)
48 expect(contains('.drp-day.is-range { background: var(--accent-soft); }')).toBe(true)
49 expect(contains('.drp-day.is-edge { background: var(--accent); color: var(--accent-ink); border-radius: 8px; }')).toBe(true)
50 expect(contains('.drp-nav.is-hidden { visibility: hidden; }')).toBe(true)
51 expect(contains('.drp-day.is-disabled:hover { background: transparent; }')).toBe(true)
52 })
53
54 test('the selectors no utility could express are present', () => {
55 expect(contains('.date-menu > summary::-webkit-details-marker { display: none; }')).toBe(true)
56 expect(contains('summary:focus-visible {')).toBe(true)
57 expect(flat).toContain('@media(max-width:1023px)')
58 })
59
60 test('the phone layout collapses to one calendar', () => {
61 // Inside the media block, so it also proves an @media rule survived whole.
62 expect(contains('.drp-cal.is-right { display: none; }')).toBe(true)
63 expect(contains('.drp-cal.is-left .drp-nav.is-hidden { visibility: visible; }')).toBe(true)
64 })
65
66 test('each preflight entry holds exactly one top-level rule', () => {
67 /*
68 * The invariant that keeps the rest of this file true. A getCSS() returning
69 * several rules silently loses some of them -- measured on commshq, where
70 * ten in one string came back with two rules gone and a @keyframes body
71 * spliced into the rule before it. Adding a rule to an existing entry is
72 * the easy mistake, so it fails here rather than on the page.
73 *
74 * This app's entries only: the engine contributes its own preflight, and
75 * the Tailwind reset is one entry holding 38 rules.
76 */
77 for (const preflight of appPreflights) {
78 const css = preflight.getCSS()
79 let depth = 0
80 let closes = 0
81 for (const ch of css) {
82 if (ch === '{')
83 depth++
84 else if (ch === '}') {
85 depth--
86 if (depth === 0)
87 closes++
88 }
89 }
90 expect(`${css.slice(0, 60)} -> ${closes}`).toBe(`${css.slice(0, 60)} -> 1`)
91 }
92 })
93})
94
95describe('stx-standards rule 3', () => {
96 test('no view or component carries a style block', () => {
97 const stx = (dir: string): string[] => {
98 const out: string[] = []
99 for (const entry of readdirSync(dir)) {
100 const full = join(dir, entry)
101 if (statSync(full).isDirectory())
102 out.push(...stx(full))
103 else if (entry.endsWith('.stx'))
104 out.push(full)
105 }
106 return out
107 }
108 for (const file of stx(join(ROOT, 'resources'))) {
109 const source = readFileSync(file, 'utf8')
110 // An opening tag at the start of a line. Prose about a <style> block that
111 // USED to be here is not a violation, and this app's comments have
112 // several -- matching '<style' anywhere counts those.
113 expect(`${file}: ${/^[ \t]*<style[ >]/m.test(source)}`).toBe(`${file}: false`)
114 }
115 })
116})