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