deictic 0.7.0 → 0.8.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/API.md +21 -2
- package/README.md +2 -1
- package/dist/bun.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +77 -51
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/next.js +1 -1
- package/dist/recommended/index.d.ts +1 -1
- package/dist/recordings/client.js +8 -2
- package/dist/recordings/client.js.map +1 -1
- package/dist/shared/endpoints.js +26 -6
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/index.d.ts +35 -3
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index7.d.ts +22 -2
- package/dist/shared/index7.d.ts.map +1 -1
- package/dist/shared/index9.d.ts +1 -1
- package/dist/shared/integration.d.ts +1 -1
- package/dist/shared/integration.js +59 -5
- package/dist/shared/integration.js.map +1 -1
- package/dist/shared/package.js +23 -0
- package/dist/shared/package.js.map +1 -0
- package/dist/shared/packages.js +14 -23
- package/dist/shared/packages.js.map +1 -1
- package/dist/shared/playwright.js +11 -3
- package/dist/shared/playwright.js.map +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +12 -3
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +52 -4
- package/dist/shared/tasks.js.map +1 -1
- package/dist/shared/watch.js +2 -1
- package/dist/shared/watch.js.map +1 -1
- package/dist/tailwind/index.js +7 -2
- package/dist/tailwind/index.js.map +1 -1
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/client.js +50 -9
- package/dist/tasks/client.js.map +1 -1
- package/dist/tasks/index.d.ts +2 -2
- package/dist/webpack.js +1 -1
- package/package.json +2 -1
- package/src/cli/task.ts +20 -4
- package/src/cli/watch.ts +3 -1
- package/src/client/index.ts +76 -43
- package/src/index.ts +35 -2
- package/src/plugins/recordings/client.ts +8 -2
- package/src/plugins/screenshots/playwright.ts +8 -3
- package/src/plugins/tailwind/index.ts +3 -2
- package/src/plugins/tasks/client.ts +13 -3
- package/src/plugins/tasks/composer.ts +1 -1
- package/src/plugins/tasks/drawer.ts +3 -3
- package/src/plugins/tasks/index.ts +81 -3
- package/src/plugins/tasks/pins.ts +12 -7
- package/src/plugins/tasks/which.ts +34 -0
- package/src/tools/endpoints.ts +31 -5
- package/src/tools/packages.ts +12 -4
- package/src/tools/plugins.ts +18 -4
- package/src/tools/problems.ts +60 -0
package/dist/index.d.ts
CHANGED
|
@@ -19,5 +19,5 @@
|
|
|
19
19
|
*
|
|
20
20
|
* Both halves import from here, so the parser is imported for its types only: the browser must not load it.
|
|
21
21
|
*/
|
|
22
|
-
import { A as
|
|
23
|
-
export { ApiOf, ClientApis, ClientContext, ClientPlugin, Done, Drawer, LightboxAction, LightboxItem, LightboxOptions, Loc, type Modifier, PanelContext, Point, Refusal, Resumed, Route, ServerApis, ServerContext, ServerPlugin, type Shortcut, Source, Spot, Standalone, Target, TextEdit, ToolPanel, Tray, TrayItem, defineClientPlugin, definePlugin };
|
|
22
|
+
import { A as Modifier, C as Target, D as TrayItem, E as Tray, O as defineClientPlugin, S as Standalone, T as ToolPanel, _ as ServerApis, a as Done, b as Source, c as LightboxItem, d as PanelContext, f as Point, g as Route, h as Resumed, i as ClientPlugin, j as Shortcut, k as definePlugin, l as LightboxOptions, m as Refusal, n as ClientApis, o as Drawer, p as Problem, r as ClientContext, s as LightboxAction, t as ApiOf, u as Loc, v as ServerContext, w as TextEdit, x as Spot, y as ServerPlugin } from "./shared/index.js";
|
|
23
|
+
export { ApiOf, ClientApis, ClientContext, ClientPlugin, Done, Drawer, LightboxAction, LightboxItem, LightboxOptions, Loc, type Modifier, PanelContext, Point, Problem, Refusal, Resumed, Route, ServerApis, ServerContext, ServerPlugin, type Shortcut, Source, Spot, Standalone, Target, TextEdit, ToolPanel, Tray, TrayItem, defineClientPlugin, definePlugin };
|
package/dist/next.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createServer } from "node:http";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { n as nodeMiddleware, r as redirect, t as endpoints } from "./shared/endpoints.js";
|
|
4
|
-
import {
|
|
4
|
+
import { h as JSX, o as prepare, s as writeClient, t as beside } from "./shared/integration.js";
|
|
5
5
|
// src/next.ts
|
|
6
6
|
/**
|
|
7
7
|
* `deictic/next`: deictic in `next dev`, on Turbopack or webpack (`--webpack`). Nothing runs in `next build`.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Only the server halves, as every factory is: each names its page half, which the integration imports. A plugin
|
|
7
7
|
* outside the preset (Tailwind, your own) goes beside it: `plugins: [...recommended(), tailwind()]`.
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { y as ServerPlugin } from "../shared/index.js";
|
|
10
10
|
import { i as AnnotationsOptions } from "../shared/index2.js";
|
|
11
11
|
import { n as LogsOptions } from "../shared/index5.js";
|
|
12
12
|
import { t as NetworkOptions } from "../shared/index6.js";
|
|
@@ -118,7 +118,7 @@ const clock = (ms) => {
|
|
|
118
118
|
};
|
|
119
119
|
var client_default = defineClientPlugin({
|
|
120
120
|
name: "recordings",
|
|
121
|
-
setup: ({ base, root, options, use, request, tools, tray, drawer, lightbox }) => {
|
|
121
|
+
setup: ({ base, root, options, use, request, report, tools, tray, drawer, lightbox }) => {
|
|
122
122
|
const { masking, canvas } = options;
|
|
123
123
|
let running;
|
|
124
124
|
const group = Object.assign(document.createElement("div"), { className: "tool-group recorder" });
|
|
@@ -177,7 +177,13 @@ var client_default = defineClientPlugin({
|
|
|
177
177
|
})).id;
|
|
178
178
|
};
|
|
179
179
|
const extra = (name) => use(name)?.plugin({ sinceLoad: from !== void 0 }).catch((e) => {
|
|
180
|
-
|
|
180
|
+
const why = e instanceof Error ? e.message : String(e);
|
|
181
|
+
report({
|
|
182
|
+
key: `page:recordings:${name}:${why.split("\n", 1)[0].slice(0, 200)}`,
|
|
183
|
+
kind: "setup",
|
|
184
|
+
message: `recordings go without ${name}, as it couldn't be loaded: install what it needs (\`deictic init\` does), then load the page again: ${why}`,
|
|
185
|
+
...e instanceof Error && e.stack !== void 0 ? { details: e.stack } : {}
|
|
186
|
+
});
|
|
181
187
|
});
|
|
182
188
|
const [rrweb, id, ...extras] = await Promise.all([
|
|
183
189
|
import("rrweb").catch((e) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/recordings/ours.ts","../../src/plugins/recordings/client.ts"],"sourcesContent":["/**\n * Keeps deictic's own UI out of a recording. Blocking the overlay keeps it out of the first snapshot,\n * but rrweb watches a blocked host's shadow root all the same, so what's added there later (the toolbar,\n * a note's field) comes as mutations. This drops them, and clicks and input on those nodes, by the IDs\n * rrweb gave them: the host's, and every node added under one of ours.\n *\n * The pointer's moves over them stay, on the page's root instead: the replay moves its cursor only over a\n * node it has, and while a drawing tool is picked the pointer is over ours the whole time.\n */\n\n/** The parts of rrweb's events this reads; the rest passes as it is. */\ninterface Event {\n type: number;\n data?: unknown;\n}\n\ninterface Mutation {\n source: 0;\n adds: { parentId: number; node: { id: number } }[];\n removes: { parentId: number; id: number }[];\n texts: { id: number }[];\n attributes: { id: number }[];\n}\n\n/** rrweb's numbers: an incremental snapshot, and the sources whose data is a list of pointer positions. */\nconst INCREMENTAL = 3;\nconst MUTATION = 0;\nconst POSITIONS = new Set([1, 6, 12]);\n\n/** A filter for `emit`: the event without our nodes, or nothing when nothing else is left in it. */\nexport function dropOurs<E extends Event>(hostId: () => number, pageId: () => number): (event: E) => E | undefined {\n const ours = new Set<number>();\n return (event) => {\n if (ours.size === 0) {\n const id = hostId();\n if (id > 0) ours.add(id);\n }\n if (event.type !== INCREMENTAL || typeof event.data !== 'object' || event.data === null) return event;\n const data = event.data as { source: number; id?: number; positions?: { id: number }[] };\n\n if (data.source === MUTATION) {\n const m = data as Mutation;\n // Added parents and children come in any order: claim until nothing more is ours.\n for (let grew = true; grew;) {\n grew = false;\n for (const add of m.adds) {\n if (ours.has(add.parentId) && !ours.has(add.node.id)) {\n ours.add(add.node.id);\n grew = true;\n }\n }\n }\n const kept: Mutation = {\n ...m,\n adds: m.adds.filter((a) => !ours.has(a.node.id)),\n removes: m.removes.filter((r) => !ours.has(r.id) && !ours.has(r.parentId)),\n texts: m.texts.filter((t) => !ours.has(t.id)),\n attributes: m.attributes.filter((a) => !ours.has(a.id)),\n };\n const left = kept.adds.length + kept.removes.length + kept.texts.length + kept.attributes.length;\n return left === 0 ? undefined : { ...event, data: kept };\n }\n if (POSITIONS.has(data.source) && Array.isArray(data.positions)) {\n const page = pageId();\n const positions = data.positions.map((p) => (ours.has(p.id) ? { ...p, id: page } : p));\n return { ...event, data: { ...data, positions } };\n }\n return data.id !== undefined && ours.has(data.id) ? undefined : event;\n };\n}\n","/**\n * The recordings plugin's page half. Its tool in the tool panel is Record: `record()` starts rrweb (imported\n * then), and while one is going the panel stays, with the time, the mic where the voice plugin is loaded, and\n * Stop and Discard in Record's place. A recording that's stopped goes in the tray, for the next task.\n *\n * The events go to the server as they happen (`begin`, a `part` each second, `end` on Stop), and what the next\n * page needs to carry on is kept in the tab's session storage: a reload, or a link to another page of the site,\n * leaves the recording going. The page that loads starts rrweb again under the same ID, which makes it a\n * recording of several pages as rrweb has them (a `Meta` and a snapshot for each), puts its controls back with\n * the time running, and turns the mic back on where it was.\n *\n * Nothing of deictic's is recorded: the overlay is blocked, as rrweb blocks. The marks are, as custom\n * events: the page's annotations, as SVGs in page coordinates, at the start and at each change.\n */\nimport { toolButton } from '#src/client/dom.ts';\nimport { playMark, trayed } from '#src/client/drawer.ts';\nimport { liveWaveform } from '#src/client/waveform.ts';\nimport { defineClientPlugin } from '#src/index.ts';\nimport type { ResolvedMasking } from '#src/plugins/screenshots/index.ts';\n\nimport type { Take } from '#src/plugins/voice/index.ts';\n\nimport type { Kept, Meta, Recorder, Recording, RecordPlugin, VoiceClip } from './index.ts';\nimport { END, MARKS, PAGE } from './marks.ts';\nimport { dropOurs } from './ours.ts';\n\n/** Where the recording going on is kept, for the tab's next page to carry on with. */\nconst GOING = 'deictic:recording';\n/** How often the events are sent, in milliseconds. */\nconst EVERY = 1000;\n\n/** A recording going on, as the next page needs it. */\ninterface Carried {\n id: string;\n startedAt: number;\n /** The next part's place among the parts. */\n seq: number;\n /** The mic's clips so far, and whether it was on. */\n clips: VoiceClip[];\n mic: boolean;\n}\n\nfunction carried(): Carried | undefined {\n try {\n return (JSON.parse(sessionStorage.getItem(GOING) ?? 'null') as Carried | null) ?? undefined;\n } catch {\n // Storage can be off: nothing carries over, then.\n return undefined;\n }\n}\n\nfunction carry(going: Carried | undefined): void {\n try {\n if (going === undefined) sessionStorage.removeItem(GOING);\n else sessionStorage.setItem(GOING, JSON.stringify(going));\n } catch {\n // Not kept, then: a page load ends the recording.\n }\n}\n\nconst STYLE = `\n.recorder .going { display: flex; align-items: center; gap: 4px; }\n/* Away while nothing records: laid out empty, it would still count in the group's gap. */\n.recorder .going[hidden] { display: none; }\n/* While one goes, its controls are its section's alone: the other tools that capture (a shot, the mic, a task) wait. */\n.tool-panel:has(.recorder.going) .tool-group[data-section='capture']:not(.recorder) { display: none; }\n.tool-panel.vertical .recorder .going { flex-direction: column; }\n.recorder .live { display: inline-flex; align-items: center; gap: 6px; padding: 0 4px; font: 12px ui-monospace, monospace; }\n.tool-panel.vertical .recorder .live { flex-direction: column; gap: 2px; padding: 4px 0; }\n.recorder .dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; animation: deictic-blink 1.2s infinite; }\n.recorder .mic[aria-pressed='true'], .recorder .mic[aria-pressed='true']:hover { background: #ef4444; color: #fff; }\n.recorder .wave { width: 44px; height: 18px; }\n.tool-panel.vertical .recorder .wave { width: 28px; }\n@keyframes deictic-blink { 50% { opacity: 0.3; } }\n`;\n\n/** Each icon's strokes, on a 24-pixel grid. */\nconst RECORD = '<circle cx=\"12\" cy=\"12\" r=\"8\"/><circle cx=\"12\" cy=\"12\" r=\"3\" fill=\"currentColor\"/>';\nconst STOP = '<rect x=\"6\" y=\"6\" width=\"12\" height=\"12\" rx=\"1\" fill=\"currentColor\"/>';\nconst DISCARD = '<path d=\"M6 6l12 12M18 6 6 18\"/>';\nconst MIC = '<rect x=\"9\" y=\"3\" width=\"6\" height=\"11\" rx=\"3\"/><path d=\"M5 11a7 7 0 0 0 14 0M12 18v3\"/>';\n\nconst clock = (ms: number) => {\n const s = Math.floor(ms / 1000);\n return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;\n};\n\nexport default defineClientPlugin<never, never, Recorder>({\n name: 'recordings',\n setup: ({ base, root, options, use, request, tools, tray, drawer, lightbox }) => {\n const { masking, canvas } = options as { masking: ResolvedMasking; canvas?: false | { fps: number } };\n let running: Promise<Recording | undefined> | undefined;\n\n // In the tool panel: Record, and in its place while one is going, what `record` puts there.\n const group = Object.assign(document.createElement('div'), { className: 'tool-group recorder' });\n const going = Object.assign(document.createElement('div'), { className: 'going', hidden: true });\n const start = toolButton(RECORD, 'Record', 'R', () => {\n run().catch((e: unknown) => {\n // Said where it was asked for: its tooltip, which a missing package's fix fits in.\n start.classList.add('problem');\n start.title = e instanceof Error ? e.message : String(e);\n });\n });\n group.append(Object.assign(document.createElement('style'), { textContent: STYLE }), start, going);\n // Beside the other tools that capture the page: a shot, a recording, the mic.\n tools.add(group, { section: 'capture' });\n // In the drawer until a task takes them: each plays back in the lightbox.\n drawer.add(\n trayed({ tray }, 'recordings', 'Recordings', (item, i, all) => {\n const { url, duration, voice } = item.value as Recording;\n const name = `${all.length === 1 ? 'Recording' : `Recording ${i + 1}`} ${clock(duration)}`;\n return {\n label: [playMark(), `${name}${voice === undefined ? '' : ' · voice'}`],\n // The replay filling the frame, without a header of its own: the lightbox names it.\n open: (from) => lightbox([{ kind: 'page', url: `${url}${url.includes('?') ? '&' : '?'}embed`, title: name }], { from }),\n };\n }),\n );\n\n const post = async (route: string, body: unknown, keepalive = false) => {\n const res = await request(route, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(body),\n ...(keepalive ? { keepalive } : {}),\n });\n // `url`: where it replays, said by what keeps it with no server to serve it from (a `standalone` build).\n const answer = (await res.json()) as { id?: string; url?: string; problem?: string };\n if (answer.id === undefined) throw new Error(`recordings: ${answer.problem ?? res.statusText}`);\n return { id: answer.id, url: answer.url };\n };\n\n /** Records until Stop or Discard: a new recording, or `from`, one a page before this started. */\n const record = async (from?: Carried): Promise<Recording | undefined> => {\n const startedAt = from?.startedAt ?? Date.now();\n const begin = async (): Promise<string> => {\n const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };\n const colorScheme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n return (await post('begin', { page: location.href, viewport, colorScheme, startedAt } satisfies Meta)).id;\n };\n // What else goes in the recording, where its plugin is loaded: the console's lines and the page's requests, each\n // rrweb's own plugin, which listens from when rrweb starts until it stops. One that can't be had (its package\n // isn't installed) is said, and the recording goes on without.\n const extra = (name: 'logs' | 'network'): Promise<RecordPlugin | undefined> | undefined =>\n use(name)\n // A page that carries a recording on made requests before this: those of its load are the recording's too.\n ?.plugin({ sinceLoad: from !== undefined })\n .catch((e: unknown) => {\n console.warn(`deictic: this recording has no ${name}`, e);\n return undefined;\n });\n const [rrweb, id, ...extras] = await Promise.all([\n import('rrweb').catch((e: unknown) => {\n throw new Error('recordings need rrweb: add it to your devDependencies', { cause: e });\n }),\n from?.id ?? begin(),\n extra('logs'),\n extra('network'),\n ]);\n const clips: VoiceClip[] = from?.clips ?? [];\n // What the server doesn't have yet, and the place of the next part sent.\n let unsent: { type: number; data?: unknown }[] = [];\n let seq = from?.seq ?? 0;\n const host = root.host;\n const keep = dropOurs<(typeof unsent)[number]>(\n () => rrweb.record.mirror.getId(host),\n () => rrweb.record.mirror.getId(document.documentElement),\n );\n // The page's address changing with no load (a router's `pushState`, Back within the app, a hash), which rrweb\n // doesn't record: a custom event, so the recording says where each stretch happened. Nothing tells of\n // `pushState`, so it's read as each event comes, and as the clock ticks for a route that draws nothing.\n let href = location.href;\n const moved = () => {\n if (location.href === href) return;\n href = location.href;\n rrweb.record.addCustomEvent(PAGE, { href });\n };\n const stopRecording = rrweb.record({\n emit: (event) => {\n // Before what the new route drew, which is what comes next.\n moved();\n const kept = keep(event);\n if (kept !== undefined) unsent.push(kept);\n },\n plugins: extras.filter((plugin) => plugin !== undefined),\n blockClass: masking.blockClass,\n // deictic's own UI, the overlay: a blocked element is kept as an empty box its size, and it has none.\n blockSelector: ['deictic-overlay', ...(masking.blockSelector ? [masking.blockSelector] : [])].join(', '),\n maskTextClass: masking.maskTextClass,\n ...(masking.maskTextSelector ? { maskTextSelector: masking.maskTextSelector } : {}),\n maskAllInputs: masking.maskAllInputs,\n maskInputOptions: { password: true },\n inlineStylesheet: true,\n // A canvas as pictures of it, a few a second and only when it changed: rrweb's other way keeps every call\n // drawn on it, for which it wraps each drawing method of every canvas.\n ...(canvas === false || canvas === undefined\n ? {}\n : { recordCanvas: true, sampling: { canvas: canvas.fps }, dataURLOptions: { type: 'image/webp', quality: 0.6 } }),\n });\n\n // The marks, now and at each change: an SVG whose view is the page from its top left, at 1:1.\n const marks = use('annotations');\n const mark = () => {\n const area = { x: -scrollX, y: -scrollY, width: 1, height: 1 };\n rrweb.record.addCustomEvent(MARKS, {\n svg: marks?.svg(area) ?? '',\n // The same marks as data, in page coordinates, for whatever reads the recording but doesn't draw it.\n annotations: marks?.list() ?? [],\n });\n };\n mark();\n\n // The mic, where the voice plugin is loaded: each stretch it's on is a clip, at its time in the recording.\n const voice = use('voice');\n let take: Take | undefined;\n /** What the next page carries on from, kept as it changes: a page that's going has no time to say it then. */\n let over = false;\n const save = () =>\n // Not once it's ended, as its last events go: the next page would carry on with one that's over.\n over || carry({ id, startedAt, seq, clips, mic: take !== undefined });\n const unsubscribe = marks?.subscribe(mark);\n\n // One part at a time, each with its place. A part that didn't arrive goes again with the next, before it.\n let sending: Promise<void> = Promise.resolve();\n const flush = () => {\n const next = sending\n .catch(() => {})\n .then(async () => {\n if (unsent.length === 0) return;\n const part = unsent;\n unsent = [];\n const at = seq++;\n save();\n try {\n await post(`part/${id}?seq=${at}`, part);\n } catch (e) {\n unsent = [...part, ...unsent];\n throw e;\n }\n });\n sending = next;\n return next;\n };\n // A problem is heard at Stop, where it matters: a part that fails meanwhile goes again a second on.\n const flushing = setInterval(() => void flush().catch(() => {}), EVERY);\n save();\n\n return new Promise((done, fail) => {\n const live = Object.assign(document.createElement('span'), { className: 'live' });\n const dot = Object.assign(document.createElement('span'), { className: 'dot' });\n const time = document.createElement('span');\n live.append(dot, time);\n\n // The mic's live waveform beside it while it's on, so it's plain it hears.\n const wave = Object.assign(document.createElement('canvas'), { className: 'wave', hidden: true });\n let stopWave: (() => void) | undefined;\n const unwave = () => {\n stopWave?.();\n stopWave = undefined;\n wave.hidden = true;\n };\n // What the mic is doing (asking for it, keeping a take): the next toggle, and the end, wait for it.\n let busy: Promise<void> = Promise.resolve();\n const micOff = async () => {\n const ending = take;\n take = undefined;\n unwave();\n if (ending === undefined) return;\n try {\n const clip = await ending.stop();\n clips.push({ id: clip.id, at: ending.started - startedAt, duration: clip.duration });\n } catch (e) {\n // The recording is worth keeping without it.\n console.warn('deictic: the voice clip was not kept', e);\n }\n };\n const mic = voice === undefined ? undefined : toolButton(MIC, 'Turn the mic on', 'K', () => toggle());\n const toggle = () => {\n busy = busy.then(async () => {\n if (voice === undefined || mic === undefined) return;\n if (take !== undefined) {\n await micOff();\n } else {\n try {\n take = await voice.start();\n mic.classList.remove('problem');\n wave.hidden = false;\n stopWave = liveWaveform(wave, take.stream, { played: '#ef4444', rest: '#52525b' });\n } catch (e) {\n mic.classList.add('problem');\n mic.title = e instanceof Error ? e.message : String(e);\n return;\n }\n }\n const on = take !== undefined;\n mic.setAttribute('aria-pressed', String(on));\n mic.title = on ? 'Turn the mic off' : 'Turn the mic on';\n mic.setAttribute('aria-label', mic.title);\n save();\n });\n };\n mic?.classList.add('mic');\n mic?.setAttribute('aria-pressed', 'false');\n // On, as the page before left it: a browser that was let use the mic gives it again without asking.\n if (from?.mic === true) toggle();\n\n // The page is going, for another or for good, with no time to wait for anything: what's sent of the mic's\n // take is its clip, the next page is told where things stand, and the last events go as the page does.\n const leave = () => {\n const spoken = take?.soFar();\n if (take !== undefined && spoken !== undefined)\n clips.push({ id: spoken.id, at: take.started - startedAt, duration: spoken.duration });\n const part = unsent;\n unsent = [];\n const at = seq++;\n save();\n // Not behind `sending`, which a page that's going never gets to: the server orders the parts by their place.\n // A browser sends 64 KB at most for a page that's gone, so a last second busier than that is lost.\n if (part.length > 0) void post(`part/${id}?seq=${at}`, part, true).catch(() => {});\n };\n addEventListener('pagehide', leave);\n\n const end = async (kept: boolean) => {\n rrweb.record.addCustomEvent(END, {});\n stopRecording?.();\n unsubscribe?.();\n clearInterval(flushing);\n clearInterval(ticking);\n removeEventListener('pagehide', leave);\n idle();\n over = true;\n carry(undefined);\n await busy;\n if (!kept) {\n unwave();\n take?.cancel();\n void post(`discard/${id}`, {}).catch(() => {});\n return done(undefined);\n }\n await micOff();\n const duration = Date.now() - startedAt;\n const voiced = clips.length > 0 ? { voice: clips } : {};\n try {\n await flush();\n const { url } = await post(`end/${id}`, { duration, ...voiced } satisfies Pick<Kept, 'duration' | 'voice'>);\n done({ id, url: url ?? `${base}__deictic/plugins/recordings/replay/${id}`, duration, ...voiced });\n } catch (e) {\n fail(e);\n }\n };\n // Record's key again: it's Stop while one is going.\n const stop = toolButton(STOP, 'Stop', 'R', () => void end(true));\n const discard = toolButton(DISCARD, 'Discard', 'Shift+R', () => void end(false));\n going.replaceChildren(live, ...(mic ? [mic, wave] : []), stop, discard);\n // The panel stays while it goes: its controls are what ends it.\n const unkeep = tools.keep();\n start.hidden = true;\n going.hidden = false;\n group.classList.add('going');\n const idle = () => {\n unkeep();\n going.replaceChildren();\n going.hidden = true;\n start.hidden = false;\n group.classList.remove('going');\n };\n\n const tick = () => {\n moved();\n time.textContent = clock(Date.now() - startedAt);\n };\n tick();\n const ticking = setInterval(tick, 250);\n });\n };\n\n const run = (from?: Carried) => {\n start.disabled = true;\n start.classList.remove('problem');\n start.title = 'Record';\n const mine = record(from).finally(() => {\n if (running === mine) running = undefined;\n start.disabled = false;\n });\n running = mine;\n // One that's stopped and kept is the next task's, whoever started it.\n mine.then(\n (recording) => recording !== undefined && tray.add('recordings', recording.id, recording),\n () => {},\n );\n return mine;\n };\n // One the page before this left going: carried on at once, whoever asks for it later (`going`), or no one.\n const left = carried();\n if (left !== undefined) {\n run(left).catch((e: unknown) => {\n // Not for the page after this to try again.\n carry(undefined);\n console.warn('deictic: the recording did not carry on, or was not kept', e);\n });\n }\n // A page shown again as it was left (Back, out of the browser's cache) knows nothing of what happened since:\n // loaded afresh, it carries on like any other.\n window.addEventListener('pageshow', (e) => {\n if (e.persisted && (running !== undefined || carried() !== undefined)) location.reload();\n });\n\n return {\n recording: () => running !== undefined,\n going: () => running,\n record: async () => {\n if (running !== undefined) throw new Error('recordings: one is going already: stop it first');\n return run();\n },\n };\n },\n});\n"],"mappings":";;;;;;;AAyBA,MAAM,cAAc;AACpB,MAAM,WAAW;AACjB,MAAM,4BAAY,IAAI,IAAI;CAAC;CAAG;CAAG;AAAE,CAAC;;AAGpC,SAAgB,SAA0B,QAAsB,QAAmD;CACjH,MAAM,uBAAO,IAAI,IAAY;CAC7B,QAAQ,UAAU;EAChB,IAAI,KAAK,SAAS,GAAG;GACnB,MAAM,KAAK,OAAO;GAClB,IAAI,KAAK,GAAG,KAAK,IAAI,EAAE;EACzB;EACA,IAAI,MAAM,SAAS,eAAe,OAAO,MAAM,SAAS,YAAY,MAAM,SAAS,MAAM,OAAO;EAChG,MAAM,OAAO,MAAM;EAEnB,IAAI,KAAK,WAAW,UAAU;GAC5B,MAAM,IAAI;GAEV,KAAK,IAAI,OAAO,MAAM,OAAO;IAC3B,OAAO;IACP,KAAK,MAAM,OAAO,EAAE,MAClB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IAAI,MAAM,iDAAiD;IAC5F,OAAO,IAAI;GACb;EACF;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/recordings/ours.ts","../../src/plugins/recordings/client.ts"],"sourcesContent":["/**\n * Keeps deictic's own UI out of a recording. Blocking the overlay keeps it out of the first snapshot,\n * but rrweb watches a blocked host's shadow root all the same, so what's added there later (the toolbar,\n * a note's field) comes as mutations. This drops them, and clicks and input on those nodes, by the IDs\n * rrweb gave them: the host's, and every node added under one of ours.\n *\n * The pointer's moves over them stay, on the page's root instead: the replay moves its cursor only over a\n * node it has, and while a drawing tool is picked the pointer is over ours the whole time.\n */\n\n/** The parts of rrweb's events this reads; the rest passes as it is. */\ninterface Event {\n type: number;\n data?: unknown;\n}\n\ninterface Mutation {\n source: 0;\n adds: { parentId: number; node: { id: number } }[];\n removes: { parentId: number; id: number }[];\n texts: { id: number }[];\n attributes: { id: number }[];\n}\n\n/** rrweb's numbers: an incremental snapshot, and the sources whose data is a list of pointer positions. */\nconst INCREMENTAL = 3;\nconst MUTATION = 0;\nconst POSITIONS = new Set([1, 6, 12]);\n\n/** A filter for `emit`: the event without our nodes, or nothing when nothing else is left in it. */\nexport function dropOurs<E extends Event>(hostId: () => number, pageId: () => number): (event: E) => E | undefined {\n const ours = new Set<number>();\n return (event) => {\n if (ours.size === 0) {\n const id = hostId();\n if (id > 0) ours.add(id);\n }\n if (event.type !== INCREMENTAL || typeof event.data !== 'object' || event.data === null) return event;\n const data = event.data as { source: number; id?: number; positions?: { id: number }[] };\n\n if (data.source === MUTATION) {\n const m = data as Mutation;\n // Added parents and children come in any order: claim until nothing more is ours.\n for (let grew = true; grew;) {\n grew = false;\n for (const add of m.adds) {\n if (ours.has(add.parentId) && !ours.has(add.node.id)) {\n ours.add(add.node.id);\n grew = true;\n }\n }\n }\n const kept: Mutation = {\n ...m,\n adds: m.adds.filter((a) => !ours.has(a.node.id)),\n removes: m.removes.filter((r) => !ours.has(r.id) && !ours.has(r.parentId)),\n texts: m.texts.filter((t) => !ours.has(t.id)),\n attributes: m.attributes.filter((a) => !ours.has(a.id)),\n };\n const left = kept.adds.length + kept.removes.length + kept.texts.length + kept.attributes.length;\n return left === 0 ? undefined : { ...event, data: kept };\n }\n if (POSITIONS.has(data.source) && Array.isArray(data.positions)) {\n const page = pageId();\n const positions = data.positions.map((p) => (ours.has(p.id) ? { ...p, id: page } : p));\n return { ...event, data: { ...data, positions } };\n }\n return data.id !== undefined && ours.has(data.id) ? undefined : event;\n };\n}\n","/**\n * The recordings plugin's page half. Its tool in the tool panel is Record: `record()` starts rrweb (imported\n * then), and while one is going the panel stays, with the time, the mic where the voice plugin is loaded, and\n * Stop and Discard in Record's place. A recording that's stopped goes in the tray, for the next task.\n *\n * The events go to the server as they happen (`begin`, a `part` each second, `end` on Stop), and what the next\n * page needs to carry on is kept in the tab's session storage: a reload, or a link to another page of the site,\n * leaves the recording going. The page that loads starts rrweb again under the same ID, which makes it a\n * recording of several pages as rrweb has them (a `Meta` and a snapshot for each), puts its controls back with\n * the time running, and turns the mic back on where it was.\n *\n * Nothing of deictic's is recorded: the overlay is blocked, as rrweb blocks. The marks are, as custom\n * events: the page's annotations, as SVGs in page coordinates, at the start and at each change.\n */\nimport { toolButton } from '#src/client/dom.ts';\nimport { playMark, trayed } from '#src/client/drawer.ts';\nimport { liveWaveform } from '#src/client/waveform.ts';\nimport { defineClientPlugin } from '#src/index.ts';\nimport type { ResolvedMasking } from '#src/plugins/screenshots/index.ts';\n\nimport type { Take } from '#src/plugins/voice/index.ts';\n\nimport type { Kept, Meta, Recorder, Recording, RecordPlugin, VoiceClip } from './index.ts';\nimport { END, MARKS, PAGE } from './marks.ts';\nimport { dropOurs } from './ours.ts';\n\n/** Where the recording going on is kept, for the tab's next page to carry on with. */\nconst GOING = 'deictic:recording';\n/** How often the events are sent, in milliseconds. */\nconst EVERY = 1000;\n\n/** A recording going on, as the next page needs it. */\ninterface Carried {\n id: string;\n startedAt: number;\n /** The next part's place among the parts. */\n seq: number;\n /** The mic's clips so far, and whether it was on. */\n clips: VoiceClip[];\n mic: boolean;\n}\n\nfunction carried(): Carried | undefined {\n try {\n return (JSON.parse(sessionStorage.getItem(GOING) ?? 'null') as Carried | null) ?? undefined;\n } catch {\n // Storage can be off: nothing carries over, then.\n return undefined;\n }\n}\n\nfunction carry(going: Carried | undefined): void {\n try {\n if (going === undefined) sessionStorage.removeItem(GOING);\n else sessionStorage.setItem(GOING, JSON.stringify(going));\n } catch {\n // Not kept, then: a page load ends the recording.\n }\n}\n\nconst STYLE = `\n.recorder .going { display: flex; align-items: center; gap: 4px; }\n/* Away while nothing records: laid out empty, it would still count in the group's gap. */\n.recorder .going[hidden] { display: none; }\n/* While one goes, its controls are its section's alone: the other tools that capture (a shot, the mic, a task) wait. */\n.tool-panel:has(.recorder.going) .tool-group[data-section='capture']:not(.recorder) { display: none; }\n.tool-panel.vertical .recorder .going { flex-direction: column; }\n.recorder .live { display: inline-flex; align-items: center; gap: 6px; padding: 0 4px; font: 12px ui-monospace, monospace; }\n.tool-panel.vertical .recorder .live { flex-direction: column; gap: 2px; padding: 4px 0; }\n.recorder .dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; animation: deictic-blink 1.2s infinite; }\n.recorder .mic[aria-pressed='true'], .recorder .mic[aria-pressed='true']:hover { background: #ef4444; color: #fff; }\n.recorder .wave { width: 44px; height: 18px; }\n.tool-panel.vertical .recorder .wave { width: 28px; }\n@keyframes deictic-blink { 50% { opacity: 0.3; } }\n`;\n\n/** Each icon's strokes, on a 24-pixel grid. */\nconst RECORD = '<circle cx=\"12\" cy=\"12\" r=\"8\"/><circle cx=\"12\" cy=\"12\" r=\"3\" fill=\"currentColor\"/>';\nconst STOP = '<rect x=\"6\" y=\"6\" width=\"12\" height=\"12\" rx=\"1\" fill=\"currentColor\"/>';\nconst DISCARD = '<path d=\"M6 6l12 12M18 6 6 18\"/>';\nconst MIC = '<rect x=\"9\" y=\"3\" width=\"6\" height=\"11\" rx=\"3\"/><path d=\"M5 11a7 7 0 0 0 14 0M12 18v3\"/>';\n\nconst clock = (ms: number) => {\n const s = Math.floor(ms / 1000);\n return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;\n};\n\nexport default defineClientPlugin<never, never, Recorder>({\n name: 'recordings',\n setup: ({ base, root, options, use, request, report, tools, tray, drawer, lightbox }) => {\n const { masking, canvas } = options as { masking: ResolvedMasking; canvas?: false | { fps: number } };\n let running: Promise<Recording | undefined> | undefined;\n\n // In the tool panel: Record, and in its place while one is going, what `record` puts there.\n const group = Object.assign(document.createElement('div'), { className: 'tool-group recorder' });\n const going = Object.assign(document.createElement('div'), { className: 'going', hidden: true });\n const start = toolButton(RECORD, 'Record', 'R', () => {\n run().catch((e: unknown) => {\n // Said where it was asked for: its tooltip, which a missing package's fix fits in.\n start.classList.add('problem');\n start.title = e instanceof Error ? e.message : String(e);\n });\n });\n group.append(Object.assign(document.createElement('style'), { textContent: STYLE }), start, going);\n // Beside the other tools that capture the page: a shot, a recording, the mic.\n tools.add(group, { section: 'capture' });\n // In the drawer until a task takes them: each plays back in the lightbox.\n drawer.add(\n trayed({ tray }, 'recordings', 'Recordings', (item, i, all) => {\n const { url, duration, voice } = item.value as Recording;\n const name = `${all.length === 1 ? 'Recording' : `Recording ${i + 1}`} ${clock(duration)}`;\n return {\n label: [playMark(), `${name}${voice === undefined ? '' : ' · voice'}`],\n // The replay filling the frame, without a header of its own: the lightbox names it.\n open: (from) => lightbox([{ kind: 'page', url: `${url}${url.includes('?') ? '&' : '?'}embed`, title: name }], { from }),\n };\n }),\n );\n\n const post = async (route: string, body: unknown, keepalive = false) => {\n const res = await request(route, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(body),\n ...(keepalive ? { keepalive } : {}),\n });\n // `url`: where it replays, said by what keeps it with no server to serve it from (a `standalone` build).\n const answer = (await res.json()) as { id?: string; url?: string; problem?: string };\n if (answer.id === undefined) throw new Error(`recordings: ${answer.problem ?? res.statusText}`);\n return { id: answer.id, url: answer.url };\n };\n\n /** Records until Stop or Discard: a new recording, or `from`, one a page before this started. */\n const record = async (from?: Carried): Promise<Recording | undefined> => {\n const startedAt = from?.startedAt ?? Date.now();\n const begin = async (): Promise<string> => {\n const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };\n const colorScheme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n return (await post('begin', { page: location.href, viewport, colorScheme, startedAt } satisfies Meta)).id;\n };\n // What else goes in the recording, where its plugin is loaded: the console's lines and the page's requests, each\n // rrweb's own plugin, which listens from when rrweb starts until it stops. One that can't be had (its package\n // isn't installed) is said, and the recording goes on without.\n const extra = (name: 'logs' | 'network'): Promise<RecordPlugin | undefined> | undefined =>\n use(name)\n // A page that carries a recording on made requests before this: those of its load are the recording's too.\n ?.plugin({ sinceLoad: from !== undefined })\n .catch((e: unknown) => {\n const why = e instanceof Error ? e.message : String(e);\n report({\n key: `page:recordings:${name}:${why.split('\\n', 1)[0]!.slice(0, 200)}`,\n kind: 'setup',\n message: `recordings go without ${name}, as it couldn't be loaded: install what it needs (\\`deictic init\\` does), then load the page again: ${why}`,\n ...(e instanceof Error && e.stack !== undefined ? { details: e.stack } : {}),\n });\n return undefined;\n });\n const [rrweb, id, ...extras] = await Promise.all([\n import('rrweb').catch((e: unknown) => {\n throw new Error('recordings need rrweb: add it to your devDependencies', { cause: e });\n }),\n from?.id ?? begin(),\n extra('logs'),\n extra('network'),\n ]);\n const clips: VoiceClip[] = from?.clips ?? [];\n // What the server doesn't have yet, and the place of the next part sent.\n let unsent: { type: number; data?: unknown }[] = [];\n let seq = from?.seq ?? 0;\n const host = root.host;\n const keep = dropOurs<(typeof unsent)[number]>(\n () => rrweb.record.mirror.getId(host),\n () => rrweb.record.mirror.getId(document.documentElement),\n );\n // The page's address changing with no load (a router's `pushState`, Back within the app, a hash), which rrweb\n // doesn't record: a custom event, so the recording says where each stretch happened. Nothing tells of\n // `pushState`, so it's read as each event comes, and as the clock ticks for a route that draws nothing.\n let href = location.href;\n const moved = () => {\n if (location.href === href) return;\n href = location.href;\n rrweb.record.addCustomEvent(PAGE, { href });\n };\n const stopRecording = rrweb.record({\n emit: (event) => {\n // Before what the new route drew, which is what comes next.\n moved();\n const kept = keep(event);\n if (kept !== undefined) unsent.push(kept);\n },\n plugins: extras.filter((plugin) => plugin !== undefined),\n blockClass: masking.blockClass,\n // deictic's own UI, the overlay: a blocked element is kept as an empty box its size, and it has none.\n blockSelector: ['deictic-overlay', ...(masking.blockSelector ? [masking.blockSelector] : [])].join(', '),\n maskTextClass: masking.maskTextClass,\n ...(masking.maskTextSelector ? { maskTextSelector: masking.maskTextSelector } : {}),\n maskAllInputs: masking.maskAllInputs,\n maskInputOptions: { password: true },\n inlineStylesheet: true,\n // A canvas as pictures of it, a few a second and only when it changed: rrweb's other way keeps every call\n // drawn on it, for which it wraps each drawing method of every canvas.\n ...(canvas === false || canvas === undefined\n ? {}\n : { recordCanvas: true, sampling: { canvas: canvas.fps }, dataURLOptions: { type: 'image/webp', quality: 0.6 } }),\n });\n\n // The marks, now and at each change: an SVG whose view is the page from its top left, at 1:1.\n const marks = use('annotations');\n const mark = () => {\n const area = { x: -scrollX, y: -scrollY, width: 1, height: 1 };\n rrweb.record.addCustomEvent(MARKS, {\n svg: marks?.svg(area) ?? '',\n // The same marks as data, in page coordinates, for whatever reads the recording but doesn't draw it.\n annotations: marks?.list() ?? [],\n });\n };\n mark();\n\n // The mic, where the voice plugin is loaded: each stretch it's on is a clip, at its time in the recording.\n const voice = use('voice');\n let take: Take | undefined;\n /** What the next page carries on from, kept as it changes: a page that's going has no time to say it then. */\n let over = false;\n const save = () =>\n // Not once it's ended, as its last events go: the next page would carry on with one that's over.\n over || carry({ id, startedAt, seq, clips, mic: take !== undefined });\n const unsubscribe = marks?.subscribe(mark);\n\n // One part at a time, each with its place. A part that didn't arrive goes again with the next, before it.\n let sending: Promise<void> = Promise.resolve();\n const flush = () => {\n const next = sending\n .catch(() => {})\n .then(async () => {\n if (unsent.length === 0) return;\n const part = unsent;\n unsent = [];\n const at = seq++;\n save();\n try {\n await post(`part/${id}?seq=${at}`, part);\n } catch (e) {\n unsent = [...part, ...unsent];\n throw e;\n }\n });\n sending = next;\n return next;\n };\n // A problem is heard at Stop, where it matters: a part that fails meanwhile goes again a second on.\n const flushing = setInterval(() => void flush().catch(() => {}), EVERY);\n save();\n\n return new Promise((done, fail) => {\n const live = Object.assign(document.createElement('span'), { className: 'live' });\n const dot = Object.assign(document.createElement('span'), { className: 'dot' });\n const time = document.createElement('span');\n live.append(dot, time);\n\n // The mic's live waveform beside it while it's on, so it's plain it hears.\n const wave = Object.assign(document.createElement('canvas'), { className: 'wave', hidden: true });\n let stopWave: (() => void) | undefined;\n const unwave = () => {\n stopWave?.();\n stopWave = undefined;\n wave.hidden = true;\n };\n // What the mic is doing (asking for it, keeping a take): the next toggle, and the end, wait for it.\n let busy: Promise<void> = Promise.resolve();\n const micOff = async () => {\n const ending = take;\n take = undefined;\n unwave();\n if (ending === undefined) return;\n try {\n const clip = await ending.stop();\n clips.push({ id: clip.id, at: ending.started - startedAt, duration: clip.duration });\n } catch (e) {\n // The recording is worth keeping without it.\n console.warn('deictic: the voice clip was not kept', e);\n }\n };\n const mic = voice === undefined ? undefined : toolButton(MIC, 'Turn the mic on', 'K', () => toggle());\n const toggle = () => {\n busy = busy.then(async () => {\n if (voice === undefined || mic === undefined) return;\n if (take !== undefined) {\n await micOff();\n } else {\n try {\n take = await voice.start();\n mic.classList.remove('problem');\n wave.hidden = false;\n stopWave = liveWaveform(wave, take.stream, { played: '#ef4444', rest: '#52525b' });\n } catch (e) {\n mic.classList.add('problem');\n mic.title = e instanceof Error ? e.message : String(e);\n return;\n }\n }\n const on = take !== undefined;\n mic.setAttribute('aria-pressed', String(on));\n mic.title = on ? 'Turn the mic off' : 'Turn the mic on';\n mic.setAttribute('aria-label', mic.title);\n save();\n });\n };\n mic?.classList.add('mic');\n mic?.setAttribute('aria-pressed', 'false');\n // On, as the page before left it: a browser that was let use the mic gives it again without asking.\n if (from?.mic === true) toggle();\n\n // The page is going, for another or for good, with no time to wait for anything: what's sent of the mic's\n // take is its clip, the next page is told where things stand, and the last events go as the page does.\n const leave = () => {\n const spoken = take?.soFar();\n if (take !== undefined && spoken !== undefined)\n clips.push({ id: spoken.id, at: take.started - startedAt, duration: spoken.duration });\n const part = unsent;\n unsent = [];\n const at = seq++;\n save();\n // Not behind `sending`, which a page that's going never gets to: the server orders the parts by their place.\n // A browser sends 64 KB at most for a page that's gone, so a last second busier than that is lost.\n if (part.length > 0) void post(`part/${id}?seq=${at}`, part, true).catch(() => {});\n };\n addEventListener('pagehide', leave);\n\n const end = async (kept: boolean) => {\n rrweb.record.addCustomEvent(END, {});\n stopRecording?.();\n unsubscribe?.();\n clearInterval(flushing);\n clearInterval(ticking);\n removeEventListener('pagehide', leave);\n idle();\n over = true;\n carry(undefined);\n await busy;\n if (!kept) {\n unwave();\n take?.cancel();\n void post(`discard/${id}`, {}).catch(() => {});\n return done(undefined);\n }\n await micOff();\n const duration = Date.now() - startedAt;\n const voiced = clips.length > 0 ? { voice: clips } : {};\n try {\n await flush();\n const { url } = await post(`end/${id}`, { duration, ...voiced } satisfies Pick<Kept, 'duration' | 'voice'>);\n done({ id, url: url ?? `${base}__deictic/plugins/recordings/replay/${id}`, duration, ...voiced });\n } catch (e) {\n fail(e);\n }\n };\n // Record's key again: it's Stop while one is going.\n const stop = toolButton(STOP, 'Stop', 'R', () => void end(true));\n const discard = toolButton(DISCARD, 'Discard', 'Shift+R', () => void end(false));\n going.replaceChildren(live, ...(mic ? [mic, wave] : []), stop, discard);\n // The panel stays while it goes: its controls are what ends it.\n const unkeep = tools.keep();\n start.hidden = true;\n going.hidden = false;\n group.classList.add('going');\n const idle = () => {\n unkeep();\n going.replaceChildren();\n going.hidden = true;\n start.hidden = false;\n group.classList.remove('going');\n };\n\n const tick = () => {\n moved();\n time.textContent = clock(Date.now() - startedAt);\n };\n tick();\n const ticking = setInterval(tick, 250);\n });\n };\n\n const run = (from?: Carried) => {\n start.disabled = true;\n start.classList.remove('problem');\n start.title = 'Record';\n const mine = record(from).finally(() => {\n if (running === mine) running = undefined;\n start.disabled = false;\n });\n running = mine;\n // One that's stopped and kept is the next task's, whoever started it.\n mine.then(\n (recording) => recording !== undefined && tray.add('recordings', recording.id, recording),\n () => {},\n );\n return mine;\n };\n // One the page before this left going: carried on at once, whoever asks for it later (`going`), or no one.\n const left = carried();\n if (left !== undefined) {\n run(left).catch((e: unknown) => {\n // Not for the page after this to try again.\n carry(undefined);\n console.warn('deictic: the recording did not carry on, or was not kept', e);\n });\n }\n // A page shown again as it was left (Back, out of the browser's cache) knows nothing of what happened since:\n // loaded afresh, it carries on like any other.\n window.addEventListener('pageshow', (e) => {\n if (e.persisted && (running !== undefined || carried() !== undefined)) location.reload();\n });\n\n return {\n recording: () => running !== undefined,\n going: () => running,\n record: async () => {\n if (running !== undefined) throw new Error('recordings: one is going already: stop it first');\n return run();\n },\n };\n },\n});\n"],"mappings":";;;;;;;AAyBA,MAAM,cAAc;AACpB,MAAM,WAAW;AACjB,MAAM,4BAAY,IAAI,IAAI;CAAC;CAAG;CAAG;AAAE,CAAC;;AAGpC,SAAgB,SAA0B,QAAsB,QAAmD;CACjH,MAAM,uBAAO,IAAI,IAAY;CAC7B,QAAQ,UAAU;EAChB,IAAI,KAAK,SAAS,GAAG;GACnB,MAAM,KAAK,OAAO;GAClB,IAAI,KAAK,GAAG,KAAK,IAAI,EAAE;EACzB;EACA,IAAI,MAAM,SAAS,eAAe,OAAO,MAAM,SAAS,YAAY,MAAM,SAAS,MAAM,OAAO;EAChG,MAAM,OAAO,MAAM;EAEnB,IAAI,KAAK,WAAW,UAAU;GAC5B,MAAM,IAAI;GAEV,KAAK,IAAI,OAAO,MAAM,OAAO;IAC3B,OAAO;IACP,KAAK,MAAM,OAAO,EAAE,MAClB,IAAI,KAAK,IAAI,IAAI,QAAQ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;EAC5E,CAAC;EAIH,OAAO,iBAAiB,aAAa,MAAM;GACzC,IAAI,EAAE,cAAc,YAAY,KAAA,KAAa,QAAQ,MAAM,KAAA,IAAY,SAAS,OAAO;EACzF,CAAC;EAED,OAAO;GACL,iBAAiB,YAAY,KAAA;GAC7B,aAAa;GACb,QAAQ,YAAY;IAClB,IAAI,YAAY,KAAA,GAAW,MAAM,IAAI,MAAM,iDAAiD;IAC5F,OAAO,IAAI;GACb;EACF;CACF;AACF,CAAC"}
|
package/dist/shared/endpoints.js
CHANGED
|
@@ -2,8 +2,8 @@ import { t as Refusal } from "./src.js";
|
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { t as keptIn } from "./kept.js";
|
|
5
|
-
import { c as setUp,
|
|
6
|
-
import { r as
|
|
5
|
+
import { _ as lineStarts, b as parse, c as setUp, d as reporter, f as stackOf, g as isHost, l as messageOf, m as parseAstro, p as ASTRO, u as problemIn, v as offsetOf, y as openingsIn } from "./integration.js";
|
|
6
|
+
import { r as missingProblem } from "./packages.js";
|
|
7
7
|
// src/tools/source.ts
|
|
8
8
|
/**
|
|
9
9
|
* The source a server half reads: a target's file, parsed, and the opening tag the page's attribute
|
|
@@ -258,9 +258,10 @@ const scopeIn = ({ plugin, target }) => plugin === void 0 || target === void 0 ?
|
|
|
258
258
|
function endpoints({ root, plugins, base = "/", open, history = new History(root, { plugins }) }) {
|
|
259
259
|
const byName = new Map(plugins.map((p) => [p.name, p]));
|
|
260
260
|
const prefix = `${base}__deictic/`;
|
|
261
|
-
const
|
|
262
|
-
const
|
|
263
|
-
|
|
261
|
+
const report = reporter(plugins, () => ready);
|
|
262
|
+
const ready = setUp(root, plugins, report);
|
|
263
|
+
const gone = missingProblem(root, plugins);
|
|
264
|
+
if (gone !== void 0) report(gone);
|
|
264
265
|
const pluginOf = (name) => {
|
|
265
266
|
const plugin = byName.get(name);
|
|
266
267
|
if (plugin === void 0) throw new Refusal(`no plugin "${name}" on the server: is it in the bundler plugin's \`plugins\`?`);
|
|
@@ -312,10 +313,14 @@ function endpoints({ root, plugins, base = "/", open, history = new History(root
|
|
|
312
313
|
const route = url.pathname.slice(prefix.length);
|
|
313
314
|
const origin = req.headers.get("origin");
|
|
314
315
|
const sameOrigin = origin !== null && new URL(origin).host === url.host;
|
|
316
|
+
let where = route;
|
|
317
|
+
let plugin;
|
|
315
318
|
try {
|
|
316
319
|
const context = await ready;
|
|
317
320
|
if (route.startsWith("plugins/")) {
|
|
318
321
|
const [name = "", first = ""] = route.slice(8).split("/");
|
|
322
|
+
where = `plugins/${name}/${first}`;
|
|
323
|
+
plugin = name;
|
|
319
324
|
const handle = byName.get(name)?.routes?.[first];
|
|
320
325
|
if (handle === void 0) return new Response(`no endpoint ${url.pathname}`, { status: 404 });
|
|
321
326
|
if (req.method !== "GET" && req.method !== "HEAD" && !sameOrigin) return Response.json({ problem: `only the page itself may ${req.method} to ${name}` }, { status: 403 });
|
|
@@ -332,12 +337,27 @@ function endpoints({ root, plugins, base = "/", open, history = new History(root
|
|
|
332
337
|
}
|
|
333
338
|
if (route === "open") return await open(resolveFile(root, loc.file), loc);
|
|
334
339
|
const handler = routes[route];
|
|
335
|
-
if (handler === void 0) return new Response(`no endpoint ${url.pathname}`, { status: 404 });
|
|
340
|
+
if (handler === void 0 && route !== "problem") return new Response(`no endpoint ${url.pathname}`, { status: 404 });
|
|
336
341
|
if (req.method !== "POST" || !sameOrigin || req.headers.get("content-type")?.startsWith("application/json") !== true) return Response.json({ problem: "edits come from the page, as JSON" }, { status: 403 });
|
|
342
|
+
if (handler === void 0) {
|
|
343
|
+
const problem = problemIn(await req.json());
|
|
344
|
+
if (problem === void 0) return Response.json({ problem: "a problem has a key, a kind and a message" }, { status: 400 });
|
|
345
|
+
report(problem);
|
|
346
|
+
return Response.json({});
|
|
347
|
+
}
|
|
337
348
|
const body = await req.json();
|
|
349
|
+
plugin = body.plugin;
|
|
338
350
|
return Response.json(await (route === "read" ? handler(body) : serially(() => handler(body))));
|
|
339
351
|
} catch (e) {
|
|
340
352
|
if (e instanceof Refusal) return Response.json({ problem: e.message }, { status: 422 });
|
|
353
|
+
const message = messageOf(e);
|
|
354
|
+
report({
|
|
355
|
+
key: `error:${where}:${message.split("\n", 1)[0].slice(0, 200)}`,
|
|
356
|
+
kind: "bug",
|
|
357
|
+
...plugin === void 0 ? {} : { plugin },
|
|
358
|
+
message: `${prefix}${where} failed: ${message}`,
|
|
359
|
+
...stackOf(e)
|
|
360
|
+
});
|
|
341
361
|
return Response.json({ problem: e instanceof Error ? e.stack ?? e.message : String(e) }, { status: 500 });
|
|
342
362
|
}
|
|
343
363
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoints.js","names":[],"sources":["../../src/tools/source.ts","../../src/tools/history.ts","../../src/tools/endpoints.ts"],"sourcesContent":["/**\n * The source a server half reads: a target's file, parsed, and the opening tag the page's attribute\n * points at. Files are only ever read and written under the project's root, outside `node_modules`.\n */\nimport { readFileSync } from 'node:fs';\nimport { isAbsolute, relative, resolve, sep } from 'node:path';\n\nimport { Refusal, type Source, type Target, type TextEdit } from '#src/index.ts';\n\nimport { ASTRO, parseAstro, type Parsed } from './astro.ts';\nimport { isHost, lineStarts, offsetOf, openingsIn, parse } from './locate.ts';\n\n/** A file from the project's root, as an absolute path; refused anywhere the page has no business writing. */\nexport function resolveFile(root: string, file: string): string {\n const path = resolve(root, file);\n const from = relative(root, path);\n // `relative` gives an absolute path for another drive.\n if (from === '' || from.startsWith('..') || isAbsolute(from) || from.split(sep).includes('node_modules'))\n throw new Refusal(`${file} is not a file of this project's own`);\n return path;\n}\n\nexport function readSource(root: string, file: string): string {\n try {\n return readFileSync(resolveFile(root, file), 'utf8');\n } catch (e) {\n if (e instanceof Refusal) throw e;\n throw new Refusal(`can't read ${file}: has it moved since the page loaded?`, { cause: e });\n }\n}\n\n/**\n * The target's file and element, as they are on disk now. The element is the one the page's mark names, or else the\n * only one of its tag on that line: the page may count columns in code a plugin before deictic's changed.\n */\nexport function sourceAt(root: string, target: Target): Source {\n const { file, line, column } = target.loc;\n const code = readSource(root, file);\n const lines = lineStarts(code);\n const offset = offsetOf(lines, line, column);\n const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);\n const tagged = elements.filter((el) => isHost(el) && el.name.type === 'JSXIdentifier' && el.name.name === target.tag);\n const start = lines[line - 1];\n const onLine = start === undefined ? [] : tagged.filter((el) => el.start >= start && el.start < (lines[line] ?? Infinity));\n const element = tagged.find((el) => el.start === offset) ?? (onLine.length === 1 ? onLine[0] : undefined);\n if (element === undefined) throw new Refusal(notThere(target, code, lines, onLine.length));\n return { file, code, program, element, read: (other) => readSource(root, other) };\n}\n\n/** Why the page's element isn't in the file, from what the file has there: it may not have changed at all. */\nfunction notThere({ loc: { file, line, column }, tag }: Target, code: string, lines: number[], onLine: number): string {\n const start = lines[line - 1];\n const found =\n start === undefined\n ? `${file} has no line ${line}`\n : onLine === 0\n ? `line ${line} of ${file} has no <${tag}>: it reads \\`${clip(code.slice(start, (lines[line] ?? code.length + 1) - 1).trim())}\\``\n : `line ${line} of ${file} has ${onLine} <${tag}>s, none at column ${column}`;\n return `${found}. The page isn't running the file as it is: reload it, and if it says this again, a plugin before deictic's changes the file, so put deictic first`;\n}\n\nconst clip = (text: string) => (text.length > 80 ? `${text.slice(0, 79)}…` : text);\n\nfunction jsx(file: string, code: string): Parsed {\n const { program, errors } = parse(file, code);\n if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0]!.message})`);\n return { program, elements: openingsIn(program) };\n}\n\nfunction astro(root: string, file: string, code: string): Parsed {\n const parsed = parseAstro(root, code);\n if ('problem' in parsed) throw new Refusal(`${file} can't be read: ${parsed.problem}`);\n return parsed;\n}\n\n/** Each file's text after its edits, which must not overlap. */\nexport function applyEdits(source: Source, edits: TextEdit[]): Map<string, string> {\n const byFile = Map.groupBy(edits, (e) => e.file ?? source.file);\n const out = new Map<string, string>();\n for (const [file, list] of byFile) {\n const sorted = list.toSorted((a, b) => b.start - a.start);\n let code = file === source.file ? source.code : source.read(file);\n let floor = Infinity;\n for (const edit of sorted) {\n if (edit.end > floor) throw new Error(`deictic: edits to ${file} overlap at ${edit.end}`);\n code = code.slice(0, edit.start) + edit.text + code.slice(edit.end);\n floor = edit.start;\n }\n out.set(file, code);\n }\n return out;\n}\n","/**\n * Every change deictic made, to undo and redo. A change to files holds each file's whole text\n * before and after: source files are small, and the texts make undo exact without a diff to go stale.\n * A change a plugin made itself (`Done`) holds the plugin's name and its record, and undoing it is the\n * plugin's `undo`.\n *\n * Each change has a scope, the plugin and the element it was made on, and the popup undoes and redoes\n * within its own: the latest change of this tab on this element, not the latest of all. So a change\n * is taken back out of order, with later ones to the same file still in it. Then only the lines the\n * change wrote go back to what they were, where they're still in the file as it wrote them, once.\n *\n * Anything else is refused, not merged: a file whose lines were edited since has the editor's own undo\n * for it; and a redo likewise. A plugin's undo refuses on its own terms. Kept under `.deictic`, so it\n * outlives a restart of the dev server and stays out of git.\n */\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport { Refusal, type ServerPlugin } from '#src/index.ts';\n\nimport { keptIn } from './kept.ts';\nimport { resolveFile } from './source.ts';\n\nexport interface FileChange {\n file: string;\n /** The text before, or nothing for a file the change made. */\n before: string | null;\n after: string;\n}\n\n/** Whose a change is: the plugin whose tab made it, and the element it was open on, as `file:line:column`. */\nexport interface Scope {\n plugin: string;\n target: string;\n}\n\ninterface Base {\n id: number;\n at: string;\n label: string;\n /** None on a change made without one, which only an undo of the whole history reaches. */\n scope?: Scope;\n}\n\nexport type Change = Base & ({ files: FileChange[] } | { plugin: string; record: unknown });\n\n/** A change as the page lists it. `files` is empty for one a plugin made itself. */\nexport interface Summary {\n id: number;\n at: string;\n label: string;\n files: string[];\n}\n\nexport interface HistoryOptions {\n /** Whose `undo` and `redo` take back the changes they made themselves. */\n plugins?: ServerPlugin[];\n store?: string;\n}\n\nconst LIMIT = 200;\n\n/** Whether a change is in a scope: any is in none. */\nconst within = (scope: Scope | undefined) => (c: Change) =>\n scope === undefined || (c.scope?.plugin === scope.plugin && c.scope.target === scope.target);\n\nconst summary = (c: Change): Summary => ({ id: c.id, at: c.at, label: c.label, files: 'files' in c ? c.files.map((f) => f.file) : [] });\n\nexport class History {\n #done: Change[] = [];\n #undone: Change[] = [];\n readonly #root: string;\n readonly #store: string;\n readonly #plugins: Map<string, ServerPlugin>;\n\n constructor(root: string, { plugins = [], store = keptIn(root, 'history.json') }: HistoryOptions = {}) {\n this.#root = root;\n this.#store = store;\n this.#plugins = new Map(plugins.map((p) => [p.name, p]));\n if (!existsSync(store)) return;\n try {\n ({ done: this.#done, undone: this.#undone } = JSON.parse(readFileSync(store, 'utf8')) as { done: Change[]; undone: Change[] });\n } catch {\n // A history that doesn't read is one we start over, not one to stop the dev server for.\n }\n }\n\n /** Writes each file's new text and records it as one change. A redo after it, in its scope, is gone, as in any editor. */\n commit(label: string, texts: Map<string, string>, scope?: Scope): Summary {\n const files: FileChange[] = [];\n for (const [file, after] of texts) {\n const path = resolveFile(this.#root, file);\n const before = existsSync(path) ? readFileSync(path, 'utf8') : null;\n if (before !== after) files.push({ file, before, after });\n }\n if (files.length === 0) throw new Refusal('nothing to change: the source already says that');\n for (const f of files) write(resolveFile(this.#root, f.file), f.after);\n return this.#push({ label, files }, scope);\n }\n\n /** Records a change `plugin` made itself, with what its `undo` needs. */\n record(label: string, plugin: string, record: unknown, scope?: Scope): Summary {\n return this.#push({ label, plugin, record }, scope);\n }\n\n /** Takes back the latest change, of a scope where one is given. */\n async undo(scope?: Scope): Promise<Summary> {\n const change = this.#done.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to undo' : 'nothing to undo here');\n if ('files' in change) this.#put(change, 'after', 'before');\n else change.record = (await this.#pluginOf(change, 'undo').undo!(change.record)) ?? change.record;\n this.#done = this.#done.filter((c) => c !== change);\n this.#undone.push(change);\n this.#save();\n return summary(change);\n }\n\n /** Makes the change last undone again, of a scope where one is given. */\n async redo(scope?: Scope): Promise<Summary> {\n const change = this.#undone.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to redo' : 'nothing to redo here');\n if ('files' in change) this.#put(change, 'before', 'after');\n else change.record = await this.#pluginOf(change, 'redo').redo!(change.record);\n this.#undone = this.#undone.filter((c) => c !== change);\n this.#done.push(change);\n this.#save();\n return summary(change);\n }\n\n list(scope?: Scope): { done: Summary[]; undone: Summary[] } {\n return { done: this.#done.filter(within(scope)).map(summary), undone: this.#undone.filter(within(scope)).map(summary) };\n }\n\n #push(change: Omit<Base, 'id' | 'at'> & ({ files: FileChange[] } | { plugin: string; record: unknown }), scope?: Scope): Summary {\n const id = Math.max(0, ...[...this.#done, ...this.#undone].map((c) => c.id)) + 1;\n const made = { id, at: new Date().toISOString(), ...change, ...(scope === undefined ? {} : { scope }) };\n this.#done = [...this.#done, made].slice(-LIMIT);\n // What was undone in this scope can't be redone over the new change; another scope's still can.\n this.#undone = this.#undone.filter((c) => !within(scope)(c));\n this.#save();\n return summary(made);\n }\n\n #pluginOf(change: { label: string; plugin: string }, step: 'undo' | 'redo'): ServerPlugin {\n const plugin = this.#plugins.get(change.plugin);\n if (plugin?.[step] === undefined) {\n throw new Refusal(\n `can't ${step} \"${change.label}\": the ${change.plugin} plugin that made it isn't loaded, so add it back to \\`plugins\\``,\n );\n }\n return plugin;\n }\n\n /**\n * Puts each file's `to` text back, once every one of them still reads as its `from`, or still has the\n * lines that differ as `from` has them: then those lines alone change, and the rest stays as it is now.\n */\n #put(change: Base & { files: FileChange[] }, from: 'before' | 'after', to: 'before' | 'after'): void {\n const paths = change.files.map((f) => resolveFile(this.#root, f.file));\n const texts = change.files.map((f, i) => {\n const now = existsSync(paths[i]!) ? readFileSync(paths[i]!, 'utf8') : null;\n if (now === f[from]) return f[to];\n const text = now === null || f[from] === null || f[to] === null ? undefined : swapped(now, f[from], f[to]);\n if (text === undefined) {\n throw new Refusal(\n `${f.file} changed since \"${change.label}\" ${from === 'after' ? 'was made' : 'was undone'}: use the editor's undo there`,\n );\n }\n return text;\n });\n texts.forEach((text, i) => {\n if (text === null) rmSync(paths[i]!);\n else write(paths[i]!, text);\n });\n }\n\n #save(): void {\n write(this.#store, JSON.stringify({ done: this.#done, undone: this.#undone }));\n }\n}\n\n/**\n * `now` with the lines that differ between `from` and `to` put as `to` has them, where `now` has them as\n * `from` does, in one place only. Nothing where it doesn't (they were edited, or there are two of them), or\n * where `from` has no such lines to find (the change only removed some).\n */\nfunction swapped(now: string, from: string, to: string): string | undefined {\n const [a, b, lines] = [from.split('\\n'), to.split('\\n'), now.split('\\n')];\n let head = 0;\n while (head < a.length && head < b.length && a[head] === b[head]) head++;\n let tail = 0;\n while (tail < a.length - head && tail < b.length - head && a.at(-1 - tail) === b.at(-1 - tail)) tail++;\n const theirs = a.slice(head, a.length - tail);\n if (theirs.length === 0) return undefined;\n const found = lines.flatMap((_, i) => (theirs.every((line, j) => lines[i + j] === line) ? [i] : []));\n if (found.length !== 1) return undefined;\n return [...lines.slice(0, found[0]), ...b.slice(head, b.length - tail), ...lines.slice(found[0]! + theirs.length)].join('\\n');\n}\n\nfunction write(path: string, text: string): void {\n mkdirSync(dirname(path), { recursive: true });\n writeFileSync(path, text);\n}\n","/**\n * The dev server's half of deictic, under `/__deictic/`: `read` and `apply` an op through a\n * plugin, `undo`, `redo` and `history`, and `open`, which opens a place in the editor. Written over\n * `Request` and `Response`, so each integration mounts them its own way (Vite as middleware), and\n * served from the page's own origin, so no token travels to the page. `undo`, `redo` and `history` are a\n * plugin's on an element where the request names them (as the popup does: its tab, its element), and\n * the whole history's where it doesn't.\n *\n * Everything but `open` and `history` writes or may, so only the page itself may send it: a POST of\n * JSON from the same origin, which a form or a script on another site can't send without asking first.\n *\n * Each plugin's own `routes` are under `plugins/<name>/`. A `GET` there reaches the plugin as it\n * comes; anything else only from the page's own origin, in whatever type it sends (an image, say).\n * Nothing is answered before every plugin's `setup` has run.\n */\nimport type { IncomingMessage, ServerResponse } from 'node:http';\n\nimport { type Loc, Refusal, type ServerPlugin, type Source, type Target } from '#src/index.ts';\n\nimport { History, type Scope } from './history.ts';\nimport { missingMessage } from './packages.ts';\nimport { setUp } from './plugins.ts';\nimport { applyEdits, resolveFile, sourceAt } from './source.ts';\n\nexport interface EndpointOptions {\n root: string;\n plugins: ServerPlugin[];\n /** The path the endpoints sit under, ending in `/`: `/` by default. */\n base?: string;\n /** Opens a place in the editor: a redirect to the dev server's own launcher. */\n open: (path: string, loc: Loc) => Response | Promise<Response>;\n history?: History;\n}\n\ninterface Body {\n plugin: string;\n target: Target;\n op?: unknown;\n}\n\nconst scopeOf = (plugin: string, { file, line, column }: Loc): Scope => ({ plugin, target: `${file}:${line}:${column}` });\n/** The scope an undo or a redo names, or none for the whole history. */\nconst scopeIn = ({ plugin, target }: Partial<Body>) =>\n plugin === undefined || target === undefined ? undefined : scopeOf(plugin, target.loc);\n\n/** Answers deictic's requests, and nothing for any other path. */\nexport function endpoints({ root, plugins, base = '/', open, history = new History(root, { plugins }) }: EndpointOptions) {\n const byName = new Map(plugins.map((p) => [p.name, p]));\n const prefix = `${base}__deictic/`;\n // Started now, awaited by every request: a plugin's API is there before anything asks for it.\n const ready = setUp(root, plugins);\n const gone = missingMessage(root, plugins);\n if (gone !== undefined) console.warn(gone);\n\n const pluginOf = (name: string) => {\n const plugin = byName.get(name);\n if (plugin === undefined) throw new Refusal(`no plugin \"${name}\" on the server: is it in the bundler plugin's \\`plugins\\`?`);\n return plugin;\n };\n\n const routes: Record<string, (body: Body) => Promise<unknown>> = {\n read: async ({ plugin, target }) => ({ model: await readOf(pluginOf(plugin), target) }),\n apply: async ({ plugin: name, target, op }) => {\n const plugin = pluginOf(name);\n if (plugin.apply === undefined) throw new Refusal(`${name} changes nothing from its panel: it has no \\`apply\\``);\n const source = sourceOf(target);\n const before = await readOf(plugin, target, source);\n const { file, line } = target.loc;\n const label = `${name} ${file}:${line}: ${plugin.describe?.(op, before) ?? 'edit'}`;\n const result = await plugin.apply(source, target, op);\n const scope = scopeOf(name, target.loc);\n if (!Array.isArray(result)) return { change: history.record(label, name, result.done, scope), model: await readOf(plugin, target) };\n // Edits to a file whose element isn't found would go who knows where: refused, as only they need it.\n if (source instanceof Refusal) throw source;\n const change = history.commit(label, applyEdits(source, result), scope);\n return { model: await readOf(plugin, target), change };\n },\n undo: async (body) => ({ change: await history.undo(scopeIn(body)) }),\n redo: async (body) => ({ change: await history.redo(scopeIn(body)) }),\n };\n // The source or why it can't be had, for the plugin to decide: only an edit to the file needs it, not a task.\n const sourceOf = (target: Target): Source | Refusal => {\n try {\n return sourceAt(root, target);\n } catch (e) {\n if (e instanceof Refusal) return e;\n throw e;\n }\n };\n // A plugin without `read` has no model, and no need for its element to be where the page says.\n const readOf = (plugin: ServerPlugin, target: Target, source?: Source | Refusal) =>\n plugin.read === undefined ? null : plugin.read(source ?? sourceOf(target), target);\n // One write at a time: a plugin's change may wait on the network, and an undo sent meanwhile must\n // take back that change, not the one before it.\n let queue: Promise<unknown> = Promise.resolve();\n const serially = <T>(run: () => Promise<T>): Promise<T> => {\n const next = queue.then(run, run);\n queue = next.catch(() => {});\n return next;\n };\n\n return async (req: Request): Promise<Response | undefined> => {\n const url = new URL(req.url);\n if (!url.pathname.startsWith(prefix)) return undefined;\n const route = url.pathname.slice(prefix.length);\n const origin = req.headers.get('origin');\n const sameOrigin = origin !== null && new URL(origin).host === url.host;\n try {\n const context = await ready;\n if (route.startsWith('plugins/')) {\n const [name = '', first = ''] = route.slice('plugins/'.length).split('/');\n const handle = byName.get(name)?.routes?.[first];\n if (handle === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'GET' && req.method !== 'HEAD' && !sameOrigin)\n return Response.json({ problem: `only the page itself may ${req.method} to ${name}` }, { status: 403 });\n return await handle(req, context);\n }\n const loc = {\n file: url.searchParams.get('file') ?? '',\n line: Number(url.searchParams.get('line')),\n column: Number(url.searchParams.get('column')),\n };\n if (route === 'history') {\n const plugin = url.searchParams.get('plugin');\n return Response.json(history.list(plugin === null ? undefined : scopeOf(plugin, loc)));\n }\n if (route === 'open') return await open(resolveFile(root, loc.file), loc);\n const handler = routes[route];\n if (handler === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'POST' || !sameOrigin || req.headers.get('content-type')?.startsWith('application/json') !== true)\n return Response.json({ problem: 'edits come from the page, as JSON' }, { status: 403 });\n const body = (await req.json()) as Body;\n return Response.json(await (route === 'read' ? handler(body) : serially(() => handler(body))));\n } catch (e) {\n if (e instanceof Refusal) return Response.json({ problem: e.message }, { status: 422 });\n return Response.json({ problem: e instanceof Error ? (e.stack ?? e.message) : String(e) }, { status: 500 });\n }\n };\n}\n\n/** A redirect within the page's origin, to a launcher the dev server answers itself. */\nexport const redirect = (path: string) => new Response(null, { status: 307, headers: { Location: path } });\n\n/**\n * The endpoints as Node middleware, for Vite's server. The request's host is the one the page was\n * served from: a proxy's `x-forwarded-host` before its own.\n */\nexport function nodeMiddleware(\n handle: (req: Request) => Promise<Response | undefined>,\n): (req: IncomingMessage, res: ServerResponse, next: () => void) => void {\n return (req, res, next) => {\n // Before reading the body, which a request for anything else leaves to whoever answers it.\n if (req.url?.includes('/__deictic/') !== true) return next();\n const forwarded = req.headers['x-forwarded-host'];\n const host = (Array.isArray(forwarded) ? forwarded[0] : forwarded) ?? req.headers.host ?? 'localhost';\n const headers = new Headers();\n for (const [name, value] of Object.entries(req.headers))\n for (const v of Array.isArray(value) ? value : value === undefined ? [] : [value]) headers.append(name, v);\n\n const chunks: Buffer[] = [];\n req.on('data', (chunk: Buffer) => chunks.push(chunk));\n req.on('end', () => {\n const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : Buffer.concat(chunks);\n handle(new Request(`http://${host}${req.url}`, { method: req.method, headers, body }))\n .then(async (response) => {\n if (response === undefined) return next();\n res.statusCode = response.status;\n response.headers.forEach((value, name) => res.setHeader(name, value));\n res.end(Buffer.from(await response.arrayBuffer()));\n })\n .catch((e: unknown) => {\n res.statusCode = 500;\n res.end(e instanceof Error ? e.message : String(e));\n });\n });\n };\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,YAAY,MAAc,MAAsB;CAC9D,MAAM,OAAO,QAAQ,MAAM,IAAI;CAC/B,MAAM,OAAO,SAAS,MAAM,IAAI;CAEhC,IAAI,SAAS,MAAM,KAAK,WAAW,IAAI,KAAK,WAAW,IAAI,KAAK,KAAK,MAAM,GAAG,CAAC,CAAC,SAAS,cAAc,GACrG,MAAM,IAAI,QAAQ,GAAG,KAAK,qCAAqC;CACjE,OAAO;AACT;AAEA,SAAgB,WAAW,MAAc,MAAsB;CAC7D,IAAI;EACF,OAAO,aAAa,YAAY,MAAM,IAAI,GAAG,MAAM;CACrD,SAAS,GAAG;EACV,IAAI,aAAa,SAAS,MAAM;EAChC,MAAM,IAAI,QAAQ,cAAc,KAAK,wCAAwC,EAAE,OAAO,EAAE,CAAC;CAC3F;AACF;;;;;AAMA,SAAgB,SAAS,MAAc,QAAwB;CAC7D,MAAM,EAAE,MAAM,MAAM,WAAW,OAAO;CACtC,MAAM,OAAO,WAAW,MAAM,IAAI;CAClC,MAAM,QAAQ,WAAW,IAAI;CAC7B,MAAM,SAAS,SAAS,OAAO,MAAM,MAAM;CAC3C,MAAM,EAAE,SAAS,aAAa,MAAM,KAAK,IAAI,IAAI,MAAM,MAAM,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI;CACzF,MAAM,SAAS,SAAS,QAAQ,OAAO,OAAO,EAAE,KAAK,GAAG,KAAK,SAAS,mBAAmB,GAAG,KAAK,SAAS,OAAO,GAAG;CACpH,MAAM,QAAQ,MAAM,OAAO;CAC3B,MAAM,SAAS,UAAU,KAAA,IAAY,CAAC,IAAI,OAAO,QAAQ,OAAO,GAAG,SA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Q;EAC1F,MAAM,UAAU,IAAI,QAAQ;EAC5B,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,IAAI,OAAO,GACpD,KAAK,MAAM,KAAK,MAAM,QAAQ,KAAK,IAAI,QAAQ,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,KAAK,GAAG,QAAQ,OAAO,MAAM,CAAC;EAE3G,MAAM,SAAmB,CAAC;EAC1B,IAAI,GAAG,SAAS,UAAkB,OAAO,KAAK,KAAK,CAAC;EACpD,IAAI,GAAG,aAAa;GAClB,MAAM,OAAO,IAAI,WAAW,SAAS,IAAI,WAAW,SAAS,KAAA,IAAY,OAAO,OAAO,MAAM;GAC7F,OAAO,IAAI,QAAQ,UAAU,OAAO,IAAI,OAAO;IAAE,QAAQ,IAAI;IAAQ;IAAS;GAAK,CAAC,CAAC,CAAC,CACnF,KAAK,OAAO,aAAa;IACxB,IAAI,aAAa,KAAA,GAAW,OAAO,KAAK;IACxC,IAAI,aAAa,SAAS;IAC1B,SAAS,QAAQ,SAAS,OAAO,SAAS,IAAI,UAAU,MAAM,KAAK,CAAC;IACpE,IAAI,IAAI,OAAO,KAAK,MAAM,SAAS,YAAY,CAAC,CAAC;GACnD,CAAC,CAAC,CACD,OAAO,MAAe;IACrB,IAAI,aAAa;IACjB,IAAI,IAAI,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;GACpD,CAAC;EACL,CAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"endpoints.js","names":[],"sources":["../../src/tools/source.ts","../../src/tools/history.ts","../../src/tools/endpoints.ts"],"sourcesContent":["/**\n * The source a server half reads: a target's file, parsed, and the opening tag the page's attribute\n * points at. Files are only ever read and written under the project's root, outside `node_modules`.\n */\nimport { readFileSync } from 'node:fs';\nimport { isAbsolute, relative, resolve, sep } from 'node:path';\n\nimport { Refusal, type Source, type Target, type TextEdit } from '#src/index.ts';\n\nimport { ASTRO, parseAstro, type Parsed } from './astro.ts';\nimport { isHost, lineStarts, offsetOf, openingsIn, parse } from './locate.ts';\n\n/** A file from the project's root, as an absolute path; refused anywhere the page has no business writing. */\nexport function resolveFile(root: string, file: string): string {\n const path = resolve(root, file);\n const from = relative(root, path);\n // `relative` gives an absolute path for another drive.\n if (from === '' || from.startsWith('..') || isAbsolute(from) || from.split(sep).includes('node_modules'))\n throw new Refusal(`${file} is not a file of this project's own`);\n return path;\n}\n\nexport function readSource(root: string, file: string): string {\n try {\n return readFileSync(resolveFile(root, file), 'utf8');\n } catch (e) {\n if (e instanceof Refusal) throw e;\n throw new Refusal(`can't read ${file}: has it moved since the page loaded?`, { cause: e });\n }\n}\n\n/**\n * The target's file and element, as they are on disk now. The element is the one the page's mark names, or else the\n * only one of its tag on that line: the page may count columns in code a plugin before deictic's changed.\n */\nexport function sourceAt(root: string, target: Target): Source {\n const { file, line, column } = target.loc;\n const code = readSource(root, file);\n const lines = lineStarts(code);\n const offset = offsetOf(lines, line, column);\n const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);\n const tagged = elements.filter((el) => isHost(el) && el.name.type === 'JSXIdentifier' && el.name.name === target.tag);\n const start = lines[line - 1];\n const onLine = start === undefined ? [] : tagged.filter((el) => el.start >= start && el.start < (lines[line] ?? Infinity));\n const element = tagged.find((el) => el.start === offset) ?? (onLine.length === 1 ? onLine[0] : undefined);\n if (element === undefined) throw new Refusal(notThere(target, code, lines, onLine.length));\n return { file, code, program, element, read: (other) => readSource(root, other) };\n}\n\n/** Why the page's element isn't in the file, from what the file has there: it may not have changed at all. */\nfunction notThere({ loc: { file, line, column }, tag }: Target, code: string, lines: number[], onLine: number): string {\n const start = lines[line - 1];\n const found =\n start === undefined\n ? `${file} has no line ${line}`\n : onLine === 0\n ? `line ${line} of ${file} has no <${tag}>: it reads \\`${clip(code.slice(start, (lines[line] ?? code.length + 1) - 1).trim())}\\``\n : `line ${line} of ${file} has ${onLine} <${tag}>s, none at column ${column}`;\n return `${found}. The page isn't running the file as it is: reload it, and if it says this again, a plugin before deictic's changes the file, so put deictic first`;\n}\n\nconst clip = (text: string) => (text.length > 80 ? `${text.slice(0, 79)}…` : text);\n\nfunction jsx(file: string, code: string): Parsed {\n const { program, errors } = parse(file, code);\n if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0]!.message})`);\n return { program, elements: openingsIn(program) };\n}\n\nfunction astro(root: string, file: string, code: string): Parsed {\n const parsed = parseAstro(root, code);\n if ('problem' in parsed) throw new Refusal(`${file} can't be read: ${parsed.problem}`);\n return parsed;\n}\n\n/** Each file's text after its edits, which must not overlap. */\nexport function applyEdits(source: Source, edits: TextEdit[]): Map<string, string> {\n const byFile = Map.groupBy(edits, (e) => e.file ?? source.file);\n const out = new Map<string, string>();\n for (const [file, list] of byFile) {\n const sorted = list.toSorted((a, b) => b.start - a.start);\n let code = file === source.file ? source.code : source.read(file);\n let floor = Infinity;\n for (const edit of sorted) {\n if (edit.end > floor) throw new Error(`deictic: edits to ${file} overlap at ${edit.end}`);\n code = code.slice(0, edit.start) + edit.text + code.slice(edit.end);\n floor = edit.start;\n }\n out.set(file, code);\n }\n return out;\n}\n","/**\n * Every change deictic made, to undo and redo. A change to files holds each file's whole text\n * before and after: source files are small, and the texts make undo exact without a diff to go stale.\n * A change a plugin made itself (`Done`) holds the plugin's name and its record, and undoing it is the\n * plugin's `undo`.\n *\n * Each change has a scope, the plugin and the element it was made on, and the popup undoes and redoes\n * within its own: the latest change of this tab on this element, not the latest of all. So a change\n * is taken back out of order, with later ones to the same file still in it. Then only the lines the\n * change wrote go back to what they were, where they're still in the file as it wrote them, once.\n *\n * Anything else is refused, not merged: a file whose lines were edited since has the editor's own undo\n * for it; and a redo likewise. A plugin's undo refuses on its own terms. Kept under `.deictic`, so it\n * outlives a restart of the dev server and stays out of git.\n */\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport { Refusal, type ServerPlugin } from '#src/index.ts';\n\nimport { keptIn } from './kept.ts';\nimport { resolveFile } from './source.ts';\n\nexport interface FileChange {\n file: string;\n /** The text before, or nothing for a file the change made. */\n before: string | null;\n after: string;\n}\n\n/** Whose a change is: the plugin whose tab made it, and the element it was open on, as `file:line:column`. */\nexport interface Scope {\n plugin: string;\n target: string;\n}\n\ninterface Base {\n id: number;\n at: string;\n label: string;\n /** None on a change made without one, which only an undo of the whole history reaches. */\n scope?: Scope;\n}\n\nexport type Change = Base & ({ files: FileChange[] } | { plugin: string; record: unknown });\n\n/** A change as the page lists it. `files` is empty for one a plugin made itself. */\nexport interface Summary {\n id: number;\n at: string;\n label: string;\n files: string[];\n}\n\nexport interface HistoryOptions {\n /** Whose `undo` and `redo` take back the changes they made themselves. */\n plugins?: ServerPlugin[];\n store?: string;\n}\n\nconst LIMIT = 200;\n\n/** Whether a change is in a scope: any is in none. */\nconst within = (scope: Scope | undefined) => (c: Change) =>\n scope === undefined || (c.scope?.plugin === scope.plugin && c.scope.target === scope.target);\n\nconst summary = (c: Change): Summary => ({ id: c.id, at: c.at, label: c.label, files: 'files' in c ? c.files.map((f) => f.file) : [] });\n\nexport class History {\n #done: Change[] = [];\n #undone: Change[] = [];\n readonly #root: string;\n readonly #store: string;\n readonly #plugins: Map<string, ServerPlugin>;\n\n constructor(root: string, { plugins = [], store = keptIn(root, 'history.json') }: HistoryOptions = {}) {\n this.#root = root;\n this.#store = store;\n this.#plugins = new Map(plugins.map((p) => [p.name, p]));\n if (!existsSync(store)) return;\n try {\n ({ done: this.#done, undone: this.#undone } = JSON.parse(readFileSync(store, 'utf8')) as { done: Change[]; undone: Change[] });\n } catch {\n // A history that doesn't read is one we start over, not one to stop the dev server for.\n }\n }\n\n /** Writes each file's new text and records it as one change. A redo after it, in its scope, is gone, as in any editor. */\n commit(label: string, texts: Map<string, string>, scope?: Scope): Summary {\n const files: FileChange[] = [];\n for (const [file, after] of texts) {\n const path = resolveFile(this.#root, file);\n const before = existsSync(path) ? readFileSync(path, 'utf8') : null;\n if (before !== after) files.push({ file, before, after });\n }\n if (files.length === 0) throw new Refusal('nothing to change: the source already says that');\n for (const f of files) write(resolveFile(this.#root, f.file), f.after);\n return this.#push({ label, files }, scope);\n }\n\n /** Records a change `plugin` made itself, with what its `undo` needs. */\n record(label: string, plugin: string, record: unknown, scope?: Scope): Summary {\n return this.#push({ label, plugin, record }, scope);\n }\n\n /** Takes back the latest change, of a scope where one is given. */\n async undo(scope?: Scope): Promise<Summary> {\n const change = this.#done.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to undo' : 'nothing to undo here');\n if ('files' in change) this.#put(change, 'after', 'before');\n else change.record = (await this.#pluginOf(change, 'undo').undo!(change.record)) ?? change.record;\n this.#done = this.#done.filter((c) => c !== change);\n this.#undone.push(change);\n this.#save();\n return summary(change);\n }\n\n /** Makes the change last undone again, of a scope where one is given. */\n async redo(scope?: Scope): Promise<Summary> {\n const change = this.#undone.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to redo' : 'nothing to redo here');\n if ('files' in change) this.#put(change, 'before', 'after');\n else change.record = await this.#pluginOf(change, 'redo').redo!(change.record);\n this.#undone = this.#undone.filter((c) => c !== change);\n this.#done.push(change);\n this.#save();\n return summary(change);\n }\n\n list(scope?: Scope): { done: Summary[]; undone: Summary[] } {\n return { done: this.#done.filter(within(scope)).map(summary), undone: this.#undone.filter(within(scope)).map(summary) };\n }\n\n #push(change: Omit<Base, 'id' | 'at'> & ({ files: FileChange[] } | { plugin: string; record: unknown }), scope?: Scope): Summary {\n const id = Math.max(0, ...[...this.#done, ...this.#undone].map((c) => c.id)) + 1;\n const made = { id, at: new Date().toISOString(), ...change, ...(scope === undefined ? {} : { scope }) };\n this.#done = [...this.#done, made].slice(-LIMIT);\n // What was undone in this scope can't be redone over the new change; another scope's still can.\n this.#undone = this.#undone.filter((c) => !within(scope)(c));\n this.#save();\n return summary(made);\n }\n\n #pluginOf(change: { label: string; plugin: string }, step: 'undo' | 'redo'): ServerPlugin {\n const plugin = this.#plugins.get(change.plugin);\n if (plugin?.[step] === undefined) {\n throw new Refusal(\n `can't ${step} \"${change.label}\": the ${change.plugin} plugin that made it isn't loaded, so add it back to \\`plugins\\``,\n );\n }\n return plugin;\n }\n\n /**\n * Puts each file's `to` text back, once every one of them still reads as its `from`, or still has the\n * lines that differ as `from` has them: then those lines alone change, and the rest stays as it is now.\n */\n #put(change: Base & { files: FileChange[] }, from: 'before' | 'after', to: 'before' | 'after'): void {\n const paths = change.files.map((f) => resolveFile(this.#root, f.file));\n const texts = change.files.map((f, i) => {\n const now = existsSync(paths[i]!) ? readFileSync(paths[i]!, 'utf8') : null;\n if (now === f[from]) return f[to];\n const text = now === null || f[from] === null || f[to] === null ? undefined : swapped(now, f[from], f[to]);\n if (text === undefined) {\n throw new Refusal(\n `${f.file} changed since \"${change.label}\" ${from === 'after' ? 'was made' : 'was undone'}: use the editor's undo there`,\n );\n }\n return text;\n });\n texts.forEach((text, i) => {\n if (text === null) rmSync(paths[i]!);\n else write(paths[i]!, text);\n });\n }\n\n #save(): void {\n write(this.#store, JSON.stringify({ done: this.#done, undone: this.#undone }));\n }\n}\n\n/**\n * `now` with the lines that differ between `from` and `to` put as `to` has them, where `now` has them as\n * `from` does, in one place only. Nothing where it doesn't (they were edited, or there are two of them), or\n * where `from` has no such lines to find (the change only removed some).\n */\nfunction swapped(now: string, from: string, to: string): string | undefined {\n const [a, b, lines] = [from.split('\\n'), to.split('\\n'), now.split('\\n')];\n let head = 0;\n while (head < a.length && head < b.length && a[head] === b[head]) head++;\n let tail = 0;\n while (tail < a.length - head && tail < b.length - head && a.at(-1 - tail) === b.at(-1 - tail)) tail++;\n const theirs = a.slice(head, a.length - tail);\n if (theirs.length === 0) return undefined;\n const found = lines.flatMap((_, i) => (theirs.every((line, j) => lines[i + j] === line) ? [i] : []));\n if (found.length !== 1) return undefined;\n return [...lines.slice(0, found[0]), ...b.slice(head, b.length - tail), ...lines.slice(found[0]! + theirs.length)].join('\\n');\n}\n\nfunction write(path: string, text: string): void {\n mkdirSync(dirname(path), { recursive: true });\n writeFileSync(path, text);\n}\n","/**\n * The dev server's half of deictic, under `/__deictic/`: `read` and `apply` an op through a\n * plugin, `undo`, `redo` and `history`, and `open`, which opens a place in the editor. Written over\n * `Request` and `Response`, so each integration mounts them its own way (Vite as middleware), and\n * served from the page's own origin, so no token travels to the page. `undo`, `redo` and `history` are a\n * plugin's on an element where the request names them (as the popup does: its tab, its element), and\n * the whole history's where it doesn't.\n *\n * Everything but `open` and `history` writes or may, so only the page itself may send it: a POST of\n * JSON from the same origin, which a form or a script on another site can't send without asking first.\n * `problem` is the page's way to report one (`Problem`): it and the server's own, and any request that fails with\n * something other than a `Refusal`, are said once and handed to the plugins that hear of them (`problems.ts`).\n *\n * Each plugin's own `routes` are under `plugins/<name>/`. A `GET` there reaches the plugin as it\n * comes; anything else only from the page's own origin, in whatever type it sends (an image, say).\n * Nothing is answered before every plugin's `setup` has run.\n */\nimport type { IncomingMessage, ServerResponse } from 'node:http';\n\nimport { type Loc, Refusal, type ServerPlugin, type Source, type Target } from '#src/index.ts';\n\nimport { History, type Scope } from './history.ts';\nimport { missingProblem } from './packages.ts';\nimport { setUp } from './plugins.ts';\nimport { messageOf, problemIn, reporter, stackOf } from './problems.ts';\nimport { applyEdits, resolveFile, sourceAt } from './source.ts';\n\nexport interface EndpointOptions {\n root: string;\n plugins: ServerPlugin[];\n /** The path the endpoints sit under, ending in `/`: `/` by default. */\n base?: string;\n /** Opens a place in the editor: a redirect to the dev server's own launcher. */\n open: (path: string, loc: Loc) => Response | Promise<Response>;\n history?: History;\n}\n\ninterface Body {\n plugin: string;\n target: Target;\n op?: unknown;\n}\n\nconst scopeOf = (plugin: string, { file, line, column }: Loc): Scope => ({ plugin, target: `${file}:${line}:${column}` });\n/** The scope an undo or a redo names, or none for the whole history. */\nconst scopeIn = ({ plugin, target }: Partial<Body>) =>\n plugin === undefined || target === undefined ? undefined : scopeOf(plugin, target.loc);\n\n/** Answers deictic's requests, and nothing for any other path. */\nexport function endpoints({ root, plugins, base = '/', open, history = new History(root, { plugins }) }: EndpointOptions) {\n const byName = new Map(plugins.map((p) => [p.name, p]));\n const prefix = `${base}__deictic/`;\n // What goes wrong that nothing in the page caused: said, and handed to the plugins that hear of it once set up.\n const report = reporter(plugins, () => ready);\n // Started now, awaited by every request: a plugin's API is there before anything asks for it.\n const ready = setUp(root, plugins, report);\n const gone = missingProblem(root, plugins);\n if (gone !== undefined) report(gone);\n\n const pluginOf = (name: string) => {\n const plugin = byName.get(name);\n if (plugin === undefined) throw new Refusal(`no plugin \"${name}\" on the server: is it in the bundler plugin's \\`plugins\\`?`);\n return plugin;\n };\n\n const routes: Record<string, (body: Body) => Promise<unknown>> = {\n read: async ({ plugin, target }) => ({ model: await readOf(pluginOf(plugin), target) }),\n apply: async ({ plugin: name, target, op }) => {\n const plugin = pluginOf(name);\n if (plugin.apply === undefined) throw new Refusal(`${name} changes nothing from its panel: it has no \\`apply\\``);\n const source = sourceOf(target);\n const before = await readOf(plugin, target, source);\n const { file, line } = target.loc;\n const label = `${name} ${file}:${line}: ${plugin.describe?.(op, before) ?? 'edit'}`;\n const result = await plugin.apply(source, target, op);\n const scope = scopeOf(name, target.loc);\n if (!Array.isArray(result)) return { change: history.record(label, name, result.done, scope), model: await readOf(plugin, target) };\n // Edits to a file whose element isn't found would go who knows where: refused, as only they need it.\n if (source instanceof Refusal) throw source;\n const change = history.commit(label, applyEdits(source, result), scope);\n return { model: await readOf(plugin, target), change };\n },\n undo: async (body) => ({ change: await history.undo(scopeIn(body)) }),\n redo: async (body) => ({ change: await history.redo(scopeIn(body)) }),\n };\n // The source or why it can't be had, for the plugin to decide: only an edit to the file needs it, not a task.\n const sourceOf = (target: Target): Source | Refusal => {\n try {\n return sourceAt(root, target);\n } catch (e) {\n if (e instanceof Refusal) return e;\n throw e;\n }\n };\n // A plugin without `read` has no model, and no need for its element to be where the page says.\n const readOf = (plugin: ServerPlugin, target: Target, source?: Source | Refusal) =>\n plugin.read === undefined ? null : plugin.read(source ?? sourceOf(target), target);\n // One write at a time: a plugin's change may wait on the network, and an undo sent meanwhile must\n // take back that change, not the one before it.\n let queue: Promise<unknown> = Promise.resolve();\n const serially = <T>(run: () => Promise<T>): Promise<T> => {\n const next = queue.then(run, run);\n queue = next.catch(() => {});\n return next;\n };\n\n return async (req: Request): Promise<Response | undefined> => {\n const url = new URL(req.url);\n if (!url.pathname.startsWith(prefix)) return undefined;\n const route = url.pathname.slice(prefix.length);\n const origin = req.headers.get('origin');\n const sameOrigin = origin !== null && new URL(origin).host === url.host;\n // What failed, for a problem's key: a plugin's route by its first segment, not the IDs after it.\n let where = route;\n let plugin: string | undefined;\n try {\n const context = await ready;\n if (route.startsWith('plugins/')) {\n const [name = '', first = ''] = route.slice('plugins/'.length).split('/');\n where = `plugins/${name}/${first}`;\n plugin = name;\n const handle = byName.get(name)?.routes?.[first];\n if (handle === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'GET' && req.method !== 'HEAD' && !sameOrigin)\n return Response.json({ problem: `only the page itself may ${req.method} to ${name}` }, { status: 403 });\n return await handle(req, context);\n }\n const loc = {\n file: url.searchParams.get('file') ?? '',\n line: Number(url.searchParams.get('line')),\n column: Number(url.searchParams.get('column')),\n };\n if (route === 'history') {\n const plugin = url.searchParams.get('plugin');\n return Response.json(history.list(plugin === null ? undefined : scopeOf(plugin, loc)));\n }\n if (route === 'open') return await open(resolveFile(root, loc.file), loc);\n const handler = routes[route];\n if (handler === undefined && route !== 'problem') return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'POST' || !sameOrigin || req.headers.get('content-type')?.startsWith('application/json') !== true)\n return Response.json({ problem: 'edits come from the page, as JSON' }, { status: 403 });\n if (handler === undefined) {\n const problem = problemIn(await req.json());\n if (problem === undefined) return Response.json({ problem: 'a problem has a key, a kind and a message' }, { status: 400 });\n report(problem);\n return Response.json({});\n }\n const body = (await req.json()) as Body;\n plugin = body.plugin;\n return Response.json(await (route === 'read' ? handler(body) : serially(() => handler(body))));\n } catch (e) {\n if (e instanceof Refusal) return Response.json({ problem: e.message }, { status: 422 });\n // Not a refusal, which says what to do instead: something broke, which no one in the page can fix.\n const message = messageOf(e);\n report({\n key: `error:${where}:${message.split('\\n', 1)[0]!.slice(0, 200)}`,\n kind: 'bug',\n ...(plugin === undefined ? {} : { plugin }),\n message: `${prefix}${where} failed: ${message}`,\n ...stackOf(e),\n });\n return Response.json({ problem: e instanceof Error ? (e.stack ?? e.message) : String(e) }, { status: 500 });\n }\n };\n}\n\n/** A redirect within the page's origin, to a launcher the dev server answers itself. */\nexport const redirect = (path: string) => new Response(null, { status: 307, headers: { Location: path } });\n\n/**\n * The endpoints as Node middleware, for Vite's server. The request's host is the one the page was\n * served from: a proxy's `x-forwarded-host` before its own.\n */\nexport function nodeMiddleware(\n handle: (req: Request) => Promise<Response | undefined>,\n): (req: IncomingMessage, res: ServerResponse, next: () => void) => void {\n return (req, res, next) => {\n // Before reading the body, which a request for anything else leaves to whoever answers it.\n if (req.url?.includes('/__deictic/') !== true) return next();\n const forwarded = req.headers['x-forwarded-host'];\n const host = (Array.isArray(forwarded) ? forwarded[0] : forwarded) ?? req.headers.host ?? 'localhost';\n const headers = new Headers();\n for (const [name, value] of Object.entries(req.headers))\n for (const v of Array.isArray(value) ? value : value === undefined ? [] : [value]) headers.append(name, v);\n\n const chunks: Buffer[] = [];\n req.on('data', (chunk: Buffer) => chunks.push(chunk));\n req.on('end', () => {\n const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : Buffer.concat(chunks);\n handle(new Request(`http://${host}${req.url}`, { method: req.method, headers, body }))\n .then(async (response) => {\n if (response === undefined) return next();\n res.statusCode = response.status;\n response.headers.forEach((value, name) => res.setHeader(name, value));\n res.end(Buffer.from(await response.arrayBuffer()));\n })\n .catch((e: unknown) => {\n res.statusCode = 500;\n res.end(e instanceof Error ? e.message : String(e));\n });\n });\n };\n}\n"],"mappings":";;;;;;;;;;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AI,aAAa;IACjB,IAAI,IAAI,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;GACpD,CAAC;EACL,CAAC;CACH;AACF"}
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -63,6 +63,29 @@ interface Done<Record = unknown> {
|
|
|
63
63
|
done: Record;
|
|
64
64
|
}
|
|
65
65
|
type Maybe<T> = T | Promise<T>;
|
|
66
|
+
/**
|
|
67
|
+
* Something of deictic's that went wrong, which nothing a person did in the page caused: a package the project
|
|
68
|
+
* hasn't installed, a plugin that failed. The dev server says it, and hands it to each plugin with a `problem`
|
|
69
|
+
* (tasks posts it to the board, for an agent to fix).
|
|
70
|
+
*/
|
|
71
|
+
interface Problem {
|
|
72
|
+
/**
|
|
73
|
+
* What tells it apart, and the same problem again from a new one: `packages:rrweb`, `setup:tailwind`. Never a
|
|
74
|
+
* time or an ID, so a problem that comes back is known.
|
|
75
|
+
*/
|
|
76
|
+
key: string;
|
|
77
|
+
/**
|
|
78
|
+
* `setup`: the project's to fix, as `message` says (install a package, configure a plugin). `bug`: deictic's own, or
|
|
79
|
+
* a plugin's, to report where it's made, not to patch where it's installed.
|
|
80
|
+
*/
|
|
81
|
+
kind: 'setup' | 'bug';
|
|
82
|
+
/** What went wrong, and the fix where there is one, as any problem message says it. */
|
|
83
|
+
message: string;
|
|
84
|
+
/** What more there is to look into: a stack. */
|
|
85
|
+
details?: string;
|
|
86
|
+
/** The plugin it's about, where it's one's: none for deictic's own. */
|
|
87
|
+
plugin?: string;
|
|
88
|
+
}
|
|
66
89
|
/**
|
|
67
90
|
* Each plugin's API to the others on the server, by name. A plugin adds its own, so `use` knows its type:
|
|
68
91
|
* `declare module 'deictic' { interface ServerApis { screenshots: Screenshots } }`.
|
|
@@ -76,10 +99,12 @@ interface ServerContext {
|
|
|
76
99
|
/** The project's root, as an absolute path. */
|
|
77
100
|
root: string;
|
|
78
101
|
/**
|
|
79
|
-
* Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded
|
|
80
|
-
* `needs` always is; any other may not be, so check.
|
|
102
|
+
* Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded (or its `setup` failed,
|
|
103
|
+
* which is reported). One the plugin `needs` always is loaded; any other may not be, so check.
|
|
81
104
|
*/
|
|
82
105
|
use: <Name extends string>(name: Name) => ApiOf<ServerApis, Name> | undefined;
|
|
106
|
+
/** Says a problem of the plugin's own, as deictic says its own: in the dev server's output, and to each plugin's `problem`. */
|
|
107
|
+
report: (problem: Problem) => void;
|
|
83
108
|
}
|
|
84
109
|
/**
|
|
85
110
|
* A route of the plugin's own, at `/__deictic/plugins/<name>/<route>`, and below it. A `GET` must
|
|
@@ -125,6 +150,11 @@ interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, Api = un
|
|
|
125
150
|
redo?(record: Record): Maybe<Record>;
|
|
126
151
|
/** Says what an op does, for the history: `className: px-2 → px-4`. */
|
|
127
152
|
describe?(op: Op, before: Model): string;
|
|
153
|
+
/**
|
|
154
|
+
* Hears each problem deictic or a plugin reports, on the server or in the page, after every `setup` has run: once
|
|
155
|
+
* per `key` while the dev server runs. Its own failure is only said, never reported again.
|
|
156
|
+
*/
|
|
157
|
+
problem?(problem: Problem): Maybe<void>;
|
|
128
158
|
}
|
|
129
159
|
declare const definePlugin: <Model, Op, Record = unknown, Api = unknown>(plugin: ServerPlugin<Model, Op, Record, Api>) => ServerPlugin<Model, Op, Record, Api>;
|
|
130
160
|
/** Where something is in an element, in CSS pixels from its top left. */
|
|
@@ -224,6 +254,8 @@ interface ClientContext {
|
|
|
224
254
|
use: <Name extends string>(name: Name) => ApiOf<ClientApis, Name> | undefined;
|
|
225
255
|
/** Asks one of this plugin's own routes, from the page: `request('shots', { method: 'POST', body: blob })`. */
|
|
226
256
|
request: (route: string, init?: RequestInit) => Promise<Response>;
|
|
257
|
+
/** Says a problem of the plugin's own to the dev server, as the server half's `report` does: its `plugin` is this one. */
|
|
258
|
+
report: (problem: Problem) => void;
|
|
227
259
|
/**
|
|
228
260
|
* Opens the popup on an element at a plugin's tab, as its shortcut would, or with `at` on a spot in it: the
|
|
229
261
|
* popup is then beside the spot, which is what's lit, and the tab's context has it. An element rendered again
|
|
@@ -352,5 +384,5 @@ interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {
|
|
|
352
384
|
mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;
|
|
353
385
|
}
|
|
354
386
|
declare const defineClientPlugin: <Model, Op, Api = unknown>(plugin: ClientPlugin<Model, Op, Api>) => ClientPlugin<Model, Op, Api>;
|
|
355
|
-
export {
|
|
387
|
+
export { Modifier as A, Target as C, TrayItem as D, Tray as E, defineClientPlugin as O, Standalone as S, ToolPanel as T, ServerApis as _, Done as a, Source as b, LightboxItem as c, PanelContext as d, Point as f, Route as g, Resumed as h, ClientPlugin as i, Shortcut as j, definePlugin as k, LightboxOptions as l, Refusal as m, ClientApis as n, Drawer as o, Problem as p, ClientContext as r, LightboxAction as s, ApiOf as t, Loc as u, ServerContext as v, TextEdit as w, Spot as x, ServerPlugin as y };
|
|
356
388
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/shortcut.ts","../../src/index.ts"],"mappings":";;;;;;;;;;KAUY;UAEK;;EAEf,YAAY;;EAEZ;;;UCYe;EACf;EACA;EACA;;;UAIe;EACf,KAAK;EACL;;;UAIe;EACf;EACA;EACA;EACA;;;UAIe;;EAEf;EACA;;EAEA,SAAS;;EAET,SAAS;;EAET,KAAK;;;;;;;KAQK,cAAc,SAAS,YAAY,WAAW,QAAQ;;cAGrD,gBAAgB;EAClB;;;;;;UAOM,KAAK;EACpB,MAAM;;KAGH,MAAM,KAAK,IAAI,QAAQ;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/shortcut.ts","../../src/index.ts"],"mappings":";;;;;;;;;;KAUY;UAEK;;EAEf,YAAY;;EAEZ;;;UCYe;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