@luci-dev/capture 0.5.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +4 -2
- package/dist/a11y.d.ts +3 -2
- package/dist/a11y.d.ts.map +1 -1
- package/dist/a11y.js +85 -13
- package/dist/a11y.js.map +1 -1
- package/dist/color.d.ts.map +1 -1
- package/dist/color.js +40 -8
- package/dist/color.js.map +1 -1
- package/dist/component.d.ts +22 -5
- package/dist/component.d.ts.map +1 -1
- package/dist/component.js +160 -46
- package/dist/component.js.map +1 -1
- package/dist/dom.d.ts +8 -6
- package/dist/dom.d.ts.map +1 -1
- package/dist/dom.js +99 -11
- package/dist/dom.js.map +1 -1
- package/dist/font.d.ts.map +1 -1
- package/dist/font.js +17 -3
- package/dist/font.js.map +1 -1
- package/dist/icon.js +12 -12
- package/dist/icon.js.map +1 -1
- package/dist/luci-capture.js +7109 -2694
- package/dist/model.d.ts +6 -7
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +13 -4
- package/dist/model.js.map +1 -1
- package/dist/page.d.ts +17 -3
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +287 -16
- package/dist/page.js.map +1 -1
- package/dist/responsive.d.ts +3 -1
- package/dist/responsive.d.ts.map +1 -1
- package/dist/responsive.js +23 -3
- package/dist/responsive.js.map +1 -1
- package/dist/section.d.ts +2 -1
- package/dist/section.d.ts.map +1 -1
- package/dist/section.js +28 -18
- package/dist/section.js.map +1 -1
- package/dist/spacing.d.ts +2 -0
- package/dist/spacing.d.ts.map +1 -1
- package/dist/spacing.js +50 -8
- package/dist/spacing.js.map +1 -1
- package/dist/states.d.ts +6 -0
- package/dist/states.d.ts.map +1 -1
- package/dist/states.js +81 -12
- package/dist/states.js.map +1 -1
- package/dist/text.d.ts +7 -1
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +175 -26
- package/dist/text.js.map +1 -1
- package/dist/ui/check.d.ts +14 -0
- package/dist/ui/check.d.ts.map +1 -1
- package/dist/ui/check.js +71 -55
- package/dist/ui/check.js.map +1 -1
- package/dist/ui/devSettings.d.ts +70 -3
- package/dist/ui/devSettings.d.ts.map +1 -1
- package/dist/ui/devSettings.js +165 -17
- package/dist/ui/devSettings.js.map +1 -1
- package/dist/ui/index.d.ts +6 -2
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +6 -2
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/mount.d.ts +16 -2
- package/dist/ui/mount.d.ts.map +1 -1
- package/dist/ui/mount.js +5 -0
- package/dist/ui/mount.js.map +1 -1
- package/dist/ui/onSpec.d.ts +61 -0
- package/dist/ui/onSpec.d.ts.map +1 -0
- package/dist/ui/onSpec.js +516 -0
- package/dist/ui/onSpec.js.map +1 -0
- package/dist/ui/projectLabel.d.ts +11 -0
- package/dist/ui/projectLabel.d.ts.map +1 -0
- package/dist/ui/projectLabel.js +15 -0
- package/dist/ui/projectLabel.js.map +1 -0
- package/dist/ui/remap.d.ts.map +1 -1
- package/dist/ui/remap.js +7 -3
- package/dist/ui/remap.js.map +1 -1
- package/dist/ui/specWatcher.d.ts +79 -0
- package/dist/ui/specWatcher.d.ts.map +1 -0
- package/dist/ui/specWatcher.js +702 -0
- package/dist/ui/specWatcher.js.map +1 -0
- package/dist/ui/styles.d.ts +4 -1
- package/dist/ui/styles.d.ts.map +1 -1
- package/dist/ui/styles.js +344 -3
- package/dist/ui/styles.js.map +1 -1
- package/dist/ui/toolbar.d.ts +16 -2
- package/dist/ui/toolbar.d.ts.map +1 -1
- package/dist/ui/toolbar.js +249 -79
- package/dist/ui/toolbar.js.map +1 -1
- package/dist/ui/tools.d.ts +5 -4
- package/dist/ui/tools.d.ts.map +1 -1
- package/dist/ui/tools.js +44 -13
- package/dist/ui/tools.js.map +1 -1
- package/dist/ui/updateBanner.d.ts +13 -0
- package/dist/ui/updateBanner.d.ts.map +1 -0
- package/dist/ui/updateBanner.js +105 -0
- package/dist/ui/updateBanner.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type OnSpecConfig, type RuleMeta, type SpecComponent, type SpecTaskState } from '@luci-dev/format/capture';
|
|
2
|
+
import { type ReviewerRole } from '@luci-dev/format/feedback';
|
|
3
|
+
export declare const ON_SPEC_TAG = "luci-on-spec";
|
|
4
|
+
export interface OnSpecCallbacks {
|
|
5
|
+
onExcuse: (input: {
|
|
6
|
+
componentId: string;
|
|
7
|
+
reason: string;
|
|
8
|
+
role: ReviewerRole;
|
|
9
|
+
}) => Promise<void>;
|
|
10
|
+
onUpdateRule: (input: {
|
|
11
|
+
componentId: string;
|
|
12
|
+
ruleFile: string;
|
|
13
|
+
selector: string;
|
|
14
|
+
role: ReviewerRole;
|
|
15
|
+
}) => Promise<void>;
|
|
16
|
+
onSendBack: (input: {
|
|
17
|
+
componentId: string;
|
|
18
|
+
note?: string;
|
|
19
|
+
role: ReviewerRole;
|
|
20
|
+
}) => Promise<void>;
|
|
21
|
+
onMarkReviewed: (input: {
|
|
22
|
+
ruleFile: string;
|
|
23
|
+
role: ReviewerRole;
|
|
24
|
+
}) => Promise<void>;
|
|
25
|
+
onAddRule: (input: {
|
|
26
|
+
component: SpecComponent;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
onCheckNow: () => Promise<void>;
|
|
29
|
+
onSaveRole: (role: ReviewerRole) => Promise<void>;
|
|
30
|
+
verdictForElement?: (el: Element) => SpecComponent | null;
|
|
31
|
+
}
|
|
32
|
+
export interface OnSpecStateView {
|
|
33
|
+
state: SpecTaskState;
|
|
34
|
+
rulesMeta: Record<string, RuleMeta>;
|
|
35
|
+
report: string;
|
|
36
|
+
settings: Required<OnSpecConfig>;
|
|
37
|
+
profile: {
|
|
38
|
+
role: ReviewerRole;
|
|
39
|
+
saved: boolean;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface OnSpecMountOptions {
|
|
43
|
+
doc?: Document;
|
|
44
|
+
initial: OnSpecStateView;
|
|
45
|
+
callbacks: OnSpecCallbacks;
|
|
46
|
+
}
|
|
47
|
+
export interface OnSpecHandle {
|
|
48
|
+
readonly host: HTMLElement;
|
|
49
|
+
update(next: Partial<OnSpecStateView>): void;
|
|
50
|
+
/** Reveal on-page paw pins; optionally focus/highlight one component by selector. */
|
|
51
|
+
revealPins(options?: {
|
|
52
|
+
selector?: string;
|
|
53
|
+
openPopover?: boolean;
|
|
54
|
+
}): void;
|
|
55
|
+
open(): void;
|
|
56
|
+
close(): void;
|
|
57
|
+
destroy(): void;
|
|
58
|
+
}
|
|
59
|
+
/** Mount the calm On spec pill, on-page pins, overview panel, and optional hover badge in its own shadow root. */
|
|
60
|
+
export declare function mountOnSpec(options: OnSpecMountOptions): OnSpecHandle;
|
|
61
|
+
//# sourceMappingURL=onSpec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onSpec.d.ts","sourceRoot":"","sources":["../../src/ui/onSpec.tsx"],"names":[],"mappings":"AAaA,OAAO,EAQL,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,aAAa,EAElB,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAmB9E,eAAO,MAAM,WAAW,iBAAiB,CAAC;AAE1C,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,YAAY,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChG,YAAY,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,YAAY,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxH,UAAU,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,YAAY,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjG,cAAc,EAAE,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,YAAY,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnF,SAAS,EAAE,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,aAAa,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,UAAU,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,iBAAiB,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,aAAa,GAAG,IAAI,CAAC;CAC3D;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACjC,OAAO,EAAE;QAAE,IAAI,EAAE,YAAY,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;CACjD;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,eAAe,CAAC;IACzB,SAAS,EAAE,eAAe,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC;IAC7C,qFAAqF;IACrF,UAAU,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACzE,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,IAAI,IAAI,CAAC;IACd,OAAO,IAAI,IAAI,CAAC;CACjB;AAu7BD,kHAAkH;AAClH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,YAAY,CAgErE"}
|
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* On spec devtool UI (v0.7, Brief 01 req. 1-4, 14-20, 22-23, 25):
|
|
4
|
+
* - Calm after-edit pill ("1/1 on spec" / "0/1 on spec · 1 drift") with Lucide paw-print
|
|
5
|
+
* that settles over 200ms ease-out when earned (off under prefers-reduced-motion).
|
|
6
|
+
* - Annotate-style on-page component pins anchored directly to each tracked element,
|
|
7
|
+
* with a focused single-component popover + element highlight ring on hover/click.
|
|
8
|
+
* - Compact overview panel with icon-only Re-check, pins toggle, single-line Copy report,
|
|
9
|
+
* human-readable labels (raw CSS selectors tucked inside "Why this rule?"), and full
|
|
10
|
+
* Excuse / Update rule / Send back / Why this rule? / one-time role prompt flows.
|
|
11
|
+
* - Optional on-page hover badge (off by default).
|
|
12
|
+
*/
|
|
13
|
+
import { h, render } from 'preact';
|
|
14
|
+
import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
|
|
15
|
+
import { SPEC_MATCHES_PHRASE, SPEC_STATE_LABELS, formatDriftDetail, formatRuleOrigin, formatSpecReport, formatSpecSummary, getRuleChallengeStatus } from '@luci-dev/format/capture';
|
|
16
|
+
import { REVIEWER_ROLES } from '@luci-dev/format/feedback';
|
|
17
|
+
import { Icon, IconCheck, IconClose, IconCopy, IconHide, IconInfo, IconOnSpec, IconReset, IconSuccess, IconWarning, UI_CSS, loadFonts } from '@luci-dev/ui';
|
|
18
|
+
import { LUCI_UI_ATTRIBUTE } from '../dom.js';
|
|
19
|
+
import { ON_SPEC_CSS } from './styles.js';
|
|
20
|
+
import { readUiPrefs, UI_PREFS_EVENT } from './theme.js';
|
|
21
|
+
export const ON_SPEC_TAG = 'luci-on-spec';
|
|
22
|
+
function StateIcon({ state, earned }) {
|
|
23
|
+
if (state === 'on-spec') {
|
|
24
|
+
return (_jsx("span", { class: earned ? 'os-paw-earned' : undefined, children: _jsx(Icon, { icon: IconOnSpec, size: "compact" }) }));
|
|
25
|
+
}
|
|
26
|
+
if (state === 'drift')
|
|
27
|
+
return _jsx(Icon, { icon: IconWarning, size: "compact" });
|
|
28
|
+
if (state === 'excused')
|
|
29
|
+
return _jsx(Icon, { icon: IconSuccess, size: "compact" });
|
|
30
|
+
return _jsx(Icon, { icon: IconInfo, size: "compact" });
|
|
31
|
+
}
|
|
32
|
+
const normalizeRuleKey = (ruleFile) => ruleFile.replace(/^\.luci\/design\//, '').replace(/^\/+/, '');
|
|
33
|
+
function findLiveElement(doc, selector) {
|
|
34
|
+
if (!selector)
|
|
35
|
+
return null;
|
|
36
|
+
if (!selector.includes(' >> ')) {
|
|
37
|
+
try {
|
|
38
|
+
return doc.querySelector(selector);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const parts = selector.split(' >> ');
|
|
45
|
+
let cur = doc;
|
|
46
|
+
for (const part of parts) {
|
|
47
|
+
try {
|
|
48
|
+
const next = cur.querySelector(part);
|
|
49
|
+
if (!next)
|
|
50
|
+
return null;
|
|
51
|
+
cur = next.shadowRoot ?? next;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return cur instanceof Element ? cur : null;
|
|
58
|
+
}
|
|
59
|
+
function elementSnippet(el) {
|
|
60
|
+
if (!el)
|
|
61
|
+
return '';
|
|
62
|
+
const text = el.getAttribute('aria-label') || el.innerText || el.textContent || '';
|
|
63
|
+
const raw = text.trim().replace(/\s+/g, ' ');
|
|
64
|
+
return raw.length > 36 ? `${raw.slice(0, 35)}…` : raw;
|
|
65
|
+
}
|
|
66
|
+
const clamp = (v, min, max) => Math.max(min, Math.min(v, Math.max(min, max)));
|
|
67
|
+
function OnSpecView({ doc, store, callbacks }) {
|
|
68
|
+
const win = doc.defaultView ?? window;
|
|
69
|
+
const [snap, setSnap] = useState(() => store.get());
|
|
70
|
+
useEffect(() => store.subscribe(() => setSnap(store.get())), [store]);
|
|
71
|
+
const { data, open, revealReq } = snap;
|
|
72
|
+
const setOpen = (v) => store.setOpen(v);
|
|
73
|
+
const { state, rulesMeta, report, settings, profile } = data;
|
|
74
|
+
const components = state.components;
|
|
75
|
+
const [side, setSide] = useState(() => (readUiPrefs(doc).dock === 'left' ? 'right' : 'left'));
|
|
76
|
+
const [copied, setCopied] = useState(false);
|
|
77
|
+
const [busy, setBusy] = useState(false);
|
|
78
|
+
const [checkState, setCheckState] = useState('idle');
|
|
79
|
+
const checkDoneTimerRef = useRef(null);
|
|
80
|
+
const [errorMsg, setErrorMsg] = useState(null);
|
|
81
|
+
const [whyOpenId, setWhyOpenId] = useState(null);
|
|
82
|
+
const [activeAction, setActiveAction] = useState(null);
|
|
83
|
+
const [excuseReason, setExcuseReason] = useState('');
|
|
84
|
+
const [sendBackNote, setSendBackNote] = useState('');
|
|
85
|
+
const [pendingRole, setPendingRole] = useState(null);
|
|
86
|
+
const [chosenRole, setChosenRole] = useState(profile.role);
|
|
87
|
+
// On-page Annotate-style pins: calm by default, auto-shown on drift, panel open, or after save
|
|
88
|
+
const [pinsVisible, setPinsVisible] = useState(false);
|
|
89
|
+
const [selectedPinId, setSelectedPinId] = useState(null);
|
|
90
|
+
const [hoveredId, setHoveredId] = useState(null);
|
|
91
|
+
const [layoutTick, setLayoutTick] = useState(0);
|
|
92
|
+
// Track newly earned On spec IDs & drift transitions
|
|
93
|
+
const prevStatesRef = useRef(new Map());
|
|
94
|
+
const [earnedIds, setEarnedIds] = useState(new Set());
|
|
95
|
+
const [pillEarned, setPillEarned] = useState(false);
|
|
96
|
+
// Optional hover badge state (off by default)
|
|
97
|
+
const [hoverInfo, setHoverInfo] = useState(null);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
setChosenRole(profile.role);
|
|
100
|
+
}, [profile.role]);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
const syncDock = () => setSide(readUiPrefs(doc).dock === 'left' ? 'right' : 'left');
|
|
103
|
+
doc.addEventListener(UI_PREFS_EVENT, syncDock);
|
|
104
|
+
return () => doc.removeEventListener(UI_PREFS_EVENT, syncDock);
|
|
105
|
+
}, [doc]);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
const prev = prevStatesRef.current;
|
|
108
|
+
const newlyEarned = new Set();
|
|
109
|
+
let newDrift = false;
|
|
110
|
+
for (const c of components) {
|
|
111
|
+
const prevState = prev.get(c.id);
|
|
112
|
+
if (c.state === 'on-spec' && prevState && prevState !== 'on-spec') {
|
|
113
|
+
newlyEarned.add(c.id);
|
|
114
|
+
}
|
|
115
|
+
if (c.state === 'drift' && prevState !== 'drift') {
|
|
116
|
+
newDrift = true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
prevStatesRef.current = new Map(components.map(c => [c.id, c.state]));
|
|
120
|
+
if (newDrift)
|
|
121
|
+
setPinsVisible(true);
|
|
122
|
+
if (newlyEarned.size > 0) {
|
|
123
|
+
setEarnedIds(newlyEarned);
|
|
124
|
+
setPillEarned(true);
|
|
125
|
+
const t = setTimeout(() => { setEarnedIds(new Set()); setPillEarned(false); }, 350);
|
|
126
|
+
return () => clearTimeout(t);
|
|
127
|
+
}
|
|
128
|
+
}, [components]);
|
|
129
|
+
// Clear selected pin if its component was pruned
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (selectedPinId && !components.some(c => c.id === selectedPinId)) {
|
|
132
|
+
setSelectedPinId(null);
|
|
133
|
+
}
|
|
134
|
+
}, [components, selectedPinId]);
|
|
135
|
+
// Handle explicit revealPins requests (e.g. after Save to project or "Show pin" click)
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (!revealReq)
|
|
138
|
+
return;
|
|
139
|
+
setPinsVisible(true);
|
|
140
|
+
setLayoutTick(t => t + 1);
|
|
141
|
+
if (revealReq.selector) {
|
|
142
|
+
const targetComp = components.find(c => c.selector === revealReq.selector) ?? null;
|
|
143
|
+
const el = findLiveElement(doc, revealReq.selector);
|
|
144
|
+
if (el && revealReq.openPopover) {
|
|
145
|
+
try {
|
|
146
|
+
el.scrollIntoView?.({ behavior: 'smooth', block: 'center' });
|
|
147
|
+
}
|
|
148
|
+
catch { /* ignore */ }
|
|
149
|
+
}
|
|
150
|
+
if (targetComp && revealReq.openPopover) {
|
|
151
|
+
setOpen(false);
|
|
152
|
+
setSelectedPinId(targetComp.id);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}, [revealReq?.seq]);
|
|
156
|
+
// Keep pin coordinates synced with page scroll & resize while pins or highlight are active
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (!pinsVisible && !hoveredId && !selectedPinId)
|
|
159
|
+
return;
|
|
160
|
+
let raf = 0;
|
|
161
|
+
const bump = () => {
|
|
162
|
+
if (raf)
|
|
163
|
+
return;
|
|
164
|
+
raf = win.requestAnimationFrame(() => {
|
|
165
|
+
raf = 0;
|
|
166
|
+
setLayoutTick(t => t + 1);
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
win.addEventListener('scroll', bump, true);
|
|
170
|
+
win.addEventListener('resize', bump);
|
|
171
|
+
return () => {
|
|
172
|
+
if (raf)
|
|
173
|
+
win.cancelAnimationFrame(raf);
|
|
174
|
+
win.removeEventListener('scroll', bump, true);
|
|
175
|
+
win.removeEventListener('resize', bump);
|
|
176
|
+
};
|
|
177
|
+
}, [win, pinsVisible, hoveredId, selectedPinId]);
|
|
178
|
+
// Escape closes an open pin popover or the overview panel
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
if (!selectedPinId && !open)
|
|
181
|
+
return;
|
|
182
|
+
const onKey = (e) => {
|
|
183
|
+
if (e.key !== 'Escape')
|
|
184
|
+
return;
|
|
185
|
+
if (selectedPinId) {
|
|
186
|
+
setSelectedPinId(null);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (open)
|
|
190
|
+
store.setOpen(false);
|
|
191
|
+
};
|
|
192
|
+
doc.addEventListener('keydown', onKey, true);
|
|
193
|
+
return () => doc.removeEventListener('keydown', onKey, true);
|
|
194
|
+
}, [doc, selectedPinId, open, store]);
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
if (!settings.hoverBadge || !callbacks.verdictForElement) {
|
|
197
|
+
setHoverInfo(null);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const onMove = (e) => {
|
|
201
|
+
const target = e.target;
|
|
202
|
+
if (!target || target.closest(`[${LUCI_UI_ATTRIBUTE}]`)) {
|
|
203
|
+
setHoverInfo(null);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const verdict = callbacks.verdictForElement?.(target);
|
|
207
|
+
if (!verdict) {
|
|
208
|
+
setHoverInfo(null);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const r = target.getBoundingClientRect();
|
|
212
|
+
setHoverInfo({
|
|
213
|
+
state: verdict.state,
|
|
214
|
+
name: verdict.name,
|
|
215
|
+
x: Math.max(8, Math.min(r.left, (win.innerWidth || 1200) - 180)),
|
|
216
|
+
y: Math.max(8, r.top - 28)
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
const onLeave = () => setHoverInfo(null);
|
|
220
|
+
doc.addEventListener('pointermove', onMove, true);
|
|
221
|
+
doc.addEventListener('pointerleave', onLeave, true);
|
|
222
|
+
return () => {
|
|
223
|
+
doc.removeEventListener('pointermove', onMove, true);
|
|
224
|
+
doc.removeEventListener('pointerleave', onLeave, true);
|
|
225
|
+
};
|
|
226
|
+
}, [doc, win, settings.hoverBadge, callbacks.verdictForElement]);
|
|
227
|
+
// Compute live pin positions for components present on this page
|
|
228
|
+
const livePins = useMemo(() => {
|
|
229
|
+
void layoutTick;
|
|
230
|
+
const out = [];
|
|
231
|
+
for (const comp of components) {
|
|
232
|
+
const el = findLiveElement(doc, comp.selector);
|
|
233
|
+
if (!el)
|
|
234
|
+
continue;
|
|
235
|
+
const rect = el.getBoundingClientRect();
|
|
236
|
+
if (rect.width <= 0 || rect.height <= 0)
|
|
237
|
+
continue;
|
|
238
|
+
out.push({ comp, el, rect, snippet: elementSnippet(el) });
|
|
239
|
+
}
|
|
240
|
+
return out;
|
|
241
|
+
}, [doc, components, layoutTick]);
|
|
242
|
+
const pinById = useMemo(() => new Map(livePins.map(p => [p.comp.id, p])), [livePins]);
|
|
243
|
+
const selectedPin = selectedPinId ? pinById.get(selectedPinId) ?? null : null;
|
|
244
|
+
const activeHighlight = (hoveredId ? pinById.get(hoveredId) : null) ?? selectedPin ?? null;
|
|
245
|
+
const withRoleCheck = async (label, run) => {
|
|
246
|
+
if (!profile.saved) {
|
|
247
|
+
setPendingRole({ label, run });
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
setBusy(true);
|
|
251
|
+
setErrorMsg(null);
|
|
252
|
+
try {
|
|
253
|
+
await run(profile.role);
|
|
254
|
+
}
|
|
255
|
+
catch (err) {
|
|
256
|
+
setErrorMsg(err instanceof Error ? err.message : String(err));
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
setBusy(false);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
const confirmRoleAndContinue = async () => {
|
|
263
|
+
if (!pendingRole)
|
|
264
|
+
return;
|
|
265
|
+
setBusy(true);
|
|
266
|
+
setErrorMsg(null);
|
|
267
|
+
try {
|
|
268
|
+
await callbacks.onSaveRole(chosenRole);
|
|
269
|
+
const action = pendingRole;
|
|
270
|
+
setPendingRole(null);
|
|
271
|
+
await action.run(chosenRole);
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
setErrorMsg(err instanceof Error ? err.message : String(err));
|
|
275
|
+
}
|
|
276
|
+
finally {
|
|
277
|
+
setBusy(false);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
useEffect(() => () => {
|
|
281
|
+
if (checkDoneTimerRef.current)
|
|
282
|
+
clearTimeout(checkDoneTimerRef.current);
|
|
283
|
+
}, []);
|
|
284
|
+
const runCheckNow = async () => {
|
|
285
|
+
if (busy || checkState === 'checking')
|
|
286
|
+
return;
|
|
287
|
+
if (checkDoneTimerRef.current) {
|
|
288
|
+
clearTimeout(checkDoneTimerRef.current);
|
|
289
|
+
checkDoneTimerRef.current = null;
|
|
290
|
+
}
|
|
291
|
+
setBusy(true);
|
|
292
|
+
setCheckState('checking');
|
|
293
|
+
setErrorMsg(null);
|
|
294
|
+
try {
|
|
295
|
+
await Promise.all([
|
|
296
|
+
callbacks.onCheckNow(),
|
|
297
|
+
new Promise(resolve => setTimeout(resolve, 260))
|
|
298
|
+
]);
|
|
299
|
+
setCheckState('done');
|
|
300
|
+
checkDoneTimerRef.current = setTimeout(() => {
|
|
301
|
+
checkDoneTimerRef.current = null;
|
|
302
|
+
setCheckState('idle');
|
|
303
|
+
}, 1600);
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
setCheckState('idle');
|
|
307
|
+
setErrorMsg(err instanceof Error ? err.message : String(err));
|
|
308
|
+
}
|
|
309
|
+
finally {
|
|
310
|
+
setBusy(false);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
const copyReport = async () => {
|
|
314
|
+
const md = report || formatSpecReport(state, rulesMeta);
|
|
315
|
+
try {
|
|
316
|
+
await win.navigator.clipboard?.writeText(md);
|
|
317
|
+
setCopied(true);
|
|
318
|
+
setTimeout(() => setCopied(false), 1800);
|
|
319
|
+
}
|
|
320
|
+
catch {
|
|
321
|
+
setErrorMsg('Could not copy to clipboard.');
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
const locateComponent = (comp) => {
|
|
325
|
+
const el = findLiveElement(doc, comp.selector);
|
|
326
|
+
setPinsVisible(true);
|
|
327
|
+
if (el) {
|
|
328
|
+
try {
|
|
329
|
+
el.scrollIntoView?.({ behavior: 'smooth', block: 'center' });
|
|
330
|
+
}
|
|
331
|
+
catch { /* ignore */ }
|
|
332
|
+
}
|
|
333
|
+
setLayoutTick(t => t + 1);
|
|
334
|
+
setOpen(false);
|
|
335
|
+
setSelectedPinId(comp.id);
|
|
336
|
+
};
|
|
337
|
+
const renderRolePrompt = () => (pendingRole ? (_jsxs("div", { class: "os-role-prompt", "data-part": "role-prompt", children: [_jsx("strong", { children: "Choose your role once" }), _jsxs("p", { class: "os-sub", children: ["Saved locally in ", _jsx("code", { children: "~/.luci/profile.json" }), " (roles only, never personal names). Used when you Excuse or Update a rule."] }), _jsx("div", { class: "os-role-choices", role: "radiogroup", "aria-label": "Your role", children: REVIEWER_ROLES.map(r => (_jsx("button", { type: "button", class: `btn btn-sm ${chosenRole === r ? 'btn-primary' : 'btn-secondary'}`, "data-role-choice": r, "aria-pressed": chosenRole === r, onClick: () => setChosenRole(r), children: r }, r))) }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn btn-primary btn-sm", "data-action": "role-confirm", disabled: busy, onClick: () => void confirmRoleAndContinue(), children: "Save role & continue" }), _jsx("button", { type: "button", class: "btn btn-ghost btn-sm", onClick: () => setPendingRole(null), children: "Cancel" })] })] })) : null);
|
|
338
|
+
const renderComponentBody = (comp, snippet, mode) => {
|
|
339
|
+
const ruleKey = comp.ruleFile ? normalizeRuleKey(comp.ruleFile) : null;
|
|
340
|
+
const meta = ruleKey ? rulesMeta[ruleKey] ?? null : null;
|
|
341
|
+
const challenge = getRuleChallengeStatus(meta);
|
|
342
|
+
const isWhyOpen = whyOpenId === comp.id;
|
|
343
|
+
const isEditingThis = activeAction?.id === comp.id;
|
|
344
|
+
const showSnippet = snippet && snippet.toLowerCase() !== comp.name.toLowerCase();
|
|
345
|
+
const hasLiveEl = pinById.has(comp.id);
|
|
346
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { class: "os-row-top", children: [_jsx("div", { class: "os-comp-meta", children: mode === 'list' && hasLiveEl ? (_jsxs("button", { type: "button", class: "os-comp-link", "data-action": "locate-component", title: `Show on page (${comp.selector})`, onClick: () => locateComponent(comp), children: [_jsx("span", { class: "os-comp-name", children: comp.name }), showSnippet && _jsx("span", { class: "os-comp-snippet", children: snippet })] })) : (_jsxs("div", { class: "os-comp-heading", title: comp.selector, children: [_jsx("span", { class: "os-comp-name", children: comp.name }), showSnippet && _jsx("span", { class: "os-comp-snippet", children: snippet })] })) }), _jsxs("div", { class: "os-row-right", children: [_jsxs("span", { class: "os-badge", "data-part": "on-spec-state", "data-state": comp.state, children: [_jsx(StateIcon, { state: comp.state, earned: earnedIds.has(comp.id) }), _jsx("span", { children: SPEC_STATE_LABELS[comp.state] })] }), mode === 'popover' && (_jsx("button", { type: "button", class: "btn-ghost btn-sm btn-icon", "data-action": "close-popover", "aria-label": "Close component check", onClick: () => setSelectedPinId(null), children: _jsx(Icon, { icon: IconClose, size: "compact" }) }))] })] }), comp.state === 'on-spec' && (_jsxs("div", { class: "os-on-spec-line", children: [_jsx("p", { class: "os-sub", children: SPEC_MATCHES_PHRASE }), comp.ruleFile && (_jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "why-rule", title: "Inspect where this saved rule came from and its decision history", "aria-expanded": isWhyOpen, onClick: () => setWhyOpenId(isWhyOpen ? null : comp.id), children: "Why this rule?" }))] })), comp.state === 'drift' && (_jsxs(_Fragment, { children: [comp.needsHuman && (_jsxs("p", { class: "os-sub", "data-part": "needs-human-note", children: [_jsx("strong", { children: "Needs you" }), " \u2014 2 automatic fix rounds reached. Choose Excuse, Update rule, or Send back."] })), comp.differences.length > 0 && (_jsxs("ul", { class: "os-diffs", children: [comp.differences.slice(0, 4).map((d, i) => (_jsx("li", { children: formatDriftDetail(d) }, i))), comp.differences.length > 4 && (_jsxs("li", { children: ["+", comp.differences.length - 4, " more differences"] }))] })), _jsxs("div", { class: "os-actions", "data-part": "decision-bar", children: [_jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "excuse-open", title: "Allow this drift with a required reason (records your role and clears the gate for this item)", onClick: () => {
|
|
347
|
+
setActiveAction({ id: comp.id, kind: 'excuse' });
|
|
348
|
+
setExcuseReason('');
|
|
349
|
+
}, children: "Excuse" }), comp.ruleFile && (_jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "update-rule-open", title: "Replace the saved .design.md rule with this component's current live styles", onClick: () => setActiveAction({ id: comp.id, kind: 'update' }), children: "Update rule" })), _jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "send-back-open", title: "Queue a Feedback fix note for your agent and reset its 2 automatic fix rounds", onClick: () => {
|
|
350
|
+
setActiveAction({ id: comp.id, kind: 'send-back' });
|
|
351
|
+
setSendBackNote('');
|
|
352
|
+
}, children: "Send back" }), comp.ruleFile && (_jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "why-rule", title: "Inspect where this saved rule came from and its decision history", "aria-expanded": isWhyOpen, onClick: () => setWhyOpenId(isWhyOpen ? null : comp.id), children: "Why this rule?" }))] })] })), comp.state === 'excused' && (_jsxs(_Fragment, { children: [_jsx("p", { class: "os-sub", "data-part": "excuse-reason", children: comp.excuse ? `${comp.excuse.reason} — ${comp.excuse.role}, ${comp.excuse.at.slice(0, 10)}` : 'Excused' }), comp.ruleFile && (_jsx("div", { class: "os-actions", children: _jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "why-rule", "aria-expanded": isWhyOpen, onClick: () => setWhyOpenId(isWhyOpen ? null : comp.id), children: "Why this rule?" }) }))] })), comp.state === 'no-rule' && (_jsxs("div", { class: "os-actions", children: [_jsx("span", { class: "os-sub", children: "No saved rule matches this component." }), _jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "add-rule", title: "Capture this component right now as a saved rule in .luci/design/", disabled: busy, onClick: async () => {
|
|
353
|
+
setBusy(true);
|
|
354
|
+
try {
|
|
355
|
+
await callbacks.onAddRule({ component: comp });
|
|
356
|
+
}
|
|
357
|
+
finally {
|
|
358
|
+
setBusy(false);
|
|
359
|
+
}
|
|
360
|
+
}, children: "Add a rule?" })] })), challenge.challenged && challenge.message && comp.ruleFile && (_jsxs("div", { class: "os-challenge", "data-part": "challenge-banner", children: [_jsx("span", { children: challenge.message }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "challenge-update-rule", title: "Replace the saved rule with this component's current live styles", onClick: () => setActiveAction({ id: comp.id, kind: 'update' }), children: "Update rule" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "mark-reviewed", title: "Confirm the saved rule is still right and clear this challenge banner", disabled: busy, onClick: () => void withRoleCheck('Keep as is (reviewed)', async (role) => {
|
|
361
|
+
await callbacks.onMarkReviewed({ ruleFile: comp.ruleFile, role });
|
|
362
|
+
}), children: "Keep as is (reviewed)" })] })] })), isEditingThis && activeAction?.kind === 'excuse' && (_jsxs("div", { class: "os-inline-box", "data-part": "excuse-box", children: [_jsx("label", { class: "os-sub", for: `excuse-${mode}-${comp.id}`, children: "Reason (required)" }), _jsx("input", { id: `excuse-${mode}-${comp.id}`, type: "text", "data-part": "excuse-input", placeholder: "Why is this difference intentional?", value: excuseReason, onInput: (e) => setExcuseReason(e.currentTarget.value) }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-primary btn-sm", "data-action": "excuse-confirm", disabled: busy || excuseReason.trim().length === 0, onClick: () => void withRoleCheck('Excuse', async (role) => {
|
|
363
|
+
await callbacks.onExcuse({ componentId: comp.id, reason: excuseReason.trim(), role });
|
|
364
|
+
setActiveAction(null);
|
|
365
|
+
setExcuseReason('');
|
|
366
|
+
}), children: "Save excuse" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => setActiveAction(null), children: "Cancel" })] })] })), isEditingThis && activeAction?.kind === 'update' && comp.ruleFile && (_jsxs("div", { class: "os-inline-box", "data-part": "update-rule-confirm-box", children: [_jsxs("p", { class: "os-sub", children: ["Save the current build as the rule for ", _jsx("strong", { children: comp.name }), "? This updates ", _jsx("code", { children: comp.ruleFile }), "."] }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-primary btn-sm", "data-action": "update-rule-confirm", disabled: busy, onClick: () => void withRoleCheck('Update rule', async (role) => {
|
|
367
|
+
await callbacks.onUpdateRule({
|
|
368
|
+
componentId: comp.id,
|
|
369
|
+
ruleFile: comp.ruleFile,
|
|
370
|
+
selector: comp.selector,
|
|
371
|
+
role
|
|
372
|
+
});
|
|
373
|
+
setActiveAction(null);
|
|
374
|
+
}), children: "Confirm update" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => setActiveAction(null), children: "Cancel" })] })] })), isEditingThis && activeAction?.kind === 'send-back' && (_jsxs("div", { class: "os-inline-box", "data-part": "send-back-box", children: [_jsx("label", { class: "os-sub", for: `sendback-${mode}-${comp.id}`, children: "Note for your agent (optional)" }), _jsx("input", { id: `sendback-${mode}-${comp.id}`, type: "text", "data-part": "send-back-input", placeholder: "e.g. Use the 16px token from our spacing scale", value: sendBackNote, onInput: (e) => setSendBackNote(e.currentTarget.value) }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-primary btn-sm", "data-action": "send-back-confirm", disabled: busy, onClick: async () => {
|
|
375
|
+
setBusy(true);
|
|
376
|
+
setErrorMsg(null);
|
|
377
|
+
try {
|
|
378
|
+
await callbacks.onSendBack({
|
|
379
|
+
componentId: comp.id,
|
|
380
|
+
...(sendBackNote.trim() ? { note: sendBackNote.trim() } : {}),
|
|
381
|
+
role: profile.role
|
|
382
|
+
});
|
|
383
|
+
setActiveAction(null);
|
|
384
|
+
setSendBackNote('');
|
|
385
|
+
}
|
|
386
|
+
catch (err) {
|
|
387
|
+
setErrorMsg(err instanceof Error ? err.message : String(err));
|
|
388
|
+
}
|
|
389
|
+
finally {
|
|
390
|
+
setBusy(false);
|
|
391
|
+
}
|
|
392
|
+
}, children: "Send to agent" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => setActiveAction(null), children: "Cancel" })] })] })), isWhyOpen && comp.ruleFile && (_jsxs("div", { class: "os-why", "data-part": "why-rule-card", children: [_jsx("strong", { children: "Why this rule? (Saved history)" }), _jsxs("span", { children: ["Rule file: ", _jsx("code", { children: comp.ruleFile })] }), _jsxs("span", { class: "os-comp-sel", children: ["Selector: ", _jsx("code", { children: comp.selector })] }), meta ? (_jsxs(_Fragment, { children: [_jsxs("span", { children: ["Origin: ", formatRuleOrigin(meta)] }), _jsxs("span", { children: ["Originally confirmed by: ", meta.confirmedByRole, " on ", meta.confirmedAt.slice(0, 10)] }), meta.history.length > 0 && (_jsx("ul", { class: "os-history", children: meta.history.slice(-8).map((entry, idx) => (_jsxs("li", { children: [_jsx("strong", { children: entry.kind }), " (", entry.role, ", ", entry.at.slice(0, 10), ")", entry.reason ? ` — ${entry.reason}` : entry.note ? ` — ${entry.note}` : ''] }, idx))) }))] })) : (_jsx("span", { children: "Origin: Saved in .luci/design/" })), _jsxs("span", { class: "os-comp-sel", children: ["Your current role: ", profile.role, " (used for new decisions)"] })] }))] }));
|
|
393
|
+
};
|
|
394
|
+
const summaryText = formatSpecSummary(components);
|
|
395
|
+
const hasDrift = components.some(c => c.state === 'drift');
|
|
396
|
+
const showPill = components.length > 0 || open;
|
|
397
|
+
const vw = win.innerWidth || 1280;
|
|
398
|
+
const vh = win.innerHeight || 800;
|
|
399
|
+
// Position focused popover near the selected element without leaving the viewport
|
|
400
|
+
const popoverStyle = useMemo(() => {
|
|
401
|
+
if (!selectedPin)
|
|
402
|
+
return undefined;
|
|
403
|
+
const width = Math.min(400, vw - 24);
|
|
404
|
+
const left = clamp(selectedPin.rect.left, 12, vw - width - 12);
|
|
405
|
+
const spaceBelow = vh - selectedPin.rect.bottom - 16;
|
|
406
|
+
if (spaceBelow >= 220 || spaceBelow >= selectedPin.rect.top) {
|
|
407
|
+
return { left: `${left}px`, top: `${clamp(selectedPin.rect.bottom + 8, 12, vh - 120)}px`, width: `${width}px` };
|
|
408
|
+
}
|
|
409
|
+
return { left: `${left}px`, bottom: `${clamp(vh - selectedPin.rect.top + 8, 12, vh - 120)}px`, width: `${width}px` };
|
|
410
|
+
}, [selectedPin, vw, vh]);
|
|
411
|
+
return (_jsxs("div", { class: "luci-theme", "data-theme": readUiPrefs(doc).theme, children: [activeHighlight && (_jsx("div", { class: "highlight os-highlight", "data-part": "on-spec-highlight", "aria-hidden": "true", style: {
|
|
412
|
+
left: `${activeHighlight.rect.left - 3}px`,
|
|
413
|
+
top: `${activeHighlight.rect.top - 3}px`,
|
|
414
|
+
width: `${activeHighlight.rect.width + 6}px`,
|
|
415
|
+
height: `${activeHighlight.rect.height + 6}px`
|
|
416
|
+
} })), pinsVisible && livePins.map(({ comp, rect, snippet }) => {
|
|
417
|
+
if (rect.bottom <= 0 || rect.top >= vh || rect.right <= 0 || rect.left >= vw)
|
|
418
|
+
return null;
|
|
419
|
+
const pinLeft = clamp(rect.right - 14, 8, vw - 52);
|
|
420
|
+
const pinTop = clamp(rect.top - 14, 8, vh - 36);
|
|
421
|
+
const isSelected = selectedPinId === comp.id;
|
|
422
|
+
const diffCount = comp.state === 'drift' ? comp.differences.length : 0;
|
|
423
|
+
const label = `${comp.name}${snippet && snippet.toLowerCase() !== comp.name.toLowerCase() ? ` (${snippet})` : ''}: ${SPEC_STATE_LABELS[comp.state]}`;
|
|
424
|
+
return (_jsxs("button", { type: "button", class: "os-pin", "data-part": "on-spec-pin", "data-spec-state": comp.state, "data-component-id": comp.id, "data-selected": isSelected ? 'true' : undefined, "aria-label": label, "aria-expanded": isSelected, title: label, style: { left: `${pinLeft}px`, top: `${pinTop}px` }, onPointerEnter: () => setHoveredId(comp.id), onPointerLeave: () => setHoveredId(prev => (prev === comp.id ? null : prev)), onClick: (e) => {
|
|
425
|
+
e.stopPropagation();
|
|
426
|
+
setOpen(false);
|
|
427
|
+
setSelectedPinId(prev => (prev === comp.id ? null : comp.id));
|
|
428
|
+
}, children: [_jsx("span", { class: earnedIds.has(comp.id) ? 'os-paw-earned' : undefined, children: _jsx(Icon, { icon: IconOnSpec, size: "compact" }) }), diffCount > 0 && _jsx("span", { class: "os-pin-count", children: diffCount })] }, comp.id));
|
|
429
|
+
}), selectedPin && popoverStyle && (_jsxs("div", { class: "os-popover", role: "dialog", "aria-label": `On spec: ${selectedPin.comp.name}`, "data-part": "on-spec-popover", "data-component-id": selectedPin.comp.id, style: popoverStyle, children: [errorMsg && _jsx("p", { class: "os-sub", role: "alert", children: errorMsg }), renderRolePrompt(), renderComponentBody(selectedPin.comp, selectedPin.snippet, 'popover')] })), hoverInfo && (_jsxs("div", { class: "os-hover-badge", "data-part": "on-spec-hover-badge", "data-spec-state": hoverInfo.state, style: { left: `${hoverInfo.x}px`, top: `${hoverInfo.y}px` }, children: [_jsx(StateIcon, { state: hoverInfo.state }), _jsx("span", { children: SPEC_STATE_LABELS[hoverInfo.state] })] })), showPill && (_jsxs("button", { type: "button", class: "os-pill", "data-part": "on-spec-pill", "data-side": side, "data-has-drift": hasDrift ? 'true' : undefined, "aria-expanded": open, "aria-label": `On spec: ${summaryText}`, title: "On spec: click to view component verdicts, drift actions and Spec report", onClick: () => {
|
|
430
|
+
const nextOpen = !open;
|
|
431
|
+
setSelectedPinId(null);
|
|
432
|
+
setOpen(nextOpen);
|
|
433
|
+
if (nextOpen)
|
|
434
|
+
setPinsVisible(true);
|
|
435
|
+
}, children: [_jsx("span", { class: pillEarned ? 'os-paw-earned' : undefined, children: _jsx(Icon, { icon: IconOnSpec, size: "compact" }) }), _jsx("span", { children: summaryText })] })), open && (_jsxs("div", { class: "os-panel", role: "dialog", "aria-label": "On spec", "data-part": "on-spec-panel", "data-side": side, children: [_jsxs("div", { class: "os-head", children: [_jsxs("h2", { class: "os-title", children: [_jsx(Icon, { icon: IconOnSpec, size: "content" }), _jsx("span", { children: "On spec" })] }), _jsxs("div", { class: "os-head-actions", children: [_jsx("button", { type: "button", class: `btn-secondary btn-sm btn-icon${checkState === 'done' ? ' os-btn-done' : ''}`, "data-action": "check-now", "data-check-state": checkState, "aria-busy": checkState === 'checking' ? 'true' : undefined, "aria-label": checkState === 'checking' ? 'Checking' : checkState === 'done' ? 'Checked' : 'Re-check', title: checkState === 'checking' ? 'Checking…' : checkState === 'done' ? 'Checked just now' : 'Re-run On spec checks at both widths right now', disabled: busy || checkState === 'checking', onClick: () => void runCheckNow(), children: _jsx("span", { class: checkState === 'checking' ? 'os-spin' : undefined, children: _jsx(Icon, { icon: checkState === 'done' ? IconSuccess : IconReset, size: "compact" }) }) }), _jsx("button", { type: "button", class: "btn-secondary btn-sm btn-icon", "data-action": "toggle-pins", "aria-pressed": pinsVisible, "aria-label": pinsVisible ? 'Hide pins on page' : 'Show pins on page', title: pinsVisible ? 'Hide on-page component pins' : 'Show on-page component pins', onClick: () => {
|
|
436
|
+
setPinsVisible(v => {
|
|
437
|
+
const next = !v;
|
|
438
|
+
if (!next)
|
|
439
|
+
setSelectedPinId(null);
|
|
440
|
+
return next;
|
|
441
|
+
});
|
|
442
|
+
}, children: _jsx(Icon, { icon: pinsVisible ? IconCheck : IconHide, size: "compact" }) }), _jsxs("button", { type: "button", class: "btn-secondary btn-sm btn-with-ico", "data-action": "copy-spec-report", title: "Copy a markdown Spec report of every checked component", onClick: () => void copyReport(), children: [_jsx(Icon, { icon: copied ? IconSuccess : IconCopy, size: "compact" }), _jsx("span", { children: copied ? 'Copied' : 'Copy report' })] }), _jsx("button", { type: "button", class: "btn-ghost btn-sm btn-icon", "data-action": "close-on-spec", "aria-label": "Close On spec", title: "Close On spec panel", onClick: () => setOpen(false), children: _jsx(Icon, { icon: IconClose, size: "compact" }) })] })] }), _jsx("p", { class: "os-summary", "data-part": "on-spec-summary", children: checkState === 'checking'
|
|
443
|
+
? 'Checking components…'
|
|
444
|
+
: checkState === 'done'
|
|
445
|
+
? `${summaryText} · Checked just now · Role: ${profile.role}`
|
|
446
|
+
: components.length === 0
|
|
447
|
+
? `No components checked yet. Save a component rule in Capture or edit a ruled component. · Role: ${profile.role}`
|
|
448
|
+
: `${summaryText} · ${components.every(c => c.state === 'on-spec') ? SPEC_MATCHES_PHRASE : `Widths: ${state.widths.map(w => `${w}px`).join(', ')}`} · Role: ${profile.role}` }), errorMsg && _jsx("p", { class: "os-sub", role: "alert", children: errorMsg }), renderRolePrompt(), components.length > 0 && (_jsx("ul", { class: "os-list", "data-part": "on-spec-list", children: components.map(comp => {
|
|
449
|
+
const pin = pinById.get(comp.id);
|
|
450
|
+
return (_jsx("li", { class: "os-row", "data-part": "on-spec-row", "data-spec-state": comp.state, "data-component-id": comp.id, onPointerEnter: () => { if (pin)
|
|
451
|
+
setHoveredId(comp.id); }, onPointerLeave: () => setHoveredId(prev => (prev === comp.id ? null : prev)), children: renderComponentBody(comp, pin?.snippet ?? '', 'list') }, comp.id));
|
|
452
|
+
}) }))] }))] }));
|
|
453
|
+
}
|
|
454
|
+
/** Mount the calm On spec pill, on-page pins, overview panel, and optional hover badge in its own shadow root. */
|
|
455
|
+
export function mountOnSpec(options) {
|
|
456
|
+
const doc = options.doc ?? document;
|
|
457
|
+
loadFonts(doc);
|
|
458
|
+
// One On spec host per document
|
|
459
|
+
doc.querySelectorAll(ON_SPEC_TAG).forEach(el => el.remove());
|
|
460
|
+
const host = doc.createElement(ON_SPEC_TAG);
|
|
461
|
+
host.setAttribute(LUCI_UI_ATTRIBUTE, '');
|
|
462
|
+
const root = host.attachShadow({ mode: 'open' });
|
|
463
|
+
const style = doc.createElement('style');
|
|
464
|
+
style.textContent = `${UI_CSS}\n${ON_SPEC_CSS}`;
|
|
465
|
+
const mountEl = doc.createElement('div');
|
|
466
|
+
root.append(style, mountEl);
|
|
467
|
+
doc.documentElement.appendChild(host);
|
|
468
|
+
let snap = {
|
|
469
|
+
data: { ...options.initial },
|
|
470
|
+
open: false,
|
|
471
|
+
revealReq: null
|
|
472
|
+
};
|
|
473
|
+
let revealSeq = 0;
|
|
474
|
+
const listeners = new Set();
|
|
475
|
+
const emit = () => { for (const fn of listeners)
|
|
476
|
+
fn(); };
|
|
477
|
+
const store = {
|
|
478
|
+
get: () => snap,
|
|
479
|
+
setOpen(v) {
|
|
480
|
+
if (snap.open === v)
|
|
481
|
+
return;
|
|
482
|
+
snap = { ...snap, open: v };
|
|
483
|
+
emit();
|
|
484
|
+
},
|
|
485
|
+
subscribe(fn) {
|
|
486
|
+
listeners.add(fn);
|
|
487
|
+
return () => { listeners.delete(fn); };
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
// Mount Preact root ONCE; all subsequent updates flow through React/Preact state via `store`
|
|
491
|
+
render(_jsx(OnSpecView, { doc: doc, store: store, callbacks: options.callbacks }), mountEl);
|
|
492
|
+
return {
|
|
493
|
+
host,
|
|
494
|
+
update(next) {
|
|
495
|
+
snap = { ...snap, data: { ...snap.data, ...next } };
|
|
496
|
+
emit();
|
|
497
|
+
},
|
|
498
|
+
revealPins(opts = {}) {
|
|
499
|
+
revealSeq += 1;
|
|
500
|
+
snap = { ...snap, revealReq: { seq: revealSeq, ...opts } };
|
|
501
|
+
emit();
|
|
502
|
+
},
|
|
503
|
+
open() {
|
|
504
|
+
store.setOpen(true);
|
|
505
|
+
},
|
|
506
|
+
close() {
|
|
507
|
+
store.setOpen(false);
|
|
508
|
+
},
|
|
509
|
+
destroy() {
|
|
510
|
+
listeners.clear();
|
|
511
|
+
render(null, mountEl);
|
|
512
|
+
host.remove();
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
//# sourceMappingURL=onSpec.js.map
|