@smartmemory/wiki-components 0.5.0 → 0.6.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.
Files changed (62) hide show
  1. package/README.md +14 -2
  2. package/package.json +26 -4
  3. package/src/data-client.d.ts +27 -1
  4. package/src/data-client.jsx +3 -0
  5. package/src/graph/components/wiki/DocCard.jsx +46 -0
  6. package/src/graph/components/wiki/GraphBreadcrumb.jsx +23 -0
  7. package/src/graph/components/wiki/GraphCanvas.jsx +663 -0
  8. package/src/graph/components/wiki/GraphCanvas3D.jsx +1366 -0
  9. package/src/graph/components/wiki/GraphDocPane.jsx +56 -0
  10. package/src/graph/components/wiki/GraphLegend.jsx +119 -0
  11. package/src/graph/components/wiki/GraphLevelPicker.jsx +35 -0
  12. package/src/graph/components/wiki/graph/FilterChips.jsx +45 -0
  13. package/src/graph/components/wiki/graph/Omnibox.jsx +74 -0
  14. package/src/graph/components/wiki/graph/badges.js +46 -0
  15. package/src/graph/components/wiki/graph/bubbles3d.js +95 -0
  16. package/src/graph/components/wiki/graph/canvasBase.js +138 -0
  17. package/src/graph/components/wiki/graph/containment.js +49 -0
  18. package/src/graph/components/wiki/graph/overlay.js +134 -0
  19. package/src/graph/components/wiki/graph/pixiBase.js +210 -0
  20. package/src/graph/components/wiki/graph/threeBase.js +231 -0
  21. package/src/graph/hooks/useDebounced.js +11 -0
  22. package/src/graph/host.jsx +56 -0
  23. package/src/graph/index.d.ts +26 -0
  24. package/src/graph/index.js +4 -0
  25. package/src/graph/lib/areaFamilies.js +32 -0
  26. package/src/graph/lib/camFollow.js +30 -0
  27. package/src/graph/lib/canvasPort.js +93 -0
  28. package/src/graph/lib/cardVisibility.js +58 -0
  29. package/src/graph/lib/docCard.js +28 -0
  30. package/src/graph/lib/forceWorker.js +123 -0
  31. package/src/graph/lib/forceWorker3d.js +136 -0
  32. package/src/graph/lib/graph3d.js +330 -0
  33. package/src/graph/lib/graphArrows.js +108 -0
  34. package/src/graph/lib/graphExplore.js +546 -0
  35. package/src/graph/lib/graphFind.js +46 -0
  36. package/src/graph/lib/graphLasso.js +44 -0
  37. package/src/graph/lib/graphLevels.js +367 -0
  38. package/src/graph/lib/graphOrient.js +145 -0
  39. package/src/graph/lib/graphPath.js +86 -0
  40. package/src/graph/lib/graphPin.js +48 -0
  41. package/src/graph/lib/graphPress.js +27 -0
  42. package/src/graph/lib/graphShell.js +296 -0
  43. package/src/graph/lib/graphTheme.js +50 -0
  44. package/src/graph/lib/graphView.js +343 -0
  45. package/src/graph/lib/graphViews.js +103 -0
  46. package/src/graph/lib/groupBubbles.js +128 -0
  47. package/src/graph/lib/hubLines.js +51 -0
  48. package/src/graph/lib/idleTurn.js +31 -0
  49. package/src/graph/lib/labelDepth.js +59 -0
  50. package/src/graph/lib/layoutClient.js +69 -0
  51. package/src/graph/lib/layoutEngine.js +184 -0
  52. package/src/graph/lib/linkWeight.js +67 -0
  53. package/src/graph/lib/orphanPull.js +10 -0
  54. package/src/graph/lib/perf.js +14 -0
  55. package/src/graph/lib/reducedMotion.js +36 -0
  56. package/src/graph/lib/robustFit.js +62 -0
  57. package/src/graph/lib/wikiGraph.js +298 -0
  58. package/src/graph/pages/GraphPage.jsx +703 -0
  59. package/src/index.d.ts +6 -1
  60. package/src/index.js +2 -1
  61. package/src/lib.js +3 -0
  62. package/src/parts/Markdown.jsx +22 -0
package/README.md CHANGED
@@ -26,7 +26,7 @@ npm install @smartmemory/wiki-components react react-dom date-fns lucide-react
26
26
 
27
27
  ## Contract
28
28
 
29
- `src/data-client.d.ts` is the contract: nine calls (`identity`, `featureHub`, `decisions`, `decisionsPage`, `sourcesPage`, `docsByArea`, `ledger`, `upcomingCalls`, `search`), the endpoint and
29
+ `src/data-client.d.ts` is the contract: twelve calls (`identity`, `featureHub`, `decisions`, `decisionsPage`, `sourcesPage`, `docsByArea`, `ledger`, `upcomingCalls`, `search`, `graphAll`, `graphPage`, `note`), the endpoint and
30
30
  request body each maps to on the wiki API, and the result types (from `wiki/contracts/query.schema.json`). The same list is
31
31
  runtime data in `DATA_CLIENT_CALLS`; `ui/test/wiki-components.test.jsx` pins the typed file, the table and the app's client
32
32
  to each other. `<WikiDataProvider>` refuses a client missing a method.
@@ -35,6 +35,7 @@ to each other. `<WikiDataProvider>` refuses a client missing a method.
35
35
 
36
36
  ```jsx
37
37
  import { WikiDataProvider, FeatureHub, Search, Decisions, Sources, AreaDocs, Ledger, wikiPath } from "@smartmemory/wiki-components";
38
+ import { GraphHost, GraphPage } from "@smartmemory/wiki-components/graph";
38
39
 
39
40
  <WikiDataProvider client={myClient}>
40
41
  <FeatureHub featureId="CORE-1" workspace="wiki-eng" />
@@ -45,6 +46,7 @@ import { WikiDataProvider, FeatureHub, Search, Decisions, Sources, AreaDocs, Led
45
46
  <Sources workspace="wiki-eng" />
46
47
  <AreaDocs area="search" workspace="wiki-eng" onNavigate={go} hrefFor={href} />
47
48
  <Ledger workspace="wiki-eng" />
49
+ <GraphHost value={{ workspace: "wiki-eng", useSearchParams, Link, useColorMode, aspectHint }}><GraphPage /></GraphHost>
48
50
  </WikiDataProvider>
49
51
  ```
50
52
 
@@ -69,6 +71,16 @@ import { WikiDataProvider, FeatureHub, Search, Decisions, Sources, AreaDocs, Led
69
71
  (`GET /feeds/upcoming_calls`), which resolves `{items, errors}`, or `null` when the host does not serve the feed (the
70
72
  section is then left out; an empty feed still shows "No upcoming calls."). The window is 30 days back to one day ahead of
71
73
  `now`, an optional prop (ms since the epoch) for tests, else the first render's time. Also exported: `LedgerTimeline`.
74
+ - `Graph` (its own entry, `@smartmemory/wiki-components/graph`, so a host that never draws it does not load it) is the wiki's
75
+ Graph screen as it ran in the `/ui/` app, moved with its bodies unchanged (COMPOSE-WIKI-GRAPH-1a): 2D, the WebGL 2D base and the
76
+ lazy 3D view, filters, paths, saved views and the doc pane. It takes everything the app used to give it through
77
+ `<GraphHost value={{ workspace, useSearchParams, Link, useColorMode, requestTreeSync?, aspectHint }}>`: the view state lives in
78
+ the URL, so the host supplies `useSearchParams` (react-router's, or any hook returning `[URLSearchParams, setter]`), a `Link`
79
+ taking `to`, the design system's `useColorMode`, and the words for the greyed aspect options. Its data is
80
+ `client.graphAll({workspace})` (`POST /query/graph`, `page: {all: true}`; a host without the mode rejects with `code`
81
+ `"invalid_request"` and the screen pages with `client.graphPage({workspace, cursor?, size?})`) and, for the doc pane,
82
+ `client.note({workspace, id})` (`GET /note?workspace=&id=`). Exports: `GraphPage`, `GraphHost`, `GRAPH_ASPECTS`, `wholeGraph`,
83
+ `resetWebGL2Probe`. The package root also exports `MD` and `MD_PLUGINS` (note text rendering) and `INPUT`.
72
84
  - `workspace` / `workspaces` are optional: without them a screen calls `client.identity()` and uses the caller's grants
73
85
  (FeatureHub the first one).
74
86
  - `onNavigate(target)` receives a plain left click on a link and the search box's submit. `hrefFor(target)` is each link's
@@ -76,7 +88,7 @@ import { WikiDataProvider, FeatureHub, Search, Decisions, Sources, AreaDocs, Led
76
88
 
77
89
  ## Host requirements
78
90
 
79
- - **Peers:** `react` and `react-dom` `>=18 <20`, `date-fns` 3, `lucide-react`. The package ships JSX source (no build step);
91
+ - **Peers:** `react` and `react-dom` `>=18 <20`, `date-fns` 3, `lucide-react`; for the Graph entry also `d3-force` 3, `d3-quadtree` 3, `react-markdown` 9 or 10 and `remark-gfm` 4 (the root entry needs `remark-gfm` for `MD_PLUGINS`), and the optional `pixi.js` 8 (WebGL 2D), `three` and `d3-force-3d` (3D). The package ships JSX source (no build step);
80
92
  a Vite host transforms it (installed from npm or linked). Consumed as `file:` dependency, its bare imports resolve from its real path, so a host outside
81
93
  this repo must list `react`, `react-dom` (and `lucide-react`, `date-fns`) in `resolve.dedupe` or it loads the wiki's
82
94
  React 18 copy next to its own.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@smartmemory/wiki-components",
3
- "version": "0.5.0",
4
- "description": "The wiki's feature hub and search screens as router-free React components fed by an injected DataClient (WIKI-UI-COMPONENTS-1). Ships JSX source for a bundler host (Vite).",
3
+ "version": "0.6.0",
4
+ "description": "The wiki's screens (feature hub, search, decisions, sources, docs, ledger, graph) as router-free React components fed by an injected DataClient (WIKI-UI-COMPONENTS-1). Ships JSX source for a bundler host (Vite).",
5
5
  "license": "BUSL-1.1",
6
6
  "author": "Regression Analytics LLC",
7
7
  "repository": {
@@ -20,6 +20,10 @@
20
20
  "types": "./src/index.d.ts",
21
21
  "default": "./src/index.js"
22
22
  },
23
+ "./graph": {
24
+ "types": "./src/graph/index.d.ts",
25
+ "default": "./src/graph/index.js"
26
+ },
23
27
  "./data-client": {
24
28
  "types": "./src/data-client.d.ts"
25
29
  },
@@ -34,7 +38,25 @@
34
38
  "react": ">=18 <20",
35
39
  "react-dom": ">=18 <20",
36
40
  "date-fns": "^3.6.0",
37
- "lucide-react": ">=0.475.0"
41
+ "lucide-react": ">=0.475.0",
42
+ "d3-force": "^3.0.0",
43
+ "d3-quadtree": "^3.0.1",
44
+ "react-markdown": ">=9 <11",
45
+ "remark-gfm": "^4.0.1",
46
+ "pixi.js": "^8.22.0",
47
+ "three": "0.186.1",
48
+ "d3-force-3d": "3.0.6"
38
49
  },
39
- "sideEffects": false
50
+ "sideEffects": false,
51
+ "peerDependenciesMeta": {
52
+ "pixi.js": {
53
+ "optional": true
54
+ },
55
+ "three": {
56
+ "optional": true
57
+ },
58
+ "d3-force-3d": {
59
+ "optional": true
60
+ }
61
+ }
40
62
  }
@@ -1,4 +1,4 @@
1
- // WIKI-UI-COMPONENTS-1: the DataClient contract. Every call the FeatureHub, Search, Decisions, Sources, AreaDocs and Ledger screens make, and nothing else.
1
+ // WIKI-UI-COMPONENTS-1: the DataClient contract. Every call the FeatureHub, Search, Decisions, Sources, AreaDocs, Ledger and Graph screens make, and nothing else.
2
2
  // A host (the wiki's /ui/ app, Compose's wiki tab) passes one object with these async methods to <WikiDataProvider>.
3
3
  // The components never fetch: each call below is the whole of their I/O.
4
4
  //
@@ -15,6 +15,9 @@
15
15
  // ledger POST /query/ledger {query: "ledger", workspace, filters: {from, to}, page: {size: 50, cursor?}} (sort is the host's: ts, newest first)
16
16
  // upcomingCalls GET /feeds/upcoming_calls?workspace= (none) -> data_envelope; an absent feed (the wiki answers 404 not_found) resolves to null
17
17
  // search POST /query/search {query: "search", workspace, filters: {q}, page: {}}
18
+ // graphAll POST /query/graph {query: "graph", workspace, filters: {}, page: {all: true}} (one-shot; a host without it rejects with code invalid_request)
19
+ // graphPage POST /query/graph {query: "graph", workspace, filters: {}, page: {size, cursor?}} (the paged fallback)
20
+ // note GET /note?workspace=&id= (none) -> {workspace, note, generated_at} (the Graph's doc pane)
18
21
  //
19
22
  // The same table is runtime data in data-client.jsx (DATA_CLIENT_CALLS); a test pins the two to each other.
20
23
  // A rejected call should reject with an Error carrying `code` (the query_error code) so the screens can show it.
@@ -118,6 +121,23 @@ export interface FeatureHubResult extends QueryResult<DocItem> {
118
121
  feature: FeatureItem | null;
119
122
  }
120
123
 
124
+ /** The graph query result: every doc of the workspace (`items`) and the links between them (`edges`). `revision`/`layout` come on the one-shot answer, `next_cursor` on a page. */
125
+ export interface GraphResult {
126
+ items: Record<string, unknown>[];
127
+ edges?: Record<string, unknown>[];
128
+ total?: number;
129
+ revision?: string;
130
+ layout?: unknown;
131
+ next_cursor?: string | null;
132
+ }
133
+
134
+ /** GET /note: one note with its text. */
135
+ export interface NoteResult {
136
+ workspace: Workspace;
137
+ note: { title?: string; type?: string; text?: string; [field: string]: unknown };
138
+ generated_at: string;
139
+ }
140
+
121
141
  /** x-named-queries.search.result (a grouped_result). */
122
142
  export interface SearchResult {
123
143
  groups: { label: string; items: SearchHit[]; total: number; next_cursor: string | null }[];
@@ -147,6 +167,12 @@ export interface DataClient {
147
167
  upcomingCalls(args: { workspace: Workspace }): Promise<UpcomingCalls | null>;
148
168
  /** POST /query/search, filters {q} (1 to 256 characters), page {}. One call per workspace searched. */
149
169
  search(args: { workspace: Workspace; q: string }): Promise<SearchResult>;
170
+ /** POST /query/graph, filters {}, page {all: true}: the whole workspace graph in one request. A host without the mode rejects with an Error whose `code` is "invalid_request" (the screen then pages with graphPage). */
171
+ graphAll(args: { workspace: Workspace }): Promise<GraphResult>;
172
+ /** POST /query/graph, filters {}, page {size, cursor?}: one page of the graph. `cursor` is the previous page's `next_cursor`, opaque. */
173
+ graphPage(args: { workspace: Workspace; cursor?: string; size?: number }): Promise<GraphResult>;
174
+ /** GET /note?workspace=&id=: one note with its text (the Graph's doc pane). */
175
+ note(args: { workspace: Workspace; id: string }): Promise<NoteResult>;
150
176
  }
151
177
 
152
178
  /** Where a screen asks the host to go (Search only; FeatureHub has no links). The host maps it to its own route
@@ -12,6 +12,9 @@ export const DATA_CLIENT_CALLS = [
12
12
  { method: "ledger", endpoint: "POST /query/ledger", query: "ledger", page: { size: 50 } },
13
13
  { method: "upcomingCalls", endpoint: "GET /feeds/upcoming_calls" },
14
14
  { method: "search", endpoint: "POST /query/search", query: "search", page: {} },
15
+ { method: "graphAll", endpoint: "POST /query/graph", query: "graph", page: { all: true } },
16
+ { method: "graphPage", endpoint: "POST /query/graph", query: "graph", page: { size: 200 } },
17
+ { method: "note", endpoint: "GET /note" },
15
18
  ];
16
19
 
17
20
  const Ctx = createContext(null);
@@ -0,0 +1,46 @@
1
+ import React, { useEffect, useRef } from "react";
2
+ import { Link } from "../../host";
3
+ import { docCardAt } from "../../lib/docCard";
4
+
5
+ /** The focused doc's card, drawn at its node in the 3D view (WIKI-GRAPH-EXPLORE-1b-SHELL B1). Each frame it asks the canvas for the
6
+ * node's `screenPositions` entry and moves itself with a style write (no React render per frame); it hides while the node is off-screen
7
+ * or behind the camera. Pin is left out as filed. `anchor` is the drawn id the card follows (docCard cardAnchor: the doc, or the collapsed folder drawn for it; null = hidden), `canvas` is the GraphCanvas3D ref, `to` the Open note link, `onPathTo(doc)` the Path to… action (round 3: starts the path lens from this doc).
8
+ * `shown` false fades it out (no fade under reduced motion) and makes it inert; `onHold` / `onRelease` fire as the pointer enters / leaves it and `onFocusIn` / `onFocusOut` as keyboard focus does (the auto-hide waits). */
9
+ export default function DocCard({ canvas, focus, anchor = focus?.id ?? null, to, onPathTo, shown = true, reduced = false, onHold, onRelease, onFocusIn, onFocusOut }) {
10
+ const box = useRef(null);
11
+ const id = anchor;
12
+ useEffect(() => {
13
+ const el = box.current;
14
+ if (!el) return undefined;
15
+ // Every imperative style the RAF writes is reset here first, so a same-mount change of anchor (including to null) never leaves the
16
+ // previous anchor's visibility or position on the element (React sees the same declarative style and would not reset it).
17
+ el.style.visibility = "hidden"; el.style.left = ""; el.style.top = "";
18
+ if (!id) return undefined;
19
+ let raf = 0, last = "";
20
+ const tick = () => {
21
+ raf = requestAnimationFrame(tick);
22
+ const parent = el.offsetParent || el.parentElement;
23
+ const w = parent?.clientWidth || 0, h = parent?.clientHeight || 0;
24
+ const p = canvas.current?.screenPositions?.([id])?.[0];
25
+ const at = docCardAt(p, el.offsetWidth, el.offsetHeight, w, h);
26
+ const key = at ? `${Math.round(at.left)},${Math.round(at.top)}` : "";
27
+ if (key === last) return;
28
+ last = key;
29
+ el.style.visibility = at ? "visible" : "hidden";
30
+ if (at) { el.style.left = `${at.left}px`; el.style.top = `${at.top}px`; }
31
+ };
32
+ raf = requestAnimationFrame(tick);
33
+ return () => cancelAnimationFrame(raf);
34
+ }, [canvas, id]);
35
+ if (!focus) return null;
36
+ return (
37
+ <div ref={box} data-testid="graph-doc-card" data-shown={shown ? "true" : "false"} style={{ visibility: "hidden", opacity: shown ? 1 : 0, transition: reduced ? "none" : "opacity 300ms" }}
38
+ inert={shown ? undefined : ""} onPointerEnter={onHold} onPointerLeave={onRelease} onFocus={onFocusIn} onBlur={onFocusOut}
39
+ className={`${shown ? "pointer-events-auto" : "pointer-events-none"} absolute left-0 top-0 z-10 w-64 max-w-[70%] rounded-lg border border-neutral-200/70 bg-ground/90 p-3 shadow-sm backdrop-blur`}>
40
+ <h2 className="text-base font-semibold text-ink">{focus.title}</h2>
41
+ <p className="mt-1 break-all font-mono text-xs text-neutral-500">{focus.folder || "(root)"}</p>
42
+ {focus.area && <p className="mt-1 text-xs text-ink2">area {focus.area}</p>}
43
+ <div className="mt-2 text-[13px]"><Link to={to} className="text-blue-600 hover:underline">Open note</Link>{onPathTo && <button type="button" onClick={() => onPathTo(focus)} className="ml-3 text-blue-600 hover:underline">Path to…</button>}</div>
44
+ </div>
45
+ );
46
+ }
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+
3
+ /** WIKI-GRAPH-LEVELS-1 c2: where the level view is. `crumbs` are the open folders, top-level first (`breadcrumb()` of the
4
+ * deepest one); "All" is always first. `onSelect(path)` collapses to that folder, `onSelect(null)` back to level 0. The
5
+ * current (last) entry is text, not a button. `all={false}` (the page has an auto-expanded base,
6
+ * WIKI-GRAPH-LEVELS-AUTOEXPAND-1) drops "All": the trail starts at the base, and `onSelect` is told the clicked path. A separate component so the later command palette can absorb it. */
7
+ export default function GraphBreadcrumb({ crumbs, onSelect, all = true }) {
8
+ const last = crumbs.length - 1;
9
+ const BTN = "rounded px-1 text-[13px] text-blue-600 hover:underline";
10
+ return (
11
+ <nav aria-label="Graph level" className="flex min-w-0 flex-wrap items-center gap-1 text-[13px] text-ink2">
12
+ {all && (last < 0 ? <span aria-current="location" className="px-1 text-ink">All</span> : <button type="button" onClick={() => onSelect(null)} className={BTN}>All</button>)}
13
+ {crumbs.map((c, i) => (
14
+ <React.Fragment key={c.path}>
15
+ {(all || i > 0) && <span aria-hidden="true" className="text-neutral-400">/</span>}
16
+ {i === last
17
+ ? <span aria-current="location" className="px-1 text-ink">{c.label}</span>
18
+ : <button type="button" onClick={() => onSelect(c.path)} className={BTN}>{c.label}</button>}
19
+ </React.Fragment>
20
+ ))}
21
+ </nav>
22
+ );
23
+ }