@luci-dev/toolbar 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 +22 -12
- package/dist/devToolbar.d.ts +3 -3
- package/dist/devToolbar.d.ts.map +1 -1
- package/dist/devToolbar.js +299 -11
- package/dist/devToolbar.js.map +1 -1
- package/dist/luci-toolbar.js +8008 -1824
- package/package.json +5 -5
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -4,28 +4,31 @@ Luci inside your own app while you develop it: leave notes on the running app fo
|
|
|
4
4
|
|
|
5
5
|
## Set up
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @luci-dev/cli
|
|
9
|
+
luci init
|
|
10
|
+
luci serve
|
|
11
|
+
```
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
1. Install Luci globally once: `npm install -g @luci-dev/cli` (requires Node 18 or later).
|
|
14
|
+
2. In your app's folder: `luci init` (once). It asks **Add Luci's dev toolbar to your app?**; press Enter (or pass `luci init --toolbar`).
|
|
15
|
+
3. `luci serve`, then open your app on this machine. Luci's button is in the bottom corner.
|
|
11
16
|
|
|
12
|
-
|
|
17
|
+
Missed it, or said no? `luci serve` asks again while the toolbar is not in the app, and `luci toolbar` adds or updates it any time. Or ask your agent to add Luci's dev toolbar: the project's agent files tell it to run `luci toolbar`.
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
<script src="http://127.0.0.1:4545/toolbar.js"></script>
|
|
16
|
-
```
|
|
19
|
+
What it adds: a few lines between `luci:toolbar` comments, before `</body>` of the app's root file (Next.js `app/layout` or `pages/_document`, SvelteKit `src/app.html`, an Astro layout, or `index.html` for Vite, Create React App, Angular and plain sites). The loader only runs on `localhost` (Next.js: in development), so a deployed site is unchanged and nothing is installed. `luci toolbar remove` takes it out again; `luci toolbar --dry-run` shows what it would add.
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
4. Optional: connect your agent to `luci-mcp` (for Claude Code, from the project folder: `claude mcp add luci-mcp -- npx -y @luci-dev/mcp@latest`), so it can read the notes and saved captures itself. Copying the prompt works without it.
|
|
19
22
|
|
|
20
|
-
**Updating:** the toolbar comes from the Luci you have installed. After updating Luci (`npm install -g @luci-dev/cli@latest`, or nothing with `npx @luci-dev/cli@latest`), stop `luci serve`, start it again and reload your app.
|
|
23
|
+
**Updating:** the toolbar comes from the Luci you have installed. After updating Luci (`npm install -g @luci-dev/cli@latest`, or nothing with `npx @luci-dev/cli@latest`), run `luci toolbar` if the loader changed, stop `luci serve`, start it again and reload your app.
|
|
21
24
|
|
|
22
|
-
`luci serve` listens on 127.0.0.1 only and answers pages on this machine only.
|
|
25
|
+
`luci serve` listens on 127.0.0.1 only and answers pages on this machine only. When `luci serve` is not running, the loader shows a small **"Luci isn't running"** badge with **Copy fix for my agent** and **Retry** (which loads the toolbar without reloading the page once `luci serve` starts).
|
|
23
26
|
|
|
24
27
|
## Feedback
|
|
25
28
|
|
|
26
29
|
- **Annotate:** click an element, write what should change, choose the intent (fix, change, question, approve) and priority. Hover shows the element and its component (React, Vue or Svelte). Esc stops.
|
|
27
30
|
- **Text:** select words on the page (outside Annotate) and press **Add feedback**.
|
|
28
|
-
- **Markers:** each note is a numbered marker on
|
|
31
|
+
- **Markers:** each note is a numbered marker on the spot you clicked: filled when new, outlined once copied, green with ✓ when you marked it done. Click one to **Mark done** (or **Reopen**), edit it (text, intent and priority) or delete it.
|
|
29
32
|
- **Copy prompt:** the notes as one prompt, grouped by page with stable IDs (`P2-A3`) and a request to report every ID. It copies the new notes (**Copy prompt (2 new)**), or every note not done yet when all were copied before (**Copy prompt (all 4)**); **▾** chooses. Paste it to your agent and read its report.
|
|
30
33
|
- **You decide what is done:** no agent changes your notes. After checking the agent's work, mark notes done one by one, or press **Mark all copied as done** in Notes. Over MCP, the agent can only read the notes (`list_feedback`, `get_feedback_prompt`).
|
|
31
34
|
- **Watch mode:** ask your agent to "watch for my feedback". It calls `watch_feedback`, which waits until you add notes, gives it only the new ones as one prompt, and is called again for the next batch. Your notes stay New until you copy or mark them.
|
|
@@ -33,8 +36,15 @@ What it adds: a few lines between `luci:toolbar` comments, before `</body>` of t
|
|
|
33
36
|
- **Pause:** freezes the page's animations, transitions and videos on the current frame.
|
|
34
37
|
- **Settings:** marker color, prompt detail (compact: selector and text; standard: + source file and components; detailed: + computed styles), and an optional webhook that receives the prompt and the items when you press **Send to webhook**.
|
|
35
38
|
|
|
39
|
+
- **After-Edit Blink:** when your agent's edit hot-reloads and changes an element you noted (or one Design Check is watching), it pulses once with a short "Updated" label. **Blink before/after** flips between the old and new look on the live page, and **Jump to** scrolls to a change that is off-screen. With reduced motion, it shows a still outline instead. Turn it off in Dev Settings.
|
|
40
|
+
- **Builder (Team Feedback):** in **Notes**, the **Builder** tab takes reviews your team copied from the Chrome extension's Team Feedback tab (paste one or several). It merges duplicate notes, filters by role, places each note on its element (and asks you to pick when the match is not clear), checks notes against your saved design files, and shows the exact text your agent will get, with roles instead of names, before you add them as notes.
|
|
41
|
+
|
|
36
42
|
With React, Vue 3 or Svelte 4/5 in development mode, each note records the components around the element (`App > Pricing > PlanCard`) and its source file (with the JSX line through source maps in React, the `.svelte` file and line from `__svelte_meta` in Svelte, and the `.vue` SFC file from `__vueParentComponent` in Vue 3). In a production build, notes keep the selector and text.
|
|
37
43
|
|
|
44
|
+
## In Storybook
|
|
45
|
+
|
|
46
|
+
`luci toolbar --storybook` adds the toolbar to `.storybook/preview-body.html` (Luci finds it on its own in a repo with Storybook and no app). Notes and design checks are kept per story (`/iframe.html?id=<story>`). `luci capture crawl <storybook-url> --storybook` captures every story.
|
|
47
|
+
|
|
38
48
|
## On a phone
|
|
39
49
|
|
|
40
50
|
Open your app on a phone (or a narrow window, under 640 px) and the toolbar adapts:
|
|
@@ -73,7 +83,7 @@ Try layout changes on the live page, then copy them as one prompt for your agent
|
|
|
73
83
|
|
|
74
84
|
**Automatic check** (v0.4): after a check, the dev toolbar checks the built component again whenever the page changes (your agent's edit reloads it), says what changed (`Checked again at 14:02: 1 difference (was 3).`) and keeps checking after a reload of the tab. Each run goes to the project, where your agent reads it with `get_design_checks`, so it can fix, let the page reload, and see whether the component now matches. **Check again when the page changes** switches it.
|
|
75
85
|
|
|
76
|
-
**DESIGN.md for Google Stitch
|
|
86
|
+
**DESIGN.md for Google Stitch** (the default **File** since 0.6.0): copy, download and export captures in the open DESIGN.md format (tokens, then prose filled in from measured values); **Save to project** keeps Luci's tables. `luci capture baseline --stitch` writes your project's own DESIGN.md.
|
|
77
87
|
|
|
78
88
|
**Use my tokens**, **Compare** and **Image** (v0.4): under any capture, **Use my tokens** rewrites it onto your project's own tokens (read from its stylesheets through `luci serve`) or tokens you paste; in the basket, tick two items to **Compare** them; the Colour tool's **Image** estimates a palette from a screenshot. Your project's own typography, colors and spacing are also in `.luci/design/project.system.*.design.md` (the design baseline, `luci capture baseline`).
|
|
79
89
|
|
package/dist/devToolbar.d.ts
CHANGED
|
@@ -14,15 +14,15 @@ export type Mode = 'feedback' | 'layout' | 'capture';
|
|
|
14
14
|
export declare const MODES: readonly [{
|
|
15
15
|
readonly id: 'feedback';
|
|
16
16
|
readonly label: 'Feedback';
|
|
17
|
-
readonly title: 'Feedback:
|
|
17
|
+
readonly title: 'Feedback: click elements or highlight text to pin notes with source lines for your agent';
|
|
18
18
|
}, {
|
|
19
19
|
readonly id: 'layout';
|
|
20
20
|
readonly label: 'Layout';
|
|
21
|
-
readonly title: 'Layout: resize, move
|
|
21
|
+
readonly title: 'Layout: resize, move, insert parts or sketch a new page, then send the plan to your agent';
|
|
22
22
|
}, {
|
|
23
23
|
readonly id: 'capture';
|
|
24
24
|
readonly label: 'Capture';
|
|
25
|
-
readonly title: 'Capture:
|
|
25
|
+
readonly title: 'Capture: measure components, text, colours, spacing or check builds against saved rules';
|
|
26
26
|
}];
|
|
27
27
|
export interface DevToolbarOptions {
|
|
28
28
|
/** The `luci serve` address. Default: the one the script was served from, else http://127.0.0.1:4545. */
|
package/dist/devToolbar.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devToolbar.d.ts","sourceRoot":"","sources":["../src/devToolbar.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"devToolbar.d.ts","sourceRoot":"","sources":["../src/devToolbar.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAGU,KAAK,WAAW,EAAE,KAAK,SAAS,EAEhD,MAAM,mBAAmB,CAAC;AAe3B,OAAO,EASL,KAAK,eAAe,EAEpB,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,cAAc,0BAA0B,CAAC;AACtD,eAAO,MAAM,YAAY,kBAAkB,CAAC;AAC5C,MAAM,MAAM,IAAI,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AACrD,2CAA2C;AAC3C,eAAO,MAAM,KAAK;aACd,EAAE,EAAE,UAAU;aAAE,KAAK,EAAE,UAAU;aAAE,KAAK,EAAE,0FAA0F;;aACpI,EAAE,EAAE,QAAQ;aAAE,KAAK,EAAE,QAAQ;aAAE,KAAK,EAAE,2FAA2F;;aACjI,EAAE,EAAE,SAAS;aAAE,KAAK,EAAE,SAAS;aAAE,KAAK,EAAE,yFAAyF;EAC3H,CAAC;AAEX,MAAM,WAAW,iBAAiB;IAChC,yGAAyG;IACzG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,oGAAoG;IACpG,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,mFAAmF;IACnF,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,uEAAuE;IACvE,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAClC,IAAI,IAAI,IAAI,CAAC;IACb,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,OAAO,IAAI,IAAI,CAAC;CACjB;AAoBD,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,GAAE,MAAoB,GAAG,WAAW,CAYvF;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAOxI;AAED,eAAO,MAAM,cAAc,oBAAoB,CAAC;AA0BhD,2CAA2C;AAC3C,wBAAsB,eAAe,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAkoBhG"}
|
package/dist/devToolbar.js
CHANGED
|
@@ -5,17 +5,17 @@
|
|
|
5
5
|
* agent reads them through luci-mcp; without it, feedback stays in this browser and the bar says
|
|
6
6
|
* how to connect.
|
|
7
7
|
*/
|
|
8
|
-
import { LUCI_UI_ATTRIBUTE, TOOLBAR_REPLACE_EVENT, UI_PREFS_EVENT, mountToolbar, readUiPrefs, writeUiPrefs } from '@luci-dev/capture';
|
|
9
|
-
import { basketItemSchema } from '@luci-dev/format/capture';
|
|
8
|
+
import { LUCI_UI_ATTRIBUTE, TOOLBAR_REPLACE_EVENT, UI_PREFS_EVENT, captureElementRuleMarkdown, mountOnSpec, mountToolbar, mountUpdateBanner, readUiPrefs, startSpecWatcher, writeUiPrefs } from '@luci-dev/capture';
|
|
9
|
+
import { DEFAULT_SPEC_WIDTHS, basketItemSchema, captureFileName, readComponentFile } from '@luci-dev/format/capture';
|
|
10
10
|
import { ANIMATIONS_CSS, COPY, TOKENS_CSS, mascotSvg } from '@luci-dev/ui';
|
|
11
11
|
import { DEFAULT_FEEDBACK_SETTINGS, bridgeBackend, bridgeReachable, browserBackend, describeTarget, mountFeedback, mountLayout } from '@luci-dev/feedback';
|
|
12
12
|
export const DEFAULT_BRIDGE = 'http://127.0.0.1:4545';
|
|
13
13
|
export const LAUNCHER_TAG = 'luci-launcher';
|
|
14
14
|
/** The modes, as the switch shows them. */
|
|
15
15
|
export const MODES = [
|
|
16
|
-
{ id: 'feedback', label: 'Feedback', title: 'Feedback:
|
|
17
|
-
{ id: 'layout', label: 'Layout', title: 'Layout: resize, move
|
|
18
|
-
{ id: 'capture', label: 'Capture', title: 'Capture:
|
|
16
|
+
{ id: 'feedback', label: 'Feedback', title: 'Feedback: click elements or highlight text to pin notes with source lines for your agent' },
|
|
17
|
+
{ id: 'layout', label: 'Layout', title: 'Layout: resize, move, insert parts or sketch a new page, then send the plan to your agent' },
|
|
18
|
+
{ id: 'capture', label: 'Capture', title: 'Capture: measure components, text, colours, spacing or check builds against saved rules' }
|
|
19
19
|
];
|
|
20
20
|
const KEYS = { capture: 'luci.capture.settings', feedback: 'luci.feedback.settings', basket: 'luci.basket', items: 'luci.feedback', mode: 'luci.mode', myTokens: 'luci.myTokens' };
|
|
21
21
|
/** localStorage, or memory when the page cannot use it (a sandboxed frame, privacy settings). */
|
|
@@ -78,7 +78,7 @@ function connectingPill(doc, place) {
|
|
|
78
78
|
const host = doc.createElement(CONNECTING_TAG);
|
|
79
79
|
host.setAttribute(LUCI_UI_ATTRIBUTE, '');
|
|
80
80
|
const root = host.attachShadow({ mode: 'open' });
|
|
81
|
-
// The Charcoal pill (brand
|
|
81
|
+
// The Charcoal pill (the brand kit, On-page toolbar), with a ginger ring turning
|
|
82
82
|
root.innerHTML = `<style>${TOKENS_CSS}
|
|
83
83
|
div{position:fixed;${cornerCss(place, 40)};z-index:2147483647;display:flex;gap:8px;align-items:center;padding:8px 16px 8px 12px;border-radius:var(--luci-radius-full);
|
|
84
84
|
background:var(--luci-color-bar);color:var(--luci-color-bar-ink);font:500 var(--luci-type-small-size)/var(--luci-type-small-line) var(--luci-font-body);box-shadow:var(--luci-shadow-edge),var(--luci-shadow-float)}
|
|
@@ -126,11 +126,232 @@ export async function mountDevToolbar(options = {}) {
|
|
|
126
126
|
connectNote = noteFor(h);
|
|
127
127
|
if (!(h.ok && h.initialized))
|
|
128
128
|
return connectNote;
|
|
129
|
+
const offlineItems = await backend.list();
|
|
129
130
|
connected = true;
|
|
130
|
-
|
|
131
|
+
health = h;
|
|
132
|
+
const bridgeB = bridgeBackend(bridge);
|
|
133
|
+
if (offlineItems.length > 0) {
|
|
134
|
+
try {
|
|
135
|
+
const existingBridge = await bridgeB.list();
|
|
136
|
+
const existingKeys = new Set(existingBridge.map(b => `${b.target?.selector ?? ''}::${b.comment}`));
|
|
137
|
+
for (const item of offlineItems) {
|
|
138
|
+
const key = `${item.target?.selector ?? ''}::${item.comment}`;
|
|
139
|
+
if (!existingKeys.has(key)) {
|
|
140
|
+
await bridgeB.add({
|
|
141
|
+
page: item.page,
|
|
142
|
+
target: item.target,
|
|
143
|
+
comment: item.comment,
|
|
144
|
+
intent: item.intent,
|
|
145
|
+
priority: item.priority,
|
|
146
|
+
...(item.layout ? { layout: item.layout } : {}),
|
|
147
|
+
...(item.wireframe ? { wireframe: item.wireframe } : {}),
|
|
148
|
+
...(item.check ? { check: item.check } : {}),
|
|
149
|
+
...(item.reviewerRoles?.length ? { reviewerRoles: item.reviewerRoles } : {})
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
await backend.clear('all');
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
console.warn('Luci: failed to migrate offline notes to bridge:', err);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
backend = bridgeB;
|
|
160
|
+
startOnSpec();
|
|
161
|
+
startUpdateBanner();
|
|
131
162
|
show(mode);
|
|
132
163
|
return null;
|
|
133
164
|
};
|
|
165
|
+
let specWatcher = null;
|
|
166
|
+
let onSpecUi = null;
|
|
167
|
+
let updateBanner = null;
|
|
168
|
+
let onSpecState = {
|
|
169
|
+
version: 1,
|
|
170
|
+
taskKey: 'default',
|
|
171
|
+
updatedAt: new Date().toISOString(),
|
|
172
|
+
widths: [...DEFAULT_SPEC_WIDTHS],
|
|
173
|
+
components: []
|
|
174
|
+
};
|
|
175
|
+
let onSpecSettings = { blockDone: true, hoverBadge: false };
|
|
176
|
+
let onSpecProfile = { role: 'Designer', saved: false };
|
|
177
|
+
const buildUpdatesBridge = () => {
|
|
178
|
+
if (!connected || !backend.getUpdates || !backend.checkUpdates || !backend.setUpdateSettings || !backend.applyUpdate) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
const b = backend;
|
|
182
|
+
return {
|
|
183
|
+
getStatus: async () => {
|
|
184
|
+
const s = await b.getUpdates();
|
|
185
|
+
updateBanner?.update(s);
|
|
186
|
+
return s;
|
|
187
|
+
},
|
|
188
|
+
checkNow: async () => {
|
|
189
|
+
const s = await b.checkUpdates();
|
|
190
|
+
updateBanner?.update(s);
|
|
191
|
+
return s;
|
|
192
|
+
},
|
|
193
|
+
setSettings: async (patch) => {
|
|
194
|
+
const s = await b.setUpdateSettings(patch);
|
|
195
|
+
updateBanner?.update(s);
|
|
196
|
+
return s;
|
|
197
|
+
},
|
|
198
|
+
applyUpdate: async () => b.applyUpdate()
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
const stopUpdateBanner = () => {
|
|
202
|
+
updateBanner?.destroy();
|
|
203
|
+
updateBanner = null;
|
|
204
|
+
};
|
|
205
|
+
const startUpdateBanner = () => {
|
|
206
|
+
stopUpdateBanner();
|
|
207
|
+
const updatesBridge = buildUpdatesBridge();
|
|
208
|
+
if (!updatesBridge)
|
|
209
|
+
return;
|
|
210
|
+
const banner = mountUpdateBanner({ doc, bridge: updatesBridge });
|
|
211
|
+
updateBanner = banner;
|
|
212
|
+
void updatesBridge.getStatus().then(status => {
|
|
213
|
+
if (updateBanner === banner)
|
|
214
|
+
banner.update(status);
|
|
215
|
+
}).catch(() => undefined);
|
|
216
|
+
};
|
|
217
|
+
const stopOnSpec = () => {
|
|
218
|
+
specWatcher?.stop();
|
|
219
|
+
specWatcher = null;
|
|
220
|
+
onSpecUi?.destroy();
|
|
221
|
+
onSpecUi = null;
|
|
222
|
+
};
|
|
223
|
+
const loadRuleFiles = async () => {
|
|
224
|
+
if (!backend.listCaptures || !backend.readCapture)
|
|
225
|
+
return [];
|
|
226
|
+
const listed = await backend.listCaptures();
|
|
227
|
+
const componentFiles = listed.filter(f => f.scope === 'component');
|
|
228
|
+
const out = [];
|
|
229
|
+
for (const f of componentFiles) {
|
|
230
|
+
try {
|
|
231
|
+
const markdown = await backend.readCapture(f.file);
|
|
232
|
+
out.push({ file: f.file, name: f.name || f.file, type: f.type || 'component', markdown });
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
// skip unreadable rule file
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return out;
|
|
239
|
+
};
|
|
240
|
+
const startOnSpec = () => {
|
|
241
|
+
stopOnSpec();
|
|
242
|
+
if (!connected || !backend.getSpec || !backend.saveSpecVerdicts)
|
|
243
|
+
return;
|
|
244
|
+
const watcher = startSpecWatcher({
|
|
245
|
+
doc,
|
|
246
|
+
loadRules: loadRuleFiles,
|
|
247
|
+
existingVerdicts: () => onSpecState.components,
|
|
248
|
+
onVerdicts: (components, widths, meta) => {
|
|
249
|
+
void backend.saveSpecVerdicts?.({ components, widths, ...(meta?.replace ? { replace: true } : {}) }).then(snap => {
|
|
250
|
+
onSpecState = snap.state;
|
|
251
|
+
onSpecSettings = snap.settings;
|
|
252
|
+
onSpecUi?.update({
|
|
253
|
+
state: snap.state,
|
|
254
|
+
rulesMeta: snap.rulesMeta,
|
|
255
|
+
report: snap.report,
|
|
256
|
+
settings: snap.settings
|
|
257
|
+
});
|
|
258
|
+
}).catch(() => undefined);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
specWatcher = watcher;
|
|
262
|
+
const ui = mountOnSpec({
|
|
263
|
+
doc,
|
|
264
|
+
initial: {
|
|
265
|
+
state: onSpecState,
|
|
266
|
+
rulesMeta: {},
|
|
267
|
+
report: '',
|
|
268
|
+
settings: onSpecSettings,
|
|
269
|
+
profile: onSpecProfile
|
|
270
|
+
},
|
|
271
|
+
callbacks: {
|
|
272
|
+
onExcuse: async ({ componentId, reason, role }) => {
|
|
273
|
+
if (!backend.excuseSpec)
|
|
274
|
+
return;
|
|
275
|
+
const snap = await backend.excuseSpec({ componentId, reason, role });
|
|
276
|
+
onSpecState = snap.state;
|
|
277
|
+
ui.update({ state: snap.state, rulesMeta: snap.rulesMeta, report: snap.report, settings: snap.settings });
|
|
278
|
+
},
|
|
279
|
+
onUpdateRule: async ({ componentId, ruleFile, selector, role }) => {
|
|
280
|
+
if (!backend.updateSpecRule)
|
|
281
|
+
return;
|
|
282
|
+
const el = doc.querySelector(selector);
|
|
283
|
+
if (!el)
|
|
284
|
+
throw new Error(`Could not find ${selector} on this page.`);
|
|
285
|
+
const markdown = await captureElementRuleMarkdown(el, doc);
|
|
286
|
+
if (!markdown)
|
|
287
|
+
throw new Error(`Could not capture ${selector} to update its rule.`);
|
|
288
|
+
const snap = await backend.updateSpecRule({ componentId, ruleFile, markdown, role });
|
|
289
|
+
onSpecState = snap.state;
|
|
290
|
+
ui.update({ state: snap.state, rulesMeta: snap.rulesMeta, report: snap.report, settings: snap.settings });
|
|
291
|
+
},
|
|
292
|
+
onSendBack: async ({ componentId, note, role }) => {
|
|
293
|
+
if (!backend.sendBackSpec)
|
|
294
|
+
return;
|
|
295
|
+
const snap = await backend.sendBackSpec({ componentId, ...(note ? { note } : {}), role });
|
|
296
|
+
onSpecState = snap.state;
|
|
297
|
+
ui.update({ state: snap.state, rulesMeta: snap.rulesMeta, report: snap.report, settings: snap.settings });
|
|
298
|
+
},
|
|
299
|
+
onMarkReviewed: async ({ ruleFile, role }) => {
|
|
300
|
+
if (!backend.markRuleReviewed)
|
|
301
|
+
return;
|
|
302
|
+
const res = await backend.markRuleReviewed({ ruleFile, role });
|
|
303
|
+
ui.update({ rulesMeta: res.rulesMeta, report: res.report });
|
|
304
|
+
},
|
|
305
|
+
onAddRule: async ({ component }) => {
|
|
306
|
+
if (!backend.saveCapture)
|
|
307
|
+
return;
|
|
308
|
+
const el = doc.querySelector(component.selector);
|
|
309
|
+
if (!el)
|
|
310
|
+
throw new Error(`Could not find ${component.selector} on this page.`);
|
|
311
|
+
const markdown = await captureElementRuleMarkdown(el, doc);
|
|
312
|
+
if (!markdown)
|
|
313
|
+
throw new Error(`Could not capture ${component.selector}.`);
|
|
314
|
+
const parsed = readComponentFile(markdown);
|
|
315
|
+
if (!parsed.ok)
|
|
316
|
+
throw new Error(parsed.error);
|
|
317
|
+
const fileName = captureFileName(parsed.value.meta);
|
|
318
|
+
const saved = await backend.saveCapture(fileName, markdown);
|
|
319
|
+
watcher.bindRule(component.selector, saved.path);
|
|
320
|
+
await watcher.run({ forceAll: true });
|
|
321
|
+
},
|
|
322
|
+
onCheckNow: async () => {
|
|
323
|
+
await watcher.run({ forceAll: true });
|
|
324
|
+
},
|
|
325
|
+
onSaveRole: async (role) => {
|
|
326
|
+
if (!backend.setUserRole)
|
|
327
|
+
return;
|
|
328
|
+
const saved = await backend.setUserRole(role);
|
|
329
|
+
onSpecProfile = saved;
|
|
330
|
+
ui.update({ profile: saved });
|
|
331
|
+
},
|
|
332
|
+
verdictForElement: (el) => watcher.verdictForElement(el)
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
onSpecUi = ui;
|
|
336
|
+
void Promise.all([
|
|
337
|
+
backend.getSpec().catch(() => null),
|
|
338
|
+
backend.getUserProfile?.().catch(() => null) ?? Promise.resolve(null)
|
|
339
|
+
]).then(([snap, prof]) => {
|
|
340
|
+
if (onSpecUi !== ui)
|
|
341
|
+
return;
|
|
342
|
+
if (snap) {
|
|
343
|
+
onSpecState = snap.state;
|
|
344
|
+
onSpecSettings = snap.settings;
|
|
345
|
+
}
|
|
346
|
+
if (prof)
|
|
347
|
+
onSpecProfile = prof;
|
|
348
|
+
ui.update({
|
|
349
|
+
...(snap ? { state: snap.state, rulesMeta: snap.rulesMeta, report: snap.report, settings: snap.settings } : {}),
|
|
350
|
+
...(prof ? { profile: prof } : {})
|
|
351
|
+
});
|
|
352
|
+
void watcher.run();
|
|
353
|
+
});
|
|
354
|
+
};
|
|
134
355
|
let session = null;
|
|
135
356
|
try {
|
|
136
357
|
session = win.sessionStorage;
|
|
@@ -145,7 +366,7 @@ export async function mountDevToolbar(options = {}) {
|
|
|
145
366
|
launcher = doc.createElement(LAUNCHER_TAG);
|
|
146
367
|
launcher.setAttribute(LUCI_UI_ATTRIBUTE, '');
|
|
147
368
|
const root = launcher.attachShadow({ mode: 'open' });
|
|
148
|
-
// Luci's head in a Ginger circle: the 48 px menu button (brand
|
|
369
|
+
// Luci's head in a Ginger circle: the 48 px menu button (the brand kit, On-page toolbar), in the
|
|
149
370
|
// corner of the bar's place, where the bar grows from
|
|
150
371
|
root.innerHTML = `<style>${TOKENS_CSS}${ANIMATIONS_CSS}
|
|
151
372
|
button{position:fixed;${cornerCss(place, 48)};z-index:2147483647;display:flex;align-items:center;justify-content:center;width:48px;height:48px;padding:0;border:0;
|
|
@@ -235,7 +456,7 @@ export async function mountDevToolbar(options = {}) {
|
|
|
235
456
|
catch {
|
|
236
457
|
return false;
|
|
237
458
|
} };
|
|
238
|
-
/** The bar grows out of the launcher's corner (opacity and transform only, brand
|
|
459
|
+
/** The bar grows out of the launcher's corner (opacity and transform only, the brand kit's motion rules). */
|
|
239
460
|
const grow = (host) => {
|
|
240
461
|
const bar = host.shadowRoot?.querySelector('.bar');
|
|
241
462
|
if (!bar || reducedMotion() || typeof bar.animate !== 'function')
|
|
@@ -408,6 +629,35 @@ export async function mountDevToolbar(options = {}) {
|
|
|
408
629
|
const projectInfo = {
|
|
409
630
|
get: async () => health.project ? { project: health.project, name: health.project.split(/[\\/]/).filter(Boolean).pop(), url: bridge } : null
|
|
410
631
|
};
|
|
632
|
+
const onSpecSettingsBridge = connected && backend.getSpecSettings && backend.setSpecSettings && backend.getUserProfile && backend.setUserRole
|
|
633
|
+
? {
|
|
634
|
+
getSettings: async () => {
|
|
635
|
+
const s = await backend.getSpecSettings();
|
|
636
|
+
onSpecSettings = { blockDone: s.blockDone, hoverBadge: s.hoverBadge };
|
|
637
|
+
onSpecUi?.update({ settings: onSpecSettings });
|
|
638
|
+
return onSpecSettings;
|
|
639
|
+
},
|
|
640
|
+
setSettings: async (patch) => {
|
|
641
|
+
const s = await backend.setSpecSettings(patch);
|
|
642
|
+
onSpecSettings = { blockDone: s.blockDone, hoverBadge: s.hoverBadge };
|
|
643
|
+
onSpecUi?.update({ settings: onSpecSettings });
|
|
644
|
+
return onSpecSettings;
|
|
645
|
+
},
|
|
646
|
+
getProfile: async () => {
|
|
647
|
+
const p = await backend.getUserProfile();
|
|
648
|
+
onSpecProfile = p;
|
|
649
|
+
onSpecUi?.update({ profile: p });
|
|
650
|
+
return p;
|
|
651
|
+
},
|
|
652
|
+
setRole: async (role) => {
|
|
653
|
+
const p = await backend.setUserRole(role);
|
|
654
|
+
onSpecProfile = p;
|
|
655
|
+
onSpecUi?.update({ profile: p });
|
|
656
|
+
return p;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
: undefined;
|
|
660
|
+
const updatesBridge = buildUpdatesBridge();
|
|
411
661
|
if (mode === 'feedback') {
|
|
412
662
|
current = mountFeedback({
|
|
413
663
|
doc,
|
|
@@ -417,6 +667,9 @@ export async function mountDevToolbar(options = {}) {
|
|
|
417
667
|
onSettingsChange: s => storage.setItem(KEYS.feedback, JSON.stringify(s)),
|
|
418
668
|
modes: modeSwitch(),
|
|
419
669
|
projectInfo,
|
|
670
|
+
...(onSpecSettingsBridge ? { onSpecSettings: onSpecSettingsBridge } : {}),
|
|
671
|
+
...(updatesBridge ? { updates: updatesBridge } : {}),
|
|
672
|
+
...(health.lastModifiedAt ? { projectLastModifiedAt: health.lastModifiedAt } : {}),
|
|
420
673
|
store: storage,
|
|
421
674
|
onClose: () => { current = null; showLauncher(); }
|
|
422
675
|
});
|
|
@@ -428,6 +681,8 @@ export async function mountDevToolbar(options = {}) {
|
|
|
428
681
|
modes: modeSwitch(),
|
|
429
682
|
...(connected ? {} : { connectNote }),
|
|
430
683
|
projectInfo,
|
|
684
|
+
...(onSpecSettingsBridge ? { onSpecSettings: onSpecSettingsBridge } : {}),
|
|
685
|
+
...(updatesBridge ? { updates: updatesBridge } : {}),
|
|
431
686
|
store: storage,
|
|
432
687
|
onClose: () => { current = null; showLauncher(); }
|
|
433
688
|
});
|
|
@@ -440,14 +695,42 @@ export async function mountDevToolbar(options = {}) {
|
|
|
440
695
|
basket: storageBasket(storage),
|
|
441
696
|
modes: modeSwitch(),
|
|
442
697
|
store: storage,
|
|
443
|
-
...(
|
|
698
|
+
...(onSpecSettingsBridge ? { onSpecSettings: onSpecSettingsBridge } : {}),
|
|
699
|
+
...(updatesBridge ? { updates: updatesBridge } : {}),
|
|
700
|
+
...(backend.saveCapture ? {
|
|
701
|
+
saveToProject: async (fileName, markdown) => {
|
|
702
|
+
const saved = await backend.saveCapture(fileName, markdown);
|
|
703
|
+
void specWatcher?.run({ forceAll: true }).then(() => {
|
|
704
|
+
if (!fileName.includes('.collection.') && !fileName.includes('.system.')) {
|
|
705
|
+
onSpecUi?.revealPins();
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
return saved;
|
|
709
|
+
}
|
|
710
|
+
} : {}),
|
|
711
|
+
...(backend.deleteCapture ? {
|
|
712
|
+
unsaveFromProject: async (fileName) => {
|
|
713
|
+
const removed = await backend.deleteCapture(fileName);
|
|
714
|
+
void specWatcher?.run({ forceAll: true });
|
|
715
|
+
return removed;
|
|
716
|
+
}
|
|
717
|
+
} : {}),
|
|
718
|
+
onViewOnSpec: (selector) => {
|
|
719
|
+
onSpecUi?.revealPins({ ...(selector ? { selector } : {}), openPopover: true });
|
|
720
|
+
},
|
|
444
721
|
projectInfo,
|
|
445
722
|
// Design check (v0.3): the project's design files, and each difference as a feedback note
|
|
446
723
|
...(backend.listCaptures && backend.readCapture ? { designs: { list: backend.listCaptures, read: backend.readCapture } } : {}),
|
|
447
724
|
addCheckNotes: (el, notes) => addCheckNotes(backend, doc, el, notes),
|
|
448
725
|
// Automatic design check (v0.4): check again when the page changes; each run goes to the project for the agent
|
|
449
726
|
autoCheck: true,
|
|
450
|
-
...(backend.saveCheck ? {
|
|
727
|
+
...(backend.saveCheck ? {
|
|
728
|
+
onCheckRun: (run) => {
|
|
729
|
+
specWatcher?.bindRule(run.selector, run.design);
|
|
730
|
+
void specWatcher?.run();
|
|
731
|
+
return backend.saveCheck(run).catch(() => undefined);
|
|
732
|
+
}
|
|
733
|
+
} : {}),
|
|
451
734
|
// "Use my tokens" (v0.4): the project's own tokens through luci serve, or tokens pasted in this browser
|
|
452
735
|
myTokens: {
|
|
453
736
|
...(backend.projectTokens ? { project: backend.projectTokens } : {}),
|
|
@@ -459,6 +742,7 @@ export async function mountDevToolbar(options = {}) {
|
|
|
459
742
|
...(backend.saveCapture && backend.proposeRule ? {
|
|
460
743
|
makeRule: async (fileName, markdown) => {
|
|
461
744
|
await backend.saveCapture(fileName, markdown);
|
|
745
|
+
void specWatcher?.run({ forceAll: true });
|
|
462
746
|
return backend.proposeRule(fileName);
|
|
463
747
|
}
|
|
464
748
|
} : {}),
|
|
@@ -473,12 +757,16 @@ export async function mountDevToolbar(options = {}) {
|
|
|
473
757
|
grow(current.host);
|
|
474
758
|
};
|
|
475
759
|
show(mode);
|
|
760
|
+
startOnSpec();
|
|
761
|
+
startUpdateBanner();
|
|
476
762
|
return {
|
|
477
763
|
get backend() { return backend; },
|
|
478
764
|
connect,
|
|
479
765
|
mode: () => mode,
|
|
480
766
|
show,
|
|
481
767
|
destroy: () => {
|
|
768
|
+
stopOnSpec();
|
|
769
|
+
stopUpdateBanner();
|
|
482
770
|
doc.removeEventListener(TOOLBAR_REPLACE_EVENT, stepAside);
|
|
483
771
|
doc.removeEventListener(UI_PREFS_EVENT, followPrefs);
|
|
484
772
|
win.removeEventListener('resize', onResize);
|