sanity-plugin-graph-view 5.0.12 → 5.0.14

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.
@@ -1,302 +1,286 @@
1
+ import { useEffect, useState } from "react";
2
+ import { useClient, useUserColorManager } from "sanity";
3
+ import { useRouter } from "sanity/router";
1
4
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { black, gray, white, COLOR_HUES, hues } from "@sanity/color";
5
+ import { COLOR_HUES, black, gray, hues, white } from "@sanity/color";
3
6
  import { useTheme } from "@sanity/ui";
4
7
  import BezierEasing from "bezier-easing";
5
8
  import deepEqual from "deep-equal";
6
9
  import { rgba } from "polished";
7
- import { useState, useEffect } from "react";
8
10
  import ForceGraph2D from "react-force-graph-2d";
9
- import { useUserColorManager, useClient } from "sanity";
10
- import { useRouter } from "sanity/router";
11
11
  import { v4 } from "uuid";
12
12
  import { styled } from "styled-components";
13
- const GraphRoot = /* @__PURE__ */ styled.div.withConfig({
14
- displayName: "GraphRoot",
15
- componentId: "sc-vxc9wk-0"
16
- })(["font-family:", ";position:absolute;top:0;left:0;width:100%;height:100%;background:", ";"], ({
17
- theme
18
- }) => theme.fonts.text.family, black.hex), GraphWrapper = /* @__PURE__ */ styled.div.withConfig({
19
- displayName: "GraphWrapper",
20
- componentId: "sc-vxc9wk-1"
21
- })(["position:relative;width:100%;height:100%;"]), HoverNode = /* @__PURE__ */ styled.div.withConfig({
22
- displayName: "HoverNode",
23
- componentId: "sc-vxc9wk-2"
24
- })(["font-family:", ";display:none;position:absolute;bottom:", "px;left:50%;transform:translate3d(-50%,0,0);background:var(--component-bg);border-radius:", "px;padding:", "px;z-index:1000;&:empty{display:none;}"], ({
25
- theme
26
- }) => theme.fonts.text.family, ({
27
- theme
28
- }) => theme.space[0], ({
29
- theme
30
- }) => theme.radius[2], ({
31
- theme
32
- }) => theme.space[2]), Legend = /* @__PURE__ */ styled.div.withConfig({
33
- displayName: "Legend",
34
- componentId: "sc-vxc9wk-3"
35
- })(["color:#ccc;position:absolute;top:", "px;left:", "px;& > div{margin:5px 0;}"], ({
36
- theme
37
- }) => theme.space[4], ({
38
- theme
39
- }) => theme.space[4]), LegendRow = /* @__PURE__ */ styled.div.withConfig({
40
- displayName: "LegendRow",
41
- componentId: "sc-vxc9wk-4"
42
- })(["display:flex;"]), LegendBadge = /* @__PURE__ */ styled.div.withConfig({
43
- displayName: "LegendBadge",
44
- componentId: "sc-vxc9wk-5"
45
- })(["width:1.25em;height:1.25em;background:currentColor;border-radius:50%;margin-right:", "px;"], ({
46
- theme
47
- }) => theme.space[2]);
13
+ const GraphRoot = styled.div.withConfig({
14
+ displayName: "GraphRoot",
15
+ componentId: "sc-kbb958-0"
16
+ })`font-family:${({ theme }) => theme.fonts.text.family};position:absolute;top:0;left:0;width:100%;height:100%;background:${black.hex};`, GraphWrapper = styled.div.withConfig({
17
+ displayName: "GraphWrapper",
18
+ componentId: "sc-kbb958-1"
19
+ })`position:relative;width:100%;height:100%;`, HoverNode = styled.div.withConfig({
20
+ displayName: "HoverNode",
21
+ componentId: "sc-kbb958-2"
22
+ })`font-family:${({ theme }) => theme.fonts.text.family};display:none;position:absolute;bottom:${({ theme }) => theme.space[0]}px;left:50%;transform:translate3d(-50%,0,0);background:var(--component-bg);border-radius:${({ theme }) => theme.radius[2]}px;padding:${({ theme }) => theme.space[2]}px;z-index:1000;&:empty{display:none;}`, Legend = styled.div.withConfig({
23
+ displayName: "Legend",
24
+ componentId: "sc-kbb958-3"
25
+ })`color:#ccc;position:absolute;top:${({ theme }) => theme.space[4]}px;left:${({ theme }) => theme.space[4]}px;& > div{margin:5px 0;}`, LegendRow = styled.div.withConfig({
26
+ displayName: "LegendRow",
27
+ componentId: "sc-kbb958-4"
28
+ })`display:flex;`, LegendBadge = styled.div.withConfig({
29
+ displayName: "LegendBadge",
30
+ componentId: "sc-kbb958-5"
31
+ })`width:1.25em;height:1.25em;background:currentColor;border-radius:50%;margin-right:${({ theme }) => theme.space[2]}px;`;
48
32
  function sizeOf(value) {
49
- return value === null ? 0 : typeof value == "object" ? Object.entries(value).reduce((total, [k, v]) => total + sizeOf(k) + sizeOf(v), 0) : Array.isArray(value) ? Object.entries(value).reduce((total, v) => total + sizeOf(v), 0) : typeof value == "string" ? value.length : 1;
33
+ return value === null ? 0 : typeof value == "object" ? Object.entries(value).reduce((total, [k, v]) => total + sizeOf(k) + sizeOf(v), 0) : Array.isArray(value) ? Object.entries(value).reduce((total, v) => total + sizeOf(v), 0) : typeof value == "string" ? value.length : 1;
50
34
  }
51
35
  function loadImage(url, w, h) {
52
- return new Promise((resolve) => {
53
- const img = new Image(w, h);
54
- img.onload = () => {
55
- resolve(img);
56
- }, img.onerror = (event) => {
57
- console.error("Image error", event), resolve(null);
58
- }, img.src = url;
59
- });
36
+ return new Promise((resolve) => {
37
+ let img = new Image(w, h);
38
+ img.onload = () => {
39
+ resolve(img);
40
+ }, img.onerror = (event) => {
41
+ console.error("Image error", event), resolve(null);
42
+ }, img.src = url;
43
+ });
60
44
  }
61
45
  function sortBy(array, f) {
62
- return array.sort((a, b) => {
63
- const va = f(a), vb = f(b);
64
- return va < vb ? -1 : va > vb ? 1 : 0;
65
- });
46
+ return array.sort((a, b) => {
47
+ let va = f(a), vb = f(b);
48
+ return va < vb ? -1 : +(va > vb);
49
+ });
66
50
  }
67
51
  function truncate(s, limit) {
68
- return s.length > limit ? `${s.substring(0, limit)}\u2026` : s;
52
+ return s.length > limit ? `${s.substring(0, limit)}…` : s;
69
53
  }
70
- const DEFAULT_QUERY = `
71
- *[
72
- !(_id in path("_.*")) &&
73
- !(_type match "system.*") &&
74
- !(_type match "sanity.*")
75
- ]
76
- `, fadeEasing = BezierEasing(0, 0.9, 1, 1), softEasing = BezierEasing(0.25, 0.1, 0, 1), idleTimeout = 1e4, imageSize = 40;
54
+ const fadeEasing = BezierEasing(0, .9, 1, 1), softEasing = BezierEasing(.25, .1, 0, 1), idleTimeout = 1e4;
77
55
  function getTopDocTypes(counts) {
78
- return sortBy(Object.keys(counts), (docType) => counts[docType] || 0).reverse().slice(0, 10);
56
+ return sortBy(Object.keys(counts), (docType) => counts[docType] || 0).reverse().slice(0, 10);
79
57
  }
80
58
  function formatDocType(docType) {
81
- return (docType.substring(0, 1).toUpperCase() + docType.substring(1)).replace(/\./g, " ").replace(/[A-Z]/g, " $&").trim();
59
+ return (docType.substring(0, 1).toUpperCase() + docType.substring(1)).replace(/\./g, " ").replace(/[A-Z]/g, " $&").trim();
82
60
  }
83
61
  function getDocTypeCounts(docs) {
84
- const types = {};
85
- for (const doc of docs)
86
- types[doc._type] = (types[doc._type] || 0) + 1;
87
- return types;
62
+ let types = {};
63
+ for (let doc of docs) types[doc._type] = (types[doc._type] || 0) + 1;
64
+ return types;
88
65
  }
89
66
  function labelFor(doc) {
90
- return `${doc.title || doc.name || doc._id}`.trim();
67
+ return `${doc.title || doc.name || doc._id}`.trim();
91
68
  }
92
69
  function valueFor(doc, maxSize) {
93
- return 5 + 100 * (sizeOf(doc) / maxSize);
70
+ return 5 + 100 * (sizeOf(doc) / maxSize);
94
71
  }
95
72
  function findRefs(obj, dest = []) {
96
- if (obj !== null) {
97
- if (typeof obj == "object")
98
- for (const [k, v] of Object.entries(obj))
99
- k === "_ref" && typeof v == "string" && v.length > 0 && dest.push(stripDraftId(v)), findRefs(v, dest);
100
- else if (Array.isArray(obj))
101
- for (const v of obj)
102
- findRefs(v, dest);
103
- }
104
- return dest;
73
+ if (obj !== null) {
74
+ if (typeof obj == "object") for (let [k, v] of Object.entries(obj)) k === "_ref" && typeof v == "string" && v.length > 0 && dest.push(stripDraftId(v)), findRefs(v, dest);
75
+ else if (Array.isArray(obj)) for (let v of obj) findRefs(v, dest);
76
+ }
77
+ return dest;
105
78
  }
106
79
  function stripDraftId(id) {
107
- return id.replace(/^drafts\./, "");
80
+ return id.replace(/^drafts\./, "");
108
81
  }
109
82
  function deduplicateDrafts(docs) {
110
- const deduped = {};
111
- for (const doc of docs)
112
- doc._id.startsWith("drafts.") || (deduped[doc._id] = doc);
113
- for (const doc of docs)
114
- if (doc._id.startsWith("drafts.")) {
115
- const id = stripDraftId(doc._id);
116
- deduped[id] = Object.assign(doc, {
117
- _id: id
118
- });
119
- }
120
- return Object.values(deduped);
121
- }
122
- class Users {
123
- _users = [];
124
- async getById(id, client) {
125
- let user = this._users.find((u) => u._id === id);
126
- return user || (user = await client.users.getById(id), this._users.push(user), user.image = await loadImage(user.imageUrl || "https://raw.githubusercontent.com/sanity-io/sanity-plugin-graph-view/main/assets/head-silhouette.jpg", imageSize, imageSize)), user;
127
- }
128
- }
129
- class Session {
130
- id = null;
131
- user = null;
132
- doc = null;
133
- lastActive = 0;
134
- startTime = 0;
135
- angle = 0;
136
- }
137
- class GraphData {
138
- sessions = [];
139
- constructor(docs = []) {
140
- const docsById = {};
141
- for (const doc of docs)
142
- docsById[doc._id] = doc;
143
- this.data = {
144
- nodes: docs.map((d) => Object.assign({
145
- id: d._id,
146
- type: "document",
147
- doc: d
148
- })),
149
- links: docs.flatMap((doc) => findRefs(doc).map((ref) => ({
150
- source: doc._id,
151
- target: ref
152
- }))).filter((link) => docsById[link.source] && docsById[link.target])
153
- };
154
- }
155
- setSession(user, docNode) {
156
- let session = this.sessions.find((s) => s.user.id === user.id && s.doc?._id === docNode.doc._id);
157
- session || (session = new Session(), session.id = v4(), session.user = user, session.startTime = Date.now(), session.doc = docNode.doc, session.angle = Math.random() * 2 * Math.PI, this.sessions.push(session)), session.lastActive = Date.now();
158
- }
159
- reapSessions() {
160
- for (let i = 0; i < this.sessions.length; i++) {
161
- const session = this.sessions[i];
162
- Date.now() - session.lastActive > idleTimeout && (this.sessions = [...this.sessions.slice(0, i), ...this.sessions.slice(i + 1)], i--);
163
- }
164
- }
165
- clone() {
166
- const copy = new GraphData();
167
- return Object.assign(copy, this), copy.data = {
168
- nodes: [...this.data.nodes],
169
- links: [...this.data.links]
170
- }, copy;
171
- }
83
+ let deduped = {};
84
+ for (let doc of docs) doc._id.startsWith("drafts.") || (deduped[doc._id] = doc);
85
+ for (let doc of docs) if (doc._id.startsWith("drafts.")) {
86
+ let id = stripDraftId(doc._id);
87
+ deduped[id] = Object.assign(doc, { _id: id });
88
+ }
89
+ return Object.values(deduped);
172
90
  }
91
+ var Users = class {
92
+ _users = [];
93
+ async getById(id, client) {
94
+ let user = this._users.find((u) => u._id === id);
95
+ return user || (user = await client.users.getById(id), this._users.push(user), user.image = await loadImage(user.imageUrl || "https://raw.githubusercontent.com/sanity-io/sanity-plugin-graph-view/main/assets/head-silhouette.jpg", 40, 40)), user;
96
+ }
97
+ }, Session = class {
98
+ id = null;
99
+ user = null;
100
+ doc = null;
101
+ lastActive = 0;
102
+ startTime = 0;
103
+ angle = 0;
104
+ }, GraphData = class GraphData {
105
+ sessions = [];
106
+ data;
107
+ constructor(docs = []) {
108
+ let docsById = {};
109
+ for (let doc of docs) docsById[doc._id] = doc;
110
+ this.data = {
111
+ nodes: docs.map((d) => Object.assign({
112
+ id: d._id,
113
+ type: "document",
114
+ doc: d
115
+ })),
116
+ links: docs.flatMap((doc) => findRefs(doc).map((ref) => ({
117
+ source: doc._id,
118
+ target: ref
119
+ }))).filter((link) => docsById[link.source] && docsById[link.target])
120
+ };
121
+ }
122
+ setSession(user, docNode) {
123
+ let session = this.sessions.find((s) => s.user.id === user.id && s.doc?._id === docNode.doc._id);
124
+ session || (session = new Session(), session.id = v4(), session.user = user, session.startTime = Date.now(), session.doc = docNode.doc, session.angle = Math.random() * 2 * Math.PI, this.sessions.push(session)), session.lastActive = Date.now();
125
+ }
126
+ reapSessions() {
127
+ for (let i = 0; i < this.sessions.length; i++) {
128
+ let session = this.sessions[i];
129
+ Date.now() - session.lastActive > idleTimeout && (this.sessions = [...this.sessions.slice(0, i), ...this.sessions.slice(i + 1)], i--);
130
+ }
131
+ }
132
+ clone() {
133
+ let copy = new GraphData();
134
+ return Object.assign(copy, this), copy.data = {
135
+ nodes: [...this.data.nodes],
136
+ links: [...this.data.links]
137
+ }, copy;
138
+ }
139
+ };
173
140
  const users = new Users();
174
- function GraphView({
175
- tool: {
176
- options: props
177
- }
178
- }) {
179
- const query = props.query || DEFAULT_QUERY, apiVersion = props.apiVersion ?? "2022-09-01", userColorManager = useUserColorManager(), [maxSize, setMaxSize] = useState(0), [hoverNode, setHoverNode] = useState(null), [documents, setDocuments] = useState([]), [docTypes, setDocTypes] = useState({}), [graph, setGraph] = useState(() => new GraphData()), router = useRouter(), client = useClient({
180
- apiVersion
181
- });
182
- useEffect(() => {
183
- client.fetch(query).then((_docs) => {
184
- const docs = deduplicateDrafts(_docs);
185
- setMaxSize(Math.max(...docs.map(sizeOf))), setDocuments(docs), setDocTypes(getDocTypeCounts(docs)), setGraph(new GraphData(docs));
186
- });
187
- }, [client, query]), useEffect(() => {
188
- const subscription = client.listen(query, {}, {}).subscribe(async (update) => {
189
- if (update.type !== "mutation") return;
190
- const doc = update.result;
191
- if (doc) {
192
- doc._id = stripDraftId(doc._id);
193
- const docsById = {};
194
- for (const d of documents)
195
- docsById[d._id] = d;
196
- let oldDoc;
197
- const docs_0 = [...documents], idx = documents.findIndex((d_0) => d_0._id === doc._id);
198
- idx >= 0 ? (oldDoc = docs_0[idx], docs_0[idx] = doc) : docs_0.push(doc), setDocuments(docs_0), setDocTypes(getDocTypeCounts(docs_0)), setMaxSize(Math.max(...docs_0.map(sizeOf)));
199
- const newGraph = graph.clone(), oldRefs = findRefs(oldDoc || {}).filter((id) => id === doc._id || docsById[id] !== null), newRefs = findRefs(doc).filter((id_0) => id_0 === doc._id || docsById[id_0] !== null);
200
- let graphChanged = !deepEqual(oldRefs, newRefs);
201
- graphChanged && (newGraph.data.links = newGraph.data.links.filter((l) => l.source.id !== doc._id).concat(newRefs.map((ref) => ({
202
- source: doc._id,
203
- target: ref
204
- }))));
205
- let docNode;
206
- const nodeIdx = graph.data.nodes.findIndex((n) => n.doc && n.doc._id === doc._id);
207
- nodeIdx >= 0 ? (docNode = graph.data.nodes[nodeIdx], docNode.doc = doc) : (docNode = {
208
- id: doc._id,
209
- type: "document",
210
- doc
211
- }, newGraph.data.nodes.push(docNode), graphChanged = !0), graphChanged && setGraph(newGraph);
212
- const user = await users.getById(update.identity, client);
213
- graph.setSession(user, docNode);
214
- } else if (update.transition === "disappear") {
215
- const docId = stripDraftId(update.documentId), docs_1 = documents.filter((d_1) => d_1._id !== docId);
216
- setDocuments(docs_1), setDocTypes(getDocTypeCounts(docs_1)), setMaxSize(Math.max(...docs_1.map(sizeOf)));
217
- const newGraph_0 = graph.clone();
218
- newGraph_0.data.links = newGraph_0.data.links.filter((l_0) => l_0.source.id !== docId && l_0.target.id !== docId), newGraph_0.data.nodes = newGraph_0.data.nodes.filter((n_0) => n_0.id !== docId), setGraph(newGraph_0);
219
- }
220
- });
221
- return () => {
222
- subscription.unsubscribe();
223
- };
224
- }, [client, query, documents, graph]), useEffect(() => {
225
- const interval = setInterval(() => graph.reapSessions(), 1e3);
226
- return () => clearInterval(interval);
227
- }, [graph]);
228
- const theme = useTheme().sanity;
229
- return /* @__PURE__ */ jsx(GraphWrapper, { theme, children: /* @__PURE__ */ jsxs(GraphRoot, { theme, children: [
230
- /* @__PURE__ */ jsx(Legend, { theme, children: getTopDocTypes(docTypes).map((docType) => /* @__PURE__ */ jsxs(LegendRow, { className: "legend__row", style: {
231
- color: getDocTypeColor(docType).fill
232
- }, children: [
233
- /* @__PURE__ */ jsx(LegendBadge, { theme }),
234
- /* @__PURE__ */ jsx("div", { children: formatDocType(docType) })
235
- ] }, docType)) }),
236
- hoverNode && /* @__PURE__ */ jsx(HoverNode, { theme, children: labelFor(hoverNode.doc) }),
237
- /* @__PURE__ */ jsx(ForceGraph2D, { graphData: graph.data, nodeAutoColorBy: "group", enableNodeDrag: !1, onNodeHover: (node) => setHoverNode(node), onNodeClick: (node_0) => {
238
- router.navigateIntent("edit", {
239
- id: node_0.doc._id,
240
- documentType: node_0.doc._type
241
- });
242
- }, linkColor: () => rgba(gray[500].hex, 0.25), nodeLabel: () => "", nodeRelSize: 1, nodeVal: (node_1) => valueFor(node_1.doc, maxSize), onRenderFramePost: (ctx, globalScale) => {
243
- for (const session of graph.sessions) {
244
- const node_2 = graph.data.nodes.find((n_1) => n_1.doc && n_1.doc._id === session?.doc?._id);
245
- if (node_2) {
246
- const idleFactorRange = idleTimeout, angle = session.angle, radius = Math.sqrt(valueFor(node_2.doc, maxSize)), image = session.user.image, userColor = userColorManager.get(session.user.displayName).tints[400].hex, distance = radius * globalScale + 40, imgW = image ? image.width : 0, imgH = image ? image.height : 0, x = node_2.x + Math.sin(angle) * distance / globalScale, y = node_2.y + Math.cos(angle) * distance / globalScale;
247
- ctx.save();
248
- try {
249
- if (ctx.globalAlpha = fadeEasing(1 - Math.min(idleFactorRange, Date.now() - session.lastActive) / idleFactorRange), ctx.font = `bold ${Math.round(12 / globalScale)}px sans-serif`, ctx.beginPath(), ctx.strokeStyle = rgba(white.hex, 1), ctx.lineWidth = 2 / globalScale, ctx.moveTo(node_2.x + Math.sin(angle) * (distance - imgW / 2) / globalScale, node_2.y + Math.cos(angle) * (distance - imgH / 2) / globalScale), ctx.lineTo(node_2.x + Math.sin(angle) * radius, node_2.y + Math.cos(angle) * radius), ctx.stroke(), ctx.beginPath(), ctx.strokeStyle = rgba(white.hex, 1), ctx.lineWidth = 2 / globalScale, ctx.arc(node_2.x, node_2.y, radius, 0, 2 * Math.PI, !1), ctx.stroke(), image) {
250
- ctx.save();
251
- try {
252
- const f = softEasing(Math.max(0, (700 - (Date.now() - session.startTime)) / 700));
253
- f > 0 && (ctx.beginPath(), ctx.fillStyle = rgba(userColor, f), ctx.arc(x, y, (imgW / 2 + 10) / globalScale, 0, 2 * Math.PI, !1), ctx.fill()), ctx.beginPath(), ctx.fillStyle = rgba(white.hex, 1), ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, !1), ctx.clip(), ctx.drawImage(image, x - imgW / globalScale / 2, y - imgH / globalScale / 2, imgW / globalScale, imgH / globalScale), ctx.strokeStyle = black.hex, ctx.lineWidth = 6 / globalScale, ctx.stroke(), ctx.strokeStyle = userColor, ctx.lineWidth = 4 / globalScale, ctx.stroke();
254
- } finally {
255
- ctx.restore();
256
- }
257
- }
258
- ctx.beginPath(), ctx.strokeStyle = rgba(black.hex, 1), ctx.lineWidth = 0.5 / globalScale, ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, !1), ctx.stroke();
259
- const above = angle >= Math.PI / 2 && angle < Math.PI * 1.5, textY = above ? y - (imgH / 2 + 5) / globalScale : y + (imgH / 2 + 5) / globalScale;
260
- ctx.fillStyle = rgba(white.hex, 1), ctx.textAlign = "center", ctx.textBaseline = above ? "bottom" : "top", ctx.fillText(session.user.displayName, x, textY);
261
- } finally {
262
- ctx.restore();
263
- }
264
- }
265
- }
266
- }, nodeCanvasObject: (node_3, ctx_0, globalScale_0) => {
267
- switch (node_3.type) {
268
- case "document": {
269
- const nodeColor = getDocTypeColor(node_3.doc._type), radius_0 = Math.sqrt(valueFor(node_3.doc, maxSize)), fontSize = Math.min(100, 10 / globalScale_0);
270
- if (ctx_0.beginPath(), ctx_0.fillStyle = hoverNode !== null && node_3.doc._id === hoverNode.doc._id ? rgba(gray[500].hex, 0.8) : nodeColor.fill, ctx_0.strokeStyle = nodeColor.border, ctx_0.lineWidth = 0.5, ctx_0.arc(node_3.x, node_3.y, radius_0, 0, 2 * Math.PI, !1), ctx_0.stroke(), ctx_0.fill(), radius_0 * globalScale_0 > 10) {
271
- ctx_0.font = `${fontSize}px sans-serif`;
272
- const w = radius_0 * 2 + 30 / globalScale_0;
273
- for (let len = 50; len >= 5; len /= 1.2) {
274
- const label = truncate(labelFor(node_3.doc), Math.round(len));
275
- if (ctx_0.measureText(label).width < w) {
276
- ctx_0.textAlign = "center", ctx_0.textBaseline = "top", ctx_0.strokeStyle = rgba(black.hex, 0.5), ctx_0.lineWidth = 2 / globalScale_0, ctx_0.strokeText(label, node_3.x, node_3.y + radius_0 + 5 / globalScale_0), ctx_0.fillText(label, node_3.x, node_3.y + radius_0 + 5 / globalScale_0);
277
- break;
278
- }
279
- }
280
- }
281
- }
282
- }
283
- }, linkCanvasObject: (link, ctx_1, globalScale_1) => {
284
- ctx_1.beginPath(), ctx_1.strokeStyle = rgba(gray[500].hex, 0.125), ctx_1.lineWidth = 2 / globalScale_1, ctx_1.moveTo(link.source.x, link.source.y), ctx_1.lineTo(link.target.x, link.target.y), ctx_1.stroke();
285
- } })
286
- ] }) });
141
+ function GraphView({ tool: { options: props } }) {
142
+ let query = props.query || "\n *[\n !(_id in path(\"_.*\")) &&\n !(_type match \"system.*\") &&\n !(_type match \"sanity.*\")\n ]\n", apiVersion = props.apiVersion ?? "2022-09-01", userColorManager = useUserColorManager(), [maxSize, setMaxSize] = useState(0), [hoverNode, setHoverNode] = useState(null), [documents, setDocuments] = useState([]), [docTypes, setDocTypes] = useState({}), [graph, setGraph] = useState(() => new GraphData()), router = useRouter(), client = useClient({ apiVersion });
143
+ useEffect(() => {
144
+ client.fetch(query).then((_docs) => {
145
+ let docs = deduplicateDrafts(_docs);
146
+ setMaxSize(Math.max(...docs.map(sizeOf))), setDocuments(docs), setDocTypes(getDocTypeCounts(docs)), setGraph(new GraphData(docs));
147
+ });
148
+ }, [client, query]), useEffect(() => {
149
+ let subscription = client.listen(query, {}, {}).subscribe(async (update) => {
150
+ if (update.type !== "mutation") return;
151
+ let doc = update.result;
152
+ if (doc) {
153
+ doc._id = stripDraftId(doc._id);
154
+ let docsById = {};
155
+ for (let d of documents) docsById[d._id] = d;
156
+ let oldDoc, docs_0 = [...documents], idx = documents.findIndex((d_0) => d_0._id === doc._id);
157
+ idx >= 0 ? (oldDoc = docs_0[idx], docs_0[idx] = doc) : docs_0.push(doc), setDocuments(docs_0), setDocTypes(getDocTypeCounts(docs_0)), setMaxSize(Math.max(...docs_0.map(sizeOf)));
158
+ let newGraph = graph.clone(), oldRefs = findRefs(oldDoc || {}).filter((id) => id === doc._id || docsById[id] !== null), newRefs = findRefs(doc).filter((id_0) => id_0 === doc._id || docsById[id_0] !== null), graphChanged = !deepEqual(oldRefs, newRefs);
159
+ graphChanged && (newGraph.data.links = newGraph.data.links.filter((l) => l.source.id !== doc._id).concat(newRefs.map((ref) => ({
160
+ source: doc._id,
161
+ target: ref
162
+ }))));
163
+ let docNode, nodeIdx = graph.data.nodes.findIndex((n) => n.doc && n.doc._id === doc._id);
164
+ nodeIdx >= 0 ? (docNode = graph.data.nodes[nodeIdx], docNode.doc = doc) : (docNode = {
165
+ id: doc._id,
166
+ type: "document",
167
+ doc
168
+ }, newGraph.data.nodes.push(docNode), graphChanged = !0), graphChanged && setGraph(newGraph);
169
+ let user = await users.getById(update.identity, client);
170
+ graph.setSession(user, docNode);
171
+ } else if (update.transition === "disappear") {
172
+ let docId = stripDraftId(update.documentId), docs_1 = documents.filter((d_1) => d_1._id !== docId);
173
+ setDocuments(docs_1), setDocTypes(getDocTypeCounts(docs_1)), setMaxSize(Math.max(...docs_1.map(sizeOf)));
174
+ let newGraph_0 = graph.clone();
175
+ newGraph_0.data.links = newGraph_0.data.links.filter((l_0) => l_0.source.id !== docId && l_0.target.id !== docId), newGraph_0.data.nodes = newGraph_0.data.nodes.filter((n_0) => n_0.id !== docId), setGraph(newGraph_0);
176
+ }
177
+ });
178
+ return () => {
179
+ subscription.unsubscribe();
180
+ };
181
+ }, [
182
+ client,
183
+ query,
184
+ documents,
185
+ graph
186
+ ]), useEffect(() => {
187
+ let interval = setInterval(() => graph.reapSessions(), 1e3);
188
+ return () => clearInterval(interval);
189
+ }, [graph]);
190
+ let theme = useTheme().sanity;
191
+ return /* @__PURE__ */ jsx(GraphWrapper, {
192
+ theme,
193
+ children: /* @__PURE__ */ jsxs(GraphRoot, {
194
+ theme,
195
+ children: [
196
+ /* @__PURE__ */ jsx(Legend, {
197
+ theme,
198
+ children: getTopDocTypes(docTypes).map((docType) => /* @__PURE__ */ jsxs(LegendRow, {
199
+ className: "legend__row",
200
+ style: { color: getDocTypeColor(docType).fill },
201
+ children: [/* @__PURE__ */ jsx(LegendBadge, { theme }), /* @__PURE__ */ jsx("div", { children: formatDocType(docType) })]
202
+ }, docType))
203
+ }),
204
+ hoverNode && /* @__PURE__ */ jsx(HoverNode, {
205
+ theme,
206
+ children: labelFor(hoverNode.doc)
207
+ }),
208
+ /* @__PURE__ */ jsx(ForceGraph2D, {
209
+ graphData: graph.data,
210
+ nodeAutoColorBy: "group",
211
+ enableNodeDrag: !1,
212
+ onNodeHover: (node) => setHoverNode(node),
213
+ onNodeClick: (node_0) => {
214
+ router.navigateIntent("edit", {
215
+ id: node_0.doc._id,
216
+ documentType: node_0.doc._type
217
+ });
218
+ },
219
+ linkColor: () => rgba(gray[500].hex, .25),
220
+ nodeLabel: () => "",
221
+ nodeRelSize: 1,
222
+ nodeVal: (node_1) => valueFor(node_1.doc, maxSize),
223
+ onRenderFramePost: (ctx, globalScale) => {
224
+ for (let session of graph.sessions) {
225
+ let node_2 = graph.data.nodes.find((n_1) => n_1.doc && n_1.doc._id === session?.doc?._id);
226
+ if (node_2) {
227
+ let idleFactorRange = idleTimeout, angle = session.angle, radius = Math.sqrt(valueFor(node_2.doc, maxSize)), image = session.user.image, userColor = userColorManager.get(session.user.displayName).tints[400].hex, distance = radius * globalScale + 40, imgW = image ? image.width : 0, imgH = image ? image.height : 0, x = node_2.x + Math.sin(angle) * distance / globalScale, y = node_2.y + Math.cos(angle) * distance / globalScale;
228
+ ctx.save();
229
+ try {
230
+ if (ctx.globalAlpha = fadeEasing(1 - Math.min(idleFactorRange, Date.now() - session.lastActive) / idleFactorRange), ctx.font = `bold ${Math.round(12 / globalScale)}px sans-serif`, ctx.beginPath(), ctx.strokeStyle = rgba(white.hex, 1), ctx.lineWidth = 2 / globalScale, ctx.moveTo(node_2.x + Math.sin(angle) * (distance - imgW / 2) / globalScale, node_2.y + Math.cos(angle) * (distance - imgH / 2) / globalScale), ctx.lineTo(node_2.x + Math.sin(angle) * radius, node_2.y + Math.cos(angle) * radius), ctx.stroke(), ctx.beginPath(), ctx.strokeStyle = rgba(white.hex, 1), ctx.lineWidth = 2 / globalScale, ctx.arc(node_2.x, node_2.y, radius, 0, 2 * Math.PI, !1), ctx.stroke(), image) {
231
+ ctx.save();
232
+ try {
233
+ let f = softEasing(Math.max(0, (700 - (Date.now() - session.startTime)) / 700));
234
+ f > 0 && (ctx.beginPath(), ctx.fillStyle = rgba(userColor, f), ctx.arc(x, y, (imgW / 2 + 10) / globalScale, 0, 2 * Math.PI, !1), ctx.fill()), ctx.beginPath(), ctx.fillStyle = rgba(white.hex, 1), ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, !1), ctx.clip(), ctx.drawImage(image, x - imgW / globalScale / 2, y - imgH / globalScale / 2, imgW / globalScale, imgH / globalScale), ctx.strokeStyle = black.hex, ctx.lineWidth = 6 / globalScale, ctx.stroke(), ctx.strokeStyle = userColor, ctx.lineWidth = 4 / globalScale, ctx.stroke();
235
+ } finally {
236
+ ctx.restore();
237
+ }
238
+ }
239
+ ctx.beginPath(), ctx.strokeStyle = rgba(black.hex, 1), ctx.lineWidth = .5 / globalScale, ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, !1), ctx.stroke();
240
+ let above = angle >= Math.PI / 2 && angle < Math.PI * 1.5, textY = above ? y - (imgH / 2 + 5) / globalScale : y + (imgH / 2 + 5) / globalScale;
241
+ ctx.fillStyle = rgba(white.hex, 1), ctx.textAlign = "center", ctx.textBaseline = above ? "bottom" : "top", ctx.fillText(session.user.displayName, x, textY);
242
+ } finally {
243
+ ctx.restore();
244
+ }
245
+ }
246
+ }
247
+ },
248
+ nodeCanvasObject: (node_3, ctx_0, globalScale_0) => {
249
+ switch (node_3.type) {
250
+ case "document": {
251
+ let nodeColor = getDocTypeColor(node_3.doc._type), radius_0 = Math.sqrt(valueFor(node_3.doc, maxSize)), fontSize = Math.min(100, 10 / globalScale_0);
252
+ if (ctx_0.beginPath(), ctx_0.fillStyle = hoverNode !== null && node_3.doc._id === hoverNode.doc._id ? rgba(gray[500].hex, .8) : nodeColor.fill, ctx_0.strokeStyle = nodeColor.border, ctx_0.lineWidth = .5, ctx_0.arc(node_3.x, node_3.y, radius_0, 0, 2 * Math.PI, !1), ctx_0.stroke(), ctx_0.fill(), radius_0 * globalScale_0 > 10) {
253
+ ctx_0.font = `${fontSize}px sans-serif`;
254
+ let w = radius_0 * 2 + 30 / globalScale_0;
255
+ for (let len = 50; len >= 5; len /= 1.2) {
256
+ let label = truncate(labelFor(node_3.doc), Math.round(len));
257
+ if (ctx_0.measureText(label).width < w) {
258
+ ctx_0.textAlign = "center", ctx_0.textBaseline = "top", ctx_0.strokeStyle = rgba(black.hex, .5), ctx_0.lineWidth = 2 / globalScale_0, ctx_0.strokeText(label, node_3.x, node_3.y + radius_0 + 5 / globalScale_0), ctx_0.fillText(label, node_3.x, node_3.y + radius_0 + 5 / globalScale_0);
259
+ break;
260
+ }
261
+ }
262
+ }
263
+ }
264
+ }
265
+ },
266
+ linkCanvasObject: (link, ctx_1, globalScale_1) => {
267
+ ctx_1.beginPath(), ctx_1.strokeStyle = rgba(gray[500].hex, .125), ctx_1.lineWidth = 2 / globalScale_1, ctx_1.moveTo(link.source.x, link.source.y), ctx_1.lineTo(link.target.x, link.target.y), ctx_1.stroke();
268
+ }
269
+ })
270
+ ]
271
+ })
272
+ });
287
273
  }
288
274
  const colorCache = {};
289
275
  let typeColorNum = 0;
290
276
  function getDocTypeColor(docType) {
291
- if (colorCache[docType])
292
- return colorCache[docType];
293
- const hue = COLOR_HUES[typeColorNum % COLOR_HUES.length];
294
- return typeColorNum += 1, colorCache[docType] = {
295
- fill: hues[hue][400].hex,
296
- border: rgba(black.hex, 0.5)
297
- }, colorCache[docType];
277
+ if (colorCache[docType]) return colorCache[docType];
278
+ let hue = COLOR_HUES[typeColorNum % COLOR_HUES.length];
279
+ return typeColorNum += 1, colorCache[docType] = {
280
+ fill: hues[hue][400].hex,
281
+ border: rgba(black.hex, .5)
282
+ }, colorCache[docType];
298
283
  }
299
- export {
300
- GraphView as default
301
- };
302
- //# sourceMappingURL=GraphView.js.map
284
+ export { GraphView as default };
285
+
286
+ //# sourceMappingURL=GraphView.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GraphView.js","sources":["../../src/tool/GraphViewStyle.tsx","../../src/tool/utils.ts","../../src/tool/GraphView.tsx"],"sourcesContent":["import {black} from '@sanity/color'\n// TODO: when upgrading to @sanity/ui@4 start using the new tokens\n// oxlint-disable typescript/no-deprecated\nimport type {Theme} from '@sanity/ui'\nimport {type PropsWithChildren} from 'react'\nimport {styled} from 'styled-components'\n\ntype Style = PropsWithChildren<{theme: SanityTheme}>\ntype SanityTheme = Theme['sanity']\n\nexport const GraphRoot: React.FC<Style> = styled.div`\n font-family: ${({theme}: Style) => theme.fonts.text.family};\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: ${black.hex};\n`\n\nexport const GraphWrapper: React.FC<Style> = styled.div`\n position: relative;\n width: 100%;\n height: 100%;\n`\n\nexport const HoverNode: React.FC<Style> = styled.div`\n font-family: ${({theme}: Style) => theme.fonts.text.family};\n display: none;\n position: absolute;\n bottom: ${({theme}: Style) => theme.space[0]}px;\n left: 50%;\n transform: translate3d(-50%, 0, 0);\n background: var(--component-bg);\n border-radius: ${({theme}: Style) => theme.radius[2]}px;\n padding: ${({theme}: Style) => theme.space[2]}px;\n z-index: 1000;\n\n &:empty {\n display: none;\n }\n`\n\nexport const Legend: React.FC<Style> = styled.div`\n color: #ccc;\n position: absolute;\n top: ${({theme}: Style) => theme.space[4]}px;\n left: ${({theme}: Style) => theme.space[4]}px;\n\n & > div {\n margin: 5px 0;\n }\n`\n\nexport const LegendRow: React.FC<\n PropsWithChildren<{className?: string; style?: React.CSSProperties}>\n> = styled.div`\n display: flex;\n`\n\nexport const LegendBadge: React.FC<Style> = styled.div`\n width: 1.25em;\n height: 1.25em;\n background: currentColor;\n border-radius: 50%;\n margin-right: ${({theme}: Style) => theme.space[2]}px;\n`\n","export function sizeOf(value: any): number {\n if (value === null) {\n return 0\n }\n\n if (typeof value === 'object') {\n return Object.entries(value).reduce((total, [k, v]) => total + sizeOf(k) + sizeOf(v), 0)\n }\n\n if (Array.isArray(value)) {\n return Object.entries(value).reduce((total, v) => total + sizeOf(v), 0)\n }\n\n if (typeof value === 'string') {\n return value.length\n }\n\n return 1\n}\n\nexport function loadImage(url: string, w: number, h: number): Promise<HTMLImageElement | null> {\n return new Promise((resolve) => {\n const img = new Image(w, h)\n // oxlint-disable-next-line prefer-add-event-listener\n img.onload = () => {\n resolve(img)\n }\n // oxlint-disable-next-line prefer-add-event-listener\n img.onerror = (event) => {\n console.error('Image error', event)\n resolve(null)\n }\n img.src = url\n })\n}\n\nexport function sortBy<T>(array: T[], f: (t: T) => number): T[] {\n return array.sort((a, b) => {\n const va = f(a)\n const vb = f(b)\n return va < vb ? -1 : va > vb ? 1 : 0\n })\n}\n\nexport function truncate(s: string, limit: number): string {\n if (s.length > limit) {\n return `${s.substring(0, limit)}…`\n }\n return s\n}\n","import {black, COLOR_HUES, gray, white, hues} from '@sanity/color'\nimport {useTheme} from '@sanity/ui'\nimport BezierEasing from 'bezier-easing'\nimport deepEqual from 'deep-equal'\nimport {rgba} from 'polished'\nimport {useEffect, useState} from 'react'\nimport ForceGraph2D from 'react-force-graph-2d'\nimport {useClient, useUserColorManager, type SanityClient, type SanityDocument} from 'sanity'\nimport {useRouter} from 'sanity/router'\nimport {v4 as uuidv4} from 'uuid'\n\nimport {GraphRoot, GraphWrapper, HoverNode, Legend, LegendBadge, LegendRow} from './GraphViewStyle'\nimport {sortBy, loadImage, sizeOf, truncate} from './utils'\n\nconst DEFAULT_QUERY = `\n *[\n !(_id in path(\"_.*\")) &&\n !(_type match \"system.*\") &&\n !(_type match \"sanity.*\")\n ]\n`\n\nconst fadeEasing = BezierEasing(0, 0.9, 1, 1)\nconst softEasing = BezierEasing(0.25, 0.1, 0.0, 1.0)\nconst idleTimeout = 10000\nconst imageSize = 40\n\nfunction getTopDocTypes(counts: Record<string, number>) {\n return sortBy(Object.keys(counts), (docType) => counts[docType] || 0)\n .reverse()\n .slice(0, 10)\n}\n\nfunction formatDocType(docType: string) {\n return (docType.substring(0, 1).toUpperCase() + docType.substring(1))\n .replace(/\\./g, ' ')\n .replace(/[A-Z]/g, ' $&')\n .trim()\n}\n\nfunction getDocTypeCounts(docs: SanityDocument[]) {\n const types: Record<string, number> = {}\n for (const doc of docs) {\n types[doc._type] = (types[doc._type] || 0) + 1\n }\n return types\n}\n\nfunction labelFor(doc: SanityDocument) {\n // oxlint-disable-next-line restrict-template-expressions,no-base-to-string\n return `${doc.title || doc.name || doc._id}`.trim()\n}\n\nfunction valueFor(doc: any, maxSize: number) {\n return 5 + 100 * (sizeOf(doc) / maxSize)\n}\n\nfunction findRefs(obj: any, dest: any[] = []) {\n if (obj !== null) {\n if (typeof obj === 'object') {\n for (const [k, v] of Object.entries(obj)) {\n if (k === '_ref' && typeof v === 'string' && v.length > 0) {\n dest.push(stripDraftId(v))\n }\n findRefs(v, dest)\n }\n } else if (Array.isArray(obj)) {\n for (const v of obj) {\n findRefs(v, dest)\n }\n }\n }\n return dest\n}\n\nfunction stripDraftId(id: string) {\n return id.replace(/^drafts\\./, '')\n}\n\nfunction deduplicateDrafts(docs: SanityDocument[]) {\n const deduped: Record<string, SanityDocument> = {}\n for (const doc of docs) {\n if (!doc._id.startsWith('drafts.')) {\n deduped[doc._id] = doc\n }\n }\n for (const doc of docs) {\n if (doc._id.startsWith('drafts.')) {\n const id = stripDraftId(doc._id)\n deduped[id] = Object.assign(doc, {_id: id})\n }\n }\n return Object.values(deduped)\n}\n\nclass Users {\n _users: any[] = []\n\n async getById(id: string, client: SanityClient) {\n let user = this._users.find((u) => u._id === id)\n if (!user) {\n user = await client.users.getById(id)\n this._users.push(user)\n user.image = await loadImage(\n user.imageUrl ||\n 'https://raw.githubusercontent.com/sanity-io/sanity-plugin-graph-view/main/assets/head-silhouette.jpg',\n imageSize,\n imageSize,\n )\n }\n return user\n }\n}\n\nclass Session {\n id: string | null = null\n user: any = null\n doc: SanityDocument | null = null\n lastActive: number = 0\n startTime: number = 0\n angle: number = 0\n}\n\nclass GraphData {\n sessions: Session[] = []\n data: any\n\n constructor(docs: SanityDocument[] = []) {\n const docsById: Record<string, SanityDocument> = {}\n for (const doc of docs) {\n docsById[doc._id] = doc\n }\n\n this.data = {\n nodes: docs.map((d) => Object.assign({id: d._id, type: 'document', doc: d})),\n links: docs\n .flatMap((doc) => findRefs(doc).map((ref) => ({source: doc._id, target: ref})))\n .filter((link) => docsById[link.source] && docsById[link.target]),\n }\n }\n\n setSession(user: any, docNode: any) {\n let session = this.sessions.find((s) => s.user.id === user.id && s.doc?._id === docNode.doc._id)\n if (!session) {\n session = new Session()\n session.id = uuidv4()\n session.user = user\n session.startTime = Date.now()\n session.doc = docNode.doc\n session.angle = Math.random() * 2 * Math.PI\n this.sessions.push(session)\n }\n session.lastActive = Date.now()\n }\n\n reapSessions() {\n for (let i = 0; i < this.sessions.length; i++) {\n const session = this.sessions[i]\n if (Date.now() - session.lastActive > idleTimeout) {\n this.sessions = [...this.sessions.slice(0, i), ...this.sessions.slice(i + 1)]\n i--\n }\n }\n }\n\n clone() {\n const copy = new GraphData()\n Object.assign(copy, this)\n copy.data = {\n nodes: [...this.data.nodes],\n links: [...this.data.links],\n }\n return copy\n }\n}\n\nconst users = new Users()\n\ninterface GraphViewConfig {\n query?: string\n /** default: '2022-09-01' */\n apiVersion?: string\n}\n\nexport default function GraphView({\n tool: {options: props},\n}: {\n tool: {options: GraphViewConfig}\n}): React.JSX.Element {\n const query = props.query || DEFAULT_QUERY\n const apiVersion = props.apiVersion ?? '2022-09-01'\n\n const userColorManager = useUserColorManager()\n const [maxSize, setMaxSize] = useState(0)\n const [hoverNode, setHoverNode] = useState<any>(null)\n const [documents, setDocuments] = useState<SanityDocument[]>([])\n const [docTypes, setDocTypes] = useState<Record<string, number>>({})\n const [graph, setGraph] = useState(() => new GraphData())\n const router = useRouter()\n const client = useClient({apiVersion})\n\n useEffect(() => {\n void client.fetch(query).then((_docs) => {\n const docs = deduplicateDrafts(_docs)\n setMaxSize(Math.max(...docs.map(sizeOf)))\n setDocuments(docs)\n setDocTypes(getDocTypeCounts(docs))\n setGraph(new GraphData(docs))\n return undefined\n })\n }, [client, query])\n\n useEffect(() => {\n const subscription = client.listen(query, {}, {}).subscribe(async (update) => {\n if (update.type !== 'mutation') return\n const doc = update.result\n if (doc) {\n doc._id = stripDraftId(doc._id)\n\n const docsById: Record<string, SanityDocument> = {}\n for (const d of documents) {\n docsById[d._id] = d\n }\n\n let oldDoc\n const docs = [...documents]\n const idx = documents.findIndex((d) => d._id === doc._id)\n if (idx >= 0) {\n oldDoc = docs[idx]\n docs[idx] = doc\n } else {\n docs.push(doc)\n }\n setDocuments(docs)\n setDocTypes(getDocTypeCounts(docs))\n setMaxSize(Math.max(...docs.map(sizeOf)))\n\n const newGraph = graph.clone()\n\n const oldRefs = findRefs(oldDoc || {}).filter(\n (id) => id === doc._id || docsById[id] !== null,\n )\n const newRefs = findRefs(doc).filter((id) => id === doc._id || docsById[id] !== null)\n\n let graphChanged = !deepEqual(oldRefs, newRefs)\n if (graphChanged) {\n newGraph.data.links = newGraph.data.links\n .filter((l: any) => l.source.id !== doc._id)\n .concat(newRefs.map((ref) => ({source: doc._id, target: ref})))\n }\n\n let docNode\n const nodeIdx = graph.data.nodes.findIndex((n: any) => n.doc && n.doc._id === doc._id)\n if (nodeIdx >= 0) {\n docNode = graph.data.nodes[nodeIdx]\n docNode.doc = doc\n } else {\n docNode = {id: doc._id, type: 'document', doc: doc}\n newGraph.data.nodes.push(docNode)\n graphChanged = true\n }\n if (graphChanged) {\n setGraph(newGraph)\n }\n\n const user = await users.getById(update.identity, client)\n graph.setSession(user, docNode)\n } else if (update.transition === 'disappear') {\n const docId = stripDraftId(update.documentId)\n\n const docs = documents.filter((d) => d._id !== docId)\n setDocuments(docs)\n setDocTypes(getDocTypeCounts(docs))\n setMaxSize(Math.max(...docs.map(sizeOf)))\n\n const newGraph = graph.clone()\n newGraph.data.links = newGraph.data.links.filter(\n (l: any) => l.source.id !== docId && l.target.id !== docId,\n )\n newGraph.data.nodes = newGraph.data.nodes.filter((n: any) => n.id !== docId)\n setGraph(newGraph)\n }\n })\n return () => {\n subscription.unsubscribe()\n }\n }, [client, query, documents, graph])\n\n useEffect(() => {\n const interval = setInterval(() => graph.reapSessions(), 1000)\n return () => clearInterval(interval)\n }, [graph])\n\n const theme = useTheme().sanity\n\n return (\n <GraphWrapper theme={theme}>\n <GraphRoot theme={theme}>\n <Legend theme={theme}>\n {getTopDocTypes(docTypes).map((docType) => (\n <LegendRow\n key={docType}\n className={'legend__row'}\n style={{color: getDocTypeColor(docType).fill}}\n >\n <LegendBadge theme={theme} />\n <div>{formatDocType(docType)}</div>\n </LegendRow>\n ))}\n </Legend>\n {hoverNode && <HoverNode theme={theme}>{labelFor(hoverNode.doc)}</HoverNode>}\n <ForceGraph2D\n graphData={graph.data}\n nodeAutoColorBy=\"group\"\n enableNodeDrag={false}\n onNodeHover={(node: any) => setHoverNode(node)}\n onNodeClick={(node: any) => {\n router.navigateIntent('edit', {id: node.doc._id, documentType: node.doc._type})\n }}\n linkColor={() => rgba(gray[500].hex, 0.25)}\n nodeLabel={() => ''}\n nodeRelSize={1}\n nodeVal={(node: any) => valueFor(node.doc, maxSize)}\n onRenderFramePost={(ctx, globalScale) => {\n for (const session of graph.sessions) {\n const node = graph.data.nodes.find(\n (n: any) => n.doc && n.doc._id === session?.doc?._id,\n )\n if (node) {\n const idleFactorRange = idleTimeout\n const angle = session.angle\n const radius = Math.sqrt(valueFor(node.doc, maxSize))\n const image = session.user.image\n const userColor = userColorManager.get(session.user.displayName).tints[400].hex\n const distance = radius * globalScale + 40\n const imgW = image ? image.width : 0\n const imgH = image ? image.height : 0\n const x = node.x + (Math.sin(angle) * distance) / globalScale\n const y = node.y + (Math.cos(angle) * distance) / globalScale\n\n ctx.save()\n try {\n ctx.globalAlpha = fadeEasing(\n 1 -\n Math.min(idleFactorRange, Date.now() - session.lastActive) / idleFactorRange,\n )\n ctx.font = `bold ${Math.round(12 / globalScale)}px sans-serif`\n\n ctx.beginPath()\n ctx.strokeStyle = rgba(white.hex, 1.0)\n ctx.lineWidth = 2 / globalScale\n ctx.moveTo(\n node.x + (Math.sin(angle) * (distance - imgW / 2)) / globalScale,\n node.y + (Math.cos(angle) * (distance - imgH / 2)) / globalScale,\n )\n ctx.lineTo(node.x + Math.sin(angle) * radius, node.y + Math.cos(angle) * radius)\n ctx.stroke()\n\n ctx.beginPath()\n ctx.strokeStyle = rgba(white.hex, 1.0)\n ctx.lineWidth = 2 / globalScale\n ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false)\n ctx.stroke()\n\n if (image) {\n ctx.save()\n try {\n const dur = 700\n const f = softEasing(\n Math.max(0, (dur - (Date.now() - session.startTime)) / dur),\n )\n if (f > 0) {\n ctx.beginPath()\n ctx.fillStyle = rgba(userColor, f)\n ctx.arc(x, y, (imgW / 2 + 10) / globalScale, 0, 2 * Math.PI, false)\n ctx.fill()\n }\n\n ctx.beginPath()\n ctx.fillStyle = rgba(white.hex, 1.0)\n ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, false)\n ctx.clip()\n\n ctx.drawImage(\n image,\n x - imgW / globalScale / 2,\n y - imgH / globalScale / 2,\n imgW / globalScale,\n imgH / globalScale,\n )\n\n ctx.strokeStyle = black.hex\n ctx.lineWidth = 6 / globalScale\n ctx.stroke()\n\n ctx.strokeStyle = userColor\n ctx.lineWidth = 4 / globalScale\n ctx.stroke()\n } finally {\n ctx.restore()\n }\n }\n\n ctx.beginPath()\n ctx.strokeStyle = rgba(black.hex, 1)\n ctx.lineWidth = 0.5 / globalScale\n ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, false)\n ctx.stroke()\n\n const above = angle >= Math.PI / 2 && angle < Math.PI * 1.5\n const textY = above\n ? y - (imgH / 2 + 5) / globalScale\n : y + (imgH / 2 + 5) / globalScale\n ctx.fillStyle = rgba(white.hex, 1.0)\n ctx.textAlign = 'center'\n ctx.textBaseline = above ? 'bottom' : 'top'\n ctx.fillText(session.user.displayName, x, textY)\n } finally {\n ctx.restore()\n }\n }\n }\n }}\n nodeCanvasObject={(node: any, ctx, globalScale) => {\n switch (node.type) {\n case 'document': {\n const nodeColor = getDocTypeColor(node.doc._type)\n const radius = Math.sqrt(valueFor(node.doc, maxSize))\n const fontSize = Math.min(100, 10.0 / globalScale)\n\n ctx.beginPath()\n ctx.fillStyle =\n hoverNode !== null && node.doc._id === hoverNode.doc._id\n ? rgba(gray[500].hex, 0.8)\n : nodeColor.fill\n ctx.strokeStyle = nodeColor.border\n ctx.lineWidth = 0.5\n ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false)\n ctx.stroke()\n ctx.fill()\n\n if (radius * globalScale > 10) {\n ctx.font = `${fontSize}px sans-serif`\n const w = radius * 2 + 30 / globalScale\n for (let len = 50; len >= 5; len /= 1.2) {\n const label = truncate(labelFor(node.doc), Math.round(len))\n const textMetrics = ctx.measureText(label)\n if (textMetrics.width < w) {\n // ctx.fillStyle = rgba(color.white.hex, 1.0)\n ctx.textAlign = 'center'\n ctx.textBaseline = 'top'\n\n ctx.strokeStyle = rgba(black.hex, 0.5)\n ctx.lineWidth = 2 / globalScale\n ctx.strokeText(label, node.x, node.y + radius + 5 / globalScale)\n\n ctx.fillText(label, node.x, node.y + radius + 5 / globalScale)\n break\n }\n }\n }\n }\n }\n }}\n linkCanvasObject={(link: any, ctx, globalScale) => {\n ctx.beginPath()\n ctx.strokeStyle = rgba(gray[500].hex, 0.125)\n ctx.lineWidth = 2 / globalScale\n ctx.moveTo(link.source.x, link.source.y)\n ctx.lineTo(link.target.x, link.target.y)\n ctx.stroke()\n }}\n />\n </GraphRoot>\n </GraphWrapper>\n )\n}\n\nconst colorCache: Record<string, {fill: string; border: string}> = {}\nlet typeColorNum = 0\n\nfunction getDocTypeColor(docType: any) {\n if (colorCache[docType]) {\n return colorCache[docType]\n }\n\n const hue = COLOR_HUES[typeColorNum % COLOR_HUES.length]\n\n typeColorNum += 1\n\n colorCache[docType] = {\n fill: hues[hue][400].hex,\n border: rgba(black.hex, 0.5),\n }\n\n return colorCache[docType]\n}\n"],"names":["GraphRoot","styled","div","withConfig","displayName","componentId","theme","fonts","text","family","black","hex","GraphWrapper","HoverNode","space","radius","Legend","LegendRow","LegendBadge","sizeOf","value","Object","entries","reduce","total","k","v","Array","isArray","length","loadImage","url","w","h","Promise","resolve","img","Image","onload","onerror","event","console","error","src","sortBy","array","f","sort","a","b","va","vb","truncate","s","limit","substring","DEFAULT_QUERY","fadeEasing","BezierEasing","softEasing","idleTimeout","imageSize","getTopDocTypes","counts","keys","docType","reverse","slice","formatDocType","toUpperCase","replace","trim","getDocTypeCounts","docs","types","doc","_type","labelFor","title","name","_id","valueFor","maxSize","findRefs","obj","dest","push","stripDraftId","id","deduplicateDrafts","deduped","startsWith","assign","values","Users","_users","getById","client","user","find","u","users","image","imageUrl","Session","lastActive","startTime","angle","GraphData","sessions","constructor","docsById","data","nodes","map","d","type","links","flatMap","ref","source","target","filter","link","setSession","docNode","session","uuidv4","Date","now","Math","random","PI","reapSessions","i","clone","copy","GraphView","tool","options","props","query","apiVersion","userColorManager","useUserColorManager","setMaxSize","useState","hoverNode","setHoverNode","documents","setDocuments","docTypes","setDocTypes","graph","setGraph","router","useRouter","useClient","useEffect","fetch","then","_docs","max","subscription","listen","subscribe","update","result","oldDoc","idx","findIndex","newGraph","oldRefs","newRefs","graphChanged","deepEqual","l","concat","nodeIdx","n","identity","transition","docId","documentId","unsubscribe","interval","setInterval","clearInterval","useTheme","sanity","color","getDocTypeColor","fill","node","navigateIntent","documentType","rgba","gray","ctx","globalScale","idleFactorRange","sqrt","userColor","get","tints","distance","imgW","width","imgH","height","x","sin","y","cos","save","globalAlpha","min","font","round","beginPath","strokeStyle","white","lineWidth","moveTo","lineTo","stroke","arc","dur","fillStyle","clip","drawImage","restore","above","textY","textAlign","textBaseline","fillText","nodeColor","fontSize","border","len","label","measureText","strokeText","colorCache","typeColorNum","hue","COLOR_HUES","hues"],"mappings":";;;;;;;;;;;;AAUO,MAAMA,YAA6BC,uBAAOC,IAAGC,WAAA;AAAA,EAAAC,aAAA;AAAA,EAAAC,aAAA;AAAA,CAAA,EAAA,CAAA,gBAAA,sEAAA,GAAA,GACnC,CAAC;AAAA,EAACC;AAAY,MAAMA,MAAMC,MAAMC,KAAKC,QAMtCC,MAAMC,GAAG,GAGZC,eAAgCX,uBAAOC,IAAGC,WAAA;AAAA,EAAAC,aAAA;AAAA,EAAAC,aAAA;AAAA,CAAA,EAAA,CAAA,2CAAA,CAAA,GAM1CQ,YAA6BZ,uBAAOC,IAAGC,WAAA;AAAA,EAAAC,aAAA;AAAA,EAAAC,aAAA;AAAA,CAAA,EAAA,CAAA,gBAAA,2CAAA,6FAAA,eAAA,wCAAA,GACnC,CAAC;AAAA,EAACC;AAAY,MAAMA,MAAMC,MAAMC,KAAKC,QAG1C,CAAC;AAAA,EAACH;AAAY,MAAMA,MAAMQ,MAAM,CAAC,GAI1B,CAAC;AAAA,EAACR;AAAY,MAAMA,MAAMS,OAAO,CAAC,GACxC,CAAC;AAAA,EAACT;AAAY,MAAMA,MAAMQ,MAAM,CAAC,CAAC,GAQlCE,SAA0Bf,uBAAOC,IAAGC,WAAA;AAAA,EAAAC,aAAA;AAAA,EAAAC,aAAA;AAAA,CAAA,EAAA,CAAA,qCAAA,YAAA,2BAAA,GAGxC,CAAC;AAAA,EAACC;AAAY,MAAMA,MAAMQ,MAAM,CAAC,GAChC,CAAC;AAAA,EAACR;AAAY,MAAMA,MAAMQ,MAAM,CAAC,CAAC,GAO/BG,YAEThB,uBAAOC,IAAGC,WAAA;AAAA,EAAAC,aAAA;AAAA,EAAAC,aAAA;AAAA,CAAA,EAAA,CAAA,eAAA,CAAA,GAIDa,cAA+BjB,uBAAOC,IAAGC,WAAA;AAAA,EAAAC,aAAA;AAAA,EAAAC,aAA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1L,MAAMC,KAAK,GAAG;AAAA,EAAA,GAGtByO,WAAWnL,OAAO;AAC3B;"}
1
+ {"version":3,"file":"GraphView.js","names":["black","Theme","PropsWithChildren","styled","Style","theme","SanityTheme","GraphRoot","React","FC","div","fonts","text","family","hex","GraphWrapper","HoverNode","space","radius","Legend","LegendRow","className","style","CSSProperties","LegendBadge","sizeOf","value","Object","entries","reduce","total","k","v","Array","isArray","length","loadImage","url","w","h","Promise","HTMLImageElement","resolve","img","Image","onload","onerror","event","console","error","src","sortBy","array","T","f","t","sort","a","b","va","vb","truncate","s","limit","substring","black","COLOR_HUES","gray","white","hues","useTheme","BezierEasing","deepEqual","rgba","useEffect","useState","ForceGraph2D","useClient","useUserColorManager","SanityClient","SanityDocument","useRouter","v4","uuidv4","GraphRoot","GraphWrapper","HoverNode","Legend","LegendBadge","LegendRow","sortBy","loadImage","sizeOf","truncate","DEFAULT_QUERY","fadeEasing","softEasing","idleTimeout","imageSize","getTopDocTypes","counts","Record","Object","keys","docType","reverse","slice","formatDocType","substring","toUpperCase","replace","trim","getDocTypeCounts","docs","types","doc","_type","labelFor","title","name","_id","valueFor","maxSize","findRefs","obj","dest","k","v","entries","length","push","stripDraftId","Array","isArray","id","deduplicateDrafts","deduped","startsWith","assign","values","Users","_users","getById","client","user","find","u","users","image","imageUrl","Session","lastActive","startTime","angle","GraphData","sessions","data","constructor","docsById","nodes","map","d","type","links","flatMap","ref","source","target","filter","link","setSession","docNode","session","s","Date","now","Math","random","PI","reapSessions","i","clone","copy","GraphViewConfig","query","apiVersion","GraphView","tool","options","props","React","JSX","Element","userColorManager","setMaxSize","hoverNode","setHoverNode","documents","setDocuments","docTypes","setDocTypes","graph","setGraph","router","fetch","then","_docs","max","undefined","subscription","listen","subscribe","update","result","oldDoc","idx","findIndex","newGraph","oldRefs","newRefs","graphChanged","l","concat","nodeIdx","n","identity","transition","docId","documentId","unsubscribe","interval","setInterval","clearInterval","theme","sanity","color","getDocTypeColor","fill","node","navigateIntent","documentType","hex","ctx","globalScale","idleFactorRange","radius","sqrt","userColor","get","displayName","tints","distance","imgW","width","imgH","height","x","sin","y","cos","save","globalAlpha","min","font","round","beginPath","strokeStyle","lineWidth","moveTo","lineTo","stroke","arc","dur","f","fillStyle","clip","drawImage","restore","above","textY","textAlign","textBaseline","fillText","nodeColor","fontSize","border","w","len","label","textMetrics","measureText","strokeText","colorCache","typeColorNum","hue"],"sources":["../../src/tool/GraphViewStyle.tsx","../../src/tool/utils.ts","../../src/tool/GraphView.tsx"],"sourcesContent":["import {black} from '@sanity/color'\n// TODO: when upgrading to @sanity/ui@4 start using the new tokens\n// oxlint-disable typescript/no-deprecated\nimport type {Theme} from '@sanity/ui'\nimport {type PropsWithChildren} from 'react'\nimport {styled} from 'styled-components'\n\ntype Style = PropsWithChildren<{theme: SanityTheme}>\ntype SanityTheme = Theme['sanity']\n\nexport const GraphRoot: React.FC<Style> = styled.div`\n font-family: ${({theme}: Style) => theme.fonts.text.family};\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: ${black.hex};\n`\n\nexport const GraphWrapper: React.FC<Style> = styled.div`\n position: relative;\n width: 100%;\n height: 100%;\n`\n\nexport const HoverNode: React.FC<Style> = styled.div`\n font-family: ${({theme}: Style) => theme.fonts.text.family};\n display: none;\n position: absolute;\n bottom: ${({theme}: Style) => theme.space[0]}px;\n left: 50%;\n transform: translate3d(-50%, 0, 0);\n background: var(--component-bg);\n border-radius: ${({theme}: Style) => theme.radius[2]}px;\n padding: ${({theme}: Style) => theme.space[2]}px;\n z-index: 1000;\n\n &:empty {\n display: none;\n }\n`\n\nexport const Legend: React.FC<Style> = styled.div`\n color: #ccc;\n position: absolute;\n top: ${({theme}: Style) => theme.space[4]}px;\n left: ${({theme}: Style) => theme.space[4]}px;\n\n & > div {\n margin: 5px 0;\n }\n`\n\nexport const LegendRow: React.FC<\n PropsWithChildren<{className?: string; style?: React.CSSProperties}>\n> = styled.div`\n display: flex;\n`\n\nexport const LegendBadge: React.FC<Style> = styled.div`\n width: 1.25em;\n height: 1.25em;\n background: currentColor;\n border-radius: 50%;\n margin-right: ${({theme}: Style) => theme.space[2]}px;\n`\n","export function sizeOf(value: any): number {\n if (value === null) {\n return 0\n }\n\n if (typeof value === 'object') {\n return Object.entries(value).reduce((total, [k, v]) => total + sizeOf(k) + sizeOf(v), 0)\n }\n\n if (Array.isArray(value)) {\n return Object.entries(value).reduce((total, v) => total + sizeOf(v), 0)\n }\n\n if (typeof value === 'string') {\n return value.length\n }\n\n return 1\n}\n\nexport function loadImage(url: string, w: number, h: number): Promise<HTMLImageElement | null> {\n return new Promise((resolve) => {\n const img = new Image(w, h)\n // oxlint-disable-next-line prefer-add-event-listener\n img.onload = () => {\n resolve(img)\n }\n // oxlint-disable-next-line prefer-add-event-listener\n img.onerror = (event) => {\n console.error('Image error', event)\n resolve(null)\n }\n img.src = url\n })\n}\n\nexport function sortBy<T>(array: T[], f: (t: T) => number): T[] {\n return array.sort((a, b) => {\n const va = f(a)\n const vb = f(b)\n return va < vb ? -1 : va > vb ? 1 : 0\n })\n}\n\nexport function truncate(s: string, limit: number): string {\n if (s.length > limit) {\n return `${s.substring(0, limit)}…`\n }\n return s\n}\n","import {black, COLOR_HUES, gray, white, hues} from '@sanity/color'\nimport {useTheme} from '@sanity/ui'\nimport BezierEasing from 'bezier-easing'\nimport deepEqual from 'deep-equal'\nimport {rgba} from 'polished'\nimport {useEffect, useState} from 'react'\nimport ForceGraph2D from 'react-force-graph-2d'\nimport {useClient, useUserColorManager, type SanityClient, type SanityDocument} from 'sanity'\nimport {useRouter} from 'sanity/router'\nimport {v4 as uuidv4} from 'uuid'\n\nimport {GraphRoot, GraphWrapper, HoverNode, Legend, LegendBadge, LegendRow} from './GraphViewStyle'\nimport {sortBy, loadImage, sizeOf, truncate} from './utils'\n\nconst DEFAULT_QUERY = `\n *[\n !(_id in path(\"_.*\")) &&\n !(_type match \"system.*\") &&\n !(_type match \"sanity.*\")\n ]\n`\n\nconst fadeEasing = BezierEasing(0, 0.9, 1, 1)\nconst softEasing = BezierEasing(0.25, 0.1, 0.0, 1.0)\nconst idleTimeout = 10000\nconst imageSize = 40\n\nfunction getTopDocTypes(counts: Record<string, number>) {\n return sortBy(Object.keys(counts), (docType) => counts[docType] || 0)\n .reverse()\n .slice(0, 10)\n}\n\nfunction formatDocType(docType: string) {\n return (docType.substring(0, 1).toUpperCase() + docType.substring(1))\n .replace(/\\./g, ' ')\n .replace(/[A-Z]/g, ' $&')\n .trim()\n}\n\nfunction getDocTypeCounts(docs: SanityDocument[]) {\n const types: Record<string, number> = {}\n for (const doc of docs) {\n types[doc._type] = (types[doc._type] || 0) + 1\n }\n return types\n}\n\nfunction labelFor(doc: SanityDocument) {\n // oxlint-disable-next-line restrict-template-expressions,no-base-to-string\n return `${doc.title || doc.name || doc._id}`.trim()\n}\n\nfunction valueFor(doc: any, maxSize: number) {\n return 5 + 100 * (sizeOf(doc) / maxSize)\n}\n\nfunction findRefs(obj: any, dest: any[] = []) {\n if (obj !== null) {\n if (typeof obj === 'object') {\n for (const [k, v] of Object.entries(obj)) {\n if (k === '_ref' && typeof v === 'string' && v.length > 0) {\n dest.push(stripDraftId(v))\n }\n findRefs(v, dest)\n }\n } else if (Array.isArray(obj)) {\n for (const v of obj) {\n findRefs(v, dest)\n }\n }\n }\n return dest\n}\n\nfunction stripDraftId(id: string) {\n return id.replace(/^drafts\\./, '')\n}\n\nfunction deduplicateDrafts(docs: SanityDocument[]) {\n const deduped: Record<string, SanityDocument> = {}\n for (const doc of docs) {\n if (!doc._id.startsWith('drafts.')) {\n deduped[doc._id] = doc\n }\n }\n for (const doc of docs) {\n if (doc._id.startsWith('drafts.')) {\n const id = stripDraftId(doc._id)\n deduped[id] = Object.assign(doc, {_id: id})\n }\n }\n return Object.values(deduped)\n}\n\nclass Users {\n _users: any[] = []\n\n async getById(id: string, client: SanityClient) {\n let user = this._users.find((u) => u._id === id)\n if (!user) {\n user = await client.users.getById(id)\n this._users.push(user)\n user.image = await loadImage(\n user.imageUrl ||\n 'https://raw.githubusercontent.com/sanity-io/sanity-plugin-graph-view/main/assets/head-silhouette.jpg',\n imageSize,\n imageSize,\n )\n }\n return user\n }\n}\n\nclass Session {\n id: string | null = null\n user: any = null\n doc: SanityDocument | null = null\n lastActive: number = 0\n startTime: number = 0\n angle: number = 0\n}\n\nclass GraphData {\n sessions: Session[] = []\n data: any\n\n constructor(docs: SanityDocument[] = []) {\n const docsById: Record<string, SanityDocument> = {}\n for (const doc of docs) {\n docsById[doc._id] = doc\n }\n\n this.data = {\n nodes: docs.map((d) => Object.assign({id: d._id, type: 'document', doc: d})),\n links: docs\n .flatMap((doc) => findRefs(doc).map((ref) => ({source: doc._id, target: ref})))\n .filter((link) => docsById[link.source] && docsById[link.target]),\n }\n }\n\n setSession(user: any, docNode: any) {\n let session = this.sessions.find((s) => s.user.id === user.id && s.doc?._id === docNode.doc._id)\n if (!session) {\n session = new Session()\n session.id = uuidv4()\n session.user = user\n session.startTime = Date.now()\n session.doc = docNode.doc\n session.angle = Math.random() * 2 * Math.PI\n this.sessions.push(session)\n }\n session.lastActive = Date.now()\n }\n\n reapSessions() {\n for (let i = 0; i < this.sessions.length; i++) {\n const session = this.sessions[i]\n if (Date.now() - session.lastActive > idleTimeout) {\n this.sessions = [...this.sessions.slice(0, i), ...this.sessions.slice(i + 1)]\n i--\n }\n }\n }\n\n clone() {\n const copy = new GraphData()\n Object.assign(copy, this)\n copy.data = {\n nodes: [...this.data.nodes],\n links: [...this.data.links],\n }\n return copy\n }\n}\n\nconst users = new Users()\n\ninterface GraphViewConfig {\n query?: string\n /** default: '2022-09-01' */\n apiVersion?: string\n}\n\nexport default function GraphView({\n tool: {options: props},\n}: {\n tool: {options: GraphViewConfig}\n}): React.JSX.Element {\n const query = props.query || DEFAULT_QUERY\n const apiVersion = props.apiVersion ?? '2022-09-01'\n\n const userColorManager = useUserColorManager()\n const [maxSize, setMaxSize] = useState(0)\n const [hoverNode, setHoverNode] = useState<any>(null)\n const [documents, setDocuments] = useState<SanityDocument[]>([])\n const [docTypes, setDocTypes] = useState<Record<string, number>>({})\n const [graph, setGraph] = useState(() => new GraphData())\n const router = useRouter()\n const client = useClient({apiVersion})\n\n useEffect(() => {\n void client.fetch(query).then((_docs) => {\n const docs = deduplicateDrafts(_docs)\n setMaxSize(Math.max(...docs.map(sizeOf)))\n setDocuments(docs)\n setDocTypes(getDocTypeCounts(docs))\n setGraph(new GraphData(docs))\n return undefined\n })\n }, [client, query])\n\n useEffect(() => {\n const subscription = client.listen(query, {}, {}).subscribe(async (update) => {\n if (update.type !== 'mutation') return\n const doc = update.result\n if (doc) {\n doc._id = stripDraftId(doc._id)\n\n const docsById: Record<string, SanityDocument> = {}\n for (const d of documents) {\n docsById[d._id] = d\n }\n\n let oldDoc\n const docs = [...documents]\n const idx = documents.findIndex((d) => d._id === doc._id)\n if (idx >= 0) {\n oldDoc = docs[idx]\n docs[idx] = doc\n } else {\n docs.push(doc)\n }\n setDocuments(docs)\n setDocTypes(getDocTypeCounts(docs))\n setMaxSize(Math.max(...docs.map(sizeOf)))\n\n const newGraph = graph.clone()\n\n const oldRefs = findRefs(oldDoc || {}).filter(\n (id) => id === doc._id || docsById[id] !== null,\n )\n const newRefs = findRefs(doc).filter((id) => id === doc._id || docsById[id] !== null)\n\n let graphChanged = !deepEqual(oldRefs, newRefs)\n if (graphChanged) {\n newGraph.data.links = newGraph.data.links\n .filter((l: any) => l.source.id !== doc._id)\n .concat(newRefs.map((ref) => ({source: doc._id, target: ref})))\n }\n\n let docNode\n const nodeIdx = graph.data.nodes.findIndex((n: any) => n.doc && n.doc._id === doc._id)\n if (nodeIdx >= 0) {\n docNode = graph.data.nodes[nodeIdx]\n docNode.doc = doc\n } else {\n docNode = {id: doc._id, type: 'document', doc: doc}\n newGraph.data.nodes.push(docNode)\n graphChanged = true\n }\n if (graphChanged) {\n setGraph(newGraph)\n }\n\n const user = await users.getById(update.identity, client)\n graph.setSession(user, docNode)\n } else if (update.transition === 'disappear') {\n const docId = stripDraftId(update.documentId)\n\n const docs = documents.filter((d) => d._id !== docId)\n setDocuments(docs)\n setDocTypes(getDocTypeCounts(docs))\n setMaxSize(Math.max(...docs.map(sizeOf)))\n\n const newGraph = graph.clone()\n newGraph.data.links = newGraph.data.links.filter(\n (l: any) => l.source.id !== docId && l.target.id !== docId,\n )\n newGraph.data.nodes = newGraph.data.nodes.filter((n: any) => n.id !== docId)\n setGraph(newGraph)\n }\n })\n return () => {\n subscription.unsubscribe()\n }\n }, [client, query, documents, graph])\n\n useEffect(() => {\n const interval = setInterval(() => graph.reapSessions(), 1000)\n return () => clearInterval(interval)\n }, [graph])\n\n const theme = useTheme().sanity\n\n return (\n <GraphWrapper theme={theme}>\n <GraphRoot theme={theme}>\n <Legend theme={theme}>\n {getTopDocTypes(docTypes).map((docType) => (\n <LegendRow\n key={docType}\n className={'legend__row'}\n style={{color: getDocTypeColor(docType).fill}}\n >\n <LegendBadge theme={theme} />\n <div>{formatDocType(docType)}</div>\n </LegendRow>\n ))}\n </Legend>\n {hoverNode && <HoverNode theme={theme}>{labelFor(hoverNode.doc)}</HoverNode>}\n <ForceGraph2D\n graphData={graph.data}\n nodeAutoColorBy=\"group\"\n enableNodeDrag={false}\n onNodeHover={(node: any) => setHoverNode(node)}\n onNodeClick={(node: any) => {\n router.navigateIntent('edit', {id: node.doc._id, documentType: node.doc._type})\n }}\n linkColor={() => rgba(gray[500].hex, 0.25)}\n nodeLabel={() => ''}\n nodeRelSize={1}\n nodeVal={(node: any) => valueFor(node.doc, maxSize)}\n onRenderFramePost={(ctx, globalScale) => {\n for (const session of graph.sessions) {\n const node = graph.data.nodes.find(\n (n: any) => n.doc && n.doc._id === session?.doc?._id,\n )\n if (node) {\n const idleFactorRange = idleTimeout\n const angle = session.angle\n const radius = Math.sqrt(valueFor(node.doc, maxSize))\n const image = session.user.image\n const userColor = userColorManager.get(session.user.displayName).tints[400].hex\n const distance = radius * globalScale + 40\n const imgW = image ? image.width : 0\n const imgH = image ? image.height : 0\n const x = node.x + (Math.sin(angle) * distance) / globalScale\n const y = node.y + (Math.cos(angle) * distance) / globalScale\n\n ctx.save()\n try {\n ctx.globalAlpha = fadeEasing(\n 1 -\n Math.min(idleFactorRange, Date.now() - session.lastActive) / idleFactorRange,\n )\n ctx.font = `bold ${Math.round(12 / globalScale)}px sans-serif`\n\n ctx.beginPath()\n ctx.strokeStyle = rgba(white.hex, 1.0)\n ctx.lineWidth = 2 / globalScale\n ctx.moveTo(\n node.x + (Math.sin(angle) * (distance - imgW / 2)) / globalScale,\n node.y + (Math.cos(angle) * (distance - imgH / 2)) / globalScale,\n )\n ctx.lineTo(node.x + Math.sin(angle) * radius, node.y + Math.cos(angle) * radius)\n ctx.stroke()\n\n ctx.beginPath()\n ctx.strokeStyle = rgba(white.hex, 1.0)\n ctx.lineWidth = 2 / globalScale\n ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false)\n ctx.stroke()\n\n if (image) {\n ctx.save()\n try {\n const dur = 700\n const f = softEasing(\n Math.max(0, (dur - (Date.now() - session.startTime)) / dur),\n )\n if (f > 0) {\n ctx.beginPath()\n ctx.fillStyle = rgba(userColor, f)\n ctx.arc(x, y, (imgW / 2 + 10) / globalScale, 0, 2 * Math.PI, false)\n ctx.fill()\n }\n\n ctx.beginPath()\n ctx.fillStyle = rgba(white.hex, 1.0)\n ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, false)\n ctx.clip()\n\n ctx.drawImage(\n image,\n x - imgW / globalScale / 2,\n y - imgH / globalScale / 2,\n imgW / globalScale,\n imgH / globalScale,\n )\n\n ctx.strokeStyle = black.hex\n ctx.lineWidth = 6 / globalScale\n ctx.stroke()\n\n ctx.strokeStyle = userColor\n ctx.lineWidth = 4 / globalScale\n ctx.stroke()\n } finally {\n ctx.restore()\n }\n }\n\n ctx.beginPath()\n ctx.strokeStyle = rgba(black.hex, 1)\n ctx.lineWidth = 0.5 / globalScale\n ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, false)\n ctx.stroke()\n\n const above = angle >= Math.PI / 2 && angle < Math.PI * 1.5\n const textY = above\n ? y - (imgH / 2 + 5) / globalScale\n : y + (imgH / 2 + 5) / globalScale\n ctx.fillStyle = rgba(white.hex, 1.0)\n ctx.textAlign = 'center'\n ctx.textBaseline = above ? 'bottom' : 'top'\n ctx.fillText(session.user.displayName, x, textY)\n } finally {\n ctx.restore()\n }\n }\n }\n }}\n nodeCanvasObject={(node: any, ctx, globalScale) => {\n switch (node.type) {\n case 'document': {\n const nodeColor = getDocTypeColor(node.doc._type)\n const radius = Math.sqrt(valueFor(node.doc, maxSize))\n const fontSize = Math.min(100, 10.0 / globalScale)\n\n ctx.beginPath()\n ctx.fillStyle =\n hoverNode !== null && node.doc._id === hoverNode.doc._id\n ? rgba(gray[500].hex, 0.8)\n : nodeColor.fill\n ctx.strokeStyle = nodeColor.border\n ctx.lineWidth = 0.5\n ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false)\n ctx.stroke()\n ctx.fill()\n\n if (radius * globalScale > 10) {\n ctx.font = `${fontSize}px sans-serif`\n const w = radius * 2 + 30 / globalScale\n for (let len = 50; len >= 5; len /= 1.2) {\n const label = truncate(labelFor(node.doc), Math.round(len))\n const textMetrics = ctx.measureText(label)\n if (textMetrics.width < w) {\n // ctx.fillStyle = rgba(color.white.hex, 1.0)\n ctx.textAlign = 'center'\n ctx.textBaseline = 'top'\n\n ctx.strokeStyle = rgba(black.hex, 0.5)\n ctx.lineWidth = 2 / globalScale\n ctx.strokeText(label, node.x, node.y + radius + 5 / globalScale)\n\n ctx.fillText(label, node.x, node.y + radius + 5 / globalScale)\n break\n }\n }\n }\n }\n }\n }}\n linkCanvasObject={(link: any, ctx, globalScale) => {\n ctx.beginPath()\n ctx.strokeStyle = rgba(gray[500].hex, 0.125)\n ctx.lineWidth = 2 / globalScale\n ctx.moveTo(link.source.x, link.source.y)\n ctx.lineTo(link.target.x, link.target.y)\n ctx.stroke()\n }}\n />\n </GraphRoot>\n </GraphWrapper>\n )\n}\n\nconst colorCache: Record<string, {fill: string; border: string}> = {}\nlet typeColorNum = 0\n\nfunction getDocTypeColor(docType: any) {\n if (colorCache[docType]) {\n return colorCache[docType]\n }\n\n const hue = COLOR_HUES[typeColorNum % COLOR_HUES.length]\n\n typeColorNum += 1\n\n colorCache[docType] = {\n fill: hues[hue][400].hex,\n border: rgba(black.hex, 0.5),\n }\n\n return colorCache[docType]\n}\n"],"mappings":";;;;;;;;;;;;AAUA,MAAaO,YAA6BJ,OAAOO,IAAAA,WAAAA;;;EAAG,gBAClC,EAACL,YAAkBA,MAAMM,MAAMC,KAAKC,OAAM,oEAM5Cb,MAAMc,IAAG,IAGZC,eAAgCZ,OAAOO,IAAAA,WAAAA;;;EAAG,6CAM1CM,YAA6Bb,OAAOO,IAAAA,WAAAA;;;EAAG,gBAClC,EAACL,YAAkBA,MAAMM,MAAMC,KAAKC,OAAM,0CAG/C,EAACR,YAAkBA,MAAMY,MAAM,GAAE,4FAI1B,EAACZ,YAAkBA,MAAMa,OAAO,GAAE,cACxC,EAACb,YAAkBA,MAAMY,MAAM,GAAE,yCAQlCE,SAA0BhB,OAAOO,IAAAA,WAAAA;;;EAAG,qCAGvC,EAACL,YAAkBA,MAAMY,MAAM,GAAE,WAChC,EAACZ,YAAkBA,MAAMY,MAAM,GAAE,4BAO/BG,YAETjB,OAAOO,IAAAA,WAAAA;;;EAAG,iBAIDc,cAA+BrB,OAAOO,IAAAA,WAAAA;;;EAAG,sFAKnC,EAACL,YAAkBA,MAAMY,MAAM,GAAE;ACjEpD,SAAgBQ,OAAOC,OAAoB;CAiBzC,OAhBIA,UAAU,OACL,IAGL,OAAOA,SAAU,WACZC,OAAOC,QAAQF,KAAK,CAAC,CAACG,QAAQC,OAAO,CAACC,GAAGC,OAAOF,QAAQL,OAAOM,CAAC,IAAIN,OAAOO,CAAC,GAAG,CAAC,IAGrFC,MAAMC,QAAQR,KAAK,IACdC,OAAOC,QAAQF,KAAK,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B,GAEhBD,WAAW5L,WAAW;EACpBqI,MAAMxK,KAAKiO,IAAI,CAAC,IAAI,CAACrD;EACrB4C,QAAQpN,KAAKR,MAAMgL,KAAK,EAAG;CAC7B,GAEOmD,WAAW5L;AACpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugin.tsx"],"mappings":";UAMiB,eAAA;EACf,KAAK;AAAA;AAAA,cAKM,gBAAA,EAAkB,MAAM,QAAQ,eAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugin.tsx"],"mappings":";UAMiB;EACf;;cAKW,kBAAkB,cAAc"}
package/dist/index.js CHANGED
@@ -1,25 +1,40 @@
1
1
  import { lazy } from "react";
2
2
  import { definePlugin } from "sanity";
3
3
  import { route } from "sanity/router";
4
- import { jsx } from "react/jsx-runtime";
5
4
  import { c } from "react/compiler-runtime";
5
+ import { jsx } from "react/jsx-runtime";
6
+ /**
7
+ * Couple of things to note:
8
+ * - width and height is set to 1em
9
+ * - fill is `currentColor` - this will ensure that the icon looks uniform and
10
+ * that the hover/active state works. You can of course render anything you
11
+ * would like here, but for plugins that are to be used in more than one
12
+ * studio, we suggest these rules are followed
13
+ **/
6
14
  function GraphViewIcon() {
7
- const $ = c(1);
8
- let t0;
9
- return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", viewBox: "0 0 46.063 46.063", children: /* @__PURE__ */ jsx("path", { fill: "currentColor", d: "M18.022 38.676v2.813h-1.21q-4.864 0-6.525-1.447-1.64-1.445-1.64-5.762v-4.666q0-2.95-1.055-4.083-1.055-1.13-3.828-1.13h-1.19v-2.794h1.19q2.793 0 3.828-1.114 1.055-1.132 1.055-4.043V11.76q0-4.316 1.64-5.742 1.66-1.446 6.524-1.446h1.212v2.793h-1.328q-2.754 0-3.594.86-.84.86-.84 3.613v4.844q0 3.066-.898 4.453-.88 1.387-3.028 1.875 2.168.527 3.047 1.914.88 1.387.88 4.434v4.843q0 2.754.84 3.614.84.86 3.594.86h1.328zM28.04 38.676h1.368q2.735 0 3.555-.84.84-.84.84-3.633V29.36q0-3.047.88-4.434.878-1.387 3.046-1.914-2.17-.488-3.048-1.875-.88-1.387-.88-4.453V11.84q0-2.773-.84-3.613-.82-.86-3.554-.86H28.04V4.574h1.232q4.863 0 6.484 1.446 1.64 1.426 1.64 5.742v4.687q0 2.91 1.055 4.042 1.056 1.114 3.83 1.114h1.21V24.4h-1.21q-2.774 0-3.83 1.13-1.053 1.134-1.053 4.084v4.667q0 4.318-1.64 5.763-1.622 1.446-6.485 1.446h-1.23v-2.814z" }) }), $[0] = t0) : t0 = $[0], t0;
15
+ let $ = c(1), t0;
16
+ return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx("svg", {
17
+ xmlns: "http://www.w3.org/2000/svg",
18
+ width: "1em",
19
+ height: "1em",
20
+ viewBox: "0 0 46.063 46.063",
21
+ children: /* @__PURE__ */ jsx("path", {
22
+ fill: "currentColor",
23
+ d: "M18.022 38.676v2.813h-1.21q-4.864 0-6.525-1.447-1.64-1.445-1.64-5.762v-4.666q0-2.95-1.055-4.083-1.055-1.13-3.828-1.13h-1.19v-2.794h1.19q2.793 0 3.828-1.114 1.055-1.132 1.055-4.043V11.76q0-4.316 1.64-5.742 1.66-1.446 6.524-1.446h1.212v2.793h-1.328q-2.754 0-3.594.86-.84.86-.84 3.613v4.844q0 3.066-.898 4.453-.88 1.387-3.028 1.875 2.168.527 3.047 1.914.88 1.387.88 4.434v4.843q0 2.754.84 3.614.84.86 3.594.86h1.328zM28.04 38.676h1.368q2.735 0 3.555-.84.84-.84.84-3.633V29.36q0-3.047.88-4.434.878-1.387 3.046-1.914-2.17-.488-3.048-1.875-.88-1.387-.88-4.453V11.84q0-2.773-.84-3.613-.82-.86-3.554-.86H28.04V4.574h1.232q4.863 0 6.484 1.446 1.64 1.426 1.64 5.742v4.687q0 2.91 1.055 4.042 1.056 1.114 3.83 1.114h1.21V24.4h-1.21q-2.774 0-3.83 1.13-1.053 1.134-1.053 4.084v4.667q0 4.318-1.64 5.763-1.622 1.446-6.485 1.446h-1.23v-2.814z"
24
+ })
25
+ }), $[0] = t0) : t0 = $[0], t0;
10
26
  }
11
27
  const GraphView = lazy(() => import("./_chunks-es/GraphView.js")), contentGraphView = definePlugin((config = {}) => ({
12
- name: "@sanity/content-graph-view",
13
- tools: [{
14
- name: "graph-your-content",
15
- title: "Graph",
16
- icon: GraphViewIcon,
17
- component: GraphView,
18
- options: config,
19
- router: route.create("/:selectedDocumentId")
20
- }]
28
+ name: "@sanity/content-graph-view",
29
+ tools: [{
30
+ name: "graph-your-content",
31
+ title: "Graph",
32
+ icon: GraphViewIcon,
33
+ component: GraphView,
34
+ options: config,
35
+ router: route.create("/:selectedDocumentId")
36
+ }]
21
37
  }));
22
- export {
23
- contentGraphView
24
- };
25
- //# sourceMappingURL=index.js.map
38
+ export { contentGraphView };
39
+
40
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/tool/GraphViewIcon.tsx","../src/plugin.tsx"],"sourcesContent":["/**\n * Couple of things to note:\n * - width and height is set to 1em\n * - fill is `currentColor` - this will ensure that the icon looks uniform and\n * that the hover/active state works. You can of course render anything you\n * would like here, but for plugins that are to be used in more than one\n * studio, we suggest these rules are followed\n **/\nexport function GraphViewIcon(): React.JSX.Element {\n return (\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1em\" height=\"1em\" viewBox=\"0 0 46.063 46.063\">\n <path\n fill=\"currentColor\"\n d=\"M18.022 38.676v2.813h-1.21q-4.864 0-6.525-1.447-1.64-1.445-1.64-5.762v-4.666q0-2.95-1.055-4.083-1.055-1.13-3.828-1.13h-1.19v-2.794h1.19q2.793 0 3.828-1.114 1.055-1.132 1.055-4.043V11.76q0-4.316 1.64-5.742 1.66-1.446 6.524-1.446h1.212v2.793h-1.328q-2.754 0-3.594.86-.84.86-.84 3.613v4.844q0 3.066-.898 4.453-.88 1.387-3.028 1.875 2.168.527 3.047 1.914.88 1.387.88 4.434v4.843q0 2.754.84 3.614.84.86 3.594.86h1.328zM28.04 38.676h1.368q2.735 0 3.555-.84.84-.84.84-3.633V29.36q0-3.047.88-4.434.878-1.387 3.046-1.914-2.17-.488-3.048-1.875-.88-1.387-.88-4.453V11.84q0-2.773-.84-3.613-.82-.86-3.554-.86H28.04V4.574h1.232q4.863 0 6.484 1.446 1.64 1.426 1.64 5.742v4.687q0 2.91 1.055 4.042 1.056 1.114 3.83 1.114h1.21V24.4h-1.21q-2.774 0-3.83 1.13-1.053 1.134-1.053 4.084v4.667q0 4.318-1.64 5.763-1.622 1.446-6.485 1.446h-1.23v-2.814z\"\n />\n </svg>\n )\n}\n","import {lazy} from 'react'\nimport {definePlugin, type Plugin} from 'sanity'\nimport {route} from 'sanity/router'\n\nimport {GraphViewIcon} from './tool/GraphViewIcon'\n\nexport interface GraphViewConfig {\n query?: string\n}\n\nconst GraphView = lazy(() => import('./tool/GraphView'))\n\nexport const contentGraphView: Plugin<void | GraphViewConfig> =\n definePlugin<void | GraphViewConfig>((config: GraphViewConfig = {}) => {\n return {\n name: '@sanity/content-graph-view',\n\n tools: [\n {\n name: 'graph-your-content',\n title: 'Graph',\n icon: GraphViewIcon,\n component: GraphView,\n options: config,\n router: route.create('/:selectedDocumentId'),\n },\n ],\n }\n })\n"],"names":["GraphViewIcon","$","_c","t0","Symbol","for","GraphView","lazy","contentGraphView","definePlugin","config","name","tools","title","icon","component","options","router","route","create"],"mappings":";;;;;AAQO,SAAAA,gBAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA;AAAA,MAAAC;AAAA,SAAAF,EAAA,CAAA,MAAAG,uBAAAC,IAAA,2BAAA,KAEHF,KAAA,oBAAA,OAAA,EAAW,OAAA,8BAAmC,OAAA,OAAa,QAAA,OAAc,SAAA,qBACvE,UAAA,oBAAA,QAAA,EACO,MAAA,gBACH,GAAA,4zBAAA,CAA2zB,EAAA,CAEj0B,GAAMF,OAAAE,MAAAA,KAAAF,EAAA,CAAA,GALNE;AAKM;ACLV,MAAMG,YAAYC,KAAK,MAAM,OAAO,2BAAkB,CAAC,GAE1CC,mBACXC,aAAqC,CAACC,SAA0B,QACvD;AAAA,EACLC,MAAM;AAAA,EAENC,OAAO,CACL;AAAA,IACED,MAAM;AAAA,IACNE,OAAO;AAAA,IACPC,MAAMd;AAAAA,IACNe,WAAWT;AAAAA,IACXU,SAASN;AAAAA,IACTO,QAAQC,MAAMC,OAAO,sBAAsB;AAAA,EAAA,CAC5C;AAEL,EACD;"}
1
+ {"version":3,"file":"index.js","names":["GraphViewIcon","$","_c","t0","Symbol","for","lazy","definePlugin","Plugin","route","GraphViewIcon","GraphViewConfig","query","GraphView","contentGraphView","config","name","tools","title","icon","component","options","router","create"],"sources":["../src/tool/GraphViewIcon.tsx","../src/plugin.tsx"],"sourcesContent":["/**\n * Couple of things to note:\n * - width and height is set to 1em\n * - fill is `currentColor` - this will ensure that the icon looks uniform and\n * that the hover/active state works. You can of course render anything you\n * would like here, but for plugins that are to be used in more than one\n * studio, we suggest these rules are followed\n **/\nexport function GraphViewIcon(): React.JSX.Element {\n return (\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1em\" height=\"1em\" viewBox=\"0 0 46.063 46.063\">\n <path\n fill=\"currentColor\"\n d=\"M18.022 38.676v2.813h-1.21q-4.864 0-6.525-1.447-1.64-1.445-1.64-5.762v-4.666q0-2.95-1.055-4.083-1.055-1.13-3.828-1.13h-1.19v-2.794h1.19q2.793 0 3.828-1.114 1.055-1.132 1.055-4.043V11.76q0-4.316 1.64-5.742 1.66-1.446 6.524-1.446h1.212v2.793h-1.328q-2.754 0-3.594.86-.84.86-.84 3.613v4.844q0 3.066-.898 4.453-.88 1.387-3.028 1.875 2.168.527 3.047 1.914.88 1.387.88 4.434v4.843q0 2.754.84 3.614.84.86 3.594.86h1.328zM28.04 38.676h1.368q2.735 0 3.555-.84.84-.84.84-3.633V29.36q0-3.047.88-4.434.878-1.387 3.046-1.914-2.17-.488-3.048-1.875-.88-1.387-.88-4.453V11.84q0-2.773-.84-3.613-.82-.86-3.554-.86H28.04V4.574h1.232q4.863 0 6.484 1.446 1.64 1.426 1.64 5.742v4.687q0 2.91 1.055 4.042 1.056 1.114 3.83 1.114h1.21V24.4h-1.21q-2.774 0-3.83 1.13-1.053 1.134-1.053 4.084v4.667q0 4.318-1.64 5.763-1.622 1.446-6.485 1.446h-1.23v-2.814z\"\n />\n </svg>\n )\n}\n","import {lazy} from 'react'\nimport {definePlugin, type Plugin} from 'sanity'\nimport {route} from 'sanity/router'\n\nimport {GraphViewIcon} from './tool/GraphViewIcon'\n\nexport interface GraphViewConfig {\n query?: string\n}\n\nconst GraphView = lazy(() => import('./tool/GraphView'))\n\nexport const contentGraphView: Plugin<void | GraphViewConfig> =\n definePlugin<void | GraphViewConfig>((config: GraphViewConfig = {}) => {\n return {\n name: '@sanity/content-graph-view',\n\n tools: [\n {\n name: 'graph-your-content',\n title: 'Graph',\n icon: GraphViewIcon,\n component: GraphView,\n options: config,\n router: route.create('/:selectedDocumentId'),\n },\n ],\n }\n })\n"],"mappings":";;;;;;;;;;;;;AAQA,SAAOA,gBAAA;CAAA,IAAAC,IAAAC,EAAA,CAAA,GAAAC;CAOG,OAPHF,EAAA,OAAAG,OAAAC,IAAA,2BAAA,KAEHF,KAAA,oBAAA,OAAA;EAAW,OAAA;EAAmC,OAAA;EAAa,QAAA;EAAc,SAAA;YACvE,oBAAA,QAAA;GACO,MAAA;GACH,GAAA;EAA2zB,CAAA;CAE3zB,CAAA,GAAAF,EAAA,KAAAE,MAAAA,KAAAF,EAAA,IALNE;AAKM;ACLV,MAAMU,YAAYP,WAAW,OAAO,4BAAmB,GAE1CQ,mBACXP,cAAsCQ,SAA0B,CAAC,OACxD;CACLC,MAAM;CAENC,OAAO,CACL;EACED,MAAM;EACNE,OAAO;EACPC,MAAMT;EACNU,WAAWP;EACXQ,SAASN;EACTO,QAAQb,MAAMc,OAAO,sBAAsB;CAC7C,CAAC;AAEL,EACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-graph-view",
3
- "version": "5.0.12",
3
+ "version": "5.0.14",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/sanity-io/plugins/tree/main/plugins/sanity-plugin-graph-view#readme",
6
6
  "bugs": {
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@sanity/color": "^3.0.6",
27
- "@sanity/ui": "^3.3.0",
27
+ "@sanity/ui": "^3.3.5",
28
28
  "bezier-easing": "^2.1.0",
29
29
  "deep-equal": "^2.2.3",
30
30
  "polished": "^4.3.1",
@@ -32,17 +32,16 @@
32
32
  "uuid": "^14.0.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@sanity/pkg-utils": "^10.9.0",
36
- "@sanity/tsconfig": "^2.1.0",
35
+ "@sanity/tsconfig": "^2.2.0",
36
+ "@sanity/tsdown-config": "^0.13.1",
37
37
  "@types/deep-equal": "^1.0.4",
38
- "@types/node": "^24.13.2",
38
+ "@types/node": "^24.13.3",
39
39
  "@types/react": "^19.2.17",
40
40
  "babel-plugin-react-compiler": "^1.0.0",
41
- "babel-plugin-styled-components": "^2.3.0",
42
41
  "react": "^19.2.7",
43
42
  "sanity": "^6.3.0",
44
43
  "styled-components": "^6.4.3",
45
- "@repo/package.config": "0.0.0"
44
+ "tsdown": "^0.22.5"
46
45
  },
47
46
  "peerDependencies": {
48
47
  "react": "^19.2",
@@ -53,6 +52,6 @@
53
52
  "node": ">=20.19 <22 || >=22.12"
54
53
  },
55
54
  "scripts": {
56
- "build": "pkg build --strict --check --clean"
55
+ "build": "tsdown"
57
56
  }
58
57
  }