deictic 0.10.0 → 0.12.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 CHANGED
@@ -23,6 +23,10 @@ it adds, and what to add by hand where it can't (a config it can't read). Every
23
23
  and runs in the dev server only. deictic goes first among the plugins: one before it that changes a module would have
24
24
  the page point at that plugin's code, not the file.
25
25
 
26
+ `deictic/setup` is how `init` edits a config, for another tool's own setup: `addToConfig(file, code, entry)` adds
27
+ `entry.imports` after the config's and `entry.value` to its `list`, first or, with `last`, after the rest, or passes the
28
+ whole config to `wrap`. It answers nothing where it can't tell where, so the tool can print its snippet instead.
29
+
26
30
  ```ts
27
31
  // Vite, and anything on it (React Router, TanStack Start…): vite.config.ts
28
32
  import { deictic } from 'deictic/vite';
@@ -467,6 +471,9 @@ export default defineClientPlugin<Model, Op>({
467
471
  with anything but a `Refusal` are reported for it.
468
472
  - `setup` answers an API for other plugins, which reach it with `context.use(name)`. That's how tasks attaches
469
473
  screenshots and recordings.
474
+ - `context.onClose(callback)`, from `setup`, runs `callback` as the dev server closes: undo there what `setup` did beyond
475
+ the plugin, a global it set or a watcher it started. Vite and webpack close their servers; under Next and Bun the dev
476
+ server ends with its process, and nothing runs.
470
477
  - A change that isn't to a file answers `{ done: record }`, and the plugin's `undo` and `redo` get the record back.
471
478
  - Throw a `Refusal` for an op the plugin won't make. The panel shows its message.
472
479
  - An edit's `file` names another file under the root than the element's (a catalog's entry). One that isn't there is
@@ -476,6 +483,9 @@ export default defineClientPlugin<Model, Op>({
476
483
  tasks do. Text edits without it are refused.
477
484
  - `pointing(context)` on the page half draws what the plugin has on the page while a shortcut's keys are held, and
478
485
  answers what takes it away: tasks pins each task where its element is.
486
+ - `tag(context, at)` on the page half answers a tag of the plugin's own for what's under the pointer, at `at` in the
487
+ window's pixels, or nothing: `{ text, color }`, drawn in the caption after deictic's, white on `color` (deictic's
488
+ accent unset). prosebook's names the string's catalog key. It's asked on every move while pointing: keep it quick.
479
489
  - `pressed(context, element)` on the page half hears a shortcut's press on a marked element as it goes down, before
480
490
  the page's own handlers and before the popup takes the pointer and the focus: screenshots keeps the page as it is
481
491
  then. Keep it quick: the press waits on it.
@@ -8,7 +8,7 @@
8
8
  * Everything drawn sits in one shadow root, so neither the page's styles nor ours cross over. A
9
9
  * panel's undo and redo are its tab's on its element: the latest change that plugin made there.
10
10
  */
11
- import { C as Target, S as Standalone, c as LightboxItem, i as ClientPlugin, j as Shortcut } from "../shared/index.js";
11
+ import { M as Shortcut, S as Standalone, c as LightboxItem, i as ClientPlugin, w as Target } from "../shared/index.js";
12
12
  /**
13
13
  * Waveforms: a clip's, read off its audio, drawn as bars with what's played in the accent; and a mic's live,
14
14
  * a meter scrolling left as it hears. For the lightbox's player and whatever records the mic (the task
@@ -431,7 +431,7 @@ function spotlight(root) {
431
431
  textContent: text
432
432
  });
433
433
  return {
434
- point({ el, pointed, target, names, count }, glide = true) {
434
+ point({ el, pointed, target, names, count, tags = [] }, glide = true) {
435
435
  pointing = true;
436
436
  const box = el.getBoundingClientRect();
437
437
  const r = grown(box);
@@ -458,10 +458,19 @@ function spotlight(root) {
458
458
  from: `${target.loc.file}:${target.loc.line}`,
459
459
  opens: names.join(" / ")
460
460
  };
461
- const saying = JSON.stringify([texts, dim]);
461
+ const saying = JSON.stringify([
462
+ texts,
463
+ dim,
464
+ tags
465
+ ]);
462
466
  if (saying !== said) {
463
467
  said = saying;
464
- caption.replaceChildren(part("tag", texts.tag), ...texts.inside === "" ? [] : [part("dim", texts.inside)], part("", texts.from), ...dim.map((text) => part("dim", text)), ...names.length === 0 ? [] : [part("opens", texts.opens)]);
468
+ caption.replaceChildren(part("tag", texts.tag), ...tags.map(({ text, color }) => {
469
+ const own = part("tag", text);
470
+ if (color !== void 0) own.style.background = color;
471
+ own.style.color = "#fff";
472
+ return own;
473
+ }), ...texts.inside === "" ? [] : [part("dim", texts.inside)], part("", texts.from), ...dim.map((text) => part("dim", text)), ...names.length === 0 ? [] : [part("opens", texts.opens)]);
465
474
  }
466
475
  caption.classList.toggle("below", r.top < 40);
467
476
  caption.style.translate = `${Math.min(0, document.documentElement.clientWidth - 8 - r.left - caption.offsetWidth)}px`;
@@ -1721,12 +1730,24 @@ function start({ base, shortcut: own, plugins: given, server }) {
1721
1730
  const name = plugin.label ?? plugin.name;
1722
1731
  return [shortcut.button === "left" ? name : `${name} (${shortcut.button})`];
1723
1732
  });
1733
+ const at = pointer;
1734
+ const tags = given.flatMap(({ plugin }) => {
1735
+ if (plugin.tag === void 0) return [];
1736
+ try {
1737
+ const tag = plugin.tag(contextOf(plugin.name), at);
1738
+ return tag === void 0 ? [] : [tag];
1739
+ } catch (e) {
1740
+ report(failed(plugin.name, "tag what was pointed at", e));
1741
+ return [];
1742
+ }
1743
+ });
1724
1744
  lighting.point({
1725
1745
  el,
1726
1746
  ...hit?.pointed === void 0 ? {} : { pointed: hit.pointed },
1727
1747
  target,
1728
1748
  names,
1729
- count: sameAs(el).length
1749
+ count: sameAs(el).length,
1750
+ tags
1730
1751
  }, glide);
1731
1752
  };
1732
1753
  const update = (e) => {