sanity-plugin-graph-view 1.0.3 → 3.0.0-studio-v3.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.
@@ -0,0 +1,576 @@
1
+ import {jsx as $9Ue0q$jsx, jsxs as $9Ue0q$jsxs} from "react/jsx-runtime";
2
+ import {createPlugin as $9Ue0q$createPlugin, useClient as $9Ue0q$useClient} from "sanity";
3
+ import {route as $9Ue0q$route, useUserColorManager as $9Ue0q$useUserColorManager, useRouter as $9Ue0q$useRouter} from "sanity/_unstable";
4
+ import {useState as $9Ue0q$useState, useCallback as $9Ue0q$useCallback, useEffect as $9Ue0q$useEffect} from "react";
5
+ import {rgba as $9Ue0q$rgba} from "polished";
6
+ import $9Ue0q$deepequal from "deep-equal";
7
+ import {ForceGraph2D as $9Ue0q$ForceGraph2D} from "react-force-graph";
8
+ import {v4 as $9Ue0q$v4} from "uuid";
9
+ import $9Ue0q$beziereasing from "bezier-easing";
10
+ import {useTheme as $9Ue0q$useTheme} from "@sanity/ui";
11
+ import {gray as $9Ue0q$gray, white as $9Ue0q$white, black as $9Ue0q$black, COLOR_HUES as $9Ue0q$COLOR_HUES, hues as $9Ue0q$hues} from "@sanity/color";
12
+ import $9Ue0q$styledcomponents from "styled-components";
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ function $a62f31ea2127949a$export$c006713bb64ff575(query, params, options, onUpdate, dependencies) {
26
+ const client = (0, $9Ue0q$useClient)();
27
+ (0, $9Ue0q$useEffect)(()=>{
28
+ const subscription = client.listen(query, params, options).subscribe((update)=>{
29
+ onUpdate(update);
30
+ });
31
+ return ()=>{
32
+ subscription.unsubscribe();
33
+ };
34
+ }, dependencies);
35
+ }
36
+ function $a62f31ea2127949a$export$7b4649445b8cee9f(query, onFetch, dependencies) {
37
+ const client = (0, $9Ue0q$useClient)();
38
+ (0, $9Ue0q$useEffect)(()=>{
39
+ client.fetch(query).then((result)=>{
40
+ onFetch(result);
41
+ });
42
+ }, dependencies);
43
+ }
44
+
45
+
46
+ function $4d8ab1e120d1bd2c$export$30043de3fae42dd1(value) {
47
+ if (value === null) return 0;
48
+ if (typeof value === "object") return Object.entries(value).reduce((total, [k, v])=>total + $4d8ab1e120d1bd2c$export$30043de3fae42dd1(k) + $4d8ab1e120d1bd2c$export$30043de3fae42dd1(v), 0);
49
+ if (Array.isArray(value)) return Object.entries(value).reduce((total, v)=>total + $4d8ab1e120d1bd2c$export$30043de3fae42dd1(v), 0);
50
+ if (typeof value === "string") return value.length;
51
+ return 1;
52
+ }
53
+ function $4d8ab1e120d1bd2c$export$fe58198efe02b173(url, w, h) {
54
+ return new Promise((resolve)=>{
55
+ const img = new Image(w, h);
56
+ img.onload = ()=>{
57
+ resolve(img);
58
+ };
59
+ img.onerror = (event)=>{
60
+ // eslint-disable-next-line no-console
61
+ console.log("Image error", event);
62
+ resolve(null);
63
+ };
64
+ img.src = url;
65
+ });
66
+ }
67
+ function $4d8ab1e120d1bd2c$export$b035e44d7bb4278f(array, f) {
68
+ return array.sort((a, b)=>{
69
+ const va = f(a);
70
+ const vb = f(b);
71
+ // eslint-disable-next-line no-nested-ternary
72
+ return va < vb ? -1 : va > vb ? 1 : 0;
73
+ });
74
+ }
75
+ function $4d8ab1e120d1bd2c$export$6a506b36fdea397d(s, limit) {
76
+ if (s.length > limit) return `${s.substring(0, limit)}…`;
77
+ return s;
78
+ }
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+ const $7d4cc22b56987fa3$export$3865e82159b2890b = (0, $9Ue0q$styledcomponents).div`
87
+ font-family: ${({ theme: theme })=>theme.fonts.text.family};
88
+ position: absolute;
89
+ top: 0;
90
+ left: 0;
91
+ width: 100%;
92
+ height: 100%;
93
+ background: ${(0, $9Ue0q$black).hex};
94
+ `;
95
+ const $7d4cc22b56987fa3$export$c4a562231524e009 = (0, $9Ue0q$styledcomponents).div`
96
+ position: relative;
97
+ width: 100%;
98
+ height: 100%;
99
+ `;
100
+ const $7d4cc22b56987fa3$export$c33c2949cc668daf = (0, $9Ue0q$styledcomponents).div`
101
+ font-family: ${({ theme: theme })=>theme.fonts.text.family};
102
+ display: none;
103
+ position: absolute;
104
+ bottom: ${({ theme: theme })=>theme.space[0]}px;
105
+ left: 50%;
106
+ transform: translate3d(-50%, 0, 0);
107
+ background: var(--component-bg);
108
+ border-radius: ${({ theme: theme })=>theme.radius[2]}px;
109
+ padding: ${({ theme: theme })=>theme.space[2]}px;
110
+ z-index: 1000;
111
+
112
+ &:empty {
113
+ display: none;
114
+ }
115
+ `;
116
+ const $7d4cc22b56987fa3$export$ed247974535929c7 = (0, $9Ue0q$styledcomponents).div`
117
+ color: #ccc;
118
+ position: absolute;
119
+ top: ${({ theme: theme })=>theme.space[4]}px;
120
+ left: ${({ theme: theme })=>theme.space[4]}px;
121
+
122
+ & > div {
123
+ margin: 5px 0;
124
+ }
125
+ `;
126
+ const $7d4cc22b56987fa3$export$3953a5b2d12dbab1 = (0, $9Ue0q$styledcomponents).div`
127
+ display: flex;
128
+ `;
129
+ const $7d4cc22b56987fa3$export$f6aea9731eb36ee8 = (0, $9Ue0q$styledcomponents).div`
130
+ width: 1.25em;
131
+ height: 1.25em;
132
+ background: currentColor;
133
+ border-radius: 50%;
134
+ margin-right: ${({ theme: theme })=>theme.space[2]}px;
135
+ `;
136
+
137
+
138
+
139
+
140
+ const $40c15bf381c43ff0$var$DEFAULT_QUERY = `
141
+ *[
142
+ !(_id in path("_.*")) &&
143
+ !(_type match "system.*") &&
144
+ !(_type match "sanity.*")
145
+ ]
146
+ `;
147
+ const $40c15bf381c43ff0$var$fadeEasing = (0, $9Ue0q$beziereasing)(0, 0.9, 1, 1);
148
+ const $40c15bf381c43ff0$var$softEasing = (0, $9Ue0q$beziereasing)(0.25, 0.1, 0.0, 1.0);
149
+ const $40c15bf381c43ff0$var$idleTimeout = 10000;
150
+ const $40c15bf381c43ff0$var$imageSize = 40;
151
+ function $40c15bf381c43ff0$var$getTopDocTypes(counts) {
152
+ return (0, $4d8ab1e120d1bd2c$export$b035e44d7bb4278f)(Object.keys(counts), (docType)=>counts[docType] || 0).reverse().slice(0, 10);
153
+ }
154
+ function $40c15bf381c43ff0$var$formatDocType(docType) {
155
+ return (docType.substring(0, 1).toUpperCase() + docType.substring(1)).replace(/\./g, " ").replace(/[A-Z]/g, " $&").trim();
156
+ }
157
+ function $40c15bf381c43ff0$var$getDocTypeCounts(docs) {
158
+ const types = {};
159
+ for (const doc of docs)types[doc._type] = (types[doc._type] || 0) + 1;
160
+ return types;
161
+ }
162
+ function $40c15bf381c43ff0$var$labelFor(doc) {
163
+ return `${doc.title || doc.name || doc._id}`.trim();
164
+ }
165
+ function $40c15bf381c43ff0$var$valueFor(doc, maxSize) {
166
+ return 5 + 100 * ((0, $4d8ab1e120d1bd2c$export$30043de3fae42dd1)(doc) / maxSize);
167
+ }
168
+ function $40c15bf381c43ff0$var$findRefs(obj, dest = []) {
169
+ if (obj !== null) {
170
+ if (typeof obj === "object") for (const [k, v] of Object.entries(obj)){
171
+ if (k === "_ref" && typeof v === "string" && v.length > 0) dest.push($40c15bf381c43ff0$var$stripDraftId(v));
172
+ $40c15bf381c43ff0$var$findRefs(v, dest);
173
+ }
174
+ else if (Array.isArray(obj)) for (const v1 of obj)$40c15bf381c43ff0$var$findRefs(v1, dest);
175
+ }
176
+ return dest;
177
+ }
178
+ function $40c15bf381c43ff0$var$stripDraftId(id) {
179
+ return id.replace(/^drafts\./, "");
180
+ }
181
+ function $40c15bf381c43ff0$var$deduplicateDrafts(docs) {
182
+ const deduped = {};
183
+ for (const doc of docs)if (!/^drafts\./.test(doc._id)) deduped[doc._id] = doc;
184
+ for (const doc1 of docs)if (/^drafts\./.test(doc1._id)) {
185
+ const id = $40c15bf381c43ff0$var$stripDraftId(doc1._id);
186
+ deduped[id] = Object.assign(doc1, {
187
+ _id: id
188
+ });
189
+ }
190
+ return Object.values(deduped);
191
+ }
192
+ class $40c15bf381c43ff0$var$Users {
193
+ _users = [];
194
+ async getById(id, client) {
195
+ let user = this._users.find((u)=>u._id === id);
196
+ if (!user) {
197
+ user = await client.users.getById(id);
198
+ this._users.push(user);
199
+ user.image = await (0, $4d8ab1e120d1bd2c$export$fe58198efe02b173)(user.imageUrl || "https://raw.githubusercontent.com/sanity-io/sanity-plugin-graph-view/main/assets/head-silhouette.jpg", $40c15bf381c43ff0$var$imageSize, $40c15bf381c43ff0$var$imageSize);
200
+ }
201
+ return user;
202
+ }
203
+ }
204
+ class $40c15bf381c43ff0$var$Session {
205
+ id = null;
206
+ user = null;
207
+ doc = null;
208
+ lastActive = 0;
209
+ startTime = 0;
210
+ angle = 0;
211
+ }
212
+ class $40c15bf381c43ff0$var$GraphData {
213
+ sessions = [];
214
+ constructor(docs = []){
215
+ const docsById = {};
216
+ for (const doc2 of docs)docsById[doc2._id] = doc2;
217
+ this.data = {
218
+ nodes: docs.map((d)=>Object.assign({
219
+ id: d._id,
220
+ type: "document",
221
+ doc: d
222
+ })),
223
+ links: docs.flatMap((doc)=>$40c15bf381c43ff0$var$findRefs(doc).map((ref)=>({
224
+ source: doc._id,
225
+ target: ref
226
+ }))).filter((link)=>docsById[link.source] && docsById[link.target])
227
+ };
228
+ }
229
+ setSession(user, docNode) {
230
+ let session = this.sessions.find((s)=>s.user.id === user.id && s.doc?._id === docNode.doc._id);
231
+ if (!session) {
232
+ session = new $40c15bf381c43ff0$var$Session();
233
+ session.id = (0, $9Ue0q$v4)();
234
+ session.user = user;
235
+ session.startTime = Date.now();
236
+ session.doc = docNode.doc;
237
+ session.angle = Math.random() * 2 * Math.PI;
238
+ this.sessions.push(session);
239
+ }
240
+ session.lastActive = Date.now();
241
+ }
242
+ reapSessions() {
243
+ for(let i = 0; i < this.sessions.length; i++){
244
+ const session = this.sessions[i];
245
+ if (Date.now() - session.lastActive > $40c15bf381c43ff0$var$idleTimeout) {
246
+ this.sessions = [
247
+ ...this.sessions.slice(0, i),
248
+ ...this.sessions.slice(i + 1)
249
+ ];
250
+ i--;
251
+ }
252
+ }
253
+ }
254
+ clone() {
255
+ const copy = new $40c15bf381c43ff0$var$GraphData();
256
+ Object.assign(copy, this);
257
+ copy.data = {
258
+ nodes: [
259
+ ...this.data.nodes
260
+ ],
261
+ links: [
262
+ ...this.data.links
263
+ ]
264
+ };
265
+ return copy;
266
+ }
267
+ }
268
+ const $40c15bf381c43ff0$var$users = new $40c15bf381c43ff0$var$Users();
269
+ function $40c15bf381c43ff0$export$6a7fe3ef90e8d566(props) {
270
+ const query = props.query || $40c15bf381c43ff0$var$DEFAULT_QUERY;
271
+ const userColorManager = (0, $9Ue0q$useUserColorManager)();
272
+ const [maxSize, setMaxSize] = (0, $9Ue0q$useState)(0);
273
+ const [hoverNode, setHoverNode] = (0, $9Ue0q$useState)(null);
274
+ const [documents, setDocuments] = (0, $9Ue0q$useState)([]);
275
+ const [docTypes, setDocTypes] = (0, $9Ue0q$useState)({});
276
+ const [graph, setGraph] = (0, $9Ue0q$useState)(()=>new $40c15bf381c43ff0$var$GraphData());
277
+ const router = (0, $9Ue0q$useRouter)();
278
+ const client = (0, $9Ue0q$useClient)();
279
+ const fetchCallback = (0, $9Ue0q$useCallback)((_docs)=>{
280
+ const docs = $40c15bf381c43ff0$var$deduplicateDrafts(_docs);
281
+ setMaxSize(Math.max(...docs.map((0, $4d8ab1e120d1bd2c$export$30043de3fae42dd1))));
282
+ setDocuments(docs);
283
+ setDocTypes($40c15bf381c43ff0$var$getDocTypeCounts(docs));
284
+ setGraph(new $40c15bf381c43ff0$var$GraphData(docs));
285
+ }, []);
286
+ const listenCallback = (0, $9Ue0q$useCallback)(async (update)=>{
287
+ const doc = update.result;
288
+ if (doc) {
289
+ doc._id = $40c15bf381c43ff0$var$stripDraftId(doc._id);
290
+ const docsById = {};
291
+ for (const d1 of documents)docsById[d1._id] = d1;
292
+ let oldDoc;
293
+ const docs = [
294
+ ...documents
295
+ ];
296
+ const idx = documents.findIndex((d)=>d._id === doc._id);
297
+ if (idx >= 0) {
298
+ oldDoc = docs[idx];
299
+ docs[idx] = doc;
300
+ } else docs.push(doc);
301
+ setDocuments(docs);
302
+ setDocTypes($40c15bf381c43ff0$var$getDocTypeCounts(docs));
303
+ setMaxSize(Math.max(...docs.map((0, $4d8ab1e120d1bd2c$export$30043de3fae42dd1))));
304
+ const newGraph = graph.clone();
305
+ const oldRefs = $40c15bf381c43ff0$var$findRefs(oldDoc || {}).filter((id)=>id === doc._id || docsById[id] !== null);
306
+ const newRefs = $40c15bf381c43ff0$var$findRefs(doc).filter((id)=>id === doc._id || docsById[id] !== null);
307
+ let graphChanged = !(0, $9Ue0q$deepequal)(oldRefs, newRefs);
308
+ if (graphChanged) newGraph.data.links = newGraph.data.links.filter((l)=>l.source.id !== doc._id).concat(newRefs.map((ref)=>({
309
+ source: doc._id,
310
+ target: ref
311
+ })));
312
+ let docNode;
313
+ const nodeIdx = graph.data.nodes.findIndex((n)=>n.doc && n.doc._id === doc._id);
314
+ if (nodeIdx >= 0) {
315
+ docNode = graph.data.nodes[nodeIdx];
316
+ docNode.doc = doc;
317
+ } else {
318
+ docNode = {
319
+ id: doc._id,
320
+ type: "document",
321
+ doc: doc
322
+ };
323
+ newGraph.data.nodes.push(docNode);
324
+ graphChanged = true;
325
+ }
326
+ if (graphChanged) setGraph(newGraph);
327
+ const user = await $40c15bf381c43ff0$var$users.getById(update.identity, client);
328
+ graph.setSession(user, docNode);
329
+ } else if (update.transition === "disappear") {
330
+ const docId = $40c15bf381c43ff0$var$stripDraftId(update.documentId);
331
+ const docs = documents.filter((d)=>d._id !== docId);
332
+ setDocuments(docs);
333
+ setDocTypes($40c15bf381c43ff0$var$getDocTypeCounts(docs));
334
+ setMaxSize(Math.max(...docs.map((0, $4d8ab1e120d1bd2c$export$30043de3fae42dd1))));
335
+ const newGraph = graph.clone();
336
+ newGraph.data.links = newGraph.data.links.filter((l)=>l.source.id !== docId && l.target.id !== docId);
337
+ newGraph.data.nodes = newGraph.data.nodes.filter((n)=>n.id !== docId);
338
+ setGraph(newGraph);
339
+ }
340
+ }, [
341
+ documents,
342
+ graph,
343
+ client
344
+ ]);
345
+ (0, $a62f31ea2127949a$export$7b4649445b8cee9f)(query, fetchCallback, []);
346
+ (0, $a62f31ea2127949a$export$c006713bb64ff575)(query, {}, {}, listenCallback, [
347
+ documents,
348
+ graph
349
+ ]);
350
+ (0, $9Ue0q$useEffect)(()=>{
351
+ const interval = setInterval(()=>graph.reapSessions(), 1000);
352
+ return ()=>clearInterval(interval);
353
+ }, [
354
+ graph
355
+ ]);
356
+ const theme = (0, $9Ue0q$useTheme)().sanity;
357
+ return /*#__PURE__*/ (0, $9Ue0q$jsx)((0, $7d4cc22b56987fa3$export$c4a562231524e009), {
358
+ theme: theme,
359
+ children: /*#__PURE__*/ (0, $9Ue0q$jsxs)((0, $7d4cc22b56987fa3$export$3865e82159b2890b), {
360
+ theme: theme,
361
+ children: [
362
+ /*#__PURE__*/ (0, $9Ue0q$jsx)((0, $7d4cc22b56987fa3$export$ed247974535929c7), {
363
+ theme: theme,
364
+ children: $40c15bf381c43ff0$var$getTopDocTypes(docTypes).map((docType)=>/*#__PURE__*/ (0, $9Ue0q$jsxs)((0, $7d4cc22b56987fa3$export$3953a5b2d12dbab1), {
365
+ className: "legend__row",
366
+ style: {
367
+ color: $40c15bf381c43ff0$var$getDocTypeColor(docType).fill
368
+ },
369
+ children: [
370
+ /*#__PURE__*/ (0, $9Ue0q$jsx)((0, $7d4cc22b56987fa3$export$f6aea9731eb36ee8), {
371
+ theme: theme
372
+ }),
373
+ /*#__PURE__*/ (0, $9Ue0q$jsx)("div", {
374
+ children: $40c15bf381c43ff0$var$formatDocType(docType)
375
+ })
376
+ ]
377
+ }, docType))
378
+ }),
379
+ hoverNode && /*#__PURE__*/ (0, $9Ue0q$jsx)((0, $7d4cc22b56987fa3$export$c33c2949cc668daf), {
380
+ theme: theme,
381
+ children: $40c15bf381c43ff0$var$labelFor(hoverNode.doc)
382
+ }),
383
+ /*#__PURE__*/ (0, $9Ue0q$jsx)((0, $9Ue0q$ForceGraph2D), {
384
+ graphData: graph.data,
385
+ nodeAutoColorBy: "group",
386
+ enableNodeDrag: false,
387
+ onNodeHover: (node)=>setHoverNode(node),
388
+ onNodeClick: (node)=>{
389
+ router.navigateIntent("edit", {
390
+ id: node.doc._id,
391
+ documentType: node.doc._type
392
+ });
393
+ },
394
+ linkColor: ()=>(0, $9Ue0q$rgba)((0, $9Ue0q$gray)[500].hex, 0.25),
395
+ nodeLabel: ()=>"",
396
+ nodeRelSize: 1,
397
+ nodeVal: (node)=>$40c15bf381c43ff0$var$valueFor(node.doc, maxSize),
398
+ onRenderFramePost: (ctx, globalScale)=>{
399
+ for (const session of graph.sessions){
400
+ const node = graph.data.nodes.find((n)=>n.doc && n.doc._id === session?.doc?._id);
401
+ if (node) {
402
+ const idleFactorRange = $40c15bf381c43ff0$var$idleTimeout;
403
+ const angle = session.angle;
404
+ const radius = Math.sqrt($40c15bf381c43ff0$var$valueFor(node.doc, maxSize));
405
+ const image = session.user.image;
406
+ const userColor = userColorManager.get(session.user.displayName).tints[400].hex;
407
+ const distance = radius * globalScale + 40;
408
+ const imgW = image ? image.width : 0;
409
+ const imgH = image ? image.height : 0;
410
+ const x = node.x + Math.sin(angle) * distance / globalScale;
411
+ const y = node.y + Math.cos(angle) * distance / globalScale;
412
+ ctx.save();
413
+ try {
414
+ ctx.globalAlpha = $40c15bf381c43ff0$var$fadeEasing(1 - Math.min(idleFactorRange, Date.now() - session.lastActive) / idleFactorRange);
415
+ ctx.font = `bold ${Math.round(12 / globalScale)}px sans-serif`;
416
+ ctx.beginPath();
417
+ ctx.strokeStyle = (0, $9Ue0q$rgba)((0, $9Ue0q$white).hex, 1.0);
418
+ ctx.lineWidth = 2 / globalScale;
419
+ ctx.moveTo(node.x + Math.sin(angle) * (distance - imgW / 2) / globalScale, node.y + Math.cos(angle) * (distance - imgH / 2) / globalScale);
420
+ ctx.lineTo(node.x + Math.sin(angle) * radius, node.y + Math.cos(angle) * radius);
421
+ ctx.stroke();
422
+ ctx.beginPath();
423
+ ctx.strokeStyle = (0, $9Ue0q$rgba)((0, $9Ue0q$white).hex, 1.0);
424
+ ctx.lineWidth = 2 / globalScale;
425
+ ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false);
426
+ ctx.stroke();
427
+ if (image) {
428
+ ctx.save();
429
+ // eslint-disable-next-line max-depth
430
+ try {
431
+ const dur = 700;
432
+ const f = $40c15bf381c43ff0$var$softEasing(Math.max(0, (dur - (Date.now() - session.startTime)) / dur));
433
+ // eslint-disable-next-line max-depth
434
+ if (f > 0) {
435
+ ctx.beginPath();
436
+ ctx.fillStyle = (0, $9Ue0q$rgba)(userColor, f);
437
+ ctx.arc(x, y, (imgW / 2 + 10) / globalScale, 0, 2 * Math.PI, false);
438
+ ctx.fill();
439
+ }
440
+ ctx.beginPath();
441
+ ctx.fillStyle = (0, $9Ue0q$rgba)((0, $9Ue0q$white).hex, 1.0);
442
+ ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, false);
443
+ ctx.clip();
444
+ ctx.drawImage(image, x - imgW / globalScale / 2, y - imgH / globalScale / 2, imgW / globalScale, imgH / globalScale);
445
+ ctx.strokeStyle = (0, $9Ue0q$black).hex;
446
+ ctx.lineWidth = 6 / globalScale;
447
+ ctx.stroke();
448
+ ctx.strokeStyle = userColor;
449
+ ctx.lineWidth = 4 / globalScale;
450
+ ctx.stroke();
451
+ } finally{
452
+ ctx.restore();
453
+ }
454
+ }
455
+ ctx.beginPath();
456
+ ctx.strokeStyle = (0, $9Ue0q$rgba)((0, $9Ue0q$black).hex, 1);
457
+ ctx.lineWidth = 0.5 / globalScale;
458
+ ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, false);
459
+ ctx.stroke();
460
+ const above = angle >= Math.PI / 2 && angle < Math.PI * 1.5;
461
+ const textY = above ? y - (imgH / 2 + 5) / globalScale : y + (imgH / 2 + 5) / globalScale;
462
+ ctx.fillStyle = (0, $9Ue0q$rgba)((0, $9Ue0q$white).hex, 1.0);
463
+ ctx.textAlign = "center";
464
+ ctx.textBaseline = above ? "bottom" : "top";
465
+ ctx.fillText(session.user.displayName, x, textY);
466
+ } finally{
467
+ ctx.restore();
468
+ }
469
+ }
470
+ }
471
+ },
472
+ nodeCanvasObject: (node, ctx, globalScale)=>{
473
+ // eslint-disable-next-line default-case
474
+ switch(node.type){
475
+ case "document":
476
+ {
477
+ const nodeColor = $40c15bf381c43ff0$var$getDocTypeColor(node.doc._type);
478
+ const radius = Math.sqrt($40c15bf381c43ff0$var$valueFor(node.doc, maxSize));
479
+ const fontSize = Math.min(100, 10.0 / globalScale);
480
+ ctx.beginPath();
481
+ ctx.fillStyle = hoverNode !== null && node.doc._id === hoverNode.doc._id ? (0, $9Ue0q$rgba)((0, $9Ue0q$gray)[500].hex, 0.8) : nodeColor.fill;
482
+ ctx.strokeStyle = nodeColor.border;
483
+ ctx.lineWidth = 0.5;
484
+ ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false);
485
+ ctx.stroke();
486
+ ctx.fill();
487
+ if (radius * globalScale > 10) {
488
+ ctx.font = `${fontSize}px sans-serif`;
489
+ const w = radius * 2 + 30 / globalScale;
490
+ for(let len = 50; len >= 5; len /= 1.2){
491
+ const label = (0, $4d8ab1e120d1bd2c$export$6a506b36fdea397d)($40c15bf381c43ff0$var$labelFor(node.doc), Math.round(len));
492
+ const textMetrics = ctx.measureText(label);
493
+ if (textMetrics.width < w) {
494
+ // ctx.fillStyle = rgba(color.white.hex, 1.0)
495
+ ctx.textAlign = "center";
496
+ ctx.textBaseline = "top";
497
+ ctx.strokeStyle = (0, $9Ue0q$rgba)((0, $9Ue0q$black).hex, 0.5);
498
+ ctx.lineWidth = 2 / globalScale;
499
+ ctx.strokeText(label, node.x, node.y + radius + 5 / globalScale);
500
+ ctx.fillText(label, node.x, node.y + radius + 5 / globalScale);
501
+ break;
502
+ }
503
+ }
504
+ }
505
+ }
506
+ }
507
+ },
508
+ linkCanvasObject: (link, ctx, globalScale)=>{
509
+ ctx.beginPath();
510
+ ctx.strokeStyle = (0, $9Ue0q$rgba)((0, $9Ue0q$gray)[500].hex, 0.125);
511
+ ctx.lineWidth = 2 / globalScale;
512
+ ctx.moveTo(link.source.x, link.source.y);
513
+ ctx.lineTo(link.target.x, link.target.y);
514
+ ctx.stroke();
515
+ }
516
+ })
517
+ ]
518
+ })
519
+ });
520
+ }
521
+ const $40c15bf381c43ff0$var$colorCache = {};
522
+ let $40c15bf381c43ff0$var$typeColorNum = 0;
523
+ function $40c15bf381c43ff0$var$getDocTypeColor(docType) {
524
+ if ($40c15bf381c43ff0$var$colorCache[docType]) return $40c15bf381c43ff0$var$colorCache[docType];
525
+ const hue = (0, $9Ue0q$COLOR_HUES)[$40c15bf381c43ff0$var$typeColorNum % (0, $9Ue0q$COLOR_HUES).length];
526
+ $40c15bf381c43ff0$var$typeColorNum += 1;
527
+ $40c15bf381c43ff0$var$colorCache[docType] = {
528
+ fill: (0, $9Ue0q$hues)[hue][400].hex,
529
+ border: (0, $9Ue0q$rgba)((0, $9Ue0q$black).hex, 0.5)
530
+ };
531
+ return $40c15bf381c43ff0$var$colorCache[docType];
532
+ }
533
+
534
+
535
+
536
+
537
+ const $c82d90e983fc06b4$export$401cc1e36cc18bf0 = ()=>/*#__PURE__*/ (0, $9Ue0q$jsx)("svg", {
538
+ xmlns: "http://www.w3.org/2000/svg",
539
+ width: "1em",
540
+ height: "1em",
541
+ viewBox: "0 0 46.063 46.063",
542
+ children: /*#__PURE__*/ (0, $9Ue0q$jsx)("path", {
543
+ fill: "currentColor",
544
+ 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"
545
+ })
546
+ });
547
+
548
+
549
+
550
+
551
+
552
+ const $090815f5086f7f29$export$e3438defddc96622 = (0, $9Ue0q$createPlugin)((config = {})=>{
553
+ return {
554
+ name: "@sanity/content-graph-view",
555
+ tools: (prev)=>{
556
+ return [
557
+ ...prev,
558
+ {
559
+ name: "graph-your-content",
560
+ title: "Graph",
561
+ icon: (0, $c82d90e983fc06b4$export$401cc1e36cc18bf0),
562
+ component: function component() {
563
+ return /*#__PURE__*/ (0, $9Ue0q$jsx)((0, $40c15bf381c43ff0$export$6a7fe3ef90e8d566), {
564
+ ...config
565
+ });
566
+ },
567
+ router: (0, $9Ue0q$route).create("/:selectedDocumentId")
568
+ },
569
+ ];
570
+ }
571
+ };
572
+ });
573
+
574
+
575
+ export {$090815f5086f7f29$export$e3438defddc96622 as contentGraphView};
576
+ //# sourceMappingURL=index.modern.js.map