sanity-plugin-graph-view 3.1.0 → 3.2.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.
@@ -1,71 +1,70 @@
1
1
  "use strict";
2
- var jsxRuntime = require("react/jsx-runtime"), BezierEasing = require("bezier-easing"), deepEqual = require("deep-equal"), polished = require("polished"), react = require("react"), reactForceGraph = require("react-force-graph"), sanity = require("sanity"), router = require("sanity/router"), uuid = require("uuid"), color = require("@sanity/color"), ui = require("@sanity/ui"), styled = require("styled-components");
2
+ var jsxRuntime = require("react/jsx-runtime"), BezierEasing = require("bezier-easing"), deepEqual = require("deep-equal"), polished = require("polished"), react = require("react"), reactForceGraph = require("react-force-graph"), sanity = require("sanity"), router = require("sanity/router"), uuid = require("uuid"), color = require("@sanity/color"), ui = require("@sanity/ui"), styledComponents = require("styled-components");
3
3
  function _interopDefaultCompat(e) {
4
4
  return e && typeof e == "object" && "default" in e ? e : { default: e };
5
5
  }
6
- var BezierEasing__default = /* @__PURE__ */ _interopDefaultCompat(BezierEasing), deepEqual__default = /* @__PURE__ */ _interopDefaultCompat(deepEqual), styled__default = /* @__PURE__ */ _interopDefaultCompat(styled);
7
- const GraphRoot = styled__default.default.div`
8
- font-family: ${({ theme }) => theme.fonts.text.family};
6
+ var BezierEasing__default = /* @__PURE__ */ _interopDefaultCompat(BezierEasing), deepEqual__default = /* @__PURE__ */ _interopDefaultCompat(deepEqual);
7
+ const GraphRoot = styledComponents.styled.div`
8
+ font-family: ${({
9
+ theme
10
+ }) => theme.fonts.text.family};
9
11
  position: absolute;
10
12
  top: 0;
11
13
  left: 0;
12
14
  width: 100%;
13
15
  height: 100%;
14
16
  background: ${color.black.hex};
15
- `, GraphWrapper = styled__default.default.div`
17
+ `, GraphWrapper = styledComponents.styled.div`
16
18
  position: relative;
17
19
  width: 100%;
18
20
  height: 100%;
19
- `, HoverNode = styled__default.default.div`
20
- font-family: ${({ theme }) => theme.fonts.text.family};
21
+ `, HoverNode = styledComponents.styled.div`
22
+ font-family: ${({
23
+ theme
24
+ }) => theme.fonts.text.family};
21
25
  display: none;
22
26
  position: absolute;
23
- bottom: ${({ theme }) => theme.space[0]}px;
27
+ bottom: ${({
28
+ theme
29
+ }) => theme.space[0]}px;
24
30
  left: 50%;
25
31
  transform: translate3d(-50%, 0, 0);
26
32
  background: var(--component-bg);
27
- border-radius: ${({ theme }) => theme.radius[2]}px;
28
- padding: ${({ theme }) => theme.space[2]}px;
33
+ border-radius: ${({
34
+ theme
35
+ }) => theme.radius[2]}px;
36
+ padding: ${({
37
+ theme
38
+ }) => theme.space[2]}px;
29
39
  z-index: 1000;
30
40
 
31
41
  &:empty {
32
42
  display: none;
33
43
  }
34
- `, Legend = styled__default.default.div`
44
+ `, Legend = styledComponents.styled.div`
35
45
  color: #ccc;
36
46
  position: absolute;
37
- top: ${({ theme }) => theme.space[4]}px;
38
- left: ${({ theme }) => theme.space[4]}px;
47
+ top: ${({
48
+ theme
49
+ }) => theme.space[4]}px;
50
+ left: ${({
51
+ theme
52
+ }) => theme.space[4]}px;
39
53
 
40
54
  & > div {
41
55
  margin: 5px 0;
42
56
  }
43
- `, LegendRow = styled__default.default.div`
57
+ `, LegendRow = styledComponents.styled.div`
44
58
  display: flex;
45
- `, LegendBadge = styled__default.default.div`
59
+ `, LegendBadge = styledComponents.styled.div`
46
60
  width: 1.25em;
47
61
  height: 1.25em;
48
62
  background: currentColor;
49
63
  border-radius: 50%;
50
- margin-right: ${({ theme }) => theme.space[2]}px;
64
+ margin-right: ${({
65
+ theme
66
+ }) => theme.space[2]}px;
51
67
  `;
52
- function useListen(query, params, options, onUpdate, dependencies, client) {
53
- react.useEffect(() => {
54
- const subscription = client.listen(query, params, options).subscribe((update) => {
55
- onUpdate(update);
56
- });
57
- return () => {
58
- subscription.unsubscribe();
59
- };
60
- }, [...dependencies, client]);
61
- }
62
- function useFetchDocuments(query, onFetch, dependencies, client) {
63
- react.useEffect(() => {
64
- client.fetch(query).then((result) => {
65
- onFetch(result);
66
- });
67
- }, [...dependencies, client]);
68
- }
69
68
  function sizeOf(value) {
70
69
  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;
71
70
  }
@@ -134,7 +133,9 @@ function deduplicateDrafts(docs) {
134
133
  for (const doc of docs)
135
134
  if (doc._id.startsWith("drafts.")) {
136
135
  const id = stripDraftId(doc._id);
137
- deduped[id] = Object.assign(doc, { _id: id });
136
+ deduped[id] = Object.assign(doc, {
137
+ _id: id
138
+ });
138
139
  }
139
140
  return Object.values(deduped);
140
141
  }
@@ -142,11 +143,7 @@ class Users {
142
143
  _users = [];
143
144
  async getById(id, client) {
144
145
  let user = this._users.find((u) => u._id === id);
145
- return user || (user = await client.users.getById(id), this._users.push(user), user.image = await loadImage(
146
- user.imageUrl || "https://raw.githubusercontent.com/sanity-io/sanity-plugin-graph-view/main/assets/head-silhouette.jpg",
147
- imageSize,
148
- imageSize
149
- )), user;
146
+ 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;
150
147
  }
151
148
  }
152
149
  class Session {
@@ -159,14 +156,20 @@ class Session {
159
156
  }
160
157
  class GraphData {
161
158
  sessions = [];
162
- data;
163
159
  constructor(docs = []) {
164
160
  const docsById = {};
165
161
  for (const doc of docs)
166
162
  docsById[doc._id] = doc;
167
163
  this.data = {
168
- nodes: docs.map((d) => Object.assign({ id: d._id, type: "document", doc: d })),
169
- links: docs.flatMap((doc) => findRefs(doc).map((ref) => ({ source: doc._id, target: ref }))).filter((link) => docsById[link.source] && docsById[link.target])
164
+ nodes: docs.map((d) => Object.assign({
165
+ id: d._id,
166
+ type: "document",
167
+ doc: d
168
+ })),
169
+ links: docs.flatMap((doc) => findRefs(doc).map((ref) => ({
170
+ source: doc._id,
171
+ target: ref
172
+ }))).filter((link) => docsById[link.source] && docsById[link.target])
170
173
  };
171
174
  }
172
175
  setSession(user, docNode) {
@@ -189,13 +192,21 @@ class GraphData {
189
192
  }
190
193
  const users = new Users();
191
194
  function GraphView({
192
- tool: { options: props }
195
+ tool: {
196
+ options: props
197
+ }
193
198
  }) {
194
- const query = props.query || DEFAULT_QUERY, apiVersion = props.apiVersion ?? "2022-09-01", userColorManager = sanity.useUserColorManager(), [maxSize, setMaxSize] = react.useState(0), [hoverNode, setHoverNode] = react.useState(null), [documents, setDocuments] = react.useState([]), [docTypes, setDocTypes] = react.useState({}), [graph, setGraph] = react.useState(() => new GraphData()), router$1 = router.useRouter(), client = sanity.useClient({ apiVersion }), fetchCallback = react.useCallback((_docs) => {
195
- const docs = deduplicateDrafts(_docs);
196
- setMaxSize(Math.max(...docs.map(sizeOf))), setDocuments(docs), setDocTypes(getDocTypeCounts(docs)), setGraph(new GraphData(docs));
197
- }, []), listenCallback = react.useCallback(
198
- async (update) => {
199
+ const query = props.query || DEFAULT_QUERY, apiVersion = props.apiVersion ?? "2022-09-01", userColorManager = sanity.useUserColorManager(), [maxSize, setMaxSize] = react.useState(0), [hoverNode, setHoverNode] = react.useState(null), [documents, setDocuments] = react.useState([]), [docTypes, setDocTypes] = react.useState({}), [graph, setGraph] = react.useState(() => new GraphData()), router$1 = router.useRouter(), client = sanity.useClient({
200
+ apiVersion
201
+ });
202
+ react.useEffect(() => {
203
+ client.fetch(query).then((_docs) => {
204
+ const docs = deduplicateDrafts(_docs);
205
+ setMaxSize(Math.max(...docs.map(sizeOf))), setDocuments(docs), setDocTypes(getDocTypeCounts(docs)), setGraph(new GraphData(docs));
206
+ });
207
+ }, [client, query]), react.useEffect(() => {
208
+ const subscription = client.listen(query, {}, {}).subscribe(async (update) => {
209
+ if (update.type !== "mutation") return;
199
210
  const doc = update.result;
200
211
  if (doc) {
201
212
  doc._id = stripDraftId(doc._id);
@@ -203,125 +214,95 @@ function GraphView({
203
214
  for (const d of documents)
204
215
  docsById[d._id] = d;
205
216
  let oldDoc;
206
- const docs = [...documents], idx = documents.findIndex((d) => d._id === doc._id);
207
- idx >= 0 ? (oldDoc = docs[idx], docs[idx] = doc) : docs.push(doc), setDocuments(docs), setDocTypes(getDocTypeCounts(docs)), setMaxSize(Math.max(...docs.map(sizeOf)));
208
- const newGraph = graph.clone(), oldRefs = findRefs(oldDoc || {}).filter(
209
- (id) => id === doc._id || docsById[id] !== null
210
- ), newRefs = findRefs(doc).filter((id) => id === doc._id || docsById[id] !== null);
217
+ const docs_0 = [...documents], idx = documents.findIndex((d_0) => d_0._id === doc._id);
218
+ 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)));
219
+ 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);
211
220
  let graphChanged = !deepEqual__default.default(oldRefs, newRefs);
212
- graphChanged && (newGraph.data.links = newGraph.data.links.filter((l) => l.source.id !== doc._id).concat(newRefs.map((ref) => ({ source: doc._id, target: ref }))));
221
+ graphChanged && (newGraph.data.links = newGraph.data.links.filter((l) => l.source.id !== doc._id).concat(newRefs.map((ref) => ({
222
+ source: doc._id,
223
+ target: ref
224
+ }))));
213
225
  let docNode;
214
226
  const nodeIdx = graph.data.nodes.findIndex((n) => n.doc && n.doc._id === doc._id);
215
- nodeIdx >= 0 ? (docNode = graph.data.nodes[nodeIdx], docNode.doc = doc) : (docNode = { id: doc._id, type: "document", doc }, newGraph.data.nodes.push(docNode), graphChanged = !0), graphChanged && setGraph(newGraph);
227
+ nodeIdx >= 0 ? (docNode = graph.data.nodes[nodeIdx], docNode.doc = doc) : (docNode = {
228
+ id: doc._id,
229
+ type: "document",
230
+ doc
231
+ }, newGraph.data.nodes.push(docNode), graphChanged = !0), graphChanged && setGraph(newGraph);
216
232
  const user = await users.getById(update.identity, client);
217
233
  graph.setSession(user, docNode);
218
234
  } else if (update.transition === "disappear") {
219
- const docId = stripDraftId(update.documentId), docs = documents.filter((d) => d._id !== docId);
220
- setDocuments(docs), setDocTypes(getDocTypeCounts(docs)), setMaxSize(Math.max(...docs.map(sizeOf)));
221
- const newGraph = graph.clone();
222
- newGraph.data.links = newGraph.data.links.filter(
223
- (l) => l.source.id !== docId && l.target.id !== docId
224
- ), newGraph.data.nodes = newGraph.data.nodes.filter((n) => n.id !== docId), setGraph(newGraph);
235
+ const docId = stripDraftId(update.documentId), docs_1 = documents.filter((d_1) => d_1._id !== docId);
236
+ setDocuments(docs_1), setDocTypes(getDocTypeCounts(docs_1)), setMaxSize(Math.max(...docs_1.map(sizeOf)));
237
+ const newGraph_0 = graph.clone();
238
+ 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);
225
239
  }
226
- },
227
- [documents, graph, client]
228
- );
229
- useFetchDocuments(query, fetchCallback, [], client), useListen(query, {}, {}, listenCallback, [documents, graph], client), react.useEffect(() => {
240
+ });
241
+ return () => {
242
+ subscription.unsubscribe();
243
+ };
244
+ }, [client, query, documents, graph]), react.useEffect(() => {
230
245
  const interval = setInterval(() => graph.reapSessions(), 1e3);
231
246
  return () => clearInterval(interval);
232
247
  }, [graph]);
233
248
  const theme = ui.useTheme().sanity;
234
249
  return /* @__PURE__ */ jsxRuntime.jsx(GraphWrapper, { theme, children: /* @__PURE__ */ jsxRuntime.jsxs(GraphRoot, { theme, children: [
235
- /* @__PURE__ */ jsxRuntime.jsx(Legend, { theme, children: getTopDocTypes(docTypes).map((docType) => /* @__PURE__ */ jsxRuntime.jsxs(
236
- LegendRow,
237
- {
238
- className: "legend__row",
239
- style: { color: getDocTypeColor(docType).fill },
240
- children: [
241
- /* @__PURE__ */ jsxRuntime.jsx(LegendBadge, { theme }),
242
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: formatDocType(docType) })
243
- ]
244
- },
245
- docType
246
- )) }),
250
+ /* @__PURE__ */ jsxRuntime.jsx(Legend, { theme, children: getTopDocTypes(docTypes).map((docType) => /* @__PURE__ */ jsxRuntime.jsxs(LegendRow, { className: "legend__row", style: {
251
+ color: getDocTypeColor(docType).fill
252
+ }, children: [
253
+ /* @__PURE__ */ jsxRuntime.jsx(LegendBadge, { theme }),
254
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: formatDocType(docType) })
255
+ ] }, docType)) }),
247
256
  hoverNode && /* @__PURE__ */ jsxRuntime.jsx(HoverNode, { theme, children: labelFor(hoverNode.doc) }),
248
- /* @__PURE__ */ jsxRuntime.jsx(
249
- reactForceGraph.ForceGraph2D,
250
- {
251
- graphData: graph.data,
252
- nodeAutoColorBy: "group",
253
- enableNodeDrag: !1,
254
- onNodeHover: (node) => setHoverNode(node),
255
- onNodeClick: (node) => {
256
- router$1.navigateIntent("edit", { id: node.doc._id, documentType: node.doc._type });
257
- },
258
- linkColor: () => polished.rgba(color.gray[500].hex, 0.25),
259
- nodeLabel: () => "",
260
- nodeRelSize: 1,
261
- nodeVal: (node) => valueFor(node.doc, maxSize),
262
- onRenderFramePost: (ctx, globalScale) => {
263
- for (const session of graph.sessions) {
264
- const node = graph.data.nodes.find(
265
- (n) => n.doc && n.doc._id === session?.doc?._id
266
- );
267
- if (node) {
268
- const idleFactorRange = idleTimeout, angle = session.angle, radius = Math.sqrt(valueFor(node.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.x + Math.sin(angle) * distance / globalScale, y = node.y + Math.cos(angle) * distance / globalScale;
257
+ /* @__PURE__ */ jsxRuntime.jsx(reactForceGraph.ForceGraph2D, { graphData: graph.data, nodeAutoColorBy: "group", enableNodeDrag: !1, onNodeHover: (node) => setHoverNode(node), onNodeClick: (node_0) => {
258
+ router$1.navigateIntent("edit", {
259
+ id: node_0.doc._id,
260
+ documentType: node_0.doc._type
261
+ });
262
+ }, linkColor: () => polished.rgba(color.gray[500].hex, 0.25), nodeLabel: () => "", nodeRelSize: 1, nodeVal: (node_1) => valueFor(node_1.doc, maxSize), onRenderFramePost: (ctx, globalScale) => {
263
+ for (const session of graph.sessions) {
264
+ const node_2 = graph.data.nodes.find((n_1) => n_1.doc && n_1.doc._id === session?.doc?._id);
265
+ if (node_2) {
266
+ 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;
267
+ ctx.save();
268
+ try {
269
+ 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 = polished.rgba(color.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 = polished.rgba(color.white.hex, 1), ctx.lineWidth = 2 / globalScale, ctx.arc(node_2.x, node_2.y, radius, 0, 2 * Math.PI, !1), ctx.stroke(), image) {
269
270
  ctx.save();
270
271
  try {
271
- if (ctx.globalAlpha = fadeEasing(
272
- 1 - Math.min(idleFactorRange, Date.now() - session.lastActive) / idleFactorRange
273
- ), ctx.font = `bold ${Math.round(12 / globalScale)}px sans-serif`, ctx.beginPath(), ctx.strokeStyle = polished.rgba(color.white.hex, 1), ctx.lineWidth = 2 / globalScale, ctx.moveTo(
274
- node.x + Math.sin(angle) * (distance - imgW / 2) / globalScale,
275
- node.y + Math.cos(angle) * (distance - imgH / 2) / globalScale
276
- ), ctx.lineTo(node.x + Math.sin(angle) * radius, node.y + Math.cos(angle) * radius), ctx.stroke(), ctx.beginPath(), ctx.strokeStyle = polished.rgba(color.white.hex, 1), ctx.lineWidth = 2 / globalScale, ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, !1), ctx.stroke(), image) {
277
- ctx.save();
278
- try {
279
- const f = softEasing(
280
- Math.max(0, (700 - (Date.now() - session.startTime)) / 700)
281
- );
282
- f > 0 && (ctx.beginPath(), ctx.fillStyle = polished.rgba(userColor, f), ctx.arc(x, y, (imgW / 2 + 10) / globalScale, 0, 2 * Math.PI, !1), ctx.fill()), ctx.beginPath(), ctx.fillStyle = polished.rgba(color.white.hex, 1), ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, !1), ctx.clip(), ctx.drawImage(
283
- image,
284
- x - imgW / globalScale / 2,
285
- y - imgH / globalScale / 2,
286
- imgW / globalScale,
287
- imgH / globalScale
288
- ), ctx.strokeStyle = color.black.hex, ctx.lineWidth = 6 / globalScale, ctx.stroke(), ctx.strokeStyle = userColor, ctx.lineWidth = 4 / globalScale, ctx.stroke();
289
- } finally {
290
- ctx.restore();
291
- }
292
- }
293
- ctx.beginPath(), ctx.strokeStyle = polished.rgba(color.black.hex, 1), ctx.lineWidth = 0.5 / globalScale, ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, !1), ctx.stroke();
294
- const above = angle >= Math.PI / 2 && angle < Math.PI * 1.5, textY = above ? y - (imgH / 2 + 5) / globalScale : y + (imgH / 2 + 5) / globalScale;
295
- ctx.fillStyle = polished.rgba(color.white.hex, 1), ctx.textAlign = "center", ctx.textBaseline = above ? "bottom" : "top", ctx.fillText(session.user.displayName, x, textY);
272
+ const f = softEasing(Math.max(0, (700 - (Date.now() - session.startTime)) / 700));
273
+ f > 0 && (ctx.beginPath(), ctx.fillStyle = polished.rgba(userColor, f), ctx.arc(x, y, (imgW / 2 + 10) / globalScale, 0, 2 * Math.PI, !1), ctx.fill()), ctx.beginPath(), ctx.fillStyle = polished.rgba(color.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 = color.black.hex, ctx.lineWidth = 6 / globalScale, ctx.stroke(), ctx.strokeStyle = userColor, ctx.lineWidth = 4 / globalScale, ctx.stroke();
296
274
  } finally {
297
275
  ctx.restore();
298
276
  }
299
277
  }
278
+ ctx.beginPath(), ctx.strokeStyle = polished.rgba(color.black.hex, 1), ctx.lineWidth = 0.5 / globalScale, ctx.arc(x, y, imgW / globalScale / 2, 0, 2 * Math.PI, !1), ctx.stroke();
279
+ const above = angle >= Math.PI / 2 && angle < Math.PI * 1.5, textY = above ? y - (imgH / 2 + 5) / globalScale : y + (imgH / 2 + 5) / globalScale;
280
+ ctx.fillStyle = polished.rgba(color.white.hex, 1), ctx.textAlign = "center", ctx.textBaseline = above ? "bottom" : "top", ctx.fillText(session.user.displayName, x, textY);
281
+ } finally {
282
+ ctx.restore();
300
283
  }
301
- },
302
- nodeCanvasObject: (node, ctx, globalScale) => {
303
- switch (node.type) {
304
- case "document": {
305
- const nodeColor = getDocTypeColor(node.doc._type), radius = Math.sqrt(valueFor(node.doc, maxSize)), fontSize = Math.min(100, 10 / globalScale);
306
- if (ctx.beginPath(), ctx.fillStyle = hoverNode !== null && node.doc._id === hoverNode.doc._id ? polished.rgba(color.gray[500].hex, 0.8) : nodeColor.fill, ctx.strokeStyle = nodeColor.border, ctx.lineWidth = 0.5, ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, !1), ctx.stroke(), ctx.fill(), radius * globalScale > 10) {
307
- ctx.font = `${fontSize}px sans-serif`;
308
- const w = radius * 2 + 30 / globalScale;
309
- for (let len = 50; len >= 5; len /= 1.2) {
310
- const label = truncate(labelFor(node.doc), Math.round(len));
311
- if (ctx.measureText(label).width < w) {
312
- ctx.textAlign = "center", ctx.textBaseline = "top", ctx.strokeStyle = polished.rgba(color.black.hex, 0.5), ctx.lineWidth = 2 / globalScale, ctx.strokeText(label, node.x, node.y + radius + 5 / globalScale), ctx.fillText(label, node.x, node.y + radius + 5 / globalScale);
313
- break;
314
- }
315
- }
284
+ }
285
+ }
286
+ }, nodeCanvasObject: (node_3, ctx_0, globalScale_0) => {
287
+ switch (node_3.type) {
288
+ case "document": {
289
+ const nodeColor = getDocTypeColor(node_3.doc._type), radius_0 = Math.sqrt(valueFor(node_3.doc, maxSize)), fontSize = Math.min(100, 10 / globalScale_0);
290
+ if (ctx_0.beginPath(), ctx_0.fillStyle = hoverNode !== null && node_3.doc._id === hoverNode.doc._id ? polished.rgba(color.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) {
291
+ ctx_0.font = `${fontSize}px sans-serif`;
292
+ const w = radius_0 * 2 + 30 / globalScale_0;
293
+ for (let len = 50; len >= 5; len /= 1.2) {
294
+ const label = truncate(labelFor(node_3.doc), Math.round(len));
295
+ if (ctx_0.measureText(label).width < w) {
296
+ ctx_0.textAlign = "center", ctx_0.textBaseline = "top", ctx_0.strokeStyle = polished.rgba(color.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);
297
+ break;
316
298
  }
317
299
  }
318
300
  }
319
- },
320
- linkCanvasObject: (link, ctx, globalScale) => {
321
- ctx.beginPath(), ctx.strokeStyle = polished.rgba(color.gray[500].hex, 0.125), ctx.lineWidth = 2 / globalScale, ctx.moveTo(link.source.x, link.source.y), ctx.lineTo(link.target.x, link.target.y), ctx.stroke();
322
301
  }
323
302
  }
324
- )
303
+ }, linkCanvasObject: (link, ctx_1, globalScale_1) => {
304
+ ctx_1.beginPath(), ctx_1.strokeStyle = polished.rgba(color.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();
305
+ } })
325
306
  ] }) });
326
307
  }
327
308
  const colorCache = {};
@@ -1 +1 @@
1
- {"version":3,"file":"GraphView.cjs","sources":["../../src/tool/GraphViewStyle.tsx","../../src/tool/hooks.ts","../../src/tool/utils.ts","../../src/tool/GraphView.tsx"],"sourcesContent":["import {type PropsWithChildren} from 'react'\nimport styled from 'styled-components'\n\nimport type {Theme} from '@sanity/ui'\n\nimport {black} from '@sanity/color'\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` as React.FC<Style>\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 = 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","import {useEffect} from 'react'\n\nimport type {ListenEvent, ListenOptions, SanityClient} from '@sanity/client'\n\nexport function useListen(\n query: string,\n params: {[key: string]: any},\n options: ListenOptions,\n onUpdate: (event: ListenEvent<any>) => void,\n dependencies: unknown[],\n client: SanityClient,\n): void {\n useEffect(() => {\n const subscription = client.listen(query, params, options).subscribe((update) => {\n onUpdate(update)\n })\n return () => {\n subscription.unsubscribe()\n }\n }, [...dependencies, client])\n}\n\nexport function useFetchDocuments(\n query: string,\n onFetch: (event: ListenEvent<any>) => void,\n dependencies: unknown[],\n client: SanityClient,\n): void {\n useEffect(() => {\n void client.fetch(query).then((result) => {\n onFetch(result)\n })\n }, [...dependencies, client])\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 img.onload = () => {\n resolve(img)\n }\n img.onerror = (event) => {\n console.log('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 BezierEasing from 'bezier-easing'\nimport deepEqual from 'deep-equal'\nimport {rgba} from 'polished'\nimport {useCallback, useEffect, useState} from 'react'\nimport {ForceGraph2D} from 'react-force-graph'\nimport {useClient, useUserColorManager} from 'sanity'\nimport {useRouter} from 'sanity/router'\nimport {v4 as uuidv4} from 'uuid'\n\nimport type {SanityDocument, SanityClient} from '@sanity/client'\n\nimport {black, COLOR_HUES, gray, white, hues} from '@sanity/color'\nimport {useTheme} from '@sanity/ui'\n\nimport {GraphRoot, GraphWrapper, HoverNode, Legend, LegendBadge, LegendRow} from './GraphViewStyle'\nimport {useFetchDocuments, useListen} from './hooks'\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 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 const fetchCallback = useCallback((_docs: any) => {\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 }, [])\n\n const listenCallback = useCallback(\n async (update: any) => {\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 // @ts-expect-error - TODO: fix this\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 [documents, graph, client],\n )\n // @ts-expect-error - TODO: fix this\n useFetchDocuments(query, fetchCallback, [], client)\n // @ts-expect-error - TODO: fix this\n useListen(query, {}, {}, listenCallback, [documents, graph], client)\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 className={'legend__row'}\n key={docType}\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":["styled","black","useEffect","BezierEasing","uuidv4","useUserColorManager","useState","router","useRouter","useClient","useCallback","deepEqual","useTheme","jsx","jsxs","ForceGraph2D","rgba","gray","white","COLOR_HUES","hues"],"mappings":";;;;;;AAUO,MAAM,YAA6BA,gBAAAA,QAAO;AAAA,iBAChC,CAAC,EAAC,MAAA,MAAkB,MAAM,MAAM,KAAK,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAM5CC,MAAAA,MAAM,GAAG;AAAA,GAGZ,eAAgCD,gBAAAA,QAAO;AAAA;AAAA;AAAA;AAAA,G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AAAA,UAAA;AAAA,QAEJ;AAAA,QACA,kBAAkB,CAAC,MAAW,KAAK,gBAAgB;AACjD,cAAI,UAAA,GACJ,IAAI,cAAce,SAAAA,KAAKC,MAAAA,KAAK,GAAG,EAAE,KAAK,KAAK,GAC3C,IAAI,YAAY,IAAI,aACpB,IAAI,OAAO,KAAK,OAAO,GAAG,KAAK,OAAO,CAAC,GACvC,IAAI,OAAO,KAAK,OAAO,GAAG,KAAK,OAAO,CAAC,GACvC,IAAI,OAAA;AAAA,QACN;AAAA,MAAA;AAAA,IAAA;AAAA,EACF,EAAA,CACF,EAAA,CACF;AAEJ;AAEA,MAAM,aAA6D,CAAA;AACnE,IAAI,eAAe;AAEnB,SAAS,gBAAgB,SAAc;AACrC,MAAI,WAAW,OAAO;AACpB,WAAO,WAAW,OAAO;AAG3B,QAAM,MAAME,MAAAA,WAAW,eAAeA,MAAAA,WAAW,MAAM;AAEvD,SAAA,gBAAgB,GAEhB,WAAW,OAAO,IAAI;AAAA,IACpB,MAAMC,MAAAA,KAAK,GAAG,EAAE,GAAG,EAAE;AAAA,IACrB,QAAQJ,SAAAA,KAAKf,YAAM,KAAK,GAAG;AAAA,EAAA,GAGtB,WAAW,OAAO;AAC3B;;"}
1
+ {"version":3,"file":"GraphView.cjs","sources":["../../src/tool/GraphViewStyle.tsx","../../src/tool/utils.ts","../../src/tool/GraphView.tsx"],"sourcesContent":["import {type PropsWithChildren} from 'react'\nimport {styled} from 'styled-components'\n\nimport type {Theme} from '@sanity/ui'\n\nimport {black} from '@sanity/color'\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` as React.FC<Style>\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 img.onload = () => {\n resolve(img)\n }\n img.onerror = (event) => {\n console.log('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 BezierEasing from 'bezier-easing'\nimport deepEqual from 'deep-equal'\nimport {rgba} from 'polished'\nimport {useEffect, useState} from 'react'\nimport {ForceGraph2D} from 'react-force-graph'\nimport {useClient, useUserColorManager, type SanityClient, type SanityDocument} from 'sanity'\nimport {useRouter} from 'sanity/router'\nimport {v4 as uuidv4} from 'uuid'\n\nimport {black, COLOR_HUES, gray, white, hues} from '@sanity/color'\nimport {useTheme} from '@sanity/ui'\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 })\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 className={'legend__row'}\n key={docType}\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 // eslint-disable-next-line react-hooks/todo\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","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","log","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","jsx","jsxs","color","getDocTypeColor","fill","ForceGraph2D","node","navigateIntent","documentType","rgba","gray","ctx","globalScale","idleFactorRange","sqrt","userColor","get","displayName","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,iBAAAA,OAAOC;AAAAA,iBAChC,CAAC;AAAA,EAACC;AAAY,MAAMA,MAAMC,MAAMC,KAAKC,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAM5CC,MAAAA,MAAMC,GAAG;AAAA,GAGZC,eAAgCR,iBAAAA,OAAOC;AAAAA;AAAAA;AAAAA;AAAAA,GAMvCQ,YAA6BT,iBAAAA,OAAOC;AAAAA,iBAChC,CAAC;AAAA,EAACC;AAAY,MAAMA,MAAMC,MAAMC,KAAKC,MAAM;AAAA;AAAA;AAAA,YAGhD,CAAC;AAAA,EAACH;AAAY,MAAMA,MAAMQ,MAAM,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA,mBAI3B,CAAC;AAAA,EAACR;AAAY,MAAMA,MAAMS,OAAO,CAAC,CAAC;AAAA,aACzC,CAAC;AAAA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