@abraca/nuxt 2.36.0 → 2.38.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.
- package/dist/module.d.mts +6 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/ADocPickModal.vue +1 -1
- package/dist/runtime/components/ADocSubPageList.d.vue.ts +46 -0
- package/dist/runtime/components/ADocSubPageList.vue +1006 -0
- package/dist/runtime/components/ADocSubPageList.vue.d.ts +46 -0
- package/dist/runtime/components/ADocumentTree.vue +3 -2
- package/dist/runtime/components/AEditor.d.vue.ts +9 -0
- package/dist/runtime/components/AEditor.vue +14 -2
- package/dist/runtime/components/AEditor.vue.d.ts +9 -0
- package/dist/runtime/components/AIconPicker.vue +27 -180
- package/dist/runtime/components/ANodePanel.d.vue.ts +8 -5
- package/dist/runtime/components/ANodePanel.vue +1 -1
- package/dist/runtime/components/ANodePanel.vue.d.ts +8 -5
- package/dist/runtime/components/AWindowLayer.vue +4 -2
- package/dist/runtime/components/docs/ADocsSearch.d.vue.ts +2 -2
- package/dist/runtime/components/docs/ADocsSearch.vue.d.ts +2 -2
- package/dist/runtime/components/editor/ADocSuggestMenu.vue +1 -1
- package/dist/runtime/components/editor/ALocationPickerPopover.vue +31 -16
- package/dist/runtime/components/renderers/ACalendarRenderer.d.vue.ts +1 -0
- package/dist/runtime/components/renderers/ACalendarRenderer.vue +309 -68
- package/dist/runtime/components/renderers/ACalendarRenderer.vue.d.ts +1 -0
- package/dist/runtime/components/renderers/AChecklistRenderer.vue +259 -40
- package/dist/runtime/components/renderers/ADashboardRenderer.vue +493 -89
- package/dist/runtime/components/renderers/AGraphRenderer.d.vue.ts +2 -0
- package/dist/runtime/components/renderers/AGraphRenderer.vue +2113 -576
- package/dist/runtime/components/renderers/AGraphRenderer.vue.d.ts +2 -0
- package/dist/runtime/components/renderers/AKanbanRenderer.vue +460 -86
- package/dist/runtime/components/renderers/AMapRenderer.d.vue.ts +7 -1
- package/dist/runtime/components/renderers/AMapRenderer.vue +999 -166
- package/dist/runtime/components/renderers/AMapRenderer.vue.d.ts +7 -1
- package/dist/runtime/components/renderers/AOutlineRenderer.d.vue.ts +2 -0
- package/dist/runtime/components/renderers/AOutlineRenderer.vue +285 -81
- package/dist/runtime/components/renderers/AOutlineRenderer.vue.d.ts +2 -0
- package/dist/runtime/components/renderers/AOverviewRenderer.vue +3 -2
- package/dist/runtime/components/renderers/ASheetsRenderer.client.vue +255 -87
- package/dist/runtime/components/renderers/ATimelineRenderer.d.vue.ts +1 -0
- package/dist/runtime/components/renderers/ATimelineRenderer.vue +224 -31
- package/dist/runtime/components/renderers/ATimelineRenderer.vue.d.ts +1 -0
- package/dist/runtime/components/renderers/calendar/ACalendarDayCell.d.vue.ts +8 -0
- package/dist/runtime/components/renderers/calendar/ACalendarDayCell.vue +12 -1
- package/dist/runtime/components/renderers/calendar/ACalendarDayCell.vue.d.ts +8 -0
- package/dist/runtime/components/renderers/calendar/ACalendarEventChip.d.vue.ts +10 -0
- package/dist/runtime/components/renderers/calendar/ACalendarEventChip.vue +15 -3
- package/dist/runtime/components/renderers/calendar/ACalendarEventChip.vue.d.ts +10 -0
- package/dist/runtime/components/renderers/calendar/ACalendarMonthView.d.vue.ts +14 -0
- package/dist/runtime/components/renderers/calendar/ACalendarMonthView.vue +6 -1
- package/dist/runtime/components/renderers/calendar/ACalendarMonthView.vue.d.ts +14 -0
- package/dist/runtime/components/renderers/sheets/ASheetsGrid.d.vue.ts +6 -6
- package/dist/runtime/components/renderers/sheets/ASheetsGrid.vue +25 -7
- package/dist/runtime/components/renderers/sheets/ASheetsGrid.vue.d.ts +6 -6
- package/dist/runtime/components/renderers/sheets/ASheetsMobileActionBar.d.vue.ts +2 -2
- package/dist/runtime/components/renderers/sheets/ASheetsMobileActionBar.vue.d.ts +2 -2
- package/dist/runtime/components/renderers/sheets/ASheetsToolbar.d.vue.ts +6 -0
- package/dist/runtime/components/renderers/sheets/ASheetsToolbar.vue +130 -23
- package/dist/runtime/components/renderers/sheets/ASheetsToolbar.vue.d.ts +6 -0
- package/dist/runtime/components/renderers/timeline/ATimelineAxis.vue +5 -3
- package/dist/runtime/components/renderers/timeline/ATimelineBar.vue +1 -1
- package/dist/runtime/components/renderers/timeline/ATimelineBarArea.d.vue.ts +0 -2
- package/dist/runtime/components/renderers/timeline/ATimelineBarArea.vue +16 -14
- package/dist/runtime/components/renderers/timeline/ATimelineBarArea.vue.d.ts +0 -2
- package/dist/runtime/components/renderers/timeline/ATimelineLabelPanel.vue +4 -2
- package/dist/runtime/composables/useAbracadabraAuth.d.ts +1 -0
- package/dist/runtime/composables/useAbracadabraAuth.js +1 -0
- package/dist/runtime/composables/useCalendarView.js +34 -11
- package/dist/runtime/composables/useConnectionStatus.d.ts +1 -1
- package/dist/runtime/composables/useGraphReferenceEdges.d.ts +26 -0
- package/dist/runtime/composables/useGraphReferenceEdges.js +138 -0
- package/dist/runtime/composables/useGraphSim.d.ts +79 -0
- package/dist/runtime/composables/useGraphSim.js +231 -0
- package/dist/runtime/composables/useSheetsDependencyGraph.d.ts +26 -0
- package/dist/runtime/composables/useSheetsDependencyGraph.js +76 -0
- package/dist/runtime/composables/useSheetsFormulas.d.ts +4 -3
- package/dist/runtime/composables/useSheetsFormulas.js +575 -26
- package/dist/runtime/composables/useTimelineView.d.ts +4 -0
- package/dist/runtime/composables/useTimelineView.js +45 -11
- package/dist/runtime/composables/useWindowManager.d.ts +4 -0
- package/dist/runtime/composables/useWindowManager.js +11 -0
- package/dist/runtime/composables/useWorkspace.d.ts +57 -0
- package/dist/runtime/composables/useWorkspace.js +58 -0
- package/dist/runtime/middleware/abracadabra-auth.js +11 -1
- package/dist/runtime/plugin-abracadabra.client.js +121 -12
- package/dist/runtime/utils/dateField.d.ts +17 -0
- package/dist/runtime/utils/dateField.js +19 -0
- package/dist/runtime/utils/itemLabel.d.ts +27 -0
- package/dist/runtime/utils/itemLabel.js +8 -0
- package/dist/runtime/utils/localDate.d.ts +15 -0
- package/dist/runtime/utils/localDate.js +16 -0
- package/dist/runtime/utils/lucideIcons.d.ts +16 -10
- package/dist/runtime/utils/lucideIcons.js +1391 -69
- package/dist/runtime/utils/resolveDocColor.d.ts +7 -0
- package/dist/runtime/utils/resolveDocColor.js +32 -0
- package/dist/runtime/utils/resolveDocIcon.d.ts +10 -0
- package/dist/runtime/utils/resolveDocIcon.js +44 -0
- package/dist/runtime/utils/rowEdges.d.ts +22 -0
- package/dist/runtime/utils/rowEdges.js +29 -0
- package/dist/runtime/utils/softKeystore.d.ts +55 -0
- package/dist/runtime/utils/softKeystore.js +160 -0
- package/package.json +1 -1
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { ref, computed, watch, nextTick, onMounted, onBeforeUnmount } from "vue";
|
|
3
|
-
import { useRuntimeConfig } from "#imports";
|
|
4
|
-
import {
|
|
3
|
+
import { useRuntimeConfig, defineShortcuts } from "#imports";
|
|
4
|
+
import { useLocalStorage } from "@vueuse/core";
|
|
5
5
|
import { getIcon, loadIcon } from "@iconify/vue";
|
|
6
|
+
import * as Y from "yjs";
|
|
6
7
|
import { useRendererBase } from "../../composables/useRendererBase";
|
|
7
8
|
import { useNodePanel } from "../../composables/useNodePanel";
|
|
9
|
+
import { useNodePanelFollow } from "../../composables/useNodePanelFollow";
|
|
10
|
+
import { useItemPresence, useViewingBroadcast } from "../../composables/useItemPresence";
|
|
11
|
+
import { useWindowManager } from "../../composables/useWindowManager";
|
|
12
|
+
import { useGraphSim } from "../../composables/useGraphSim";
|
|
13
|
+
import { useGraphReferenceEdges } from "../../composables/useGraphReferenceEdges";
|
|
14
|
+
import { computeRowEdges } from "../../utils/rowEdges";
|
|
15
|
+
import { resolveDocType } from "../../utils/docTypes";
|
|
16
|
+
import { displayLabel } from "../../utils/itemLabel";
|
|
8
17
|
import { DEFAULT_LOCALE } from "../../locale";
|
|
9
18
|
const props = defineProps({
|
|
10
19
|
docId: { type: String, required: true },
|
|
@@ -12,14 +21,17 @@ const props = defineProps({
|
|
|
12
21
|
docLabel: { type: String, required: true },
|
|
13
22
|
pageTypes: { type: Array, required: false },
|
|
14
23
|
labels: { type: Object, required: false },
|
|
15
|
-
editable: { type: Boolean, required: false, default: true }
|
|
24
|
+
editable: { type: Boolean, required: false, default: true },
|
|
25
|
+
followingUser: { type: [String, null], required: false, default: null }
|
|
16
26
|
});
|
|
17
27
|
const config = useRuntimeConfig();
|
|
18
28
|
const locale = computed(() => ({
|
|
19
29
|
...DEFAULT_LOCALE.renderers.graph,
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
31
|
...config.public?.abracadabra?.locale?.renderers?.graph ?? {},
|
|
21
32
|
...props.labels ?? {}
|
|
22
33
|
}));
|
|
34
|
+
const canWrite = computed(() => props.editable);
|
|
23
35
|
const { tree, childDoc, childProviderRef, cursors, states, setLocalState, connectedUsers } = useRendererBase(props);
|
|
24
36
|
const {
|
|
25
37
|
openNodeId,
|
|
@@ -28,11 +40,23 @@ const {
|
|
|
28
40
|
openNode,
|
|
29
41
|
closePanel
|
|
30
42
|
} = useNodePanel(childProviderRef);
|
|
31
|
-
|
|
43
|
+
useNodePanelFollow(openNodeId, openNodeLabel, openNode, closePanel, () => props.followingUser, states, setLocalState);
|
|
44
|
+
useViewingBroadcast(() => props.docId, openNodeId);
|
|
45
|
+
const { getViewers: getDocViewers } = useItemPresence();
|
|
46
|
+
function nodeViewers(id) {
|
|
47
|
+
return getDocViewers(id);
|
|
48
|
+
}
|
|
49
|
+
const wm = useWindowManager();
|
|
50
|
+
const d3Ready = ref(false);
|
|
32
51
|
const d3Error = ref(false);
|
|
52
|
+
const graphSim = useGraphSim();
|
|
53
|
+
const simRenderTick = graphSim.renderTick;
|
|
54
|
+
let simReady = false;
|
|
33
55
|
onMounted(async () => {
|
|
34
56
|
try {
|
|
35
|
-
|
|
57
|
+
const mod = await import("d3-force");
|
|
58
|
+
graphSim.bindD3(mod);
|
|
59
|
+
d3Ready.value = true;
|
|
36
60
|
} catch {
|
|
37
61
|
d3Error.value = true;
|
|
38
62
|
}
|
|
@@ -117,26 +141,19 @@ const entryById = computed(() => {
|
|
|
117
141
|
for (const e of tree.entries.value) m.set(e.id, e);
|
|
118
142
|
return m;
|
|
119
143
|
});
|
|
120
|
-
const posByEntry = computed(() => {
|
|
121
|
-
const m = /* @__PURE__ */ new Map();
|
|
122
|
-
for (const e of tree.entries.value) {
|
|
123
|
-
if (e.meta?.graphX !== void 0 && e.meta?.graphY !== void 0) {
|
|
124
|
-
m.set(e.id, {
|
|
125
|
-
x: e.meta.graphX,
|
|
126
|
-
y: e.meta.graphY,
|
|
127
|
-
pinned: e.meta.graphPinned ?? false
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return m;
|
|
132
|
-
});
|
|
133
144
|
function getGraphPos(id) {
|
|
134
|
-
|
|
145
|
+
const entry = entryById.value.get(id);
|
|
146
|
+
if (entry?.meta?.graphX !== void 0 && entry?.meta?.graphY !== void 0) {
|
|
147
|
+
return { x: entry.meta.graphX, y: entry.meta.graphY, pinned: entry.meta.graphPinned ?? false };
|
|
148
|
+
}
|
|
149
|
+
return void 0;
|
|
135
150
|
}
|
|
136
151
|
const svgRef = ref(null);
|
|
137
152
|
const vb = ref({ x: -500, y: -350, w: 1e3, h: 700 });
|
|
138
153
|
const targetVb = ref({ x: -500, y: -350, w: 1e3, h: 700 });
|
|
139
154
|
let zoomRafId = null;
|
|
155
|
+
const ZOOM_MIN_W = 40;
|
|
156
|
+
const ZOOM_MAX_W = 24e3;
|
|
140
157
|
function animateZoom() {
|
|
141
158
|
const f = 0.15;
|
|
142
159
|
const nw = vb.value.w + (targetVb.value.w - vb.value.w) * f;
|
|
@@ -161,20 +178,25 @@ function svgCoord(clientX, clientY) {
|
|
|
161
178
|
}
|
|
162
179
|
function onWheel(e) {
|
|
163
180
|
e.preventDefault();
|
|
181
|
+
pendingSettleFit = false;
|
|
182
|
+
userAdjustedView = true;
|
|
164
183
|
const wantsZoom = e.ctrlKey ? scrollBehavior.value === "pan" : scrollBehavior.value === "zoom";
|
|
165
184
|
if (wantsZoom) {
|
|
166
|
-
const sensitivity = e.ctrlKey ? 8e-3 : 25e-4;
|
|
167
185
|
const delta = Math.sign(e.deltaY) * Math.min(Math.abs(e.deltaY), 100);
|
|
168
|
-
const scale = 1 + delta *
|
|
186
|
+
const scale = 1 + delta * 8e-3;
|
|
169
187
|
const rect = svgRef.value.getBoundingClientRect();
|
|
170
188
|
const tv = targetVb.value;
|
|
171
189
|
const px = (e.clientX - rect.left) / rect.width * tv.w + tv.x;
|
|
172
190
|
const py = (e.clientY - rect.top) / rect.height * tv.h + tv.y;
|
|
191
|
+
const newW = Math.max(ZOOM_MIN_W, Math.min(ZOOM_MAX_W, tv.w * scale));
|
|
192
|
+
const newH = Math.max(ZOOM_MIN_W, Math.min(ZOOM_MAX_W, tv.h * scale));
|
|
193
|
+
const clampedScaleX = newW / tv.w;
|
|
194
|
+
const clampedScaleY = newH / tv.h;
|
|
173
195
|
targetVb.value = {
|
|
174
|
-
x: px - (px - tv.x) *
|
|
175
|
-
y: py - (py - tv.y) *
|
|
176
|
-
w:
|
|
177
|
-
h:
|
|
196
|
+
x: px - (px - tv.x) * clampedScaleX,
|
|
197
|
+
y: py - (py - tv.y) * clampedScaleY,
|
|
198
|
+
w: newW,
|
|
199
|
+
h: newH
|
|
178
200
|
};
|
|
179
201
|
if (!zoomRafId) zoomRafId = requestAnimationFrame(animateZoom);
|
|
180
202
|
} else {
|
|
@@ -186,20 +208,19 @@ function onWheel(e) {
|
|
|
186
208
|
const rect = svgRef.value.getBoundingClientRect();
|
|
187
209
|
const sx = vb.value.w / rect.width;
|
|
188
210
|
const sy = vb.value.h / rect.height;
|
|
189
|
-
vb.value
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
w: vb.value.w,
|
|
193
|
-
h: vb.value.h
|
|
194
|
-
};
|
|
211
|
+
const nx = vb.value.x + e.deltaX * sx;
|
|
212
|
+
const ny = vb.value.y + e.deltaY * sy;
|
|
213
|
+
vb.value = { x: nx, y: ny, w: vb.value.w, h: vb.value.h };
|
|
195
214
|
targetVb.value = { ...vb.value };
|
|
196
215
|
}
|
|
197
216
|
}
|
|
198
217
|
const activePointers = /* @__PURE__ */ new Map();
|
|
199
218
|
let isPinching = false;
|
|
200
219
|
let pinchStart = null;
|
|
220
|
+
let gestureWasPinch = false;
|
|
201
221
|
const isPanning = ref(false);
|
|
202
222
|
const panStart = ref({ ex: 0, ey: 0, vx: 0, vy: 0 });
|
|
223
|
+
let panMoved = false;
|
|
203
224
|
let pendingSvgMove = null;
|
|
204
225
|
let pendingNodeMove = null;
|
|
205
226
|
let pointerRafId = null;
|
|
@@ -231,47 +252,142 @@ function queueLocalState(patch) {
|
|
|
231
252
|
if (patchOut) setLocalState(patchOut);
|
|
232
253
|
});
|
|
233
254
|
}
|
|
255
|
+
let lastTapTime = 0;
|
|
256
|
+
let lastTapPos = { x: 0, y: 0 };
|
|
257
|
+
let touchDoubleTapped = false;
|
|
258
|
+
let panVelocity = { vx: 0, vy: 0 };
|
|
259
|
+
let lastPanEvent = { x: 0, y: 0, t: 0 };
|
|
260
|
+
let inertiaRafId = null;
|
|
261
|
+
const LONG_PRESS_MS = 500;
|
|
262
|
+
const LONG_PRESS_SLOP_PX = 8;
|
|
263
|
+
let longPressTimer = null;
|
|
264
|
+
let longPressStart = { x: 0, y: 0 };
|
|
265
|
+
function armLongPress(e) {
|
|
266
|
+
if (e.pointerType !== "touch" && e.pointerType !== "pen") return;
|
|
267
|
+
cancelLongPress();
|
|
268
|
+
longPressStart = { x: e.clientX, y: e.clientY };
|
|
269
|
+
const target = e.target;
|
|
270
|
+
longPressTimer = setTimeout(() => {
|
|
271
|
+
longPressTimer = null;
|
|
272
|
+
abortGestureForMenu();
|
|
273
|
+
target.dispatchEvent(new MouseEvent("contextmenu", {
|
|
274
|
+
clientX: longPressStart.x,
|
|
275
|
+
clientY: longPressStart.y,
|
|
276
|
+
bubbles: true,
|
|
277
|
+
cancelable: true,
|
|
278
|
+
view: window
|
|
279
|
+
}));
|
|
280
|
+
}, LONG_PRESS_MS);
|
|
281
|
+
}
|
|
282
|
+
function trackLongPress(e) {
|
|
283
|
+
if (longPressTimer === null) return;
|
|
284
|
+
const dx = e.clientX - longPressStart.x;
|
|
285
|
+
const dy = e.clientY - longPressStart.y;
|
|
286
|
+
if (dx * dx + dy * dy > LONG_PRESS_SLOP_PX * LONG_PRESS_SLOP_PX) cancelLongPress();
|
|
287
|
+
}
|
|
288
|
+
function cancelLongPress() {
|
|
289
|
+
if (longPressTimer !== null) {
|
|
290
|
+
clearTimeout(longPressTimer);
|
|
291
|
+
longPressTimer = null;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function abortGestureForMenu() {
|
|
295
|
+
abortNodeDragForGesture();
|
|
296
|
+
activePointers.clear();
|
|
297
|
+
isPanning.value = false;
|
|
298
|
+
isPinching = false;
|
|
299
|
+
pinchStart = null;
|
|
300
|
+
panVelocity = { vx: 0, vy: 0 };
|
|
301
|
+
}
|
|
234
302
|
function onSvgPointerDown(e) {
|
|
235
303
|
if (e.pointerType === "mouse" && e.button !== 0) return;
|
|
304
|
+
if (inertiaRafId) {
|
|
305
|
+
cancelAnimationFrame(inertiaRafId);
|
|
306
|
+
inertiaRafId = null;
|
|
307
|
+
}
|
|
236
308
|
activePointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
237
|
-
|
|
309
|
+
try {
|
|
310
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
311
|
+
} catch {
|
|
312
|
+
}
|
|
313
|
+
if (activePointers.size === 1) armLongPress(e);
|
|
314
|
+
else cancelLongPress();
|
|
238
315
|
if (activePointers.size === 1) {
|
|
316
|
+
gestureWasPinch = false;
|
|
239
317
|
isPanning.value = true;
|
|
240
318
|
isPinching = false;
|
|
319
|
+
panMoved = false;
|
|
241
320
|
if (zoomRafId) {
|
|
242
321
|
cancelAnimationFrame(zoomRafId);
|
|
243
322
|
zoomRafId = null;
|
|
244
323
|
}
|
|
245
324
|
vb.value = { ...targetVb.value };
|
|
246
325
|
panStart.value = { ex: e.clientX, ey: e.clientY, vx: targetVb.value.x, vy: targetVb.value.y };
|
|
326
|
+
lastPanEvent = { x: e.clientX, y: e.clientY, t: performance.now() };
|
|
327
|
+
panVelocity = { vx: 0, vy: 0 };
|
|
247
328
|
} else if (activePointers.size === 2) {
|
|
329
|
+
beginPinch();
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
function beginPinch() {
|
|
333
|
+
abortNodeDragForGesture();
|
|
334
|
+
cancelLongPress();
|
|
335
|
+
gestureWasPinch = true;
|
|
336
|
+
isPanning.value = false;
|
|
337
|
+
isPinching = true;
|
|
338
|
+
const pts = [...activePointers.values()];
|
|
339
|
+
const dist = Math.hypot(pts[1].x - pts[0].x, pts[1].y - pts[0].y);
|
|
340
|
+
pinchStart = {
|
|
341
|
+
dist: Math.max(dist, 1),
|
|
342
|
+
vb: { ...vb.value },
|
|
343
|
+
mid: { x: (pts[0].x + pts[1].x) / 2, y: (pts[0].y + pts[1].y) / 2 }
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
function abortNodeDragForGesture() {
|
|
347
|
+
dropTargetId.value = null;
|
|
348
|
+
dragInvalidTargets = /* @__PURE__ */ new Set();
|
|
349
|
+
const id = draggingId.value;
|
|
350
|
+
if (!id) return;
|
|
351
|
+
const node = nodeById.get(id);
|
|
352
|
+
if (node && !(getGraphPos(id)?.pinned ?? false)) {
|
|
353
|
+
node.fx = null;
|
|
354
|
+
node.fy = null;
|
|
355
|
+
graphSim.setFixed(id, null, null);
|
|
356
|
+
}
|
|
357
|
+
pendingNodeMove = null;
|
|
358
|
+
queueLocalState({ "graph:dragging": null });
|
|
359
|
+
draggingId.value = null;
|
|
360
|
+
}
|
|
361
|
+
function releaseNodeGesturePointer(e) {
|
|
362
|
+
activePointers.delete(e.pointerId);
|
|
363
|
+
if (isPinching && activePointers.size < 2) {
|
|
364
|
+
isPinching = false;
|
|
365
|
+
pinchStart = null;
|
|
248
366
|
isPanning.value = false;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
vb: { ...vb.value },
|
|
255
|
-
mid: { x: (pts[0].x + pts[1].x) / 2, y: (pts[0].y + pts[1].y) / 2 }
|
|
256
|
-
};
|
|
367
|
+
}
|
|
368
|
+
if (activePointers.size === 0) {
|
|
369
|
+
isPanning.value = false;
|
|
370
|
+
isPinching = false;
|
|
371
|
+
pinchStart = null;
|
|
257
372
|
}
|
|
258
373
|
}
|
|
259
374
|
function onSvgPointerMove(e) {
|
|
375
|
+
trackLongPress(e);
|
|
260
376
|
if (!activePointers.has(e.pointerId)) return;
|
|
261
377
|
activePointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
262
378
|
pendingSvgMove = { clientX: e.clientX, clientY: e.clientY, pointerId: e.pointerId };
|
|
263
379
|
schedulePointerFlush();
|
|
264
380
|
}
|
|
265
|
-
function flushSvgPointerMove(
|
|
381
|
+
function flushSvgPointerMove(e) {
|
|
266
382
|
if (!draggingId.value && !isPanning.value && activePointers.size === 1) {
|
|
267
|
-
queueLocalState({ pos: svgCoord(
|
|
383
|
+
queueLocalState({ pos: svgCoord(e.clientX, e.clientY) });
|
|
268
384
|
}
|
|
269
385
|
if (isPinching && activePointers.size >= 2 && pinchStart) {
|
|
270
386
|
const pts = [...activePointers.values()];
|
|
271
387
|
const currentDist = Math.max(Math.hypot(pts[1].x - pts[0].x, pts[1].y - pts[0].y), 1);
|
|
272
388
|
const scale = currentDist / pinchStart.dist;
|
|
273
|
-
const newW = Math.max(
|
|
274
|
-
const newH = Math.max(
|
|
389
|
+
const newW = Math.max(ZOOM_MIN_W, Math.min(ZOOM_MAX_W, pinchStart.vb.w / scale));
|
|
390
|
+
const newH = Math.max(ZOOM_MIN_W, Math.min(ZOOM_MAX_W, pinchStart.vb.h / scale));
|
|
275
391
|
const rect2 = svgRef.value.getBoundingClientRect();
|
|
276
392
|
const startMidSvgX = (pinchStart.mid.x - rect2.left) / rect2.width * pinchStart.vb.w + pinchStart.vb.x;
|
|
277
393
|
const startMidSvgY = (pinchStart.mid.y - rect2.top) / rect2.height * pinchStart.vb.h + pinchStart.vb.y;
|
|
@@ -287,44 +403,114 @@ function flushSvgPointerMove(m) {
|
|
|
287
403
|
const rect = svgRef.value.getBoundingClientRect();
|
|
288
404
|
const sx = targetVb.value.w / rect.width;
|
|
289
405
|
const sy = targetVb.value.h / rect.height;
|
|
290
|
-
const nx = panStart.value.vx - (
|
|
291
|
-
const ny = panStart.value.vy - (
|
|
406
|
+
const nx = panStart.value.vx - (e.clientX - panStart.value.ex) * sx;
|
|
407
|
+
const ny = panStart.value.vy - (e.clientY - panStart.value.ey) * sy;
|
|
408
|
+
if (!panMoved) {
|
|
409
|
+
const dx = e.clientX - panStart.value.ex;
|
|
410
|
+
const dy = e.clientY - panStart.value.ey;
|
|
411
|
+
if (dx * dx + dy * dy > 16) {
|
|
412
|
+
panMoved = true;
|
|
413
|
+
cancelLongPress();
|
|
414
|
+
pendingSettleFit = false;
|
|
415
|
+
userAdjustedView = true;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
292
418
|
vb.value = { ...targetVb.value, x: nx, y: ny };
|
|
293
419
|
targetVb.value = { ...targetVb.value, x: nx, y: ny };
|
|
420
|
+
const now = performance.now();
|
|
421
|
+
const dt = now - lastPanEvent.t;
|
|
422
|
+
if (dt > 0 && dt < 100) {
|
|
423
|
+
panVelocity = {
|
|
424
|
+
vx: (lastPanEvent.x - e.clientX) * sx / dt,
|
|
425
|
+
vy: (lastPanEvent.y - e.clientY) * sy / dt
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
lastPanEvent = { x: e.clientX, y: e.clientY, t: now };
|
|
429
|
+
}
|
|
430
|
+
function animateInertia() {
|
|
431
|
+
const decay = 0.92;
|
|
432
|
+
panVelocity.vx *= decay;
|
|
433
|
+
panVelocity.vy *= decay;
|
|
434
|
+
if (Math.abs(panVelocity.vx) < 0.05 && Math.abs(panVelocity.vy) < 0.05) {
|
|
435
|
+
inertiaRafId = null;
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const dt = 16;
|
|
439
|
+
vb.value = { ...vb.value, x: vb.value.x + panVelocity.vx * dt, y: vb.value.y + panVelocity.vy * dt };
|
|
440
|
+
targetVb.value = { ...vb.value };
|
|
441
|
+
inertiaRafId = requestAnimationFrame(animateInertia);
|
|
294
442
|
}
|
|
295
443
|
function onSvgPointerUp(e) {
|
|
444
|
+
cancelLongPress();
|
|
445
|
+
const wasPanning = isPanning.value && activePointers.size === 1 && !isPinching;
|
|
296
446
|
activePointers.delete(e.pointerId);
|
|
297
447
|
if (activePointers.size === 0) {
|
|
448
|
+
if (e.pointerType === "touch" && !isPinching) {
|
|
449
|
+
const now = performance.now();
|
|
450
|
+
const dx = e.clientX - lastTapPos.x;
|
|
451
|
+
const dy = e.clientY - lastTapPos.y;
|
|
452
|
+
const dist = Math.hypot(dx, dy);
|
|
453
|
+
if (now - lastTapTime < 300 && dist < 30) {
|
|
454
|
+
touchDoubleTapped = true;
|
|
455
|
+
const p = svgCoord(e.clientX, e.clientY);
|
|
456
|
+
zoomIn(p);
|
|
457
|
+
lastTapTime = 0;
|
|
458
|
+
isPanning.value = false;
|
|
459
|
+
isPinching = false;
|
|
460
|
+
pinchStart = null;
|
|
461
|
+
panVelocity = { vx: 0, vy: 0 };
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
lastTapTime = now;
|
|
465
|
+
lastTapPos = { x: e.clientX, y: e.clientY };
|
|
466
|
+
}
|
|
467
|
+
if (wasPanning) {
|
|
468
|
+
const timeSinceLastMove = performance.now() - lastPanEvent.t;
|
|
469
|
+
if (timeSinceLastMove < 60 && (Math.abs(panVelocity.vx) > 0.1 || Math.abs(panVelocity.vy) > 0.1)) {
|
|
470
|
+
inertiaRafId = requestAnimationFrame(animateInertia);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
298
473
|
isPanning.value = false;
|
|
299
474
|
isPinching = false;
|
|
300
475
|
pinchStart = null;
|
|
301
476
|
} else if (activePointers.size === 1 && isPinching) {
|
|
302
477
|
isPinching = false;
|
|
303
478
|
pinchStart = null;
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
479
|
+
const firstEntry = [...activePointers.entries()][0];
|
|
480
|
+
const pt = firstEntry?.[1];
|
|
481
|
+
if (!pt) return;
|
|
307
482
|
isPanning.value = true;
|
|
308
483
|
panStart.value = { ex: pt.x, ey: pt.y, vx: vb.value.x, vy: vb.value.y };
|
|
309
484
|
}
|
|
310
485
|
}
|
|
311
486
|
function onSvgPointerLeave(e) {
|
|
487
|
+
cancelLongPress();
|
|
312
488
|
activePointers.delete(e.pointerId);
|
|
313
489
|
if (activePointers.size === 0) {
|
|
314
490
|
isPanning.value = false;
|
|
315
491
|
isPinching = false;
|
|
316
492
|
pinchStart = null;
|
|
493
|
+
pendingSvgMove = null;
|
|
317
494
|
queueLocalState({ pos: null });
|
|
318
495
|
}
|
|
319
496
|
}
|
|
320
|
-
function
|
|
497
|
+
function onSvgPointerCancel(e) {
|
|
498
|
+
cancelLongPress();
|
|
499
|
+
activePointers.delete(e.pointerId);
|
|
500
|
+
if (activePointers.size === 0) {
|
|
501
|
+
isPanning.value = false;
|
|
502
|
+
isPinching = false;
|
|
503
|
+
pinchStart = null;
|
|
504
|
+
pendingSvgMove = null;
|
|
505
|
+
panVelocity = { vx: 0, vy: 0 };
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function fitView(opts) {
|
|
321
509
|
if (simNodes.value.length === 0) return;
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
const
|
|
325
|
-
const
|
|
326
|
-
const minY = Math.min(...ys);
|
|
327
|
-
const maxY = Math.max(...ys);
|
|
510
|
+
const minX = Math.min(...simNodes.value.map((n) => n.x - nodeRadius(n)));
|
|
511
|
+
const maxX = Math.max(...simNodes.value.map((n) => n.x + nodeRadius(n)));
|
|
512
|
+
const minY = Math.min(...simNodes.value.map((n) => n.y - nodeRadius(n)));
|
|
513
|
+
const maxY = Math.max(...simNodes.value.map((n) => n.y + nodeRadius(n)));
|
|
328
514
|
const cx = (minX + maxX) / 2;
|
|
329
515
|
const cy = (minY + maxY) / 2;
|
|
330
516
|
const pad = 120;
|
|
@@ -336,20 +522,48 @@ function fitView() {
|
|
|
336
522
|
if (w / h < aspect) w = h * aspect;
|
|
337
523
|
else h = w / aspect;
|
|
338
524
|
}
|
|
339
|
-
|
|
340
|
-
|
|
525
|
+
const target = { x: cx - w / 2, y: cy - h / 2, w, h };
|
|
526
|
+
if (opts?.animate) {
|
|
527
|
+
targetVb.value = target;
|
|
528
|
+
if (!zoomRafId) zoomRafId = requestAnimationFrame(animateZoom);
|
|
529
|
+
} else {
|
|
530
|
+
vb.value = target;
|
|
531
|
+
targetVb.value = { ...target };
|
|
532
|
+
}
|
|
341
533
|
}
|
|
342
534
|
function resetView() {
|
|
343
|
-
fitView();
|
|
535
|
+
fitView({ animate: true });
|
|
344
536
|
}
|
|
345
|
-
function
|
|
346
|
-
|
|
347
|
-
|
|
537
|
+
function visibleZoomCenter(tv) {
|
|
538
|
+
const rect = svgRef.value?.getBoundingClientRect();
|
|
539
|
+
if (!rect || rect.height <= 0 || rect.width <= 0) {
|
|
540
|
+
return { x: tv.x + tv.w / 2, y: tv.y + tv.h / 2 };
|
|
541
|
+
}
|
|
542
|
+
const TOOLBAR_OVERLAY_PX = 70;
|
|
543
|
+
const visibleCenterFracY = (rect.height / 2 - TOOLBAR_OVERLAY_PX / 2) / rect.height;
|
|
544
|
+
return {
|
|
545
|
+
x: tv.x + tv.w / 2,
|
|
546
|
+
y: tv.y + visibleCenterFracY * tv.h
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
function zoomIn(center) {
|
|
550
|
+
const tv = targetVb.value;
|
|
551
|
+
const c = center ?? visibleZoomCenter(tv);
|
|
552
|
+
const cx = c.x;
|
|
553
|
+
const cy = c.y;
|
|
554
|
+
const nw = Math.max(ZOOM_MIN_W, tv.w * 0.77);
|
|
555
|
+
const nh = Math.max(ZOOM_MIN_W, tv.h * 0.77);
|
|
556
|
+
targetVb.value = { x: cx - (cx - tv.x) * (nw / tv.w), y: cy - (cy - tv.y) * (nh / tv.h), w: nw, h: nh };
|
|
348
557
|
if (!zoomRafId) zoomRafId = requestAnimationFrame(animateZoom);
|
|
349
558
|
}
|
|
350
|
-
function zoomOut() {
|
|
351
|
-
|
|
352
|
-
|
|
559
|
+
function zoomOut(center) {
|
|
560
|
+
const tv = targetVb.value;
|
|
561
|
+
const c = center ?? visibleZoomCenter(tv);
|
|
562
|
+
const cx = c.x;
|
|
563
|
+
const cy = c.y;
|
|
564
|
+
const nw = Math.min(ZOOM_MAX_W, tv.w * 1.3);
|
|
565
|
+
const nh = Math.min(ZOOM_MAX_W, tv.h * 1.3);
|
|
566
|
+
targetVb.value = { x: cx - (cx - tv.x) * (nw / tv.w), y: cy - (cy - tv.y) * (nh / tv.h), w: nw, h: nh };
|
|
353
567
|
if (!zoomRafId) zoomRafId = requestAnimationFrame(animateZoom);
|
|
354
568
|
}
|
|
355
569
|
const viewBoxStr = computed(
|
|
@@ -359,38 +573,87 @@ const labelScale = computed(() => {
|
|
|
359
573
|
const w = svgRef.value?.clientWidth ?? 1e3;
|
|
360
574
|
return vb.value.w / w;
|
|
361
575
|
});
|
|
576
|
+
const framedWidth = computed(() => {
|
|
577
|
+
const ns = simNodes.value;
|
|
578
|
+
if (!ns.length) return ZOOM_MAX_W;
|
|
579
|
+
let minX = Infinity;
|
|
580
|
+
let maxX = -Infinity;
|
|
581
|
+
let minY = Infinity;
|
|
582
|
+
let maxY = -Infinity;
|
|
583
|
+
for (const n of ns) {
|
|
584
|
+
const r = nodeRadius(n);
|
|
585
|
+
if (n.x - r < minX) minX = n.x - r;
|
|
586
|
+
if (n.x + r > maxX) maxX = n.x + r;
|
|
587
|
+
if (n.y - r < minY) minY = n.y - r;
|
|
588
|
+
if (n.y + r > maxY) maxY = n.y + r;
|
|
589
|
+
}
|
|
590
|
+
const pad = 120;
|
|
591
|
+
let w = Math.max(300, maxX - minX + pad * 2);
|
|
592
|
+
let h = Math.max(300, maxY - minY + pad * 2);
|
|
593
|
+
const rect = svgRef.value?.getBoundingClientRect();
|
|
594
|
+
if (rect && rect.width > 0 && rect.height > 0) {
|
|
595
|
+
const aspect = rect.width / rect.height;
|
|
596
|
+
if (w / h < aspect) w = h * aspect;
|
|
597
|
+
else h = w / aspect;
|
|
598
|
+
}
|
|
599
|
+
return w;
|
|
600
|
+
});
|
|
601
|
+
const zoomedInFraction = computed(() => {
|
|
602
|
+
return Math.max(0, Math.min(1, 1 - vb.value.w / framedWidth.value));
|
|
603
|
+
});
|
|
604
|
+
const labelCountFactor = computed(
|
|
605
|
+
() => Math.min(5, Math.max(1, Math.sqrt(Math.max(1, simNodes.value.length) / 50)))
|
|
606
|
+
);
|
|
362
607
|
const labelOpacity = computed(() => {
|
|
363
608
|
if (!showLabels.value) return 0;
|
|
364
|
-
|
|
365
|
-
const
|
|
366
|
-
|
|
609
|
+
if (labelDensity.value === "all") return 1;
|
|
610
|
+
const f = labelCountFactor.value;
|
|
611
|
+
const start = 0.06 + 0.03 * (f - 1);
|
|
612
|
+
const end = start + 0.18;
|
|
613
|
+
return Math.max(0, Math.min(1, (zoomedInFraction.value - start) / (end - start)));
|
|
367
614
|
});
|
|
615
|
+
const simNodes = ref([]);
|
|
616
|
+
const nodeById = /* @__PURE__ */ new Map();
|
|
617
|
+
const renderTick = ref(0);
|
|
618
|
+
const savedDocMeta = computed(() => tree.treeMap.data?.[props.docId]?.meta);
|
|
619
|
+
const savedSpacing = computed(() => savedDocMeta.value?.graphSpacing);
|
|
620
|
+
const spacingLevel = ref(savedSpacing.value ?? "default");
|
|
621
|
+
watch(savedSpacing, (v) => {
|
|
622
|
+
if (v && v !== spacingLevel.value) spacingLevel.value = v;
|
|
623
|
+
}, { immediate: true });
|
|
368
624
|
const SPACING_PRESETS = {
|
|
369
625
|
compact: { charge: -70, linkDist: 50, centerStrength: 0.1, collideExtra: 2 },
|
|
370
626
|
default: { charge: -350, linkDist: 180, centerStrength: 0.03, collideExtra: 15 },
|
|
371
627
|
spacious: { charge: -700, linkDist: 320, centerStrength: 0.01, collideExtra: 30 }
|
|
372
628
|
};
|
|
629
|
+
function sizeScale(n) {
|
|
630
|
+
return Math.min(6, Math.max(1, Math.sqrt(Math.max(1, n) / 50)));
|
|
631
|
+
}
|
|
632
|
+
function applySizeScale(base, n) {
|
|
633
|
+
const s = sizeScale(n);
|
|
634
|
+
return {
|
|
635
|
+
charge: base.charge * s,
|
|
636
|
+
linkDist: base.linkDist * s,
|
|
637
|
+
centerStrength: base.centerStrength / Math.max(1, s * 0.7),
|
|
638
|
+
collideExtra: base.collideExtra * s
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
const scaledSpacing = computed(() => applySizeScale(SPACING_PRESETS[spacingLevel.value], simNodes.value.length));
|
|
642
|
+
function setSpacing(level) {
|
|
643
|
+
spacingLevel.value = level;
|
|
644
|
+
tree.updateMeta(props.docId, { graphSpacing: level });
|
|
645
|
+
if (!simReady) return;
|
|
646
|
+
graphSim.setSpacing(scaledSpacing.value, 0.5);
|
|
647
|
+
}
|
|
648
|
+
let lastSentLinkDist = 0;
|
|
649
|
+
watch(scaledSpacing, (sp) => {
|
|
650
|
+
if (!simReady) return;
|
|
651
|
+
const delta = Math.abs(sp.linkDist - lastSentLinkDist) / Math.max(sp.linkDist, lastSentLinkDist, 1);
|
|
652
|
+
if (delta < 0.05) return;
|
|
653
|
+
lastSentLinkDist = sp.linkDist;
|
|
654
|
+
graphSim.setSpacing(sp, 0);
|
|
655
|
+
}, { flush: "post" });
|
|
373
656
|
const SPACING_CYCLE = ["compact", "default", "spacious"];
|
|
374
|
-
const EDGE_THICKNESS_SCALE = { thin: 0.6, normal: 1, thick: 1.8 };
|
|
375
|
-
const savedDocMeta = computed(() => tree.treeMap.data?.[props.docId]?.meta);
|
|
376
|
-
const spacingLevel = ref(savedDocMeta.value?.graphSpacing ?? "default");
|
|
377
|
-
watch(() => savedDocMeta.value?.graphSpacing, (v) => {
|
|
378
|
-
if (v && v !== spacingLevel.value) spacingLevel.value = v;
|
|
379
|
-
});
|
|
380
|
-
const showLabels = ref(savedDocMeta.value?.graphShowLabels ?? true);
|
|
381
|
-
watch(() => savedDocMeta.value?.graphShowLabels, (v) => {
|
|
382
|
-
if (typeof v === "boolean" && v !== showLabels.value) showLabels.value = v;
|
|
383
|
-
});
|
|
384
|
-
const showRefEdges = ref(savedDocMeta.value?.showRefEdges ?? true);
|
|
385
|
-
watch(() => savedDocMeta.value?.showRefEdges, (v) => {
|
|
386
|
-
if (typeof v === "boolean" && v !== showRefEdges.value) showRefEdges.value = v;
|
|
387
|
-
});
|
|
388
|
-
const edgeThickness = ref(savedDocMeta.value?.graphEdgeThickness ?? "normal");
|
|
389
|
-
watch(() => savedDocMeta.value?.graphEdgeThickness, (v) => {
|
|
390
|
-
if (v && v !== edgeThickness.value) edgeThickness.value = v;
|
|
391
|
-
});
|
|
392
|
-
const edgeScale = computed(() => EDGE_THICKNESS_SCALE[edgeThickness.value]);
|
|
393
|
-
const scrollBehavior = useLocalStorage("abracadabra_graph_scroll_behavior", "pan");
|
|
394
657
|
const spacingIcon = computed(() => {
|
|
395
658
|
const icons = {
|
|
396
659
|
compact: "i-lucide-dot",
|
|
@@ -399,52 +662,11 @@ const spacingIcon = computed(() => {
|
|
|
399
662
|
};
|
|
400
663
|
return icons[spacingLevel.value];
|
|
401
664
|
});
|
|
402
|
-
function applySpacingForces() {
|
|
403
|
-
if (!sim) return;
|
|
404
|
-
const p = SPACING_PRESETS[spacingLevel.value];
|
|
405
|
-
try {
|
|
406
|
-
sim.force("charge")?.strength(p.charge);
|
|
407
|
-
const linkForce = sim.force("link");
|
|
408
|
-
if (linkForce) linkForce.distance(p.linkDist).strength(0.5);
|
|
409
|
-
sim.force("x")?.strength(p.centerStrength);
|
|
410
|
-
sim.force("y")?.strength(p.centerStrength);
|
|
411
|
-
sim.force("collide")?.radius((n) => nodeRadius(n) + p.collideExtra);
|
|
412
|
-
} catch {
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
function setSpacing(level) {
|
|
416
|
-
spacingLevel.value = level;
|
|
417
|
-
tree.updateMeta(props.docId, { graphSpacing: level });
|
|
418
|
-
applySpacingForces();
|
|
419
|
-
if (sim) {
|
|
420
|
-
sim.alpha(0.5);
|
|
421
|
-
resumeSim();
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
665
|
function cycleSpacing() {
|
|
425
|
-
if (!
|
|
666
|
+
if (!canWrite.value) return;
|
|
426
667
|
const idx = SPACING_CYCLE.indexOf(spacingLevel.value);
|
|
427
668
|
setSpacing(SPACING_CYCLE[(idx + 1) % SPACING_CYCLE.length]);
|
|
428
669
|
}
|
|
429
|
-
function setShowLabels(v) {
|
|
430
|
-
showLabels.value = v;
|
|
431
|
-
tree.updateMeta(props.docId, { graphShowLabels: v });
|
|
432
|
-
}
|
|
433
|
-
function setShowRefEdges(v) {
|
|
434
|
-
showRefEdges.value = v;
|
|
435
|
-
tree.updateMeta(props.docId, { showRefEdges: v });
|
|
436
|
-
}
|
|
437
|
-
function setEdgeThickness(v) {
|
|
438
|
-
edgeThickness.value = v;
|
|
439
|
-
tree.updateMeta(props.docId, { graphEdgeThickness: v });
|
|
440
|
-
}
|
|
441
|
-
const viewSettingsActive = computed(
|
|
442
|
-
() => !showLabels.value || !showRefEdges.value || edgeThickness.value !== "normal"
|
|
443
|
-
);
|
|
444
|
-
const simNodes = ref([]);
|
|
445
|
-
const nodeById = /* @__PURE__ */ new Map();
|
|
446
|
-
const renderTick = ref(0);
|
|
447
|
-
let sim = null;
|
|
448
670
|
const renderedNodes = computed(() => {
|
|
449
671
|
void renderTick.value;
|
|
450
672
|
void iconLoadTick.value;
|
|
@@ -460,20 +682,31 @@ const visibleNodes = computed(() => {
|
|
|
460
682
|
const x1 = v.x + v.w + mx;
|
|
461
683
|
const y0 = v.y - my;
|
|
462
684
|
const y1 = v.y + v.h + my;
|
|
463
|
-
const ls = labelScale.value;
|
|
464
685
|
return simNodes.value.filter((n) => {
|
|
465
|
-
const r = nodeRadius(n) +
|
|
686
|
+
const r = nodeRadius(n) + labelScale.value * 60;
|
|
466
687
|
return n.x + r > x0 && n.x - r < x1 && n.y + r > y0 && n.y - r < y1;
|
|
467
688
|
});
|
|
468
689
|
});
|
|
469
690
|
const allSimLinks = computed(() => {
|
|
470
|
-
void
|
|
471
|
-
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
691
|
+
void simNodes.value;
|
|
692
|
+
const wireEdges = graphSim.resolvedEdges.value;
|
|
693
|
+
const out = [];
|
|
694
|
+
for (const e of wireEdges) {
|
|
695
|
+
const s = nodeById.get(e.source);
|
|
696
|
+
const t = nodeById.get(e.target);
|
|
697
|
+
if (!s || !t) continue;
|
|
698
|
+
out.push({
|
|
699
|
+
source: s,
|
|
700
|
+
target: t,
|
|
701
|
+
isRowEdge: e.kind === "row",
|
|
702
|
+
isRefEdge: e.kind === "ref",
|
|
703
|
+
isMutual: e.isMutual
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
return out;
|
|
475
707
|
});
|
|
476
708
|
const visibleLinks = computed(() => {
|
|
709
|
+
void renderTick.value;
|
|
477
710
|
const v = vb.value;
|
|
478
711
|
const mx = v.w * 0.3;
|
|
479
712
|
const my = v.h * 0.3;
|
|
@@ -482,16 +715,39 @@ const visibleLinks = computed(() => {
|
|
|
482
715
|
const y0 = v.y - my;
|
|
483
716
|
const y1 = v.y + v.h + my;
|
|
484
717
|
return allSimLinks.value.filter((l) => {
|
|
485
|
-
const s = l.source
|
|
718
|
+
const s = l.source;
|
|
719
|
+
const t = l.target;
|
|
486
720
|
return s.x > x0 && s.x < x1 && s.y > y0 && s.y < y1 || t.x > x0 && t.x < x1 && t.y > y0 && t.y < y1;
|
|
487
721
|
});
|
|
488
722
|
});
|
|
489
|
-
const
|
|
490
|
-
|
|
723
|
+
const batchedEdgePaths = computed(() => {
|
|
724
|
+
const hSub = hoveredSubtree.value;
|
|
725
|
+
const tNodes = tracedNodes.value;
|
|
726
|
+
const spath = selectedPath.value;
|
|
727
|
+
const hpath = hoveredPath.value;
|
|
728
|
+
const showTree = showTreeEdges.value;
|
|
729
|
+
const showRow = showRowEdges.value;
|
|
730
|
+
const focus = edgeFocusMode.value;
|
|
731
|
+
const hubT = hubThreshold.value;
|
|
732
|
+
const activeIds = /* @__PURE__ */ new Set();
|
|
733
|
+
if (hoveredNodeId.value) activeIds.add(hoveredNodeId.value);
|
|
734
|
+
if (selectedNodeId.value) activeIds.add(selectedNodeId.value);
|
|
735
|
+
if (tracedNodeId.value) activeIds.add(tracedNodeId.value);
|
|
736
|
+
const interacting = activeIds.size > 0;
|
|
737
|
+
const focusActive = focus && interacting;
|
|
738
|
+
const nonHighlighted = [];
|
|
739
|
+
const highlighted = [];
|
|
491
740
|
for (const link of visibleLinks.value) {
|
|
492
|
-
|
|
741
|
+
if (link.isRowEdge && !showRow) continue;
|
|
742
|
+
if (!link.isRowEdge && !link.isRefEdge && !showTree) continue;
|
|
743
|
+
if (hubT > 0 && (link.source.neighborCount > hubT || link.target.neighborCount > hubT)) continue;
|
|
744
|
+
const tid = link.target.id;
|
|
745
|
+
const sid = link.source.id;
|
|
746
|
+
const isHighlighted = focusActive ? activeIds.has(sid) || activeIds.has(tid) : hSub.has(tid) || hSub.has(sid) || spath.has(tid) || hpath.has(tid) || tNodes.has(tid) || tNodes.has(sid);
|
|
747
|
+
if (isHighlighted) highlighted.push(link);
|
|
748
|
+
else if (!focusActive) nonHighlighted.push(link);
|
|
493
749
|
}
|
|
494
|
-
return
|
|
750
|
+
return { nonHighlighted, highlighted };
|
|
495
751
|
});
|
|
496
752
|
let savePosTimer = null;
|
|
497
753
|
function savePositionsDebounced() {
|
|
@@ -503,7 +759,7 @@ function savePositionsDebounced() {
|
|
|
503
759
|
for (const node of simNodes.value) {
|
|
504
760
|
if (remoteDragByNode.value.has(node.id)) continue;
|
|
505
761
|
if (draggingId.value === node.id) continue;
|
|
506
|
-
const existing =
|
|
762
|
+
const existing = getGraphPos(node.id);
|
|
507
763
|
const pinned = existing?.pinned ?? false;
|
|
508
764
|
if (existing && Math.abs(existing.x - node.x) < 1 && Math.abs(existing.y - node.y) < 1 && existing.pinned === pinned) continue;
|
|
509
765
|
tree.updateMeta(node.id, { graphX: node.x, graphY: node.y, graphPinned: pinned });
|
|
@@ -513,63 +769,228 @@ function savePositionsDebounced() {
|
|
|
513
769
|
else work();
|
|
514
770
|
}, 500);
|
|
515
771
|
}
|
|
516
|
-
let
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
772
|
+
let pendingSettleFit = false;
|
|
773
|
+
let userAdjustedView = false;
|
|
774
|
+
watch(simRenderTick, () => {
|
|
775
|
+
renderTick.value++;
|
|
776
|
+
});
|
|
777
|
+
watch(graphSim.isSettled, (settled) => {
|
|
778
|
+
if (settled && simNodes.value.length > 0) {
|
|
779
|
+
savePositionsDebounced();
|
|
780
|
+
if (pendingSettleFit) {
|
|
781
|
+
pendingSettleFit = false;
|
|
782
|
+
fitView({ animate: true });
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
const edgeCanvasRef = ref(null);
|
|
787
|
+
let canvasResizeObserver = null;
|
|
788
|
+
let canvasSizePx = { w: 0, h: 0, dpr: 1 };
|
|
789
|
+
let edgeColors = { border: "#888", primary: "#3b82f6", muted: "#888" };
|
|
790
|
+
function refreshEdgeColors() {
|
|
791
|
+
if (!svgRef.value) return;
|
|
792
|
+
const cs = getComputedStyle(svgRef.value);
|
|
793
|
+
edgeColors = {
|
|
794
|
+
border: cs.getPropertyValue("--ui-border").trim() || edgeColors.border,
|
|
795
|
+
primary: cs.getPropertyValue("--ui-primary").trim() || edgeColors.primary,
|
|
796
|
+
muted: cs.getPropertyValue("--ui-text-muted").trim() || edgeColors.muted
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
function syncCanvasSize() {
|
|
800
|
+
const c = edgeCanvasRef.value;
|
|
801
|
+
if (!c) return;
|
|
802
|
+
const dpr = globalThis.devicePixelRatio || 1;
|
|
803
|
+
const w = c.clientWidth;
|
|
804
|
+
const h = c.clientHeight;
|
|
805
|
+
if (w <= 0 || h <= 0) return;
|
|
806
|
+
const bw = Math.round(w * dpr);
|
|
807
|
+
const bh = Math.round(h * dpr);
|
|
808
|
+
if (c.width !== bw) c.width = bw;
|
|
809
|
+
if (c.height !== bh) c.height = bh;
|
|
810
|
+
canvasSizePx = { w, h, dpr };
|
|
811
|
+
}
|
|
812
|
+
function redrawEdgeCanvas() {
|
|
813
|
+
const c = edgeCanvasRef.value;
|
|
814
|
+
if (!c) return;
|
|
815
|
+
if (canvasSizePx.w === 0) syncCanvasSize();
|
|
816
|
+
const { w: cw, h: ch, dpr } = canvasSizePx;
|
|
817
|
+
if (cw <= 0 || ch <= 0) return;
|
|
818
|
+
const ctx = c.getContext("2d");
|
|
819
|
+
if (!ctx) return;
|
|
820
|
+
refreshEdgeColors();
|
|
821
|
+
const v = vb.value;
|
|
822
|
+
if (v.w <= 0 || v.h <= 0) return;
|
|
823
|
+
const sx = cw * dpr / v.w;
|
|
824
|
+
const sy = ch * dpr / v.h;
|
|
825
|
+
const s = Math.min(sx, sy);
|
|
826
|
+
const tx = (cw * dpr - v.w * s) / 2 - v.x * s;
|
|
827
|
+
const ty = (ch * dpr - v.h * s) / 2 - v.y * s;
|
|
828
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
829
|
+
ctx.clearRect(0, 0, c.width, c.height);
|
|
830
|
+
ctx.setTransform(s, 0, 0, s, tx, ty);
|
|
831
|
+
const links = batchedEdgePaths.value.nonHighlighted;
|
|
832
|
+
if (links.length === 0) return;
|
|
833
|
+
const dim = (hoveredNodeId.value || tracedNodeId.value) !== null;
|
|
834
|
+
const eScale = edgeScale.value;
|
|
835
|
+
ctx.lineCap = "butt";
|
|
836
|
+
ctx.setLineDash([]);
|
|
837
|
+
ctx.strokeStyle = edgeColors.muted;
|
|
838
|
+
ctx.lineWidth = 2.2 * eScale;
|
|
839
|
+
ctx.globalAlpha = dim ? 0.18 : 0.85;
|
|
840
|
+
ctx.beginPath();
|
|
841
|
+
for (const l of links) {
|
|
842
|
+
if (l.isRowEdge || l.isRefEdge) continue;
|
|
843
|
+
ctx.moveTo(l.source.x, l.source.y);
|
|
844
|
+
ctx.lineTo(l.target.x, l.target.y);
|
|
845
|
+
}
|
|
846
|
+
ctx.stroke();
|
|
847
|
+
ctx.setLineDash([4, 3]);
|
|
848
|
+
ctx.strokeStyle = edgeColors.primary;
|
|
849
|
+
ctx.lineWidth = 1 * eScale;
|
|
850
|
+
ctx.globalAlpha = dim ? 0.1 : 0.35;
|
|
851
|
+
ctx.beginPath();
|
|
852
|
+
for (const l of links) {
|
|
853
|
+
if (!l.isRowEdge) continue;
|
|
854
|
+
ctx.moveTo(l.source.x, l.source.y);
|
|
855
|
+
ctx.lineTo(l.target.x, l.target.y);
|
|
856
|
+
}
|
|
857
|
+
ctx.stroke();
|
|
858
|
+
drawRefBatch(ctx, links, false, edgeColors.muted, 1 * eScale, dim ? 0.1 : 0.4);
|
|
859
|
+
drawRefBatch(ctx, links, true, edgeColors.muted, 1.6 * eScale, dim ? 0.18 : 0.7);
|
|
860
|
+
ctx.globalAlpha = 1;
|
|
861
|
+
ctx.setLineDash([]);
|
|
862
|
+
}
|
|
863
|
+
function linkD(link) {
|
|
864
|
+
const sx = link.source.x;
|
|
865
|
+
const sy = link.source.y;
|
|
866
|
+
const tx = link.target.x;
|
|
867
|
+
const ty = link.target.y;
|
|
868
|
+
if (!link.isRefEdge) return `M${sx},${sy}L${tx},${ty}`;
|
|
869
|
+
const dx = tx - sx;
|
|
870
|
+
const dy = ty - sy;
|
|
871
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
872
|
+
const sign = link.source.id.charCodeAt(0) + link.target.id.charCodeAt(0) & 1 ? 1 : -1;
|
|
873
|
+
const bow = 0.15 * sign;
|
|
874
|
+
const px = (sx + tx) / 2 + -dy / len * len * bow;
|
|
875
|
+
const py = (sy + ty) / 2 + dx / len * len * bow;
|
|
876
|
+
return `M${sx},${sy}Q${px},${py} ${tx},${ty}`;
|
|
877
|
+
}
|
|
878
|
+
const _colorCache = /* @__PURE__ */ new Map();
|
|
879
|
+
function tintFromCss(css, alpha) {
|
|
880
|
+
const key = `${css}|${alpha}`;
|
|
881
|
+
const cached = _colorCache.get(key);
|
|
882
|
+
if (cached) return cached;
|
|
883
|
+
let resolved = "160, 160, 160";
|
|
884
|
+
try {
|
|
885
|
+
const probe = document.createElement("div");
|
|
886
|
+
probe.style.color = css;
|
|
887
|
+
document.body.appendChild(probe);
|
|
888
|
+
const rgb = getComputedStyle(probe).color;
|
|
889
|
+
document.body.removeChild(probe);
|
|
890
|
+
const m = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(rgb);
|
|
891
|
+
if (m) resolved = `${m[1]}, ${m[2]}, ${m[3]}`;
|
|
892
|
+
} catch {
|
|
524
893
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
894
|
+
const result = `rgba(${resolved}, ${alpha})`;
|
|
895
|
+
_colorCache.set(key, result);
|
|
896
|
+
return result;
|
|
897
|
+
}
|
|
898
|
+
function drawRefBatch(ctx, links, mutual, fallback, width, alpha) {
|
|
899
|
+
ctx.setLineDash(mutual ? [6, 3] : [2, 4]);
|
|
900
|
+
ctx.lineWidth = width;
|
|
901
|
+
ctx.globalAlpha = alpha;
|
|
902
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
903
|
+
for (const l of links) {
|
|
904
|
+
if (!l.isRefEdge) continue;
|
|
905
|
+
if (!!l.isMutual !== mutual) continue;
|
|
906
|
+
const srcCol = nodeColor(l.source);
|
|
907
|
+
const tint = srcCol ? tintFromCss(srcCol, 1) : fallback;
|
|
908
|
+
let arr = buckets.get(tint);
|
|
909
|
+
if (!arr) {
|
|
910
|
+
arr = [];
|
|
911
|
+
buckets.set(tint, arr);
|
|
531
912
|
}
|
|
913
|
+
arr.push(l);
|
|
532
914
|
}
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
915
|
+
for (const [tint, group] of buckets) {
|
|
916
|
+
ctx.strokeStyle = tint;
|
|
917
|
+
ctx.beginPath();
|
|
918
|
+
for (const l of group) {
|
|
919
|
+
const sx = l.source.x;
|
|
920
|
+
const sy = l.source.y;
|
|
921
|
+
const tx = l.target.x;
|
|
922
|
+
const ty = l.target.y;
|
|
923
|
+
const dx = tx - sx;
|
|
924
|
+
const dy = ty - sy;
|
|
925
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
926
|
+
const sign = l.source.id.charCodeAt(0) + l.target.id.charCodeAt(0) & 1 ? 1 : -1;
|
|
927
|
+
const bow = 0.15 * sign;
|
|
928
|
+
const px = (sx + tx) / 2 + -dy / len * len * bow;
|
|
929
|
+
const py = (sy + ty) / 2 + dx / len * len * bow;
|
|
930
|
+
ctx.moveTo(sx, sy);
|
|
931
|
+
ctx.quadraticCurveTo(px, py, tx, ty);
|
|
932
|
+
}
|
|
933
|
+
ctx.stroke();
|
|
537
934
|
}
|
|
538
|
-
}
|
|
935
|
+
}
|
|
936
|
+
function scheduleCanvasRedraw() {
|
|
937
|
+
redrawEdgeCanvas();
|
|
938
|
+
}
|
|
539
939
|
function restartSim(alpha = 0.05) {
|
|
540
|
-
if (!
|
|
940
|
+
if (!simReady) return;
|
|
541
941
|
for (const n of simNodes.value) {
|
|
542
942
|
n.vx = 0;
|
|
543
943
|
n.vy = 0;
|
|
544
944
|
}
|
|
545
|
-
|
|
546
|
-
resumeSim();
|
|
945
|
+
graphSim.restart(alpha);
|
|
547
946
|
}
|
|
548
947
|
function nodeRadius(n) {
|
|
948
|
+
const mode = sizeMode.value;
|
|
949
|
+
if (mode === "uniform") return 14;
|
|
950
|
+
if (mode === "subtree" && n.id) {
|
|
951
|
+
const c = subtreeCountById.value.get(n.id) ?? 0;
|
|
952
|
+
return Math.max(12, Math.min(40, 12 + Math.sqrt(c) * 5));
|
|
953
|
+
}
|
|
549
954
|
return Math.max(12, Math.min(36, 12 + n.neighborCount * 3.5));
|
|
550
955
|
}
|
|
956
|
+
const subtreeCountById = computed(() => {
|
|
957
|
+
const children = childrenOfMap.value;
|
|
958
|
+
const memo = /* @__PURE__ */ new Map();
|
|
959
|
+
function count(id, guard) {
|
|
960
|
+
const hit = memo.get(id);
|
|
961
|
+
if (hit !== void 0) return hit;
|
|
962
|
+
if (guard.has(id)) return 0;
|
|
963
|
+
guard.add(id);
|
|
964
|
+
let total = 0;
|
|
965
|
+
for (const c of children.get(id) ?? []) total += 1 + count(c, guard);
|
|
966
|
+
memo.set(id, total);
|
|
967
|
+
return total;
|
|
968
|
+
}
|
|
969
|
+
for (const id of children.keys()) count(id, /* @__PURE__ */ new Set());
|
|
970
|
+
return memo;
|
|
971
|
+
});
|
|
972
|
+
function truncateLabel(label) {
|
|
973
|
+
const l = displayLabel(label, locale.value.untitled);
|
|
974
|
+
return l.length > 20 ? l.slice(0, 20) + "\u2026" : l;
|
|
975
|
+
}
|
|
551
976
|
function seedPos(id) {
|
|
552
977
|
let h = 0;
|
|
553
978
|
for (const c of id) h = Math.imul(31, h) + c.charCodeAt(0) | 0;
|
|
554
979
|
const angle = (h >>> 0) / 4294967295 * 2 * Math.PI;
|
|
555
980
|
const count = allEntries.value.length;
|
|
556
|
-
const sp =
|
|
557
|
-
const baseR = Math.max(sp.linkDist, count * sp.linkDist * 0.
|
|
981
|
+
const sp = scaledSpacing.value;
|
|
982
|
+
const baseR = Math.max(sp.linkDist, Math.sqrt(count) * sp.linkDist * 0.9);
|
|
558
983
|
const r = baseR + (Math.imul(h, 1664525) >>> 0) / 4294967295 * baseR * 0.5;
|
|
559
984
|
return { x: Math.cos(angle) * r, y: Math.sin(angle) * r };
|
|
560
985
|
}
|
|
561
|
-
function
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
const dist = SPACING_PRESETS[spacingLevel.value].linkDist * 0.5;
|
|
568
|
-
return { x: parent.x + Math.cos(angle) * dist, y: parent.y + Math.sin(angle) * dist };
|
|
569
|
-
}
|
|
570
|
-
return seedPos(entry.id);
|
|
986
|
+
function reseedNear(id, cx, cy, linkDist) {
|
|
987
|
+
let h = 0;
|
|
988
|
+
for (const c of id) h = Math.imul(31, h) + c.charCodeAt(0) | 0;
|
|
989
|
+
const angle = (h >>> 0) / 4294967295 * 2 * Math.PI;
|
|
990
|
+
const r = linkDist * (0.5 + (Math.imul(h, 1664525) >>> 0) / 4294967295);
|
|
991
|
+
return { x: cx + Math.cos(angle) * r, y: cy + Math.sin(angle) * r };
|
|
571
992
|
}
|
|
572
|
-
const
|
|
993
|
+
const allEntriesUnfiltered = computed(() => {
|
|
573
994
|
const result = [];
|
|
574
995
|
function collect(parentId) {
|
|
575
996
|
for (const e of tree.childrenOf(parentId)) {
|
|
@@ -580,24 +1001,174 @@ const allEntries = computed(() => {
|
|
|
580
1001
|
collect(null);
|
|
581
1002
|
return result;
|
|
582
1003
|
});
|
|
583
|
-
const
|
|
584
|
-
const
|
|
585
|
-
const
|
|
586
|
-
for (const e of
|
|
587
|
-
if (e.
|
|
588
|
-
|
|
1004
|
+
const expandableTypes = computed(() => {
|
|
1005
|
+
const typesWithChildren = /* @__PURE__ */ new Set();
|
|
1006
|
+
const parentIds = new Set(allEntriesUnfiltered.value.map((e) => e.parentId));
|
|
1007
|
+
for (const e of allEntriesUnfiltered.value) {
|
|
1008
|
+
if (e.type && parentIds.has(e.id)) typesWithChildren.add(e.type);
|
|
1009
|
+
}
|
|
1010
|
+
return [...typesWithChildren].map((tk) => {
|
|
1011
|
+
const def = resolveDocType(tk);
|
|
1012
|
+
return { value: tk, label: def.label, icon: def.icon };
|
|
1013
|
+
}).sort((a, b) => a.label.localeCompare(b.label));
|
|
1014
|
+
});
|
|
1015
|
+
const expandedTypes = ref([]);
|
|
1016
|
+
watch(expandableTypes, (types) => {
|
|
1017
|
+
if (expandedTypes.value.length === 0) {
|
|
1018
|
+
expandedTypes.value = types.map((t) => t.value);
|
|
1019
|
+
}
|
|
1020
|
+
}, { immediate: true });
|
|
1021
|
+
const collapsedNodeSet = computed(() => {
|
|
1022
|
+
const s = /* @__PURE__ */ new Set();
|
|
1023
|
+
for (const e of allEntriesUnfiltered.value) {
|
|
1024
|
+
if (e.meta?.graphCollapsed) s.add(e.id);
|
|
1025
|
+
}
|
|
1026
|
+
return s;
|
|
1027
|
+
});
|
|
1028
|
+
const hiddenCountById = computed(() => {
|
|
1029
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
1030
|
+
for (const e of allEntriesUnfiltered.value) {
|
|
1031
|
+
let arr = childrenByParent.get(e.parentId);
|
|
1032
|
+
if (!arr) {
|
|
1033
|
+
arr = [];
|
|
1034
|
+
childrenByParent.set(e.parentId, arr);
|
|
589
1035
|
}
|
|
1036
|
+
arr.push(e.id);
|
|
590
1037
|
}
|
|
591
|
-
|
|
1038
|
+
const m = /* @__PURE__ */ new Map();
|
|
1039
|
+
for (const id of collapsedNodeSet.value) {
|
|
1040
|
+
let count = 0;
|
|
1041
|
+
const queue = [...childrenByParent.get(id) ?? []];
|
|
1042
|
+
while (queue.length) {
|
|
1043
|
+
const cur = queue.pop();
|
|
1044
|
+
count++;
|
|
1045
|
+
for (const c of childrenByParent.get(cur) ?? []) queue.push(c);
|
|
1046
|
+
}
|
|
1047
|
+
m.set(id, count);
|
|
1048
|
+
}
|
|
1049
|
+
return m;
|
|
1050
|
+
});
|
|
1051
|
+
function toggleCollapse(id) {
|
|
1052
|
+
if (!canWrite.value) return;
|
|
1053
|
+
const isCollapsed = collapsedNodeSet.value.has(id);
|
|
1054
|
+
tree.updateMeta(id, { graphCollapsed: !isCollapsed });
|
|
1055
|
+
}
|
|
1056
|
+
const allEntries = computed(() => {
|
|
1057
|
+
const expanded = new Set(expandedTypes.value);
|
|
1058
|
+
const collapsed = collapsedNodeSet.value;
|
|
1059
|
+
const result = [];
|
|
1060
|
+
function collect(parentId, skip) {
|
|
1061
|
+
for (const e of tree.childrenOf(parentId)) {
|
|
1062
|
+
if (skip) continue;
|
|
1063
|
+
result.push(e);
|
|
1064
|
+
collect(e.id, (e.type ? !expanded.has(e.type) : false) || collapsed.has(e.id));
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
collect(null, false);
|
|
1068
|
+
return result;
|
|
1069
|
+
});
|
|
1070
|
+
const allEdges = computed(() => {
|
|
1071
|
+
const nodeIds = new Set(allEntries.value.map((e) => e.id));
|
|
1072
|
+
return allEntries.value.filter((e) => e.parentId !== null && nodeIds.has(e.parentId)).map((e) => ({ source: e.parentId, target: e.id }));
|
|
592
1073
|
});
|
|
1074
|
+
const rowEdges = computed(() => computeRowEdges(allEntries.value, tree));
|
|
593
1075
|
const degreeById = computed(() => {
|
|
594
1076
|
const m = /* @__PURE__ */ new Map();
|
|
1077
|
+
const bump = (id) => m.set(id, (m.get(id) ?? 0) + 1);
|
|
595
1078
|
for (const e of allEdges.value) {
|
|
596
|
-
|
|
597
|
-
|
|
1079
|
+
bump(e.source);
|
|
1080
|
+
bump(e.target);
|
|
1081
|
+
}
|
|
1082
|
+
for (const e of rowEdges.value) {
|
|
1083
|
+
bump(e.source);
|
|
1084
|
+
bump(e.target);
|
|
1085
|
+
}
|
|
1086
|
+
for (const e of refEdges.value) {
|
|
1087
|
+
bump(e.source);
|
|
1088
|
+
bump(e.target);
|
|
598
1089
|
}
|
|
599
1090
|
return m;
|
|
600
1091
|
});
|
|
1092
|
+
const pinnedSet = computed(() => {
|
|
1093
|
+
const s = /* @__PURE__ */ new Set();
|
|
1094
|
+
for (const e of tree.entries.value) {
|
|
1095
|
+
if (e.meta?.graphPinned) s.add(e.id);
|
|
1096
|
+
}
|
|
1097
|
+
return s;
|
|
1098
|
+
});
|
|
1099
|
+
const refEdgesRaw = useGraphReferenceEdges(childProviderRef, allEntries, visibleNodes);
|
|
1100
|
+
const savedShowRefEdges = computed(() => savedDocMeta.value?.showRefEdges);
|
|
1101
|
+
const showRefEdges = ref(savedShowRefEdges.value ?? true);
|
|
1102
|
+
watch(savedShowRefEdges, (v) => {
|
|
1103
|
+
if (v !== void 0 && v !== showRefEdges.value) showRefEdges.value = v;
|
|
1104
|
+
});
|
|
1105
|
+
const refEdges = computed(() => showRefEdges.value ? refEdgesRaw.value : []);
|
|
1106
|
+
const refsByNode = computed(() => {
|
|
1107
|
+
const map = /* @__PURE__ */ new Map();
|
|
1108
|
+
const add = (k, v) => {
|
|
1109
|
+
const arr = map.get(k);
|
|
1110
|
+
if (arr) arr.push(v);
|
|
1111
|
+
else map.set(k, [v]);
|
|
1112
|
+
};
|
|
1113
|
+
for (const e of refEdges.value) {
|
|
1114
|
+
add(e.source, e.target);
|
|
1115
|
+
add(e.target, e.source);
|
|
1116
|
+
}
|
|
1117
|
+
return map;
|
|
1118
|
+
});
|
|
1119
|
+
const savedShowLabels = computed(() => savedDocMeta.value?.graphShowLabels);
|
|
1120
|
+
const showLabels = ref(savedShowLabels.value ?? true);
|
|
1121
|
+
watch(savedShowLabels, (v) => {
|
|
1122
|
+
if (v !== void 0 && v !== showLabels.value) showLabels.value = v;
|
|
1123
|
+
});
|
|
1124
|
+
const savedLabelDensity = computed(() => savedDocMeta.value?.graphLabelDensity);
|
|
1125
|
+
const labelDensity = ref(savedLabelDensity.value ?? "auto");
|
|
1126
|
+
watch(savedLabelDensity, (v) => {
|
|
1127
|
+
if (v && v !== labelDensity.value) labelDensity.value = v;
|
|
1128
|
+
});
|
|
1129
|
+
const savedLabelSize = computed(() => savedDocMeta.value?.graphLabelSize);
|
|
1130
|
+
const labelSize = ref(savedLabelSize.value ?? "m");
|
|
1131
|
+
watch(savedLabelSize, (v) => {
|
|
1132
|
+
if (v && v !== labelSize.value) labelSize.value = v;
|
|
1133
|
+
});
|
|
1134
|
+
const LABEL_SIZE_MULT = { s: 0.82, m: 1, l: 1.35 };
|
|
1135
|
+
const labelSizeMult = computed(() => LABEL_SIZE_MULT[labelSize.value] ?? 1);
|
|
1136
|
+
function labelShown(id) {
|
|
1137
|
+
if (!showLabels.value) return false;
|
|
1138
|
+
if (labelDensity.value === "hubs") return (degreeById.value.get(id) ?? 0) >= 3;
|
|
1139
|
+
return true;
|
|
1140
|
+
}
|
|
1141
|
+
const savedShowTreeEdges = computed(() => savedDocMeta.value?.graphShowTreeEdges);
|
|
1142
|
+
const showTreeEdges = ref(savedShowTreeEdges.value ?? true);
|
|
1143
|
+
watch(savedShowTreeEdges, (v) => {
|
|
1144
|
+
if (v !== void 0 && v !== showTreeEdges.value) showTreeEdges.value = v;
|
|
1145
|
+
});
|
|
1146
|
+
const savedShowRowEdges = computed(() => savedDocMeta.value?.graphShowRowEdges);
|
|
1147
|
+
const showRowEdges = ref(savedShowRowEdges.value ?? true);
|
|
1148
|
+
watch(savedShowRowEdges, (v) => {
|
|
1149
|
+
if (v !== void 0 && v !== showRowEdges.value) showRowEdges.value = v;
|
|
1150
|
+
});
|
|
1151
|
+
const savedEdgeFocusMode = computed(() => savedDocMeta.value?.graphEdgeFocusMode);
|
|
1152
|
+
const edgeFocusMode = ref(savedEdgeFocusMode.value ?? false);
|
|
1153
|
+
watch(savedEdgeFocusMode, (v) => {
|
|
1154
|
+
if (v !== void 0 && v !== edgeFocusMode.value) edgeFocusMode.value = v;
|
|
1155
|
+
});
|
|
1156
|
+
const savedHubThreshold = computed(() => savedDocMeta.value?.graphHubThreshold);
|
|
1157
|
+
const hubThreshold = ref(savedHubThreshold.value ?? 0);
|
|
1158
|
+
watch(savedHubThreshold, (v) => {
|
|
1159
|
+
if (v !== void 0 && v !== hubThreshold.value) hubThreshold.value = v;
|
|
1160
|
+
});
|
|
1161
|
+
const savedEdgeThickness = computed(() => savedDocMeta.value?.graphEdgeThickness);
|
|
1162
|
+
const edgeThickness = ref(savedEdgeThickness.value ?? "normal");
|
|
1163
|
+
watch(savedEdgeThickness, (v) => {
|
|
1164
|
+
if (v && v !== edgeThickness.value) edgeThickness.value = v;
|
|
1165
|
+
});
|
|
1166
|
+
const EDGE_THICKNESS_SCALE = { thin: 0.6, normal: 1, thick: 1.6 };
|
|
1167
|
+
const edgeScale = computed(() => EDGE_THICKNESS_SCALE[edgeThickness.value]);
|
|
1168
|
+
const scrollBehavior = useLocalStorage("abracadabra_graph_scroll_behavior", "pan");
|
|
1169
|
+
const viewSettingsActive = computed(
|
|
1170
|
+
() => expandedTypes.value.length < expandableTypes.value.length || !showRefEdges.value || !showTreeEdges.value || !showRowEdges.value || !showLabels.value || labelDensity.value !== "auto" || labelSize.value !== "m" || edgeThickness.value !== "normal" || edgeFocusMode.value || hubThreshold.value > 0
|
|
1171
|
+
);
|
|
601
1172
|
const graphKey = computed(() => {
|
|
602
1173
|
let h = 0;
|
|
603
1174
|
const djb2 = (s) => {
|
|
@@ -610,76 +1181,146 @@ const graphKey = computed(() => {
|
|
|
610
1181
|
djb2(e.target);
|
|
611
1182
|
}
|
|
612
1183
|
h = h * 33 + allEdges.value.length | 0;
|
|
1184
|
+
for (const e of rowEdges.value) {
|
|
1185
|
+
djb2(e.source);
|
|
1186
|
+
djb2(e.target);
|
|
1187
|
+
}
|
|
1188
|
+
h = h * 33 + rowEdges.value.length | 0;
|
|
1189
|
+
for (const e of refEdges.value) {
|
|
1190
|
+
djb2(e.source);
|
|
1191
|
+
djb2(e.target);
|
|
1192
|
+
}
|
|
1193
|
+
h = h * 33 + refEdges.value.length | 0;
|
|
613
1194
|
return h;
|
|
614
1195
|
});
|
|
1196
|
+
function spawnPosNearParent(entry) {
|
|
1197
|
+
const saved = getGraphPos(entry.id);
|
|
1198
|
+
if (saved) return { x: saved.x, y: saved.y };
|
|
1199
|
+
const parent = entry.parentId ? nodeById.get(entry.parentId) : null;
|
|
1200
|
+
if (parent) {
|
|
1201
|
+
const angle = Math.random() * 2 * Math.PI;
|
|
1202
|
+
const dist = scaledSpacing.value.linkDist * 0.5;
|
|
1203
|
+
return { x: parent.x + Math.cos(angle) * dist, y: parent.y + Math.sin(angle) * dist };
|
|
1204
|
+
}
|
|
1205
|
+
return seedPos(entry.id);
|
|
1206
|
+
}
|
|
1207
|
+
function buildWireEdges(nodeIds) {
|
|
1208
|
+
const out = [];
|
|
1209
|
+
for (const e of allEdges.value) {
|
|
1210
|
+
if (nodeIds.has(e.source) && nodeIds.has(e.target)) out.push({ source: e.source, target: e.target, kind: "tree" });
|
|
1211
|
+
}
|
|
1212
|
+
for (const e of rowEdges.value) {
|
|
1213
|
+
if (nodeIds.has(e.source) && nodeIds.has(e.target)) out.push({ source: e.source, target: e.target, kind: "row" });
|
|
1214
|
+
}
|
|
1215
|
+
const refPairs = /* @__PURE__ */ new Set();
|
|
1216
|
+
for (const e of refEdges.value) {
|
|
1217
|
+
if (!nodeIds.has(e.source) || !nodeIds.has(e.target)) continue;
|
|
1218
|
+
refPairs.add(`${e.source}|${e.target}`);
|
|
1219
|
+
}
|
|
1220
|
+
const emitted = /* @__PURE__ */ new Set();
|
|
1221
|
+
for (const e of refEdges.value) {
|
|
1222
|
+
if (!nodeIds.has(e.source) || !nodeIds.has(e.target)) continue;
|
|
1223
|
+
const key = e.source < e.target ? `${e.source}|${e.target}` : `${e.target}|${e.source}`;
|
|
1224
|
+
if (emitted.has(key)) continue;
|
|
1225
|
+
emitted.add(key);
|
|
1226
|
+
const isMutual = refPairs.has(`${e.target}|${e.source}`) && refPairs.has(`${e.source}|${e.target}`);
|
|
1227
|
+
out.push({ source: e.source, target: e.target, kind: "ref", isMutual });
|
|
1228
|
+
}
|
|
1229
|
+
return out;
|
|
1230
|
+
}
|
|
615
1231
|
function buildSimulation(oldPos = /* @__PURE__ */ new Map()) {
|
|
616
|
-
if (!
|
|
617
|
-
const { forceSimulation, forceManyBody, forceCollide, forceLink, forceX, forceY } = d3.value;
|
|
1232
|
+
if (!d3Ready.value) return;
|
|
618
1233
|
const entries = allEntries.value;
|
|
619
1234
|
const degree = degreeById.value;
|
|
1235
|
+
const linkDist = applySizeScale(SPACING_PRESETS[spacingLevel.value], entries.length).linkDist;
|
|
1236
|
+
const staleOutliers = /* @__PURE__ */ new Set();
|
|
1237
|
+
let centroidX = 0;
|
|
1238
|
+
let centroidY = 0;
|
|
1239
|
+
{
|
|
1240
|
+
const free = [];
|
|
1241
|
+
for (const e of entries) {
|
|
1242
|
+
const sv = getGraphPos(e.id);
|
|
1243
|
+
if (sv && !sv.pinned) free.push(sv);
|
|
1244
|
+
}
|
|
1245
|
+
if (free.length >= 4) {
|
|
1246
|
+
for (const sv of free) {
|
|
1247
|
+
centroidX += sv.x;
|
|
1248
|
+
centroidY += sv.y;
|
|
1249
|
+
}
|
|
1250
|
+
centroidX /= free.length;
|
|
1251
|
+
centroidY /= free.length;
|
|
1252
|
+
const radii = free.map((sv) => Math.hypot(sv.x - centroidX, sv.y - centroidY)).sort((a, b) => a - b);
|
|
1253
|
+
const medianR = radii[Math.floor(radii.length / 2)] ?? 0;
|
|
1254
|
+
const threshold = Math.max(medianR * 6, linkDist * 10);
|
|
1255
|
+
for (const e of entries) {
|
|
1256
|
+
const sv = getGraphPos(e.id);
|
|
1257
|
+
if (sv && !sv.pinned && Math.hypot(sv.x - centroidX, sv.y - centroidY) > threshold) {
|
|
1258
|
+
staleOutliers.add(e.id);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
620
1263
|
const nodes = entries.map((entry) => {
|
|
621
|
-
const saved =
|
|
1264
|
+
const saved = getGraphPos(entry.id);
|
|
622
1265
|
const old = oldPos.get(entry.id);
|
|
623
|
-
const
|
|
624
|
-
const
|
|
1266
|
+
const stale = staleOutliers.has(entry.id);
|
|
1267
|
+
const seed = stale ? reseedNear(entry.id, centroidX, centroidY, linkDist) : seedPos(entry.id);
|
|
625
1268
|
return {
|
|
626
1269
|
id: entry.id,
|
|
627
1270
|
label: entry.label,
|
|
1271
|
+
displayLabel: truncateLabel(entry.label),
|
|
628
1272
|
type: entry.type,
|
|
629
1273
|
color: entry.meta?.color,
|
|
630
1274
|
icon: entry.meta?.icon,
|
|
631
|
-
childCount:
|
|
632
|
-
neighborCount,
|
|
633
|
-
|
|
634
|
-
|
|
1275
|
+
childCount: tree.childrenOf(entry.id).length,
|
|
1276
|
+
neighborCount: degree.get(entry.id) ?? 0,
|
|
1277
|
+
updatedAt: entry.updatedAt,
|
|
1278
|
+
x: stale ? seed.x : saved?.x ?? old?.x ?? seed.x,
|
|
1279
|
+
y: stale ? seed.y : saved?.y ?? old?.y ?? seed.y,
|
|
635
1280
|
vx: 0,
|
|
636
1281
|
vy: 0,
|
|
637
|
-
fx: saved?.pinned ? saved.x : null,
|
|
638
|
-
fy: saved?.pinned ? saved.y : null
|
|
1282
|
+
fx: !stale && saved?.pinned ? saved.x : null,
|
|
1283
|
+
fy: !stale && saved?.pinned ? saved.y : null
|
|
639
1284
|
};
|
|
640
1285
|
});
|
|
641
1286
|
const nodeIds = new Set(nodes.map((n) => n.id));
|
|
642
|
-
const
|
|
643
|
-
pauseSim();
|
|
644
|
-
sim?.stop();
|
|
645
|
-
const p = SPACING_PRESETS[spacingLevel.value];
|
|
646
|
-
sim = forceSimulation(nodes).force("charge", forceManyBody().strength(p.charge)).force("x", forceX(0).strength(p.centerStrength)).force("y", forceY(0).strength(p.centerStrength)).force("link", forceLink(edges).id((dd) => dd.id).distance(p.linkDist).strength(0.5)).force("collide", forceCollide().radius((n) => nodeRadius(n) + p.collideExtra).strength(0.85)).alphaDecay(0.04).velocityDecay(0.4).stop();
|
|
1287
|
+
const allSimEdges = buildWireEdges(nodeIds);
|
|
647
1288
|
simNodes.value = nodes;
|
|
648
1289
|
nodeById.clear();
|
|
649
1290
|
for (const n of nodes) nodeById.set(n.id, n);
|
|
650
|
-
const hasUnpositioned = nodes.some((n) =>
|
|
1291
|
+
const hasUnpositioned = nodes.some((n) => staleOutliers.has(n.id) || !getGraphPos(n.id) && !oldPos.has(n.id));
|
|
651
1292
|
if (hasUnpositioned) {
|
|
652
1293
|
for (const n of nodes) {
|
|
653
|
-
if (
|
|
1294
|
+
if (!staleOutliers.has(n.id) && (getGraphPos(n.id) || oldPos.has(n.id))) {
|
|
654
1295
|
n.fx = n.x;
|
|
655
1296
|
n.fy = n.y;
|
|
656
1297
|
}
|
|
657
1298
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
1299
|
+
}
|
|
1300
|
+
graphSim.init({
|
|
1301
|
+
nodes,
|
|
1302
|
+
edges: allSimEdges,
|
|
1303
|
+
spacing: applySizeScale(SPACING_PRESETS[spacingLevel.value], nodes.length),
|
|
1304
|
+
presettle: hasUnpositioned
|
|
1305
|
+
});
|
|
1306
|
+
simReady = true;
|
|
1307
|
+
pendingSettleFit = true;
|
|
1308
|
+
lastSentLinkDist = applySizeScale(SPACING_PRESETS[spacingLevel.value], nodes.length).linkDist;
|
|
1309
|
+
if (hasUnpositioned) {
|
|
1310
|
+
const releases = [];
|
|
661
1311
|
for (const n of nodes) {
|
|
662
|
-
if (!
|
|
1312
|
+
if (!getGraphPos(n.id)?.pinned) {
|
|
663
1313
|
n.fx = null;
|
|
664
1314
|
n.fy = null;
|
|
1315
|
+
releases.push({ id: n.id, x: null, y: null });
|
|
665
1316
|
}
|
|
666
1317
|
}
|
|
667
|
-
|
|
668
|
-
} else {
|
|
669
|
-
renderTick.value++;
|
|
1318
|
+
if (releases.length) graphSim.setFixedMany(releases);
|
|
670
1319
|
}
|
|
1320
|
+
renderTick.value++;
|
|
671
1321
|
}
|
|
672
1322
|
let hasFitOnce = false;
|
|
673
|
-
|
|
674
|
-
if (!d3.value) return;
|
|
675
|
-
if (!sim) {
|
|
676
|
-
buildSimulation();
|
|
677
|
-
if (!hasFitOnce && simNodes.value.length > 0) {
|
|
678
|
-
hasFitOnce = true;
|
|
679
|
-
nextTick(fitView);
|
|
680
|
-
}
|
|
681
|
-
return;
|
|
682
|
-
}
|
|
1323
|
+
function applyGraphPatch() {
|
|
683
1324
|
const entries = allEntries.value;
|
|
684
1325
|
const currentIds = new Set(simNodes.value.map((n) => n.id));
|
|
685
1326
|
const newIds = new Set(entries.map((e) => e.id));
|
|
@@ -693,15 +1334,17 @@ watch(graphKey, () => {
|
|
|
693
1334
|
for (const entry of entries) {
|
|
694
1335
|
if (!currentIds.has(entry.id)) {
|
|
695
1336
|
const pos = spawnPosNearParent(entry);
|
|
696
|
-
const saved =
|
|
1337
|
+
const saved = getGraphPos(entry.id);
|
|
697
1338
|
const node = {
|
|
698
1339
|
id: entry.id,
|
|
699
1340
|
label: entry.label,
|
|
1341
|
+
displayLabel: truncateLabel(entry.label),
|
|
700
1342
|
type: entry.type,
|
|
701
1343
|
color: entry.meta?.color,
|
|
702
1344
|
icon: entry.meta?.icon,
|
|
703
|
-
childCount:
|
|
1345
|
+
childCount: tree.childrenOf(entry.id).length,
|
|
704
1346
|
neighborCount: degree.get(entry.id) ?? 0,
|
|
1347
|
+
updatedAt: entry.updatedAt,
|
|
705
1348
|
x: pos.x,
|
|
706
1349
|
y: pos.y,
|
|
707
1350
|
vx: 0,
|
|
@@ -717,89 +1360,182 @@ watch(graphKey, () => {
|
|
|
717
1360
|
const entry = entryMap.get(node.id);
|
|
718
1361
|
if (entry) {
|
|
719
1362
|
node.label = entry.label;
|
|
1363
|
+
node.displayLabel = truncateLabel(entry.label);
|
|
720
1364
|
node.type = entry.type;
|
|
721
1365
|
node.color = entry.meta?.color;
|
|
722
1366
|
node.icon = entry.meta?.icon;
|
|
1367
|
+
node.childCount = tree.childrenOf(entry.id).length;
|
|
723
1368
|
node.neighborCount = degree.get(entry.id) ?? 0;
|
|
1369
|
+
node.updatedAt = entry.updatedAt;
|
|
724
1370
|
}
|
|
725
1371
|
}
|
|
1372
|
+
const removedCount = currentIds.size - kept.length;
|
|
726
1373
|
const allNodes = [...kept, ...added];
|
|
727
1374
|
simNodes.value = allNodes;
|
|
728
|
-
sim.nodes(allNodes);
|
|
729
1375
|
const nodeIdSet = new Set(allNodes.map((n) => n.id));
|
|
730
|
-
const
|
|
731
|
-
|
|
732
|
-
|
|
1376
|
+
const allWireEdges = buildWireEdges(nodeIdSet);
|
|
1377
|
+
const structural = added.length > 0 || removedCount > 0;
|
|
1378
|
+
graphSim.patch({
|
|
1379
|
+
nodes: allNodes,
|
|
1380
|
+
edges: allWireEdges,
|
|
1381
|
+
alpha: structural ? 0.05 : 0
|
|
1382
|
+
});
|
|
1383
|
+
if (structural && !userAdjustedView) pendingSettleFit = true;
|
|
733
1384
|
if (!hasFitOnce && simNodes.value.length > 0) {
|
|
734
1385
|
hasFitOnce = true;
|
|
735
|
-
nextTick(fitView);
|
|
1386
|
+
nextTick(() => fitView());
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
let patchScheduled = false;
|
|
1390
|
+
function schedulePatch() {
|
|
1391
|
+
if (patchScheduled) return;
|
|
1392
|
+
patchScheduled = true;
|
|
1393
|
+
requestAnimationFrame(() => {
|
|
1394
|
+
patchScheduled = false;
|
|
1395
|
+
if (!simReady) return;
|
|
1396
|
+
applyGraphPatch();
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1399
|
+
watch(graphKey, () => {
|
|
1400
|
+
if (!d3Ready.value) return;
|
|
1401
|
+
if (!simReady) {
|
|
1402
|
+
buildSimulation();
|
|
1403
|
+
if (!hasFitOnce && simNodes.value.length > 0) {
|
|
1404
|
+
hasFitOnce = true;
|
|
1405
|
+
nextTick(() => fitView());
|
|
1406
|
+
}
|
|
1407
|
+
return;
|
|
736
1408
|
}
|
|
1409
|
+
schedulePatch();
|
|
737
1410
|
});
|
|
738
1411
|
watch(() => tree.entries.value, () => {
|
|
739
1412
|
let changed = false;
|
|
740
1413
|
for (const node of simNodes.value) {
|
|
741
1414
|
const entry = entryById.value.get(node.id);
|
|
742
|
-
if (entry && (entry.label !== node.label || entry.type !== node.type || entry.meta?.color !== node.color || entry.meta?.icon !== node.icon)) {
|
|
1415
|
+
if (entry && (entry.label !== node.label || entry.type !== node.type || entry.meta?.color !== node.color || entry.meta?.icon !== node.icon || entry.updatedAt !== node.updatedAt)) {
|
|
743
1416
|
node.label = entry.label;
|
|
1417
|
+
node.displayLabel = truncateLabel(entry.label);
|
|
744
1418
|
node.type = entry.type;
|
|
745
1419
|
node.color = entry.meta?.color;
|
|
746
1420
|
node.icon = entry.meta?.icon;
|
|
1421
|
+
node.updatedAt = entry.updatedAt;
|
|
747
1422
|
changed = true;
|
|
748
1423
|
}
|
|
749
1424
|
}
|
|
750
1425
|
if (changed) renderTick.value++;
|
|
751
1426
|
for (const node of simNodes.value) {
|
|
752
|
-
const
|
|
753
|
-
if (
|
|
754
|
-
node.fx =
|
|
755
|
-
node.fy =
|
|
756
|
-
} else if (!
|
|
1427
|
+
const sv = getGraphPos(node.id);
|
|
1428
|
+
if (sv?.pinned && draggingId.value !== node.id) {
|
|
1429
|
+
node.fx = sv.x;
|
|
1430
|
+
node.fy = sv.y;
|
|
1431
|
+
} else if (!sv?.pinned && draggingId.value !== node.id && !remoteDragByNode.value.has(node.id)) {
|
|
757
1432
|
node.fx = null;
|
|
758
1433
|
node.fy = null;
|
|
759
1434
|
}
|
|
760
1435
|
}
|
|
761
1436
|
});
|
|
762
1437
|
watch(childDoc, (doc) => {
|
|
763
|
-
if (doc &&
|
|
1438
|
+
if (doc && d3Ready.value) {
|
|
764
1439
|
hasFitOnce = false;
|
|
1440
|
+
userAdjustedView = false;
|
|
765
1441
|
buildSimulation();
|
|
766
1442
|
if (simNodes.value.length > 0) {
|
|
767
1443
|
hasFitOnce = true;
|
|
768
|
-
nextTick(fitView);
|
|
1444
|
+
nextTick(() => fitView());
|
|
769
1445
|
}
|
|
770
1446
|
}
|
|
771
1447
|
}, { immediate: true });
|
|
772
|
-
watch(
|
|
773
|
-
if (
|
|
1448
|
+
watch(d3Ready, (ready) => {
|
|
1449
|
+
if (ready && childDoc.value) {
|
|
774
1450
|
hasFitOnce = false;
|
|
775
1451
|
buildSimulation();
|
|
776
1452
|
if (simNodes.value.length > 0) {
|
|
777
1453
|
hasFitOnce = true;
|
|
778
|
-
nextTick(fitView);
|
|
1454
|
+
nextTick(() => fitView());
|
|
779
1455
|
}
|
|
780
1456
|
}
|
|
781
1457
|
});
|
|
782
1458
|
onBeforeUnmount(() => {
|
|
783
|
-
|
|
784
|
-
|
|
1459
|
+
simReady = false;
|
|
1460
|
+
graphSim.destroy();
|
|
785
1461
|
if (savePosTimer) clearTimeout(savePosTimer);
|
|
786
1462
|
if (zoomRafId) cancelAnimationFrame(zoomRafId);
|
|
787
1463
|
if (pointerRafId !== null) cancelAnimationFrame(pointerRafId);
|
|
788
1464
|
if (awarenessRafId !== null) cancelAnimationFrame(awarenessRafId);
|
|
1465
|
+
if (inertiaRafId !== null) cancelAnimationFrame(inertiaRafId);
|
|
789
1466
|
if (syncTimer) clearTimeout(syncTimer);
|
|
790
1467
|
detachSynced?.();
|
|
791
|
-
|
|
1468
|
+
if (canvasResizeObserver) {
|
|
1469
|
+
canvasResizeObserver.disconnect();
|
|
1470
|
+
canvasResizeObserver = null;
|
|
1471
|
+
}
|
|
1472
|
+
setLocalState({ "pos": null, "graph:dragging": null, "graph:selection": [], "graph:focus": null });
|
|
792
1473
|
});
|
|
793
1474
|
const draggingId = ref(null);
|
|
794
1475
|
const dragStart = ref({ ex: 0, ey: 0 });
|
|
795
1476
|
const dragOffset = ref({ dx: 0, dy: 0 });
|
|
796
1477
|
const wasDragged = ref(false);
|
|
1478
|
+
const dropTargetId = ref(null);
|
|
1479
|
+
const pendingDrop = ref(null);
|
|
1480
|
+
let dragInvalidTargets = /* @__PURE__ */ new Set();
|
|
1481
|
+
function updateDropTarget(dragged) {
|
|
1482
|
+
let best = null;
|
|
1483
|
+
let bestD = Infinity;
|
|
1484
|
+
for (const n of simNodes.value) {
|
|
1485
|
+
if (n.id === dragged.id || dragInvalidTargets.has(n.id)) continue;
|
|
1486
|
+
const d = Math.hypot(n.x - dragged.x, n.y - dragged.y);
|
|
1487
|
+
if (d < nodeRadius(n) + nodeRadius(dragged) * 0.6 && d < bestD) {
|
|
1488
|
+
best = n;
|
|
1489
|
+
bestD = d;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
dropTargetId.value = best?.id ?? null;
|
|
1493
|
+
}
|
|
1494
|
+
function doMoveUnder(sourceId, targetId) {
|
|
1495
|
+
if (!canWrite.value) return;
|
|
1496
|
+
tree.moveEntry(sourceId, targetId, Date.now());
|
|
1497
|
+
restartSim(0.15);
|
|
1498
|
+
}
|
|
1499
|
+
async function doLinkTo(sourceId, targetId) {
|
|
1500
|
+
if (!canWrite.value) return;
|
|
1501
|
+
try {
|
|
1502
|
+
const prov = await childProviderRef.value?.loadChild(sourceId);
|
|
1503
|
+
const ydoc = prov?.document;
|
|
1504
|
+
if (!ydoc) return;
|
|
1505
|
+
const frag = ydoc.getXmlFragment("default");
|
|
1506
|
+
if (frag.toString().includes(targetId)) return;
|
|
1507
|
+
ydoc.transact(() => {
|
|
1508
|
+
const link = new Y.XmlElement("docLink");
|
|
1509
|
+
link.setAttribute("docId", targetId);
|
|
1510
|
+
const para = new Y.XmlElement("paragraph");
|
|
1511
|
+
para.insert(0, [link]);
|
|
1512
|
+
frag.insert(frag.length, [para]);
|
|
1513
|
+
});
|
|
1514
|
+
restartSim(0.1);
|
|
1515
|
+
} catch (err) {
|
|
1516
|
+
console.warn("[AGraphRenderer] doLinkTo failed", err);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
797
1519
|
function onNodePointerDown(e, id) {
|
|
798
|
-
if (
|
|
1520
|
+
if (e.pointerType === "mouse" && e.button !== 0) return;
|
|
799
1521
|
e.stopPropagation();
|
|
1522
|
+
if (e.pointerType !== "mouse") {
|
|
1523
|
+
activePointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
1524
|
+
if (activePointers.size === 1) {
|
|
1525
|
+
gestureWasPinch = false;
|
|
1526
|
+
} else {
|
|
1527
|
+
beginPinch();
|
|
1528
|
+
return;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
armLongPress(e);
|
|
1532
|
+
if (!canWrite.value) return;
|
|
800
1533
|
const node = nodeById.get(id);
|
|
801
1534
|
if (!node) return;
|
|
802
|
-
|
|
1535
|
+
try {
|
|
1536
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
1537
|
+
} catch {
|
|
1538
|
+
}
|
|
803
1539
|
draggingId.value = id;
|
|
804
1540
|
wasDragged.value = false;
|
|
805
1541
|
dragStart.value = { ex: e.clientX, ey: e.clientY };
|
|
@@ -807,150 +1543,400 @@ function onNodePointerDown(e, id) {
|
|
|
807
1543
|
dragOffset.value = { dx: node.x - p.x, dy: node.y - p.y };
|
|
808
1544
|
node.fx = node.x;
|
|
809
1545
|
node.fy = node.y;
|
|
1546
|
+
graphSim.setFixed(id, node.fx, node.fy);
|
|
810
1547
|
queueLocalState({ "graph:dragging": { nodeId: id, x: node.x, y: node.y } });
|
|
811
1548
|
}
|
|
812
1549
|
function onNodePointerMove(e, id) {
|
|
813
|
-
|
|
1550
|
+
trackLongPress(e);
|
|
1551
|
+
if (activePointers.has(e.pointerId)) {
|
|
1552
|
+
activePointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
1553
|
+
}
|
|
1554
|
+
if (isPinching) {
|
|
1555
|
+
pendingSvgMove = { clientX: e.clientX, clientY: e.clientY, pointerId: e.pointerId };
|
|
1556
|
+
schedulePointerFlush();
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
if (!canWrite.value) return;
|
|
814
1560
|
if (draggingId.value !== id) return;
|
|
815
|
-
pendingNodeMove = { clientX: e.clientX, clientY: e.clientY, pointerId: e.pointerId };
|
|
1561
|
+
pendingNodeMove = { clientX: e.clientX, clientY: e.clientY, pointerId: e.pointerId, pointerType: e.pointerType };
|
|
816
1562
|
schedulePointerFlush();
|
|
1563
|
+
void id;
|
|
817
1564
|
}
|
|
818
|
-
function flushNodePointerMove(
|
|
1565
|
+
function flushNodePointerMove(e) {
|
|
819
1566
|
const id = draggingId.value;
|
|
820
1567
|
if (!id) return;
|
|
821
|
-
const dist = Math.hypot(
|
|
822
|
-
|
|
1568
|
+
const dist = Math.hypot(e.clientX - dragStart.value.ex, e.clientY - dragStart.value.ey);
|
|
1569
|
+
const dragThreshold = e.pointerType === "mouse" ? 4 : 10;
|
|
1570
|
+
if (dist > dragThreshold && !wasDragged.value) {
|
|
823
1571
|
wasDragged.value = true;
|
|
1572
|
+
cancelLongPress();
|
|
1573
|
+
dragInvalidTargets = /* @__PURE__ */ new Set([id, ...tree.descendantsOf(id).map((d) => d.id)]);
|
|
824
1574
|
restartSim(0.03);
|
|
825
1575
|
}
|
|
826
|
-
const p = svgCoord(
|
|
1576
|
+
const p = svgCoord(e.clientX, e.clientY);
|
|
827
1577
|
const node = nodeById.get(id);
|
|
828
|
-
if (
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
1578
|
+
if (node) {
|
|
1579
|
+
const fx = p.x + dragOffset.value.dx;
|
|
1580
|
+
const fy = p.y + dragOffset.value.dy;
|
|
1581
|
+
node.fx = fx;
|
|
1582
|
+
node.fy = fy;
|
|
1583
|
+
node.x = fx;
|
|
1584
|
+
node.y = fy;
|
|
1585
|
+
graphSim.setFixed(id, fx, fy);
|
|
1586
|
+
if (wasDragged.value && canWrite.value) updateDropTarget(node);
|
|
1587
|
+
renderTick.value++;
|
|
1588
|
+
queueLocalState({ "graph:dragging": { nodeId: id, x: fx, y: fy } });
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
function onNodePointerUp(e, id) {
|
|
1592
|
+
cancelLongPress();
|
|
1593
|
+
if (e.pointerType !== "mouse") releaseNodeGesturePointer(e);
|
|
1594
|
+
if (draggingId.value === id) onDragEnd(id, e);
|
|
833
1595
|
}
|
|
834
|
-
function
|
|
835
|
-
|
|
1596
|
+
function onNodePointerCancel(e, id) {
|
|
1597
|
+
cancelLongPress();
|
|
1598
|
+
if (e.pointerType !== "mouse") releaseNodeGesturePointer(e);
|
|
1599
|
+
dropTargetId.value = null;
|
|
1600
|
+
if (draggingId.value === id) onDragEnd(id);
|
|
836
1601
|
}
|
|
837
|
-
function onDragEnd(id) {
|
|
1602
|
+
function onDragEnd(id, e) {
|
|
838
1603
|
const node = nodeById.get(id);
|
|
1604
|
+
const dropTarget = wasDragged.value && canWrite.value ? dropTargetId.value : null;
|
|
839
1605
|
if (node) {
|
|
840
|
-
const isPinned =
|
|
841
|
-
|
|
1606
|
+
const isPinned = getGraphPos(id)?.pinned ?? false;
|
|
1607
|
+
if (wasDragged.value && !dropTarget) {
|
|
1608
|
+
tree.updateMeta(id, { graphX: node.x, graphY: node.y, graphPinned: isPinned });
|
|
1609
|
+
}
|
|
842
1610
|
if (!isPinned) {
|
|
843
1611
|
node.fx = null;
|
|
844
1612
|
node.fy = null;
|
|
1613
|
+
graphSim.setFixed(id, null, null);
|
|
845
1614
|
}
|
|
846
1615
|
}
|
|
1616
|
+
pendingNodeMove = null;
|
|
847
1617
|
queueLocalState({ "graph:dragging": null });
|
|
848
1618
|
draggingId.value = null;
|
|
1619
|
+
dropTargetId.value = null;
|
|
1620
|
+
dragInvalidTargets = /* @__PURE__ */ new Set();
|
|
1621
|
+
if (dropTarget) {
|
|
1622
|
+
const targetNode = nodeById.get(dropTarget);
|
|
1623
|
+
if (e && (e.metaKey || e.ctrlKey)) {
|
|
1624
|
+
doMoveUnder(id, dropTarget);
|
|
1625
|
+
} else if (e && e.altKey) {
|
|
1626
|
+
void doLinkTo(id, dropTarget);
|
|
1627
|
+
} else {
|
|
1628
|
+
pendingDrop.value = {
|
|
1629
|
+
sourceId: id,
|
|
1630
|
+
targetId: dropTarget,
|
|
1631
|
+
targetLabel: targetNode?.label ?? ""
|
|
1632
|
+
};
|
|
1633
|
+
const anchor = svgRef.value?.querySelector(`[data-node="${dropTarget}"]`) ?? svgRef.value;
|
|
1634
|
+
anchor?.dispatchEvent(new MouseEvent("contextmenu", {
|
|
1635
|
+
clientX: e?.clientX ?? 0,
|
|
1636
|
+
clientY: e?.clientY ?? 0,
|
|
1637
|
+
bubbles: true,
|
|
1638
|
+
cancelable: true,
|
|
1639
|
+
view: window
|
|
1640
|
+
}));
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
849
1643
|
if (wasDragged.value) restartSim(0.03);
|
|
850
1644
|
}
|
|
851
1645
|
const selectedNodeId = ref(null);
|
|
852
1646
|
function selectNode(id) {
|
|
853
1647
|
selectedNodeId.value = id;
|
|
854
|
-
|
|
1648
|
+
setLocalState({ "graph:selection": id ? [id] : [] });
|
|
1649
|
+
broadcastGraphFocus();
|
|
855
1650
|
}
|
|
1651
|
+
const tracedNodeId = ref(null);
|
|
1652
|
+
const traceMode = ref("all");
|
|
1653
|
+
const tracedNodes = computed(() => {
|
|
1654
|
+
const id = tracedNodeId.value;
|
|
1655
|
+
if (!id) return /* @__PURE__ */ new Set();
|
|
1656
|
+
const mode = traceMode.value;
|
|
1657
|
+
const set = /* @__PURE__ */ new Set([id]);
|
|
1658
|
+
if (mode === "all" || mode === "ancestors") {
|
|
1659
|
+
let cur = parentOf.value.get(id);
|
|
1660
|
+
while (cur) {
|
|
1661
|
+
set.add(cur);
|
|
1662
|
+
cur = parentOf.value.get(cur);
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
if (mode === "all" || mode === "descendants") {
|
|
1666
|
+
const queue = [id];
|
|
1667
|
+
while (queue.length) {
|
|
1668
|
+
const pid = queue.shift();
|
|
1669
|
+
for (const cid of childrenOfMap.value.get(pid) ?? []) {
|
|
1670
|
+
if (!set.has(cid)) {
|
|
1671
|
+
set.add(cid);
|
|
1672
|
+
queue.push(cid);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
if (mode === "all" || mode === "siblings") {
|
|
1678
|
+
for (const sib of rowSiblingMap.value.get(id) ?? []) set.add(sib);
|
|
1679
|
+
}
|
|
1680
|
+
if (mode === "all" || mode === "references") {
|
|
1681
|
+
for (const nbr of refsByNode.value.get(id) ?? []) set.add(nbr);
|
|
1682
|
+
}
|
|
1683
|
+
return set;
|
|
1684
|
+
});
|
|
1685
|
+
let syncingGraphFollow = false;
|
|
1686
|
+
let lastGraphFocusT = 0;
|
|
1687
|
+
function broadcastGraphFocus() {
|
|
1688
|
+
if (syncingGraphFollow || props.followingUser) return;
|
|
1689
|
+
setLocalState({
|
|
1690
|
+
"graph:focus": {
|
|
1691
|
+
selectedId: selectedNodeId.value,
|
|
1692
|
+
tracedId: tracedNodeId.value,
|
|
1693
|
+
traceMode: traceMode.value,
|
|
1694
|
+
t: Date.now()
|
|
1695
|
+
}
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
watch([tracedNodeId, traceMode], () => {
|
|
1699
|
+
broadcastGraphFocus();
|
|
1700
|
+
});
|
|
1701
|
+
function smoothPanToNode(nodeId) {
|
|
1702
|
+
const node = nodeById.get(nodeId);
|
|
1703
|
+
if (!node) return;
|
|
1704
|
+
const tv = targetVb.value;
|
|
1705
|
+
targetVb.value = {
|
|
1706
|
+
x: node.x - tv.w / 2,
|
|
1707
|
+
y: node.y - tv.h / 2,
|
|
1708
|
+
w: tv.w,
|
|
1709
|
+
h: tv.h
|
|
1710
|
+
};
|
|
1711
|
+
if (!zoomRafId) zoomRafId = requestAnimationFrame(animateZoom);
|
|
1712
|
+
}
|
|
1713
|
+
watch([() => props.followingUser, states], () => {
|
|
1714
|
+
const key = props.followingUser;
|
|
1715
|
+
if (!key) return;
|
|
1716
|
+
const state = states.value.find((s) => s.user?.publicKey === key);
|
|
1717
|
+
const focus = state?.["graph:focus"];
|
|
1718
|
+
if (!focus || focus.t <= lastGraphFocusT) return;
|
|
1719
|
+
lastGraphFocusT = focus.t;
|
|
1720
|
+
syncingGraphFollow = true;
|
|
1721
|
+
tracedNodeId.value = focus.tracedId ?? null;
|
|
1722
|
+
traceMode.value = focus.traceMode ?? "all";
|
|
1723
|
+
selectedNodeId.value = focus.selectedId ?? null;
|
|
1724
|
+
const targetId = focus.selectedId ?? focus.tracedId;
|
|
1725
|
+
if (targetId) smoothPanToNode(targetId);
|
|
1726
|
+
nextTick(() => {
|
|
1727
|
+
syncingGraphFollow = false;
|
|
1728
|
+
});
|
|
1729
|
+
});
|
|
856
1730
|
function onSvgClick() {
|
|
1731
|
+
if (gestureWasPinch) return;
|
|
1732
|
+
if (panMoved) {
|
|
1733
|
+
panMoved = false;
|
|
1734
|
+
return;
|
|
1735
|
+
}
|
|
857
1736
|
selectNode(null);
|
|
1737
|
+
tracedNodeId.value = null;
|
|
858
1738
|
}
|
|
859
1739
|
function onNodeClick(e, id, label) {
|
|
860
1740
|
e.stopPropagation();
|
|
1741
|
+
if (gestureWasPinch) return;
|
|
861
1742
|
if (wasDragged.value) return;
|
|
862
1743
|
selectNode(id);
|
|
863
1744
|
openNode(id, label);
|
|
864
1745
|
}
|
|
865
1746
|
function onSvgDblClick(e) {
|
|
866
|
-
if (
|
|
1747
|
+
if (touchDoubleTapped) {
|
|
1748
|
+
touchDoubleTapped = false;
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
if (!canWrite.value) return;
|
|
867
1752
|
if (e.target.closest("[data-node]")) return;
|
|
868
1753
|
const p = svgCoord(e.clientX, e.clientY);
|
|
869
1754
|
const id = tree.createChild(null, locale.value.untitled);
|
|
870
1755
|
tree.updateMeta(id, { graphX: p.x, graphY: p.y, graphPinned: true });
|
|
871
1756
|
}
|
|
872
1757
|
function onNodeDblClick(e, id, label) {
|
|
873
|
-
if (!props.editable) return;
|
|
874
1758
|
e.stopPropagation();
|
|
1759
|
+
if (!canWrite.value) return;
|
|
875
1760
|
editId.value = id;
|
|
876
1761
|
editValue.value = label;
|
|
877
1762
|
}
|
|
878
1763
|
const editId = ref(null);
|
|
879
1764
|
const editValue = ref("");
|
|
1765
|
+
function focusRenameInput(el) {
|
|
1766
|
+
const input = el;
|
|
1767
|
+
if (!input || document.activeElement === input) return;
|
|
1768
|
+
requestAnimationFrame(() => {
|
|
1769
|
+
input.focus();
|
|
1770
|
+
input.select();
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
880
1773
|
function commitEdit() {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
tree.renameEntry(editId.value, editValue.value.trim());
|
|
884
|
-
}
|
|
1774
|
+
const id = editId.value;
|
|
1775
|
+
const label = editValue.value.trim();
|
|
885
1776
|
editId.value = null;
|
|
1777
|
+
if (!id || !label) return;
|
|
1778
|
+
tree.renameEntry(id, label);
|
|
886
1779
|
}
|
|
887
1780
|
function addNodeAtCenter() {
|
|
888
|
-
if (!
|
|
1781
|
+
if (!canWrite.value) return;
|
|
889
1782
|
const id = tree.createChild(null, locale.value.untitled);
|
|
890
1783
|
tree.updateMeta(id, { graphX: 0, graphY: 0, graphPinned: false });
|
|
891
1784
|
}
|
|
892
1785
|
const ctxNode = ref(null);
|
|
893
1786
|
const ctxCanvas = ref(null);
|
|
894
|
-
const
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
ctxPos.value = { x: e.clientX, y: e.clientY };
|
|
903
|
-
showCtx.value = true;
|
|
904
|
-
}
|
|
1787
|
+
const ctxOpen = ref(false);
|
|
1788
|
+
watch(ctxOpen, (open) => {
|
|
1789
|
+
if (!open && pendingDrop.value) {
|
|
1790
|
+
setTimeout(() => {
|
|
1791
|
+
pendingDrop.value = null;
|
|
1792
|
+
}, 50);
|
|
1793
|
+
}
|
|
1794
|
+
});
|
|
905
1795
|
function onSvgContextMenu(e) {
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1796
|
+
const nodeEl = e.target?.closest("[data-node]");
|
|
1797
|
+
if (nodeEl) {
|
|
1798
|
+
const id = nodeEl.getAttribute("data-node");
|
|
1799
|
+
const node = nodeById.get(id);
|
|
1800
|
+
ctxNode.value = { id, label: node?.label ?? "" };
|
|
1801
|
+
ctxCanvas.value = null;
|
|
1802
|
+
} else {
|
|
1803
|
+
ctxNode.value = null;
|
|
1804
|
+
ctxCanvas.value = svgCoord(e.clientX, e.clientY);
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
async function openAsWindow(id, label) {
|
|
1808
|
+
if (wm.windows.has(id)) {
|
|
1809
|
+
wm.focusWindow(id);
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1812
|
+
const childProv = await childProviderRef.value?.loadChild(id);
|
|
1813
|
+
if (!childProv) return;
|
|
1814
|
+
if (!childProv.isSynced) {
|
|
1815
|
+
await new Promise((resolve) => {
|
|
1816
|
+
const done = () => {
|
|
1817
|
+
childProv.off("synced", done);
|
|
1818
|
+
resolve();
|
|
1819
|
+
};
|
|
1820
|
+
childProv.on("synced", done);
|
|
1821
|
+
setTimeout(resolve, 6e3);
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
const entry = tree.entries.value.find((e) => e.id === id);
|
|
1825
|
+
wm.openWindow({
|
|
1826
|
+
id,
|
|
1827
|
+
title: label,
|
|
1828
|
+
docId: id,
|
|
1829
|
+
docType: entry?.type,
|
|
1830
|
+
provider: childProv,
|
|
1831
|
+
initialTab: "editor"
|
|
1832
|
+
});
|
|
912
1833
|
}
|
|
913
|
-
useEventListener(window, "pointerdown", () => {
|
|
914
|
-
showCtx.value = false;
|
|
915
|
-
});
|
|
916
1834
|
const ctxItems = computed(() => {
|
|
917
|
-
if (
|
|
918
|
-
const
|
|
1835
|
+
if (pendingDrop.value) {
|
|
1836
|
+
const pd = pendingDrop.value;
|
|
1837
|
+
const alreadyChild = entryById.value.get(pd.sourceId)?.parentId === pd.targetId;
|
|
919
1838
|
return [
|
|
1839
|
+
[
|
|
1840
|
+
...alreadyChild ? [] : [{
|
|
1841
|
+
label: `${locale.value.moveUnder ?? "Move under"} ${pd.targetLabel}`,
|
|
1842
|
+
icon: "i-lucide-corner-down-right",
|
|
1843
|
+
onSelect: () => {
|
|
1844
|
+
pendingDrop.value = null;
|
|
1845
|
+
doMoveUnder(pd.sourceId, pd.targetId);
|
|
1846
|
+
}
|
|
1847
|
+
}],
|
|
1848
|
+
{
|
|
1849
|
+
label: `${locale.value.linkTo ?? "Link to"} ${pd.targetLabel}`,
|
|
1850
|
+
icon: "i-lucide-link",
|
|
1851
|
+
onSelect: () => {
|
|
1852
|
+
pendingDrop.value = null;
|
|
1853
|
+
void doLinkTo(pd.sourceId, pd.targetId);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
],
|
|
1857
|
+
[
|
|
1858
|
+
{
|
|
1859
|
+
label: locale.value.cancel ?? "Cancel",
|
|
1860
|
+
icon: "i-lucide-x",
|
|
1861
|
+
onSelect: () => {
|
|
1862
|
+
pendingDrop.value = null;
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
]
|
|
1866
|
+
];
|
|
1867
|
+
}
|
|
1868
|
+
if (ctxNode.value) {
|
|
1869
|
+
const isPinned = getGraphPos(ctxNode.value.id)?.pinned;
|
|
1870
|
+
const groups = [
|
|
920
1871
|
[
|
|
921
1872
|
{
|
|
922
|
-
label: "Open",
|
|
923
|
-
icon: "i-lucide-
|
|
1873
|
+
label: locale.value.openAsSlideover ?? "Open in panel",
|
|
1874
|
+
icon: "i-lucide-panel-right",
|
|
924
1875
|
onSelect: () => openNode(ctxNode.value.id, ctxNode.value.label)
|
|
925
1876
|
},
|
|
926
|
-
{
|
|
927
|
-
label: "
|
|
1877
|
+
...wm.floatWindowsAvailable.value ? [{
|
|
1878
|
+
label: locale.value.openAsWindow ?? "Open as window",
|
|
1879
|
+
icon: "i-lucide-picture-in-picture-2",
|
|
1880
|
+
onSelect: () => openAsWindow(ctxNode.value.id, ctxNode.value.label)
|
|
1881
|
+
}] : [],
|
|
1882
|
+
...canWrite.value ? [{
|
|
1883
|
+
label: locale.value.rename ?? "Rename",
|
|
928
1884
|
icon: "i-lucide-pencil",
|
|
929
1885
|
onSelect: () => {
|
|
930
1886
|
editId.value = ctxNode.value.id;
|
|
931
1887
|
editValue.value = ctxNode.value.label;
|
|
932
1888
|
}
|
|
933
|
-
},
|
|
934
|
-
{
|
|
1889
|
+
}] : [],
|
|
1890
|
+
...canWrite.value ? [{
|
|
935
1891
|
label: isPinned ? locale.value.unpin : locale.value.pin,
|
|
936
1892
|
icon: isPinned ? "i-lucide-pin-off" : "i-lucide-pin",
|
|
937
1893
|
onSelect: () => togglePin(ctxNode.value.id)
|
|
938
|
-
}
|
|
1894
|
+
}] : [],
|
|
1895
|
+
...canWrite.value && (nodeById.get(ctxNode.value.id)?.childCount ?? 0) > 0 ? [{
|
|
1896
|
+
label: collapsedNodeSet.value.has(ctxNode.value.id) ? locale.value.expandSubtree ?? "Expand subtree" : locale.value.collapseSubtree ?? "Collapse subtree",
|
|
1897
|
+
icon: collapsedNodeSet.value.has(ctxNode.value.id) ? "i-lucide-expand" : "i-lucide-shrink",
|
|
1898
|
+
onSelect: () => toggleCollapse(ctxNode.value.id)
|
|
1899
|
+
}] : []
|
|
939
1900
|
],
|
|
940
1901
|
[
|
|
941
1902
|
{
|
|
942
|
-
label: "
|
|
1903
|
+
label: tracedNodeId.value === ctxNode.value.id ? locale.value.hideConnections ?? "Hide connections" : locale.value.showConnections ?? "Show connections",
|
|
1904
|
+
icon: "i-lucide-cable",
|
|
1905
|
+
onSelect: () => {
|
|
1906
|
+
tracedNodeId.value = tracedNodeId.value === ctxNode.value.id ? null : ctxNode.value.id;
|
|
1907
|
+
}
|
|
1908
|
+
},
|
|
1909
|
+
...tracedNodeId.value === ctxNode.value.id ? [
|
|
1910
|
+
{ mode: "all", label: locale.value.traceAll ?? "All connections", icon: "i-lucide-orbit" },
|
|
1911
|
+
{ mode: "ancestors", label: locale.value.traceAncestors ?? "Ancestors", icon: "i-lucide-arrow-up" },
|
|
1912
|
+
{ mode: "descendants", label: locale.value.traceDescendants ?? "Descendants", icon: "i-lucide-arrow-down" },
|
|
1913
|
+
{ mode: "references", label: locale.value.traceReferences ?? "References", icon: "i-lucide-link" },
|
|
1914
|
+
{ mode: "siblings", label: locale.value.traceSiblings ?? "Siblings", icon: "i-lucide-columns-2" }
|
|
1915
|
+
].map((opt) => ({
|
|
1916
|
+
label: opt.label,
|
|
1917
|
+
icon: traceMode.value === opt.mode ? "i-lucide-check" : opt.icon,
|
|
1918
|
+
onSelect: () => {
|
|
1919
|
+
traceMode.value = opt.mode;
|
|
1920
|
+
}
|
|
1921
|
+
})) : []
|
|
1922
|
+
]
|
|
1923
|
+
];
|
|
1924
|
+
if (canWrite.value) {
|
|
1925
|
+
groups.push([
|
|
1926
|
+
{
|
|
1927
|
+
label: locale.value.delete,
|
|
943
1928
|
icon: "i-lucide-trash-2",
|
|
944
1929
|
color: "error",
|
|
945
1930
|
onSelect: () => tree.deleteEntry(ctxNode.value.id)
|
|
946
1931
|
}
|
|
947
|
-
]
|
|
948
|
-
|
|
1932
|
+
]);
|
|
1933
|
+
}
|
|
1934
|
+
return groups;
|
|
949
1935
|
}
|
|
950
|
-
if (ctxCanvas.value) {
|
|
1936
|
+
if (ctxCanvas.value && canWrite.value) {
|
|
951
1937
|
return [[
|
|
952
1938
|
{
|
|
953
|
-
label: locale.value.
|
|
1939
|
+
label: locale.value.createNodeHere ?? "Create node here",
|
|
954
1940
|
icon: "i-lucide-plus-circle",
|
|
955
1941
|
onSelect: () => {
|
|
956
1942
|
const id = tree.createChild(null, locale.value.untitled);
|
|
@@ -962,10 +1948,9 @@ const ctxItems = computed(() => {
|
|
|
962
1948
|
return [];
|
|
963
1949
|
});
|
|
964
1950
|
function togglePin(id) {
|
|
965
|
-
if (!props.editable) return;
|
|
966
1951
|
const node = nodeById.get(id);
|
|
967
1952
|
if (!node) return;
|
|
968
|
-
const isPinned =
|
|
1953
|
+
const isPinned = getGraphPos(id)?.pinned;
|
|
969
1954
|
tree.updateMeta(id, { graphX: node.x, graphY: node.y, graphPinned: !isPinned });
|
|
970
1955
|
node.fx = isPinned ? null : node.x;
|
|
971
1956
|
node.fy = isPinned ? null : node.y;
|
|
@@ -979,14 +1964,48 @@ const remoteDragByNode = computed(() => {
|
|
|
979
1964
|
const nid = s["graph:dragging"].nodeId;
|
|
980
1965
|
if (!map.has(nid)) {
|
|
981
1966
|
map.set(nid, {
|
|
1967
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
982
1968
|
x: s["graph:dragging"].x,
|
|
1969
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
983
1970
|
y: s["graph:dragging"].y,
|
|
984
|
-
|
|
1971
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1972
|
+
color: s.user?.color ?? "var(--ui-color-neutral-400)"
|
|
985
1973
|
});
|
|
986
1974
|
}
|
|
987
1975
|
}
|
|
988
1976
|
return map;
|
|
989
1977
|
});
|
|
1978
|
+
const prevRemoteDragIds = /* @__PURE__ */ new Set();
|
|
1979
|
+
watch(remoteDragByNode, (curr) => {
|
|
1980
|
+
if (!simReady) return;
|
|
1981
|
+
const entries = [];
|
|
1982
|
+
for (const [id, drag] of curr) {
|
|
1983
|
+
const node = nodeById.get(id);
|
|
1984
|
+
if (node && draggingId.value !== id) {
|
|
1985
|
+
node.fx = drag.x;
|
|
1986
|
+
node.fy = drag.y;
|
|
1987
|
+
node.x = drag.x;
|
|
1988
|
+
node.y = drag.y;
|
|
1989
|
+
}
|
|
1990
|
+
entries.push({ id, x: drag.x, y: drag.y });
|
|
1991
|
+
}
|
|
1992
|
+
for (const id of prevRemoteDragIds) {
|
|
1993
|
+
if (curr.has(id)) continue;
|
|
1994
|
+
const node = nodeById.get(id);
|
|
1995
|
+
const isPinned = getGraphPos(id)?.pinned ?? false;
|
|
1996
|
+
if (node && !isPinned && draggingId.value !== id) {
|
|
1997
|
+
node.fx = null;
|
|
1998
|
+
node.fy = null;
|
|
1999
|
+
}
|
|
2000
|
+
if (!isPinned) entries.push({ id, x: null, y: null });
|
|
2001
|
+
}
|
|
2002
|
+
prevRemoteDragIds.clear();
|
|
2003
|
+
for (const id of curr.keys()) prevRemoteDragIds.add(id);
|
|
2004
|
+
if (entries.length) {
|
|
2005
|
+
graphSim.setFixedMany(entries);
|
|
2006
|
+
renderTick.value++;
|
|
2007
|
+
}
|
|
2008
|
+
});
|
|
990
2009
|
const remoteSelections = computed(() => {
|
|
991
2010
|
const myId = childProviderRef.value?.awareness?.clientID;
|
|
992
2011
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -994,13 +2013,147 @@ const remoteSelections = computed(() => {
|
|
|
994
2013
|
if (s.clientId === myId) continue;
|
|
995
2014
|
for (const nid of s["graph:selection"] ?? []) {
|
|
996
2015
|
if (!map.has(nid)) map.set(nid, []);
|
|
997
|
-
map.get(nid).push({
|
|
2016
|
+
map.get(nid).push({
|
|
2017
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2018
|
+
color: s.user?.color ?? "var(--ui-color-neutral-400)",
|
|
2019
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2020
|
+
name: s.user?.name ?? "Anon"
|
|
2021
|
+
});
|
|
998
2022
|
}
|
|
999
2023
|
}
|
|
1000
2024
|
return map;
|
|
1001
2025
|
});
|
|
2026
|
+
const hoveredNodeId = ref(null);
|
|
2027
|
+
const parentOf = computed(() => {
|
|
2028
|
+
const map = /* @__PURE__ */ new Map();
|
|
2029
|
+
for (const e of allEdges.value) map.set(e.target, e.source);
|
|
2030
|
+
return map;
|
|
2031
|
+
});
|
|
2032
|
+
const childrenOfMap = computed(() => {
|
|
2033
|
+
const map = /* @__PURE__ */ new Map();
|
|
2034
|
+
for (const e of allEdges.value) {
|
|
2035
|
+
if (!map.has(e.source)) map.set(e.source, []);
|
|
2036
|
+
map.get(e.source).push(e.target);
|
|
2037
|
+
}
|
|
2038
|
+
return map;
|
|
2039
|
+
});
|
|
2040
|
+
const nodeDepth = computed(() => {
|
|
2041
|
+
const depths = /* @__PURE__ */ new Map();
|
|
2042
|
+
for (const node of simNodes.value) {
|
|
2043
|
+
let depth = 0;
|
|
2044
|
+
let pid = parentOf.value.get(node.id);
|
|
2045
|
+
while (pid) {
|
|
2046
|
+
depth++;
|
|
2047
|
+
pid = parentOf.value.get(pid);
|
|
2048
|
+
}
|
|
2049
|
+
depths.set(node.id, depth);
|
|
2050
|
+
}
|
|
2051
|
+
return depths;
|
|
2052
|
+
});
|
|
2053
|
+
function nodeOpacity(id) {
|
|
2054
|
+
const depth = nodeDepth.value.get(id) ?? 0;
|
|
2055
|
+
return Math.max(0.45, 1 - depth * 0.1);
|
|
2056
|
+
}
|
|
2057
|
+
const rowSiblingMap = computed(() => {
|
|
2058
|
+
const map = /* @__PURE__ */ new Map();
|
|
2059
|
+
for (const e of rowEdges.value) {
|
|
2060
|
+
if (!map.has(e.source)) map.set(e.source, /* @__PURE__ */ new Set());
|
|
2061
|
+
if (!map.has(e.target)) map.set(e.target, /* @__PURE__ */ new Set());
|
|
2062
|
+
map.get(e.source).add(e.target);
|
|
2063
|
+
map.get(e.target).add(e.source);
|
|
2064
|
+
}
|
|
2065
|
+
for (const [, siblings] of map) {
|
|
2066
|
+
let changed = true;
|
|
2067
|
+
while (changed) {
|
|
2068
|
+
changed = false;
|
|
2069
|
+
for (const sib of siblings) {
|
|
2070
|
+
for (const ss of map.get(sib) ?? []) {
|
|
2071
|
+
if (!siblings.has(ss)) {
|
|
2072
|
+
siblings.add(ss);
|
|
2073
|
+
changed = true;
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
return map;
|
|
2080
|
+
});
|
|
2081
|
+
const hoveredSubtree = computed(() => {
|
|
2082
|
+
const id = hoveredNodeId.value;
|
|
2083
|
+
if (!id) return /* @__PURE__ */ new Set();
|
|
2084
|
+
const set = /* @__PURE__ */ new Set([id]);
|
|
2085
|
+
const queue = [id];
|
|
2086
|
+
while (queue.length) {
|
|
2087
|
+
const pid = queue.shift();
|
|
2088
|
+
for (const cid of childrenOfMap.value.get(pid) ?? []) {
|
|
2089
|
+
if (!set.has(cid)) {
|
|
2090
|
+
set.add(cid);
|
|
2091
|
+
queue.push(cid);
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
let cur = parentOf.value.get(id);
|
|
2096
|
+
while (cur) {
|
|
2097
|
+
set.add(cur);
|
|
2098
|
+
cur = parentOf.value.get(cur);
|
|
2099
|
+
}
|
|
2100
|
+
for (const sib of rowSiblingMap.value.get(id) ?? []) set.add(sib);
|
|
2101
|
+
for (const nbr of refsByNode.value.get(id) ?? []) set.add(nbr);
|
|
2102
|
+
return set;
|
|
2103
|
+
});
|
|
2104
|
+
const selectedPath = computed(() => {
|
|
2105
|
+
const id = selectedNodeId.value;
|
|
2106
|
+
if (!id) return /* @__PURE__ */ new Set();
|
|
2107
|
+
const set = /* @__PURE__ */ new Set();
|
|
2108
|
+
let cur = id;
|
|
2109
|
+
while (cur) {
|
|
2110
|
+
set.add(cur);
|
|
2111
|
+
cur = parentOf.value.get(cur);
|
|
2112
|
+
}
|
|
2113
|
+
return set;
|
|
2114
|
+
});
|
|
2115
|
+
const hoveredPath = computed(() => {
|
|
2116
|
+
const id = hoveredNodeId.value;
|
|
2117
|
+
if (!id) return /* @__PURE__ */ new Set();
|
|
2118
|
+
const set = /* @__PURE__ */ new Set();
|
|
2119
|
+
let cur = id;
|
|
2120
|
+
while (cur) {
|
|
2121
|
+
set.add(cur);
|
|
2122
|
+
cur = parentOf.value.get(cur);
|
|
2123
|
+
}
|
|
2124
|
+
return set;
|
|
2125
|
+
});
|
|
2126
|
+
function isPathEdge(targetId) {
|
|
2127
|
+
return selectedPath.value.has(targetId);
|
|
2128
|
+
}
|
|
2129
|
+
function isHoverPathEdge(targetId) {
|
|
2130
|
+
return hoveredPath.value.has(targetId);
|
|
2131
|
+
}
|
|
2132
|
+
function isTracedEdge(link) {
|
|
2133
|
+
return tracedNodes.value.has(link.source.id) && tracedNodes.value.has(link.target.id);
|
|
2134
|
+
}
|
|
2135
|
+
watch(
|
|
2136
|
+
[renderTick, () => vb.value, batchedEdgePaths, edgeScale, hoveredNodeId, tracedNodeId],
|
|
2137
|
+
scheduleCanvasRedraw,
|
|
2138
|
+
{ flush: "post" }
|
|
2139
|
+
);
|
|
2140
|
+
watch(edgeCanvasRef, (c, prev) => {
|
|
2141
|
+
if (prev && canvasResizeObserver) {
|
|
2142
|
+
canvasResizeObserver.disconnect();
|
|
2143
|
+
canvasResizeObserver = null;
|
|
2144
|
+
}
|
|
2145
|
+
if (!c) return;
|
|
2146
|
+
syncCanvasSize();
|
|
2147
|
+
refreshEdgeColors();
|
|
2148
|
+
canvasResizeObserver = new ResizeObserver(() => {
|
|
2149
|
+
syncCanvasSize();
|
|
2150
|
+
scheduleCanvasRedraw();
|
|
2151
|
+
});
|
|
2152
|
+
canvasResizeObserver.observe(c);
|
|
2153
|
+
scheduleCanvasRedraw();
|
|
2154
|
+
});
|
|
1002
2155
|
const TYPE_COLORS = {
|
|
1003
|
-
doc: "var(--
|
|
2156
|
+
doc: "var(--ui-primary)",
|
|
1004
2157
|
kanban: "var(--color-violet-500)",
|
|
1005
2158
|
gallery: "var(--color-pink-500)",
|
|
1006
2159
|
table: "var(--color-teal-500)",
|
|
@@ -1008,13 +2161,140 @@ const TYPE_COLORS = {
|
|
|
1008
2161
|
timeline: "var(--color-amber-500)",
|
|
1009
2162
|
calendar: "var(--color-red-500)",
|
|
1010
2163
|
map: "var(--color-emerald-500)",
|
|
1011
|
-
graph: "var(--color-indigo-500)"
|
|
1012
|
-
dashboard: "var(--color-orange-500)",
|
|
1013
|
-
checklist: "var(--color-green-500)"
|
|
2164
|
+
graph: "var(--color-indigo-500)"
|
|
1014
2165
|
};
|
|
2166
|
+
const savedColorMode = computed(() => savedDocMeta.value?.graphColorMode);
|
|
2167
|
+
const colorMode = ref(savedColorMode.value ?? "auto");
|
|
2168
|
+
watch(savedColorMode, (v) => {
|
|
2169
|
+
if (v && v !== colorMode.value) colorMode.value = v;
|
|
2170
|
+
});
|
|
2171
|
+
const savedSizeMode = computed(() => savedDocMeta.value?.graphSizeMode);
|
|
2172
|
+
const sizeMode = ref(savedSizeMode.value ?? "degree");
|
|
2173
|
+
watch(savedSizeMode, (v) => {
|
|
2174
|
+
if (v && v !== sizeMode.value) sizeMode.value = v;
|
|
2175
|
+
});
|
|
2176
|
+
const DEPTH_COLORS = [
|
|
2177
|
+
"var(--ui-primary)",
|
|
2178
|
+
"var(--color-violet-500)",
|
|
2179
|
+
"var(--color-teal-500)",
|
|
2180
|
+
"var(--color-amber-500)",
|
|
2181
|
+
"var(--color-pink-500)",
|
|
2182
|
+
"var(--color-emerald-500)"
|
|
2183
|
+
];
|
|
2184
|
+
const DAY_MS = 24 * 60 * 60 * 1e3;
|
|
2185
|
+
function recencyColor(updatedAt) {
|
|
2186
|
+
if (!updatedAt) return "var(--color-slate-500)";
|
|
2187
|
+
const age = Date.now() - updatedAt;
|
|
2188
|
+
if (age < DAY_MS) return "var(--color-emerald-500)";
|
|
2189
|
+
if (age < 7 * DAY_MS) return "var(--color-teal-500)";
|
|
2190
|
+
if (age < 30 * DAY_MS) return "var(--color-amber-500)";
|
|
2191
|
+
return "var(--color-slate-500)";
|
|
2192
|
+
}
|
|
2193
|
+
function degreeColor(deg) {
|
|
2194
|
+
if (deg === 0) return "var(--color-slate-500)";
|
|
2195
|
+
if (deg <= 2) return "var(--color-teal-500)";
|
|
2196
|
+
if (deg <= 5) return "var(--color-amber-500)";
|
|
2197
|
+
return "var(--color-red-500)";
|
|
2198
|
+
}
|
|
1015
2199
|
function nodeColor(n) {
|
|
1016
|
-
|
|
1017
|
-
|
|
2200
|
+
switch (colorMode.value) {
|
|
2201
|
+
case "type":
|
|
2202
|
+
return TYPE_COLORS[n.type ?? "doc"] ?? "var(--ui-primary)";
|
|
2203
|
+
case "depth":
|
|
2204
|
+
return DEPTH_COLORS[(nodeDepth.value.get(n.id) ?? 0) % DEPTH_COLORS.length];
|
|
2205
|
+
case "recency":
|
|
2206
|
+
return recencyColor(n.updatedAt);
|
|
2207
|
+
case "degree":
|
|
2208
|
+
return degreeColor(n.neighborCount);
|
|
2209
|
+
default:
|
|
2210
|
+
return n.color ?? (TYPE_COLORS[n.type ?? "doc"] ?? "var(--ui-primary)");
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
const showMinimap = useLocalStorage("abracadabra_graph_minimap", false);
|
|
2214
|
+
const minimapRef = ref(null);
|
|
2215
|
+
let minimapMap = { scale: 1, ox: 0, oy: 0 };
|
|
2216
|
+
let minimapDragging = false;
|
|
2217
|
+
function redrawMinimap() {
|
|
2218
|
+
const c = minimapRef.value;
|
|
2219
|
+
if (!c) return;
|
|
2220
|
+
const dpr = globalThis.devicePixelRatio || 1;
|
|
2221
|
+
const cw = c.clientWidth;
|
|
2222
|
+
const ch = c.clientHeight;
|
|
2223
|
+
if (!cw || !ch) return;
|
|
2224
|
+
const bw = Math.round(cw * dpr);
|
|
2225
|
+
const bh = Math.round(ch * dpr);
|
|
2226
|
+
if (c.width !== bw) c.width = bw;
|
|
2227
|
+
if (c.height !== bh) c.height = bh;
|
|
2228
|
+
const ctx = c.getContext("2d");
|
|
2229
|
+
if (!ctx) return;
|
|
2230
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
2231
|
+
ctx.clearRect(0, 0, cw, ch);
|
|
2232
|
+
const ns = simNodes.value;
|
|
2233
|
+
if (!ns.length) return;
|
|
2234
|
+
let minX = Infinity;
|
|
2235
|
+
let maxX = -Infinity;
|
|
2236
|
+
let minY = Infinity;
|
|
2237
|
+
let maxY = -Infinity;
|
|
2238
|
+
for (const n of ns) {
|
|
2239
|
+
if (n.x < minX) minX = n.x;
|
|
2240
|
+
if (n.x > maxX) maxX = n.x;
|
|
2241
|
+
if (n.y < minY) minY = n.y;
|
|
2242
|
+
if (n.y > maxY) maxY = n.y;
|
|
2243
|
+
}
|
|
2244
|
+
const pad = 60;
|
|
2245
|
+
minX -= pad;
|
|
2246
|
+
maxX += pad;
|
|
2247
|
+
minY -= pad;
|
|
2248
|
+
maxY += pad;
|
|
2249
|
+
const scale = Math.min(cw / (maxX - minX), ch / (maxY - minY));
|
|
2250
|
+
const ox = minX - (cw / scale - (maxX - minX)) / 2;
|
|
2251
|
+
const oy = minY - (ch / scale - (maxY - minY)) / 2;
|
|
2252
|
+
minimapMap = { scale, ox, oy };
|
|
2253
|
+
for (const n of ns) {
|
|
2254
|
+
ctx.fillStyle = tintFromCss(nodeColor(n), 0.9);
|
|
2255
|
+
ctx.beginPath();
|
|
2256
|
+
ctx.arc((n.x - ox) * scale, (n.y - oy) * scale, 2, 0, Math.PI * 2);
|
|
2257
|
+
ctx.fill();
|
|
2258
|
+
}
|
|
2259
|
+
const v = vb.value;
|
|
2260
|
+
ctx.strokeStyle = tintFromCss("var(--ui-primary)", 0.9);
|
|
2261
|
+
ctx.lineWidth = 1.5;
|
|
2262
|
+
ctx.strokeRect((v.x - ox) * scale, (v.y - oy) * scale, v.w * scale, v.h * scale);
|
|
2263
|
+
}
|
|
2264
|
+
watch(
|
|
2265
|
+
[renderTick, () => vb.value, showMinimap, minimapRef],
|
|
2266
|
+
() => {
|
|
2267
|
+
if (showMinimap.value) redrawMinimap();
|
|
2268
|
+
},
|
|
2269
|
+
{ flush: "post" }
|
|
2270
|
+
);
|
|
2271
|
+
function minimapToGraph(e) {
|
|
2272
|
+
const c = minimapRef.value;
|
|
2273
|
+
const r = c.getBoundingClientRect();
|
|
2274
|
+
const { scale, ox, oy } = minimapMap;
|
|
2275
|
+
return { x: (e.clientX - r.left) / scale + ox, y: (e.clientY - r.top) / scale + oy };
|
|
2276
|
+
}
|
|
2277
|
+
function centerViewAt(p) {
|
|
2278
|
+
const tv = targetVb.value;
|
|
2279
|
+
const nv = { x: p.x - tv.w / 2, y: p.y - tv.h / 2, w: tv.w, h: tv.h };
|
|
2280
|
+
vb.value = nv;
|
|
2281
|
+
targetVb.value = { ...nv };
|
|
2282
|
+
userAdjustedView = true;
|
|
2283
|
+
pendingSettleFit = false;
|
|
2284
|
+
}
|
|
2285
|
+
function onMinimapPointerDown(e) {
|
|
2286
|
+
minimapDragging = true;
|
|
2287
|
+
try {
|
|
2288
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
2289
|
+
} catch {
|
|
2290
|
+
}
|
|
2291
|
+
centerViewAt(minimapToGraph(e));
|
|
2292
|
+
}
|
|
2293
|
+
function onMinimapPointerMove(e) {
|
|
2294
|
+
if (minimapDragging) centerViewAt(minimapToGraph(e));
|
|
2295
|
+
}
|
|
2296
|
+
function onMinimapPointerUp() {
|
|
2297
|
+
minimapDragging = false;
|
|
1018
2298
|
}
|
|
1019
2299
|
const DOC_TYPE_INITIALS = {
|
|
1020
2300
|
doc: "D",
|
|
@@ -1027,15 +2307,26 @@ const DOC_TYPE_INITIALS = {
|
|
|
1027
2307
|
map: "MP",
|
|
1028
2308
|
graph: "GR",
|
|
1029
2309
|
dashboard: "DK",
|
|
1030
|
-
|
|
1031
|
-
|
|
2310
|
+
checklist: "CL",
|
|
2311
|
+
call: "CA"
|
|
1032
2312
|
};
|
|
1033
2313
|
function docTypeInitial(type) {
|
|
1034
2314
|
return DOC_TYPE_INITIALS[type ?? "doc"] ?? "?";
|
|
1035
2315
|
}
|
|
2316
|
+
defineShortcuts({
|
|
2317
|
+
"-": () => zoomOut(),
|
|
2318
|
+
"+": () => zoomIn(),
|
|
2319
|
+
"0": resetView,
|
|
2320
|
+
"f": resetView,
|
|
2321
|
+
"escape": () => {
|
|
2322
|
+
if (openNodeId.value || editId.value) return;
|
|
2323
|
+
selectNode(null);
|
|
2324
|
+
tracedNodeId.value = null;
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
1036
2327
|
const isLoading = computed(() => {
|
|
1037
2328
|
if (d3Error.value) return false;
|
|
1038
|
-
if (!
|
|
2329
|
+
if (!d3Ready.value) return true;
|
|
1039
2330
|
if (!childDoc.value) return true;
|
|
1040
2331
|
if (!providerSynced.value && simNodes.value.length === 0) return true;
|
|
1041
2332
|
return false;
|
|
@@ -1044,7 +2335,7 @@ defineExpose({ connectedUsers });
|
|
|
1044
2335
|
</script>
|
|
1045
2336
|
|
|
1046
2337
|
<template>
|
|
1047
|
-
<div class="flex-1 min-h-0 relative overflow-hidden bg-(--ui-bg
|
|
2338
|
+
<div class="flex-1 min-h-0 relative overflow-hidden bg-(--ui-bg)">
|
|
1048
2339
|
<!-- d3-force not installed fallback -->
|
|
1049
2340
|
<div
|
|
1050
2341
|
v-if="d3Error"
|
|
@@ -1062,7 +2353,7 @@ defineExpose({ connectedUsers });
|
|
|
1062
2353
|
</p>
|
|
1063
2354
|
</div>
|
|
1064
2355
|
|
|
1065
|
-
<!-- Loading skeleton
|
|
2356
|
+
<!-- Loading skeleton -->
|
|
1066
2357
|
<div
|
|
1067
2358
|
v-else-if="isLoading"
|
|
1068
2359
|
class="flex flex-col items-center justify-center h-full gap-3 text-center"
|
|
@@ -1077,11 +2368,11 @@ defineExpose({ connectedUsers });
|
|
|
1077
2368
|
</div>
|
|
1078
2369
|
|
|
1079
2370
|
<template v-else>
|
|
1080
|
-
<!--
|
|
2371
|
+
<!-- Toolbar (bottom-center) -->
|
|
1081
2372
|
<div class="graph-toolbar-bar">
|
|
1082
2373
|
<!-- Create -->
|
|
1083
2374
|
<div
|
|
1084
|
-
v-if="
|
|
2375
|
+
v-if="canWrite"
|
|
1085
2376
|
class="toolbar-group"
|
|
1086
2377
|
>
|
|
1087
2378
|
<UTooltip :text="locale.addNode">
|
|
@@ -1095,10 +2386,9 @@ defineExpose({ connectedUsers });
|
|
|
1095
2386
|
</UTooltip>
|
|
1096
2387
|
</div>
|
|
1097
2388
|
<div
|
|
1098
|
-
v-if="
|
|
2389
|
+
v-if="canWrite"
|
|
1099
2390
|
class="toolbar-divider"
|
|
1100
2391
|
/>
|
|
1101
|
-
|
|
1102
2392
|
<!-- View -->
|
|
1103
2393
|
<div class="toolbar-group">
|
|
1104
2394
|
<UTooltip :text="locale.zoomOut">
|
|
@@ -1107,7 +2397,7 @@ defineExpose({ connectedUsers });
|
|
|
1107
2397
|
size="sm"
|
|
1108
2398
|
variant="ghost"
|
|
1109
2399
|
color="neutral"
|
|
1110
|
-
@click="zoomOut"
|
|
2400
|
+
@click="zoomOut()"
|
|
1111
2401
|
/>
|
|
1112
2402
|
</UTooltip>
|
|
1113
2403
|
<UTooltip :text="locale.zoomIn">
|
|
@@ -1116,7 +2406,7 @@ defineExpose({ connectedUsers });
|
|
|
1116
2406
|
size="sm"
|
|
1117
2407
|
variant="ghost"
|
|
1118
2408
|
color="neutral"
|
|
1119
|
-
@click="zoomIn"
|
|
2409
|
+
@click="zoomIn()"
|
|
1120
2410
|
/>
|
|
1121
2411
|
</UTooltip>
|
|
1122
2412
|
<UTooltip :text="locale.fitView">
|
|
@@ -1128,9 +2418,17 @@ defineExpose({ connectedUsers });
|
|
|
1128
2418
|
@click="resetView"
|
|
1129
2419
|
/>
|
|
1130
2420
|
</UTooltip>
|
|
2421
|
+
<UTooltip :text="locale.minimap ?? 'Minimap'">
|
|
2422
|
+
<UButton
|
|
2423
|
+
icon="i-lucide-map"
|
|
2424
|
+
size="sm"
|
|
2425
|
+
:variant="showMinimap ? 'soft' : 'ghost'"
|
|
2426
|
+
:color="showMinimap ? 'primary' : 'neutral'"
|
|
2427
|
+
@click="showMinimap = !showMinimap"
|
|
2428
|
+
/>
|
|
2429
|
+
</UTooltip>
|
|
1131
2430
|
</div>
|
|
1132
2431
|
<div class="toolbar-divider" />
|
|
1133
|
-
|
|
1134
2432
|
<!-- Simulation -->
|
|
1135
2433
|
<div class="toolbar-group">
|
|
1136
2434
|
<UTooltip :text="locale.shake">
|
|
@@ -1148,14 +2446,13 @@ defineExpose({ connectedUsers });
|
|
|
1148
2446
|
size="sm"
|
|
1149
2447
|
variant="ghost"
|
|
1150
2448
|
color="neutral"
|
|
1151
|
-
:disabled="!
|
|
2449
|
+
:disabled="!canWrite"
|
|
1152
2450
|
@click="cycleSpacing"
|
|
1153
2451
|
/>
|
|
1154
2452
|
</UTooltip>
|
|
1155
2453
|
</div>
|
|
1156
2454
|
<div class="toolbar-divider" />
|
|
1157
|
-
|
|
1158
|
-
<!-- View settings popover -->
|
|
2455
|
+
<!-- View settings -->
|
|
1159
2456
|
<UPopover :content="{ side: 'top', align: 'end' }">
|
|
1160
2457
|
<UTooltip :text="locale.viewSettings">
|
|
1161
2458
|
<UButton
|
|
@@ -1172,7 +2469,58 @@ defineExpose({ connectedUsers });
|
|
|
1172
2469
|
<USwitch
|
|
1173
2470
|
:model-value="showLabels"
|
|
1174
2471
|
size="xs"
|
|
1175
|
-
@update:model-value="
|
|
2472
|
+
@update:model-value="showLabels = $event;
|
|
2473
|
+
tree.updateMeta(props.docId, { graphShowLabels: $event })"
|
|
2474
|
+
/>
|
|
2475
|
+
</div>
|
|
2476
|
+
<template v-if="showLabels">
|
|
2477
|
+
<div class="flex items-center justify-between gap-2 pl-2">
|
|
2478
|
+
<span class="text-[11px] text-(--ui-text-dimmed)">{{ locale.labelDensity ?? "Density" }}</span>
|
|
2479
|
+
<div class="flex gap-0.5">
|
|
2480
|
+
<UButton
|
|
2481
|
+
v-for="d in ['auto', 'all', 'hubs']"
|
|
2482
|
+
:key="d"
|
|
2483
|
+
size="xs"
|
|
2484
|
+
:label="d === 'auto' ? locale.densityAuto ?? 'Auto' : d === 'all' ? locale.densityAll ?? 'All' : locale.densityHubs ?? 'Hubs'"
|
|
2485
|
+
:variant="labelDensity === d ? 'soft' : 'ghost'"
|
|
2486
|
+
:color="labelDensity === d ? 'primary' : 'neutral'"
|
|
2487
|
+
@click="labelDensity = d;
|
|
2488
|
+
tree.updateMeta(props.docId, { graphLabelDensity: d })"
|
|
2489
|
+
/>
|
|
2490
|
+
</div>
|
|
2491
|
+
</div>
|
|
2492
|
+
<div class="flex items-center justify-between gap-2 pl-2">
|
|
2493
|
+
<span class="text-[11px] text-(--ui-text-dimmed)">{{ locale.labelSize ?? "Label size" }}</span>
|
|
2494
|
+
<div class="flex gap-0.5">
|
|
2495
|
+
<UButton
|
|
2496
|
+
v-for="s in ['s', 'm', 'l']"
|
|
2497
|
+
:key="s"
|
|
2498
|
+
size="xs"
|
|
2499
|
+
:label="s.toUpperCase()"
|
|
2500
|
+
:variant="labelSize === s ? 'soft' : 'ghost'"
|
|
2501
|
+
:color="labelSize === s ? 'primary' : 'neutral'"
|
|
2502
|
+
@click="labelSize = s;
|
|
2503
|
+
tree.updateMeta(props.docId, { graphLabelSize: s })"
|
|
2504
|
+
/>
|
|
2505
|
+
</div>
|
|
2506
|
+
</div>
|
|
2507
|
+
</template>
|
|
2508
|
+
<div class="flex items-center justify-between">
|
|
2509
|
+
<span class="text-xs text-(--ui-text-muted)">{{ locale.treeEdges ?? "Tree edges" }}</span>
|
|
2510
|
+
<USwitch
|
|
2511
|
+
:model-value="showTreeEdges"
|
|
2512
|
+
size="xs"
|
|
2513
|
+
@update:model-value="showTreeEdges = $event;
|
|
2514
|
+
tree.updateMeta(props.docId, { graphShowTreeEdges: $event })"
|
|
2515
|
+
/>
|
|
2516
|
+
</div>
|
|
2517
|
+
<div class="flex items-center justify-between">
|
|
2518
|
+
<span class="text-xs text-(--ui-text-muted)">{{ locale.rowEdges ?? "Row edges" }}</span>
|
|
2519
|
+
<USwitch
|
|
2520
|
+
:model-value="showRowEdges"
|
|
2521
|
+
size="xs"
|
|
2522
|
+
@update:model-value="showRowEdges = $event;
|
|
2523
|
+
tree.updateMeta(props.docId, { graphShowRowEdges: $event })"
|
|
1176
2524
|
/>
|
|
1177
2525
|
</div>
|
|
1178
2526
|
<div class="flex items-center justify-between">
|
|
@@ -1180,9 +2528,42 @@ defineExpose({ connectedUsers });
|
|
|
1180
2528
|
<USwitch
|
|
1181
2529
|
:model-value="showRefEdges"
|
|
1182
2530
|
size="xs"
|
|
1183
|
-
@update:model-value="
|
|
2531
|
+
@update:model-value="showRefEdges = $event;
|
|
2532
|
+
tree.updateMeta(props.docId, { showRefEdges: $event })"
|
|
2533
|
+
/>
|
|
2534
|
+
</div>
|
|
2535
|
+
<div class="flex items-center justify-between gap-2">
|
|
2536
|
+
<div class="flex flex-col min-w-0">
|
|
2537
|
+
<span class="text-xs text-(--ui-text-muted)">{{ locale.focusOnHover ?? "Focus on hover" }}</span>
|
|
2538
|
+
<span class="text-[10px] text-(--ui-text-dimmed)">{{ locale.focusOnHoverDesc ?? "Hide unrelated edges" }}</span>
|
|
2539
|
+
</div>
|
|
2540
|
+
<USwitch
|
|
2541
|
+
:model-value="edgeFocusMode"
|
|
2542
|
+
size="xs"
|
|
2543
|
+
@update:model-value="edgeFocusMode = $event;
|
|
2544
|
+
tree.updateMeta(props.docId, { graphEdgeFocusMode: $event })"
|
|
1184
2545
|
/>
|
|
1185
2546
|
</div>
|
|
2547
|
+
<div class="flex items-center justify-between gap-2">
|
|
2548
|
+
<div class="flex flex-col min-w-0">
|
|
2549
|
+
<span class="text-xs text-(--ui-text-muted)">{{ locale.hideHubEdges ?? "Hide hub edges" }}</span>
|
|
2550
|
+
<span class="text-[10px] text-(--ui-text-dimmed)">{{ hubThreshold > 0 ? `>${hubThreshold} ${locale.connections ?? "connections"}` : locale.off ?? "Off" }}</span>
|
|
2551
|
+
</div>
|
|
2552
|
+
<div class="flex gap-0.5 shrink-0">
|
|
2553
|
+
<UButton
|
|
2554
|
+
v-for="ht in [0, 100, 50, 25, 10]"
|
|
2555
|
+
:key="ht"
|
|
2556
|
+
size="xs"
|
|
2557
|
+
:variant="hubThreshold === ht ? 'soft' : 'ghost'"
|
|
2558
|
+
:color="hubThreshold === ht ? 'primary' : 'neutral'"
|
|
2559
|
+
class="text-[10px]"
|
|
2560
|
+
@click="hubThreshold = ht;
|
|
2561
|
+
tree.updateMeta(props.docId, { graphHubThreshold: ht })"
|
|
2562
|
+
>
|
|
2563
|
+
{{ ht === 0 ? locale.off ?? "Off" : `>${ht}` }}
|
|
2564
|
+
</UButton>
|
|
2565
|
+
</div>
|
|
2566
|
+
</div>
|
|
1186
2567
|
<div class="flex items-center justify-between">
|
|
1187
2568
|
<span class="text-xs text-(--ui-text-muted)">{{ locale.edgeThickness }}</span>
|
|
1188
2569
|
<div class="flex gap-0.5">
|
|
@@ -1192,14 +2573,64 @@ defineExpose({ connectedUsers });
|
|
|
1192
2573
|
size="xs"
|
|
1193
2574
|
:variant="edgeThickness === th ? 'soft' : 'ghost'"
|
|
1194
2575
|
:color="edgeThickness === th ? 'primary' : 'neutral'"
|
|
1195
|
-
class="capitalize text-[10px]
|
|
1196
|
-
@click="
|
|
2576
|
+
class="capitalize text-[10px]"
|
|
2577
|
+
@click="edgeThickness = th;
|
|
2578
|
+
tree.updateMeta(props.docId, { graphEdgeThickness: th })"
|
|
1197
2579
|
>
|
|
1198
2580
|
{{ locale[`edge${th.charAt(0).toUpperCase() + th.slice(1)}`] }}
|
|
1199
2581
|
</UButton>
|
|
1200
2582
|
</div>
|
|
1201
2583
|
</div>
|
|
1202
|
-
|
|
2584
|
+
<div class="flex items-center justify-between gap-2">
|
|
2585
|
+
<span class="text-xs text-(--ui-text-muted) shrink-0">{{ locale.colorBy ?? "Color by" }}</span>
|
|
2586
|
+
<div class="flex gap-0.5 flex-wrap justify-end">
|
|
2587
|
+
<UButton
|
|
2588
|
+
v-for="m in ['auto', 'type', 'depth', 'recency', 'degree']"
|
|
2589
|
+
:key="m"
|
|
2590
|
+
size="xs"
|
|
2591
|
+
:label="m === 'auto' ? locale.colorAuto ?? 'Auto' : m === 'type' ? locale.colorType ?? 'Type' : m === 'depth' ? locale.colorDepth ?? 'Depth' : m === 'recency' ? locale.colorAge ?? 'Age' : locale.colorLinks ?? 'Links'"
|
|
2592
|
+
:variant="colorMode === m ? 'soft' : 'ghost'"
|
|
2593
|
+
:color="colorMode === m ? 'primary' : 'neutral'"
|
|
2594
|
+
class="text-[10px]"
|
|
2595
|
+
@click="colorMode = m;
|
|
2596
|
+
tree.updateMeta(props.docId, { graphColorMode: m })"
|
|
2597
|
+
/>
|
|
2598
|
+
</div>
|
|
2599
|
+
</div>
|
|
2600
|
+
<div class="flex items-center justify-between gap-2">
|
|
2601
|
+
<span class="text-xs text-(--ui-text-muted) shrink-0">{{ locale.sizeBy ?? "Size by" }}</span>
|
|
2602
|
+
<div class="flex gap-0.5">
|
|
2603
|
+
<UButton
|
|
2604
|
+
v-for="m in ['degree', 'subtree', 'uniform']"
|
|
2605
|
+
:key="m"
|
|
2606
|
+
size="xs"
|
|
2607
|
+
:label="m === 'degree' ? locale.sizeLinks ?? 'Links' : m === 'subtree' ? locale.sizeTree ?? 'Tree' : locale.sizeSame ?? 'Same'"
|
|
2608
|
+
:variant="sizeMode === m ? 'soft' : 'ghost'"
|
|
2609
|
+
:color="sizeMode === m ? 'primary' : 'neutral'"
|
|
2610
|
+
class="text-[10px]"
|
|
2611
|
+
@click="sizeMode = m;
|
|
2612
|
+
tree.updateMeta(props.docId, { graphSizeMode: m })"
|
|
2613
|
+
/>
|
|
2614
|
+
</div>
|
|
2615
|
+
</div>
|
|
2616
|
+
<template v-if="expandableTypes.length > 0">
|
|
2617
|
+
<div class="h-px bg-(--ui-border)" />
|
|
2618
|
+
<span class="text-xs font-medium text-(--ui-text-dimmed)">{{ locale.filter }}</span>
|
|
2619
|
+
<label
|
|
2620
|
+
v-for="et in expandableTypes"
|
|
2621
|
+
:key="et.value"
|
|
2622
|
+
class="flex items-center gap-2 text-sm cursor-pointer"
|
|
2623
|
+
>
|
|
2624
|
+
<UCheckbox
|
|
2625
|
+
:model-value="expandedTypes.includes(et.value)"
|
|
2626
|
+
size="xs"
|
|
2627
|
+
@update:model-value="
|
|
2628
|
+
$event ? expandedTypes = [...expandedTypes, et.value] : expandedTypes = expandedTypes.filter((v) => v !== et.value)
|
|
2629
|
+
"
|
|
2630
|
+
/>
|
|
2631
|
+
<span class="truncate">{{ et.label }}</span>
|
|
2632
|
+
</label>
|
|
2633
|
+
</template>
|
|
1203
2634
|
<!-- Personal (device-local) — not shared via the doc -->
|
|
1204
2635
|
<div class="h-px bg-(--ui-border)" />
|
|
1205
2636
|
<div class="flex items-center justify-between gap-2">
|
|
@@ -1212,7 +2643,7 @@ defineExpose({ connectedUsers });
|
|
|
1212
2643
|
size="xs"
|
|
1213
2644
|
:variant="scrollBehavior === 'pan' ? 'soft' : 'ghost'"
|
|
1214
2645
|
:color="scrollBehavior === 'pan' ? 'primary' : 'neutral'"
|
|
1215
|
-
class="text-[10px]
|
|
2646
|
+
class="text-[10px]"
|
|
1216
2647
|
@click="scrollBehavior = 'pan'"
|
|
1217
2648
|
>
|
|
1218
2649
|
{{ locale.scrollPan }}
|
|
@@ -1221,7 +2652,7 @@ defineExpose({ connectedUsers });
|
|
|
1221
2652
|
size="xs"
|
|
1222
2653
|
:variant="scrollBehavior === 'zoom' ? 'soft' : 'ghost'"
|
|
1223
2654
|
:color="scrollBehavior === 'zoom' ? 'primary' : 'neutral'"
|
|
1224
|
-
class="text-[10px]
|
|
2655
|
+
class="text-[10px]"
|
|
1225
2656
|
@click="scrollBehavior = 'zoom'"
|
|
1226
2657
|
>
|
|
1227
2658
|
{{ locale.scrollZoom }}
|
|
@@ -1233,7 +2664,7 @@ defineExpose({ connectedUsers });
|
|
|
1233
2664
|
</UPopover>
|
|
1234
2665
|
</div>
|
|
1235
2666
|
|
|
1236
|
-
<!-- Empty state
|
|
2667
|
+
<!-- Empty state -->
|
|
1237
2668
|
<div
|
|
1238
2669
|
v-if="renderedNodes.length === 0"
|
|
1239
2670
|
class="flex flex-col items-center justify-center h-full gap-3 text-center"
|
|
@@ -1246,7 +2677,7 @@ defineExpose({ connectedUsers });
|
|
|
1246
2677
|
{{ locale.empty }}
|
|
1247
2678
|
</p>
|
|
1248
2679
|
<UButton
|
|
1249
|
-
v-if="
|
|
2680
|
+
v-if="canWrite"
|
|
1250
2681
|
icon="i-lucide-plus"
|
|
1251
2682
|
:label="locale.addNode"
|
|
1252
2683
|
size="sm"
|
|
@@ -1254,261 +2685,367 @@ defineExpose({ connectedUsers });
|
|
|
1254
2685
|
/>
|
|
1255
2686
|
</div>
|
|
1256
2687
|
|
|
1257
|
-
<
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
style="touch-action: none; contain: layout style paint"
|
|
1263
|
-
overflow="visible"
|
|
1264
|
-
:viewBox="viewBoxStr"
|
|
1265
|
-
@wheel.prevent="onWheel"
|
|
1266
|
-
@pointerdown="onSvgPointerDown"
|
|
1267
|
-
@pointermove="onSvgPointerMove"
|
|
1268
|
-
@pointerup="onSvgPointerUp"
|
|
1269
|
-
@pointerleave="onSvgPointerLeave"
|
|
1270
|
-
@click="onSvgClick"
|
|
1271
|
-
@dblclick="onSvgDblClick"
|
|
1272
|
-
@contextmenu.prevent="onSvgContextMenu"
|
|
1273
|
-
>
|
|
1274
|
-
<defs>
|
|
1275
|
-
<pattern
|
|
1276
|
-
id="gdots"
|
|
1277
|
-
width="30"
|
|
1278
|
-
height="30"
|
|
1279
|
-
patternUnits="userSpaceOnUse"
|
|
1280
|
-
>
|
|
1281
|
-
<circle
|
|
1282
|
-
cx="15"
|
|
1283
|
-
cy="15"
|
|
1284
|
-
r="0.8"
|
|
1285
|
-
fill="var(--ui-border)"
|
|
1286
|
-
opacity="0.5"
|
|
1287
|
-
/>
|
|
1288
|
-
</pattern>
|
|
1289
|
-
<filter
|
|
1290
|
-
id="glow"
|
|
1291
|
-
x="-50%"
|
|
1292
|
-
y="-50%"
|
|
1293
|
-
width="200%"
|
|
1294
|
-
height="200%"
|
|
1295
|
-
>
|
|
1296
|
-
<feGaussianBlur
|
|
1297
|
-
stdDeviation="4"
|
|
1298
|
-
result="blur"
|
|
1299
|
-
/>
|
|
1300
|
-
<feMerge>
|
|
1301
|
-
<feMergeNode in="blur" />
|
|
1302
|
-
<feMergeNode in="SourceGraphic" />
|
|
1303
|
-
</feMerge>
|
|
1304
|
-
</filter>
|
|
1305
|
-
</defs>
|
|
1306
|
-
|
|
1307
|
-
<!-- Background dots -->
|
|
1308
|
-
<rect
|
|
1309
|
-
x="-5000"
|
|
1310
|
-
y="-5000"
|
|
1311
|
-
width="10000"
|
|
1312
|
-
height="10000"
|
|
1313
|
-
fill="url(#gdots)"
|
|
2688
|
+
<template v-else>
|
|
2689
|
+
<canvas
|
|
2690
|
+
ref="edgeCanvasRef"
|
|
2691
|
+
class="absolute inset-0 w-full h-full pointer-events-none"
|
|
2692
|
+
style="contain: layout style paint"
|
|
1314
2693
|
/>
|
|
1315
2694
|
|
|
1316
|
-
<!--
|
|
1317
|
-
<
|
|
1318
|
-
v-if="
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
2695
|
+
<!-- Minimap (device-local toggle) — click/drag to navigate -->
|
|
2696
|
+
<canvas
|
|
2697
|
+
v-if="showMinimap"
|
|
2698
|
+
ref="minimapRef"
|
|
2699
|
+
class="graph-minimap"
|
|
2700
|
+
@pointerdown.stop="onMinimapPointerDown"
|
|
2701
|
+
@pointermove.stop="onMinimapPointerMove"
|
|
2702
|
+
@pointerup.stop="onMinimapPointerUp"
|
|
2703
|
+
@pointercancel.stop="onMinimapPointerUp"
|
|
1324
2704
|
/>
|
|
1325
2705
|
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
data-node
|
|
1331
|
-
:transform="`translate(${node.x}, ${node.y})`"
|
|
1332
|
-
style="cursor: grab"
|
|
1333
|
-
@pointerdown.stop="onNodePointerDown($event, node.id)"
|
|
1334
|
-
@pointermove.stop="onNodePointerMove($event, node.id)"
|
|
1335
|
-
@pointerup.stop="onNodePointerUp($event, node.id)"
|
|
1336
|
-
@click.stop="onNodeClick($event, node.id, node.label)"
|
|
1337
|
-
@dblclick.stop="onNodeDblClick($event, node.id, node.label)"
|
|
1338
|
-
@contextmenu.stop.prevent="onNodeContextMenu($event, node.id, node.label)"
|
|
2706
|
+
<UContextMenu
|
|
2707
|
+
v-model:open="ctxOpen"
|
|
2708
|
+
:items="ctxItems"
|
|
2709
|
+
class="w-full h-full"
|
|
1339
2710
|
>
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
:
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
:
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
2711
|
+
<svg
|
|
2712
|
+
ref="svgRef"
|
|
2713
|
+
class="w-full h-full select-none relative"
|
|
2714
|
+
:class="isPanning ? 'cursor-grabbing' : 'cursor-default'"
|
|
2715
|
+
style="touch-action: none; contain: layout style paint"
|
|
2716
|
+
overflow="visible"
|
|
2717
|
+
:viewBox="viewBoxStr"
|
|
2718
|
+
@wheel.prevent="onWheel"
|
|
2719
|
+
@pointerdown="onSvgPointerDown"
|
|
2720
|
+
@pointermove="onSvgPointerMove"
|
|
2721
|
+
@pointerup="onSvgPointerUp"
|
|
2722
|
+
@pointerleave="onSvgPointerLeave"
|
|
2723
|
+
@pointercancel="onSvgPointerCancel"
|
|
2724
|
+
@click="onSvgClick"
|
|
2725
|
+
@dblclick="onSvgDblClick"
|
|
2726
|
+
@contextmenu="onSvgContextMenu"
|
|
2727
|
+
>
|
|
2728
|
+
<defs>
|
|
2729
|
+
<pattern
|
|
2730
|
+
id="gdots"
|
|
2731
|
+
width="30"
|
|
2732
|
+
height="30"
|
|
2733
|
+
patternUnits="userSpaceOnUse"
|
|
2734
|
+
>
|
|
2735
|
+
<circle
|
|
2736
|
+
cx="15"
|
|
2737
|
+
cy="15"
|
|
2738
|
+
r="0.8"
|
|
2739
|
+
fill="var(--ui-border)"
|
|
2740
|
+
opacity="0.5"
|
|
2741
|
+
/>
|
|
2742
|
+
</pattern>
|
|
2743
|
+
<filter
|
|
2744
|
+
id="glow"
|
|
2745
|
+
x="-50%"
|
|
2746
|
+
y="-50%"
|
|
2747
|
+
width="200%"
|
|
2748
|
+
height="200%"
|
|
2749
|
+
>
|
|
2750
|
+
<feGaussianBlur
|
|
2751
|
+
stdDeviation="4"
|
|
2752
|
+
result="blur"
|
|
2753
|
+
/>
|
|
2754
|
+
<feMerge>
|
|
2755
|
+
<feMergeNode in="blur" />
|
|
2756
|
+
<feMergeNode in="SourceGraphic" />
|
|
2757
|
+
</feMerge>
|
|
2758
|
+
</filter>
|
|
2759
|
+
<marker
|
|
2760
|
+
id="ref-arrow"
|
|
2761
|
+
viewBox="0 0 10 10"
|
|
2762
|
+
refX="10"
|
|
2763
|
+
refY="5"
|
|
2764
|
+
markerWidth="6"
|
|
2765
|
+
markerHeight="6"
|
|
2766
|
+
orient="auto-start-reverse"
|
|
2767
|
+
>
|
|
2768
|
+
<path
|
|
2769
|
+
d="M 0 0 L 10 5 L 0 10 z"
|
|
2770
|
+
fill="var(--ui-text-muted)"
|
|
2771
|
+
/>
|
|
2772
|
+
</marker>
|
|
2773
|
+
</defs>
|
|
2774
|
+
|
|
2775
|
+
<!-- Background dots — sized to the live viewBox -->
|
|
2776
|
+
<rect
|
|
2777
|
+
:x="vb.x"
|
|
2778
|
+
:y="vb.y"
|
|
2779
|
+
:width="vb.w"
|
|
2780
|
+
:height="vb.h"
|
|
2781
|
+
fill="url(#gdots)"
|
|
2782
|
+
/>
|
|
1350
2783
|
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
2784
|
+
<!-- Edges layer — non-highlighted on canvas; highlighted as SVG. -->
|
|
2785
|
+
<g>
|
|
2786
|
+
<path
|
|
2787
|
+
v-for="(link, i) in batchedEdgePaths.highlighted"
|
|
2788
|
+
:key="i"
|
|
2789
|
+
:d="linkD(link)"
|
|
2790
|
+
fill="none"
|
|
2791
|
+
:stroke="link.isRefEdge ? nodeColor(link.source) : link.isRowEdge ? 'var(--ui-primary)' : isPathEdge(link.target.id) || isHoverPathEdge(link.target.id) || isTracedEdge(link) ? 'var(--ui-primary)' : 'var(--ui-text-muted)'"
|
|
2792
|
+
:stroke-width="(link.isRefEdge ? link.isMutual ? 1.8 : hoveredSubtree.has(link.source.id) || hoveredSubtree.has(link.target.id) || tracedNodes.has(link.source.id) ? 1.8 : 1 : link.isRowEdge ? hoveredSubtree.has(link.source.id) || hoveredSubtree.has(link.target.id) || tracedNodes.has(link.source.id) ? 2 : 1 : isPathEdge(link.target.id) || isHoverPathEdge(link.target.id) || isTracedEdge(link) ? 2.8 : 2.2) * edgeScale"
|
|
2793
|
+
:stroke-dasharray="link.isRefEdge ? link.isMutual ? '6 3' : '2 4' : link.isRowEdge ? '4 3' : void 0"
|
|
2794
|
+
:marker-end="link.isRefEdge ? 'url(#ref-arrow)' : void 0"
|
|
2795
|
+
:marker-start="link.isRefEdge && link.isMutual ? 'url(#ref-arrow)' : void 0"
|
|
2796
|
+
:opacity="link.isRefEdge ? hoveredSubtree.has(link.source.id) || hoveredSubtree.has(link.target.id) || tracedNodes.has(link.source.id) || tracedNodes.has(link.target.id) ? 0.8 : hoveredNodeId || tracedNodeId ? 0.1 : 0.4 : link.isRowEdge ? hoveredSubtree.has(link.source.id) || hoveredSubtree.has(link.target.id) || tracedNodes.has(link.source.id) || tracedNodes.has(link.target.id) ? 0.8 : hoveredNodeId || tracedNodeId ? 0.1 : 0.35 : (hoveredNodeId || tracedNodeId) && !hoveredSubtree.has(link.target.id) && !isPathEdge(link.target.id) && !tracedNodes.has(link.target.id) ? 0.18 : nodeOpacity(link.target.id)"
|
|
2797
|
+
/>
|
|
2798
|
+
</g>
|
|
1361
2799
|
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
2800
|
+
<!-- Nodes layer (viewport-culled) -->
|
|
2801
|
+
<g
|
|
2802
|
+
v-for="node in visibleNodes"
|
|
2803
|
+
:key="node.id"
|
|
2804
|
+
:data-node="node.id"
|
|
2805
|
+
:transform="`translate(${node.x}, ${node.y})`"
|
|
2806
|
+
style="cursor: grab"
|
|
2807
|
+
:opacity="(hoveredNodeId || tracedNodeId) && !hoveredSubtree.has(node.id) && !selectedPath.has(node.id) && !tracedNodes.has(node.id) ? 0.25 : nodeOpacity(node.id)"
|
|
2808
|
+
@pointerdown.stop="onNodePointerDown($event, node.id)"
|
|
2809
|
+
@pointermove.stop="onNodePointerMove($event, node.id)"
|
|
2810
|
+
@pointerup.stop="onNodePointerUp($event, node.id)"
|
|
2811
|
+
@pointercancel.stop="onNodePointerCancel($event, node.id)"
|
|
2812
|
+
@pointerenter="hoveredNodeId = node.id"
|
|
2813
|
+
@pointerleave="hoveredNodeId = null"
|
|
2814
|
+
@click.stop="onNodeClick($event, node.id, node.label)"
|
|
2815
|
+
@dblclick.stop="onNodeDblClick($event, node.id, node.label)"
|
|
2816
|
+
>
|
|
2817
|
+
<!-- Remote selection halos -->
|
|
2818
|
+
<circle
|
|
2819
|
+
v-for="(sel, si) in remoteSelections.get(node.id) ?? []"
|
|
2820
|
+
:key="sel.color + si"
|
|
2821
|
+
:r="nodeRadius(node) + 9 + si * 5"
|
|
2822
|
+
fill="none"
|
|
2823
|
+
:stroke="sel.color"
|
|
2824
|
+
stroke-width="1.5"
|
|
2825
|
+
opacity="0.4"
|
|
2826
|
+
/>
|
|
1372
2827
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
2828
|
+
<!-- Drag-to-connect drop target ring -->
|
|
2829
|
+
<circle
|
|
2830
|
+
v-if="dropTargetId === node.id"
|
|
2831
|
+
:r="nodeRadius(node) + 8"
|
|
2832
|
+
fill="none"
|
|
2833
|
+
stroke="var(--ui-primary)"
|
|
2834
|
+
stroke-width="3"
|
|
2835
|
+
stroke-dasharray="6 4"
|
|
2836
|
+
opacity="0.9"
|
|
2837
|
+
/>
|
|
1380
2838
|
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
2839
|
+
<!-- Local selection glow -->
|
|
2840
|
+
<circle
|
|
2841
|
+
v-if="selectedNodeId === node.id"
|
|
2842
|
+
:r="nodeRadius(node) + 7"
|
|
2843
|
+
fill="none"
|
|
2844
|
+
stroke="var(--ui-primary)"
|
|
2845
|
+
stroke-width="2.5"
|
|
2846
|
+
filter="url(#glow)"
|
|
2847
|
+
opacity="0.9"
|
|
2848
|
+
/>
|
|
1391
2849
|
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
2850
|
+
<!-- Path-to-root highlight (ancestors of selected node) -->
|
|
2851
|
+
<circle
|
|
2852
|
+
v-else-if="selectedPath.has(node.id)"
|
|
2853
|
+
:r="nodeRadius(node) + 5"
|
|
2854
|
+
fill="none"
|
|
2855
|
+
stroke="var(--ui-primary)"
|
|
2856
|
+
stroke-width="1.5"
|
|
2857
|
+
opacity="0.5"
|
|
2858
|
+
/>
|
|
1400
2859
|
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
2860
|
+
<!-- Trace highlight ring (persistent connection tracing) -->
|
|
2861
|
+
<circle
|
|
2862
|
+
v-if="tracedNodes.has(node.id) && tracedNodeId !== node.id && selectedNodeId !== node.id"
|
|
2863
|
+
:r="nodeRadius(node) + 5"
|
|
2864
|
+
fill="none"
|
|
2865
|
+
stroke="var(--ui-primary)"
|
|
2866
|
+
stroke-width="1.5"
|
|
2867
|
+
stroke-dasharray="3 2"
|
|
2868
|
+
opacity="0.6"
|
|
2869
|
+
/>
|
|
2870
|
+
<!-- Trace origin ring (the traced node itself) -->
|
|
2871
|
+
<circle
|
|
2872
|
+
v-else-if="tracedNodeId === node.id"
|
|
2873
|
+
:r="nodeRadius(node) + 7"
|
|
2874
|
+
fill="none"
|
|
2875
|
+
stroke="var(--ui-primary)"
|
|
2876
|
+
stroke-width="2.5"
|
|
2877
|
+
opacity="0.85"
|
|
2878
|
+
/>
|
|
1413
2879
|
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
{{ node.label.length > 20 ? node.label.slice(0, 20) + "\u2026" : node.label }}
|
|
1425
|
-
</text>
|
|
2880
|
+
<!-- Remote drag ring (dashed) -->
|
|
2881
|
+
<circle
|
|
2882
|
+
v-if="remoteDragByNode.get(node.id)"
|
|
2883
|
+
:r="nodeRadius(node) + 3"
|
|
2884
|
+
fill="none"
|
|
2885
|
+
:stroke="remoteDragByNode.get(node.id).color"
|
|
2886
|
+
stroke-width="2"
|
|
2887
|
+
stroke-dasharray="5 3"
|
|
2888
|
+
opacity="0.8"
|
|
2889
|
+
/>
|
|
1426
2890
|
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
class="w-full bg-transparent text-center text-xs outline-none"
|
|
1437
|
-
style="color: var(--ui-text-highlighted)"
|
|
1438
|
-
:value="editValue"
|
|
1439
|
-
autofocus
|
|
1440
|
-
@input="editValue = $event.target.value"
|
|
1441
|
-
@blur="commitEdit"
|
|
1442
|
-
@keydown.enter="commitEdit"
|
|
1443
|
-
@keydown.escape="editId = null"
|
|
1444
|
-
@pointerdown.stop
|
|
1445
|
-
>
|
|
1446
|
-
</foreignObject>
|
|
1447
|
-
</g>
|
|
2891
|
+
<!-- Remote viewer ring (slideover/full open) — heavier than other halos -->
|
|
2892
|
+
<circle
|
|
2893
|
+
v-if="nodeViewers(node.id).length"
|
|
2894
|
+
:r="nodeRadius(node) + 4"
|
|
2895
|
+
fill="none"
|
|
2896
|
+
:stroke="nodeViewers(node.id)[0].color"
|
|
2897
|
+
stroke-width="4"
|
|
2898
|
+
opacity="0.95"
|
|
2899
|
+
/>
|
|
1448
2900
|
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
{{ c.state?.user?.name || "Anon" }}
|
|
1469
|
-
</text>
|
|
1470
|
-
</g>
|
|
1471
|
-
</g>
|
|
1472
|
-
</svg>
|
|
2901
|
+
<!-- Remote viewer dots (mini avatars) — stacked above the node -->
|
|
2902
|
+
<g
|
|
2903
|
+
v-if="nodeViewers(node.id).length"
|
|
2904
|
+
:transform="`translate(${-((Math.min(nodeViewers(node.id).length, 3) - 1) * 6)}, ${-(nodeRadius(node) + 12)})`"
|
|
2905
|
+
class="pointer-events-none"
|
|
2906
|
+
>
|
|
2907
|
+
<circle
|
|
2908
|
+
v-for="(u, i) in nodeViewers(node.id).slice(0, 3)"
|
|
2909
|
+
:key="`viewer-${i}`"
|
|
2910
|
+
:cx="i * 12"
|
|
2911
|
+
cy="0"
|
|
2912
|
+
r="5"
|
|
2913
|
+
:fill="u.color"
|
|
2914
|
+
stroke="var(--ui-bg)"
|
|
2915
|
+
stroke-width="1.5"
|
|
2916
|
+
>
|
|
2917
|
+
<title>{{ u.name }}</title>
|
|
2918
|
+
</circle>
|
|
2919
|
+
</g>
|
|
1473
2920
|
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
2921
|
+
<!-- Main circle -->
|
|
2922
|
+
<circle
|
|
2923
|
+
:r="nodeRadius(node)"
|
|
2924
|
+
:fill="nodeColor(node)"
|
|
2925
|
+
stroke="color-mix(in srgb, var(--ui-bg) 20%, var(--ui-border))"
|
|
2926
|
+
stroke-width="1"
|
|
2927
|
+
/>
|
|
1478
2928
|
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
:key="gi"
|
|
1489
|
-
>
|
|
1490
|
-
<div
|
|
1491
|
-
v-if="gi > 0"
|
|
1492
|
-
class="my-1 border-t border-(--ui-border)"
|
|
1493
|
-
/>
|
|
1494
|
-
<button
|
|
1495
|
-
v-for="item in group"
|
|
1496
|
-
:key="item.label"
|
|
1497
|
-
class="w-full flex items-center gap-2 px-3 py-1.5 hover:bg-(--ui-bg-elevated) text-left cursor-default"
|
|
1498
|
-
:class="item.color === 'error' ? 'text-(--ui-color-error-500)' : 'text-(--ui-text)'"
|
|
1499
|
-
@pointerdown.stop
|
|
1500
|
-
@click="item.onSelect();
|
|
1501
|
-
showCtx = false"
|
|
1502
|
-
>
|
|
1503
|
-
<UIcon
|
|
1504
|
-
:name="item.icon"
|
|
1505
|
-
class="size-3.5 shrink-0 opacity-70"
|
|
2929
|
+
<!-- Pinned indicator dot -->
|
|
2930
|
+
<circle
|
|
2931
|
+
v-if="pinnedSet.has(node.id)"
|
|
2932
|
+
:cx="nodeRadius(node) - 5"
|
|
2933
|
+
:cy="-(nodeRadius(node) - 5)"
|
|
2934
|
+
r="4"
|
|
2935
|
+
fill="var(--ui-bg-muted)"
|
|
2936
|
+
stroke="var(--ui-text-muted)"
|
|
2937
|
+
stroke-width="1"
|
|
1506
2938
|
/>
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
2939
|
+
|
|
2940
|
+
<!-- Collapsed-subtree badge: hidden-descendant count, click to expand -->
|
|
2941
|
+
<g
|
|
2942
|
+
v-if="collapsedNodeSet.has(node.id)"
|
|
2943
|
+
:transform="`translate(${nodeRadius(node) * 0.85}, ${nodeRadius(node) * 0.85})`"
|
|
2944
|
+
style="cursor: pointer"
|
|
2945
|
+
@pointerdown.stop
|
|
2946
|
+
@click.stop="toggleCollapse(node.id)"
|
|
2947
|
+
@dblclick.stop
|
|
2948
|
+
>
|
|
2949
|
+
<circle
|
|
2950
|
+
r="9"
|
|
2951
|
+
fill="var(--ui-primary)"
|
|
2952
|
+
stroke="var(--ui-bg)"
|
|
2953
|
+
stroke-width="1.5"
|
|
2954
|
+
/>
|
|
2955
|
+
<text
|
|
2956
|
+
text-anchor="middle"
|
|
2957
|
+
dominant-baseline="central"
|
|
2958
|
+
font-size="8"
|
|
2959
|
+
fill="var(--ui-bg)"
|
|
2960
|
+
style="pointer-events: none; user-select: none"
|
|
2961
|
+
>
|
|
2962
|
+
+{{ hiddenCountById.get(node.id) ?? 0 }}
|
|
2963
|
+
</text>
|
|
2964
|
+
</g>
|
|
2965
|
+
|
|
2966
|
+
<!-- Custom icon (native SVG — no foreignObject for Safari compat) -->
|
|
2967
|
+
<g
|
|
2968
|
+
v-if="node.icon && getIconSVG(node.icon)"
|
|
2969
|
+
:transform="`translate(${-nodeRadius(node) * 0.45}, ${-nodeRadius(node) * 0.45}) scale(${nodeRadius(node) * 0.9 / 24})`"
|
|
2970
|
+
opacity="0.9"
|
|
2971
|
+
style="pointer-events: none"
|
|
2972
|
+
v-html="getIconSVG(node.icon)"
|
|
2973
|
+
/>
|
|
2974
|
+
|
|
2975
|
+
<!-- Fallback: doc-type initial -->
|
|
2976
|
+
<text
|
|
2977
|
+
v-else-if="!node.icon"
|
|
2978
|
+
text-anchor="middle"
|
|
2979
|
+
dominant-baseline="central"
|
|
2980
|
+
:font-size="nodeRadius(node) * 0.5"
|
|
2981
|
+
fill="var(--ui-bg)"
|
|
2982
|
+
opacity="0.9"
|
|
2983
|
+
style="pointer-events: none; user-select: none"
|
|
2984
|
+
>
|
|
2985
|
+
{{ docTypeInitial(node.type) }}
|
|
2986
|
+
</text>
|
|
2987
|
+
|
|
2988
|
+
<!-- Node label below -->
|
|
2989
|
+
<text
|
|
2990
|
+
v-if="editId !== node.id && (labelShown(node.id) || hoveredSubtree.has(node.id) || tracedNodes.has(node.id))"
|
|
2991
|
+
:y="nodeRadius(node) + 14 * labelScale * labelSizeMult"
|
|
2992
|
+
text-anchor="middle"
|
|
2993
|
+
:font-size="11 * labelScale * labelSizeMult"
|
|
2994
|
+
:opacity="hoveredSubtree.has(node.id) || tracedNodes.has(node.id) ? 1 : labelOpacity"
|
|
2995
|
+
fill="var(--ui-text)"
|
|
2996
|
+
style="pointer-events: none; user-select: none"
|
|
2997
|
+
>
|
|
2998
|
+
{{ node.displayLabel }}
|
|
2999
|
+
</text>
|
|
3000
|
+
|
|
3001
|
+
<!-- Inline rename input -->
|
|
3002
|
+
<foreignObject
|
|
3003
|
+
v-if="editId === node.id"
|
|
3004
|
+
:x="-(nodeRadius(node) + 28)"
|
|
3005
|
+
:y="nodeRadius(node) + 4"
|
|
3006
|
+
:width="(nodeRadius(node) + 28) * 2"
|
|
3007
|
+
height="20"
|
|
3008
|
+
>
|
|
3009
|
+
<input
|
|
3010
|
+
:ref="focusRenameInput"
|
|
3011
|
+
class="w-full bg-transparent text-center text-xs outline-none"
|
|
3012
|
+
style="color: var(--ui-text-highlighted)"
|
|
3013
|
+
:value="editValue"
|
|
3014
|
+
@input="editValue = $event.target.value"
|
|
3015
|
+
@blur="commitEdit"
|
|
3016
|
+
@keydown.enter="commitEdit"
|
|
3017
|
+
@keydown.escape="editId = null"
|
|
3018
|
+
@pointerdown.stop
|
|
3019
|
+
>
|
|
3020
|
+
</foreignObject>
|
|
3021
|
+
</g>
|
|
3022
|
+
|
|
3023
|
+
<!-- Cursors layer (positions synced via awareness) -->
|
|
3024
|
+
<g style="pointer-events: none">
|
|
3025
|
+
<g
|
|
3026
|
+
v-for="c in cursors"
|
|
3027
|
+
:key="c.clientId"
|
|
3028
|
+
:transform="`translate(${c.x}, ${c.y})`"
|
|
3029
|
+
>
|
|
3030
|
+
<circle
|
|
3031
|
+
r="5"
|
|
3032
|
+
:fill="c.state?.user?.color || 'var(--ui-color-neutral-400)'"
|
|
3033
|
+
opacity="0.85"
|
|
3034
|
+
/>
|
|
3035
|
+
<text
|
|
3036
|
+
x="8"
|
|
3037
|
+
y="4"
|
|
3038
|
+
:font-size="10 * labelScale"
|
|
3039
|
+
:fill="c.state?.user?.color || 'var(--ui-color-neutral-400)'"
|
|
3040
|
+
style="user-select: none"
|
|
3041
|
+
>
|
|
3042
|
+
{{ c.state?.user?.name || "Anon" }}
|
|
3043
|
+
</text>
|
|
3044
|
+
</g>
|
|
3045
|
+
</g>
|
|
3046
|
+
</svg>
|
|
3047
|
+
</UContextMenu>
|
|
3048
|
+
</template>
|
|
1512
3049
|
</template>
|
|
1513
3050
|
|
|
1514
3051
|
<!-- Node panel -->
|
|
@@ -1522,5 +3059,5 @@ defineExpose({ connectedUsers });
|
|
|
1522
3059
|
</template>
|
|
1523
3060
|
|
|
1524
3061
|
<style scoped>
|
|
1525
|
-
.graph-toolbar-bar{align-items:center;backdrop-filter:blur(8px);background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:10px;bottom:2rem;display:flex;gap:3px;left:50%;padding:3px;position:absolute;transform:translateX(-50%);z-index:20}.toolbar-group{align-items:center;display:flex;gap:1px}.toolbar-divider{background:hsla(0,0%,100%,.15);flex-shrink:0;height:20px;margin:0 2px;width:1px}
|
|
3062
|
+
.graph-toolbar-bar{align-items:center;backdrop-filter:blur(8px);background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:10px;bottom:2rem;display:flex;flex-wrap:wrap;gap:3px;justify-content:center;left:50%;max-width:calc(100% - 1rem);padding:3px;position:absolute;transform:translateX(-50%);z-index:20}.toolbar-group{align-items:center;display:flex;gap:1px}.toolbar-divider{background:hsla(0,0%,100%,.15);flex-shrink:0;height:20px;margin:0 2px;width:1px}.graph-minimap{background:color-mix(in srgb,var(--ui-bg) 85%,transparent);border:1px solid var(--ui-border);border-radius:8px;bottom:.75rem;cursor:crosshair;height:120px;position:absolute;right:.75rem;touch-action:none;width:176px;z-index:20}
|
|
1526
3063
|
</style>
|