@abraca/nuxt 2.35.1 → 2.37.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/aware/AMedia.d.vue.ts +1 -1
- package/dist/runtime/components/aware/AMedia.vue.d.ts +1 -1
- 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/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/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/package.json +1 -1
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { ref, computed, onMounted } from "vue";
|
|
2
|
+
import { toLocalDateStr } from "../utils/localDate.js";
|
|
3
|
+
import { isDateOnly } from "../utils/dateField.js";
|
|
2
4
|
const ALL_WEEK_DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
3
5
|
const HOURS_START = 0;
|
|
4
6
|
const HOURS_END = 24;
|
|
5
7
|
function toDateStr(d) {
|
|
6
|
-
return d
|
|
8
|
+
return toLocalDateStr(d);
|
|
9
|
+
}
|
|
10
|
+
function eventDayStr(iso, allDay) {
|
|
11
|
+
if (allDay) return iso.slice(0, 10);
|
|
12
|
+
return toLocalDateStr(new Date(iso));
|
|
7
13
|
}
|
|
8
14
|
function isoWeekNumber(d) {
|
|
9
15
|
const date = new Date(d.getTime());
|
|
@@ -95,16 +101,22 @@ export function useCalendarView(options) {
|
|
|
95
101
|
currentDate.value = new Date(y, m, 1);
|
|
96
102
|
}
|
|
97
103
|
function entryToEvent(entry) {
|
|
98
|
-
const start = entry.meta?.datetimeStart;
|
|
104
|
+
const start = entry.meta?.datetimeStart ?? entry.meta?.dateStart;
|
|
99
105
|
if (!start) return null;
|
|
106
|
+
const end = entry.meta?.datetimeEnd ?? entry.meta?.dateEnd;
|
|
100
107
|
return {
|
|
101
108
|
id: entry.id,
|
|
102
109
|
label: entry.label,
|
|
103
110
|
color: entry.meta?.color ?? "#6366f1",
|
|
104
111
|
icon: entry.meta?.icon,
|
|
105
112
|
datetimeStart: start,
|
|
106
|
-
datetimeEnd:
|
|
107
|
-
|
|
113
|
+
datetimeEnd: end ?? start,
|
|
114
|
+
// A bare `YYYY-MM-DD` (Timeline-authored, daterange family) is inherently
|
|
115
|
+
// all-day — force it true even if a stale `allDay:false` is present, else
|
|
116
|
+
// eventDayStr would run timezone math on a date-only string and bucket it
|
|
117
|
+
// a calendar day early in negative-offset zones. Otherwise the explicit
|
|
118
|
+
// flag wins (real timed/all-day Calendar events are unaffected).
|
|
119
|
+
allDay: isDateOnly(start) ? true : entry.meta?.allDay != null ? !!entry.meta.allDay : false,
|
|
108
120
|
entry
|
|
109
121
|
};
|
|
110
122
|
}
|
|
@@ -117,7 +129,7 @@ export function useCalendarView(options) {
|
|
|
117
129
|
return result;
|
|
118
130
|
});
|
|
119
131
|
const unscheduledEntries = computed(
|
|
120
|
-
() => tree.childrenOf(null).filter((e) => !e.meta?.datetimeStart)
|
|
132
|
+
() => tree.childrenOf(null).filter((e) => !(e.meta?.datetimeStart ?? e.meta?.dateStart))
|
|
121
133
|
);
|
|
122
134
|
const weeks = computed(() => {
|
|
123
135
|
const y = year.value;
|
|
@@ -149,8 +161,8 @@ export function useCalendarView(options) {
|
|
|
149
161
|
const multiDay = [];
|
|
150
162
|
const singleDay = [];
|
|
151
163
|
for (const evt of entries) {
|
|
152
|
-
const start = evt.datetimeStart
|
|
153
|
-
const end = evt.datetimeEnd
|
|
164
|
+
const start = eventDayStr(evt.datetimeStart, evt.allDay);
|
|
165
|
+
const end = eventDayStr(evt.datetimeEnd, evt.allDay);
|
|
154
166
|
const isMulti = start !== end;
|
|
155
167
|
let startCol = -1;
|
|
156
168
|
let endCol = -1;
|
|
@@ -164,7 +176,7 @@ export function useCalendarView(options) {
|
|
|
164
176
|
}
|
|
165
177
|
if (startCol === -1 || seenIds.has(evt.id)) continue;
|
|
166
178
|
seenIds.add(evt.id);
|
|
167
|
-
if (isMulti
|
|
179
|
+
if (isMulti) {
|
|
168
180
|
multiDay.push({
|
|
169
181
|
id: evt.id,
|
|
170
182
|
label: evt.label,
|
|
@@ -240,12 +252,23 @@ export function useCalendarView(options) {
|
|
|
240
252
|
const loc = typeof navigator !== "undefined" ? navigator.language : "en-US";
|
|
241
253
|
const isToday = dateStr === todayStr.value;
|
|
242
254
|
const dayEvents = allEvents.value.filter((evt) => {
|
|
243
|
-
const evtStart = evt.datetimeStart
|
|
244
|
-
const evtEnd = evt.datetimeEnd
|
|
255
|
+
const evtStart = eventDayStr(evt.datetimeStart, evt.allDay);
|
|
256
|
+
const evtEnd = eventDayStr(evt.datetimeEnd, evt.allDay);
|
|
245
257
|
return dateStr >= evtStart && dateStr <= evtEnd;
|
|
246
258
|
});
|
|
247
259
|
const allDayEvents = dayEvents.filter((e) => e.allDay);
|
|
248
|
-
const
|
|
260
|
+
const dayStart = (/* @__PURE__ */ new Date(`${dateStr}T00:00:00`)).getTime();
|
|
261
|
+
const dayEnd = (/* @__PURE__ */ new Date(`${dateStr}T23:59:59`)).getTime();
|
|
262
|
+
const timedEvents = dayEvents.filter((e) => !e.allDay).map((evt) => {
|
|
263
|
+
const evtStart = new Date(evt.datetimeStart).getTime();
|
|
264
|
+
const evtEnd = new Date(evt.datetimeEnd).getTime();
|
|
265
|
+
if (evtStart >= dayStart && evtEnd <= dayEnd) return evt;
|
|
266
|
+
return {
|
|
267
|
+
...evt,
|
|
268
|
+
datetimeStart: evtStart < dayStart ? new Date(dayStart).toISOString() : evt.datetimeStart,
|
|
269
|
+
datetimeEnd: evtEnd > dayEnd ? new Date(dayEnd).toISOString() : evt.datetimeEnd
|
|
270
|
+
};
|
|
271
|
+
});
|
|
249
272
|
const hourSlots = [];
|
|
250
273
|
for (let h = HOURS_START; h < HOURS_END; h++) {
|
|
251
274
|
const eventsInHour = timedEvents.filter((evt) => {
|
|
@@ -16,6 +16,6 @@ type ConnectionStatusValue = 'disconnected' | 'connecting' | 'connected' | 'offl
|
|
|
16
16
|
export declare function useConnectionStatus(status?: MaybeRef<ConnectionStatusValue | string | undefined>, synced?: MaybeRef<boolean | undefined>): {
|
|
17
17
|
label: import("vue").ComputedRef<string>;
|
|
18
18
|
color: import("vue").ComputedRef<"error" | "success" | "warning">;
|
|
19
|
-
icon: import("vue").ComputedRef<"i-lucide-cloud-
|
|
19
|
+
icon: import("vue").ComputedRef<"i-lucide-cloud-off" | "i-lucide-cloud-check" | "i-lucide-cloud">;
|
|
20
20
|
};
|
|
21
21
|
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useGraphReferenceEdges
|
|
3
|
+
*
|
|
4
|
+
* Graph-specific reference-edge scanner. Lazily loads child docs, scans their
|
|
5
|
+
* content (doc-links + doc-embeds) for outbound references, and returns a
|
|
6
|
+
* reactive edge list. Visible docs load eagerly; the rest fill in via a
|
|
7
|
+
* low-priority idle background sweep so off-screen ref edges still resolve
|
|
8
|
+
* without loading every doc upfront.
|
|
9
|
+
*
|
|
10
|
+
* This is a graph-tuned variant of the shared `utils/docReferenceEdges.ts` —
|
|
11
|
+
* it adds the `visibleEntries` eager set, the idle sweep, transient
|
|
12
|
+
* (non-evictable) loads so a large graph doesn't evict early-scanned docs
|
|
13
|
+
* before their sync delta arrives, and a coalesced version signal so a cold
|
|
14
|
+
* load doesn't pay an O(D) Map rebuild per scanned doc.
|
|
15
|
+
*
|
|
16
|
+
* Mirrors cou-sh/app/utils/docReferenceEdges.ts (the composable half).
|
|
17
|
+
*/
|
|
18
|
+
import { type ShallowRef, type ComputedRef } from 'vue';
|
|
19
|
+
export declare function useGraphReferenceEdges(childProviderRef: ShallowRef<any>, allEntries: ComputedRef<Array<{
|
|
20
|
+
id: string;
|
|
21
|
+
}>>, visibleEntries?: ComputedRef<Array<{
|
|
22
|
+
id: string;
|
|
23
|
+
}>>): ComputedRef<{
|
|
24
|
+
source: string;
|
|
25
|
+
target: string;
|
|
26
|
+
}[]>;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { computed, watch, onUnmounted, shallowRef } from "vue";
|
|
2
|
+
import { scanDocReferences } from "../utils/docReferenceEdges.js";
|
|
3
|
+
export function useGraphReferenceEdges(childProviderRef, allEntries, visibleEntries) {
|
|
4
|
+
const refMapData = /* @__PURE__ */ new Map();
|
|
5
|
+
const refMapVersion = shallowRef(0);
|
|
6
|
+
let bumpScheduled = false;
|
|
7
|
+
function bumpRefMap() {
|
|
8
|
+
if (bumpScheduled) return;
|
|
9
|
+
bumpScheduled = true;
|
|
10
|
+
queueMicrotask(() => {
|
|
11
|
+
bumpScheduled = false;
|
|
12
|
+
refMapVersion.value++;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
const observers = /* @__PURE__ */ new Map();
|
|
16
|
+
const loaded = /* @__PURE__ */ new Set();
|
|
17
|
+
const debounceTimers = /* @__PURE__ */ new Map();
|
|
18
|
+
let destroyed = false;
|
|
19
|
+
function scanAndStore(docId, fragment) {
|
|
20
|
+
const refs = scanDocReferences(fragment);
|
|
21
|
+
const prev = refMapData.get(docId);
|
|
22
|
+
if (!prev || prev.length !== refs.length || prev.some((r, i) => r !== refs[i])) {
|
|
23
|
+
refMapData.set(docId, refs);
|
|
24
|
+
bumpRefMap();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function observeFragment(docId, fragment) {
|
|
28
|
+
const handler = () => {
|
|
29
|
+
const existing = debounceTimers.get(docId);
|
|
30
|
+
if (existing) clearTimeout(existing);
|
|
31
|
+
debounceTimers.set(docId, setTimeout(() => {
|
|
32
|
+
debounceTimers.delete(docId);
|
|
33
|
+
if (!destroyed) scanAndStore(docId, fragment);
|
|
34
|
+
}, 500));
|
|
35
|
+
};
|
|
36
|
+
fragment.observeDeep(handler);
|
|
37
|
+
observers.set(docId, () => fragment.unobserveDeep(handler));
|
|
38
|
+
}
|
|
39
|
+
async function loadBatch(ids, opts = {}) {
|
|
40
|
+
const provider = childProviderRef.value;
|
|
41
|
+
if (!provider) return;
|
|
42
|
+
const batchSize = opts.batchSize ?? 5;
|
|
43
|
+
const gapMs = opts.gapMs ?? 0;
|
|
44
|
+
for (let i = 0; i < ids.length; i += batchSize) {
|
|
45
|
+
if (destroyed) return;
|
|
46
|
+
const batch = ids.slice(i, i + batchSize);
|
|
47
|
+
await Promise.all(batch.map(async (id) => {
|
|
48
|
+
if (loaded.has(id) || destroyed) return;
|
|
49
|
+
loaded.add(id);
|
|
50
|
+
try {
|
|
51
|
+
const childProv = await provider.loadChild(id, { evictable: false });
|
|
52
|
+
if (destroyed) return;
|
|
53
|
+
const doc = childProv.document;
|
|
54
|
+
const fragment = doc.getXmlFragment("default");
|
|
55
|
+
scanAndStore(id, fragment);
|
|
56
|
+
observeFragment(id, fragment);
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
if (i + batchSize < ids.length) {
|
|
61
|
+
await new Promise((r) => setTimeout(r, gapMs));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
let sweepHandle = null;
|
|
66
|
+
function cancelSweep() {
|
|
67
|
+
if (sweepHandle == null) return;
|
|
68
|
+
const cic = globalThis.cancelIdleCallback;
|
|
69
|
+
if (cic) cic(sweepHandle);
|
|
70
|
+
else clearTimeout(sweepHandle);
|
|
71
|
+
sweepHandle = null;
|
|
72
|
+
}
|
|
73
|
+
function scheduleBackgroundSweep() {
|
|
74
|
+
if (sweepHandle != null || destroyed) return;
|
|
75
|
+
const run = () => {
|
|
76
|
+
sweepHandle = null;
|
|
77
|
+
if (destroyed) return;
|
|
78
|
+
const rest = allEntries.value.map((e) => e.id).filter((id) => !loaded.has(id));
|
|
79
|
+
if (rest.length > 0) loadBatch(rest, { batchSize: 3, gapMs: 150 });
|
|
80
|
+
};
|
|
81
|
+
const ric = globalThis.requestIdleCallback;
|
|
82
|
+
sweepHandle = ric ? ric(run, { timeout: 5e3 }) : setTimeout(run, 1500);
|
|
83
|
+
}
|
|
84
|
+
watch(allEntries, (entries) => {
|
|
85
|
+
const entryIds = new Set(entries.map((e) => e.id));
|
|
86
|
+
for (const [id, cleanup] of observers) {
|
|
87
|
+
if (!entryIds.has(id)) {
|
|
88
|
+
cleanup();
|
|
89
|
+
observers.delete(id);
|
|
90
|
+
loaded.delete(id);
|
|
91
|
+
const timer = debounceTimers.get(id);
|
|
92
|
+
if (timer) {
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
debounceTimers.delete(id);
|
|
95
|
+
}
|
|
96
|
+
if (refMapData.has(id)) {
|
|
97
|
+
refMapData.delete(id);
|
|
98
|
+
bumpRefMap();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!visibleEntries) {
|
|
103
|
+
const toLoad = entries.map((e) => e.id).filter((id) => !loaded.has(id));
|
|
104
|
+
if (toLoad.length > 0) loadBatch(toLoad);
|
|
105
|
+
} else {
|
|
106
|
+
scheduleBackgroundSweep();
|
|
107
|
+
}
|
|
108
|
+
}, { immediate: true });
|
|
109
|
+
if (visibleEntries) {
|
|
110
|
+
watch(visibleEntries, (visible) => {
|
|
111
|
+
const toLoad = visible.map((e) => e.id).filter((id) => !loaded.has(id));
|
|
112
|
+
if (toLoad.length > 0) loadBatch(toLoad);
|
|
113
|
+
}, { immediate: true });
|
|
114
|
+
}
|
|
115
|
+
onUnmounted(() => {
|
|
116
|
+
destroyed = true;
|
|
117
|
+
cancelSweep();
|
|
118
|
+
for (const cleanup of observers.values()) cleanup();
|
|
119
|
+
observers.clear();
|
|
120
|
+
for (const timer of debounceTimers.values()) clearTimeout(timer);
|
|
121
|
+
debounceTimers.clear();
|
|
122
|
+
});
|
|
123
|
+
const edges = computed(() => {
|
|
124
|
+
void refMapVersion.value;
|
|
125
|
+
const entryIds = new Set(allEntries.value.map((e) => e.id));
|
|
126
|
+
const result = [];
|
|
127
|
+
for (const [sourceId, targetIds] of refMapData) {
|
|
128
|
+
if (!entryIds.has(sourceId)) continue;
|
|
129
|
+
for (const targetId of targetIds) {
|
|
130
|
+
if (entryIds.has(targetId) && targetId !== sourceId) {
|
|
131
|
+
result.push({ source: sourceId, target: targetId });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
});
|
|
137
|
+
return edges;
|
|
138
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useGraphSim
|
|
3
|
+
*
|
|
4
|
+
* Owns the d3-force simulation for `AGraphRenderer.vue`. Exposes a small
|
|
5
|
+
* imperative API (`init` / `patch` / `setSpacing` / `setFixed` /
|
|
6
|
+
* `setFixedMany` / `restart` / `stop` / `destroy`) plus reactive `renderTick`,
|
|
7
|
+
* `isSettled`, `alpha`, and `resolvedEdges`.
|
|
8
|
+
*
|
|
9
|
+
* ── Main-thread, not a Web Worker ──────────────────────────────────────────
|
|
10
|
+
* cou-sh runs this in a dedicated `graphSim.worker.ts` via
|
|
11
|
+
* `new Worker(new URL('../workers/graphSim.worker.ts', import.meta.url))`.
|
|
12
|
+
* That pattern does NOT survive the module's build pipeline
|
|
13
|
+
* (`nuxt-module-build` / unbuild) nor Vite-dev's native-ESM serving — the same
|
|
14
|
+
* caveat AMapRenderer / ALocationPickerPopover already document for mapbox's
|
|
15
|
+
* worker. So this port keeps the EXACT same API surface but ticks d3-force on
|
|
16
|
+
* the main thread via requestAnimationFrame. Position frames patch the bound
|
|
17
|
+
* node objects in place and bump `renderTick`, identical to the worker's
|
|
18
|
+
* position-frame contract; `resolvedEdges` is the live link list.
|
|
19
|
+
*
|
|
20
|
+
* d3-force is an OPTIONAL peer dep, so this composable never imports it
|
|
21
|
+
* statically. The renderer dynamic-imports d3-force and hands the module to
|
|
22
|
+
* `bindD3()`; until then the sim is inert (no-ops), and the renderer shows its
|
|
23
|
+
* install-fallback. Mirrors cou-sh's worker API so the renderer body reads the
|
|
24
|
+
* same on both sides.
|
|
25
|
+
*/
|
|
26
|
+
export interface GraphSimNode {
|
|
27
|
+
id: string;
|
|
28
|
+
neighborCount: number;
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
vx: number;
|
|
32
|
+
vy: number;
|
|
33
|
+
fx: number | null;
|
|
34
|
+
fy: number | null;
|
|
35
|
+
index?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface GraphSimEdge {
|
|
38
|
+
source: string;
|
|
39
|
+
target: string;
|
|
40
|
+
kind: 'tree' | 'row' | 'ref';
|
|
41
|
+
isMutual?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface GraphSpacingPreset {
|
|
44
|
+
charge: number;
|
|
45
|
+
linkDist: number;
|
|
46
|
+
centerStrength: number;
|
|
47
|
+
collideExtra: number;
|
|
48
|
+
}
|
|
49
|
+
type D3ForceModule = any;
|
|
50
|
+
export declare function useGraphSim(): {
|
|
51
|
+
renderTick: import("vue").Ref<number, number>;
|
|
52
|
+
isSettled: import("vue").Ref<boolean, boolean>;
|
|
53
|
+
alpha: import("vue").Ref<number, number>;
|
|
54
|
+
resolvedEdges: import("vue").ShallowRef<GraphSimEdge[], GraphSimEdge[]>;
|
|
55
|
+
bindD3: (mod: D3ForceModule) => void;
|
|
56
|
+
init: (opts: {
|
|
57
|
+
nodes: GraphSimNode[];
|
|
58
|
+
edges: GraphSimEdge[];
|
|
59
|
+
spacing: GraphSpacingPreset;
|
|
60
|
+
presettle: boolean;
|
|
61
|
+
}) => void;
|
|
62
|
+
patch: (opts: {
|
|
63
|
+
nodes: GraphSimNode[];
|
|
64
|
+
edges: GraphSimEdge[];
|
|
65
|
+
alpha: number;
|
|
66
|
+
}) => void;
|
|
67
|
+
setSpacing: (spacing: GraphSpacingPreset, reheat?: number) => void;
|
|
68
|
+
setFixed: (id: string, x: number | null, y: number | null) => void;
|
|
69
|
+
setFixedMany: (entries: Array<{
|
|
70
|
+
id: string;
|
|
71
|
+
x: number | null;
|
|
72
|
+
y: number | null;
|
|
73
|
+
}>) => void;
|
|
74
|
+
restart: (alphaValue: number) => void;
|
|
75
|
+
stop: () => void;
|
|
76
|
+
destroy: () => void;
|
|
77
|
+
getMirrorNodes: () => GraphSimNode[];
|
|
78
|
+
};
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { ref, shallowRef } from "vue";
|
|
2
|
+
function nodeRadius(n) {
|
|
3
|
+
return Math.max(12, Math.min(36, 12 + n.neighborCount * 3.5));
|
|
4
|
+
}
|
|
5
|
+
export function useGraphSim() {
|
|
6
|
+
const renderTick = ref(0);
|
|
7
|
+
const isSettled = ref(false);
|
|
8
|
+
const alpha = ref(0);
|
|
9
|
+
const resolvedEdges = shallowRef([]);
|
|
10
|
+
let d3 = null;
|
|
11
|
+
let sim = null;
|
|
12
|
+
let currentSpacing = { charge: -350, linkDist: 180, centerStrength: 0.03, collideExtra: 15 };
|
|
13
|
+
let mirrorNodes = [];
|
|
14
|
+
const mirrorById = /* @__PURE__ */ new Map();
|
|
15
|
+
let rafHandle = null;
|
|
16
|
+
let tickFrame = 0;
|
|
17
|
+
const TICK_INTERVAL_MS = 16;
|
|
18
|
+
function bindD3(mod) {
|
|
19
|
+
d3 = mod;
|
|
20
|
+
}
|
|
21
|
+
function bindNodes(nodes) {
|
|
22
|
+
mirrorNodes = nodes;
|
|
23
|
+
mirrorById.clear();
|
|
24
|
+
for (const n of nodes) mirrorById.set(n.id, n);
|
|
25
|
+
}
|
|
26
|
+
function buildLinks(edges) {
|
|
27
|
+
return edges.map((e) => ({
|
|
28
|
+
source: e.source,
|
|
29
|
+
target: e.target,
|
|
30
|
+
kind: e.kind,
|
|
31
|
+
isMutual: e.isMutual
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
function rebuildSimulation(nodes, edges) {
|
|
35
|
+
if (!d3) return;
|
|
36
|
+
const { forceSimulation, forceManyBody, forceCollide, forceLink, forceX, forceY } = d3;
|
|
37
|
+
const sp = currentSpacing;
|
|
38
|
+
const links = buildLinks(edges);
|
|
39
|
+
sim = forceSimulation(nodes).force("charge", forceManyBody().strength(sp.charge)).force("x", forceX(0).strength(sp.centerStrength)).force("y", forceY(0).strength(sp.centerStrength)).force("link", forceLink(links).id((d) => d.id).distance((d) => d.kind === "ref" ? sp.linkDist * 2 : d.kind === "row" ? sp.linkDist * 1.5 : sp.linkDist).strength((d) => d.kind === "ref" ? 0.08 : d.kind === "row" ? 0.15 : 0.5)).force("collide", forceCollide().radius((n) => nodeRadius(n) + sp.collideExtra).strength(0.85)).alphaDecay(0.04).velocityDecay(0.4).stop();
|
|
40
|
+
}
|
|
41
|
+
function applySpacingToSim() {
|
|
42
|
+
if (!sim) return;
|
|
43
|
+
const sp = currentSpacing;
|
|
44
|
+
sim.force("charge")?.strength(sp.charge);
|
|
45
|
+
const linkF = sim.force("link");
|
|
46
|
+
if (linkF) {
|
|
47
|
+
linkF.distance((d) => d.kind === "ref" ? sp.linkDist * 2 : d.kind === "row" ? sp.linkDist * 1.5 : sp.linkDist).strength((d) => d.kind === "ref" ? 0.08 : d.kind === "row" ? 0.15 : 0.5);
|
|
48
|
+
}
|
|
49
|
+
sim.force("x")?.strength(sp.centerStrength);
|
|
50
|
+
sim.force("y")?.strength(sp.centerStrength);
|
|
51
|
+
sim.force("collide")?.radius((n) => nodeRadius(n) + sp.collideExtra);
|
|
52
|
+
}
|
|
53
|
+
function applyPositions() {
|
|
54
|
+
if (!sim) return;
|
|
55
|
+
for (const n of sim.nodes()) {
|
|
56
|
+
const node = mirrorById.get(n.id);
|
|
57
|
+
if (!node) continue;
|
|
58
|
+
node.x = n.x;
|
|
59
|
+
node.y = n.y;
|
|
60
|
+
node.vx = n.vx;
|
|
61
|
+
node.vy = n.vy;
|
|
62
|
+
}
|
|
63
|
+
alpha.value = sim.alpha();
|
|
64
|
+
renderTick.value++;
|
|
65
|
+
}
|
|
66
|
+
function publishEdges() {
|
|
67
|
+
if (!sim) return;
|
|
68
|
+
const linkF = sim.force("link");
|
|
69
|
+
if (!linkF) return;
|
|
70
|
+
const rawLinks = linkF.links();
|
|
71
|
+
resolvedEdges.value = rawLinks.map((l) => ({
|
|
72
|
+
source: l.source.id,
|
|
73
|
+
target: l.target.id,
|
|
74
|
+
kind: l.kind,
|
|
75
|
+
isMutual: l.isMutual
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
function renderEvery(a) {
|
|
79
|
+
if (a > 0.05) return 1;
|
|
80
|
+
if (a > 0.02) return 2;
|
|
81
|
+
if (a > 5e-3) return 4;
|
|
82
|
+
return 8;
|
|
83
|
+
}
|
|
84
|
+
function startTickLoop() {
|
|
85
|
+
if (rafHandle !== null || !sim) return;
|
|
86
|
+
let last = 0;
|
|
87
|
+
const loop = (t) => {
|
|
88
|
+
if (!sim) {
|
|
89
|
+
rafHandle = null;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (sim.alpha() < sim.alphaMin()) {
|
|
93
|
+
rafHandle = null;
|
|
94
|
+
applyPositions();
|
|
95
|
+
isSettled.value = true;
|
|
96
|
+
alpha.value = 0;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (t - last >= TICK_INTERVAL_MS) {
|
|
100
|
+
last = t;
|
|
101
|
+
sim.tick();
|
|
102
|
+
tickFrame++;
|
|
103
|
+
if (tickFrame % renderEvery(sim.alpha()) === 0) applyPositions();
|
|
104
|
+
}
|
|
105
|
+
rafHandle = requestAnimationFrame(loop);
|
|
106
|
+
};
|
|
107
|
+
rafHandle = requestAnimationFrame(loop);
|
|
108
|
+
}
|
|
109
|
+
function stopTickLoop() {
|
|
110
|
+
if (rafHandle !== null) {
|
|
111
|
+
cancelAnimationFrame(rafHandle);
|
|
112
|
+
rafHandle = null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function init(opts) {
|
|
116
|
+
if (!d3) return;
|
|
117
|
+
stopTickLoop();
|
|
118
|
+
bindNodes(opts.nodes);
|
|
119
|
+
isSettled.value = false;
|
|
120
|
+
currentSpacing = opts.spacing;
|
|
121
|
+
rebuildSimulation(opts.nodes, opts.edges);
|
|
122
|
+
if (!sim) return;
|
|
123
|
+
if (opts.presettle) {
|
|
124
|
+
sim.alpha(1);
|
|
125
|
+
const alphaMin = sim.alphaMin();
|
|
126
|
+
const decay = sim.alphaDecay();
|
|
127
|
+
const ticks = Math.ceil(Math.log(alphaMin) / Math.log(1 - decay));
|
|
128
|
+
for (let i = 0; i < ticks; i++) sim.tick();
|
|
129
|
+
} else {
|
|
130
|
+
sim.alpha(0);
|
|
131
|
+
}
|
|
132
|
+
publishEdges();
|
|
133
|
+
applyPositions();
|
|
134
|
+
if (sim.alpha() >= sim.alphaMin()) {
|
|
135
|
+
startTickLoop();
|
|
136
|
+
} else {
|
|
137
|
+
isSettled.value = true;
|
|
138
|
+
alpha.value = 0;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function patch(opts) {
|
|
142
|
+
if (!d3) return;
|
|
143
|
+
bindNodes(opts.nodes);
|
|
144
|
+
if (!sim) {
|
|
145
|
+
rebuildSimulation(opts.nodes, opts.edges);
|
|
146
|
+
} else {
|
|
147
|
+
sim.nodes(opts.nodes);
|
|
148
|
+
const linkF = sim.force("link");
|
|
149
|
+
if (linkF) linkF.links(buildLinks(opts.edges));
|
|
150
|
+
}
|
|
151
|
+
if (!sim) return;
|
|
152
|
+
if (opts.alpha > 0) {
|
|
153
|
+
isSettled.value = false;
|
|
154
|
+
for (const n of sim.nodes()) {
|
|
155
|
+
n.vx = 0;
|
|
156
|
+
n.vy = 0;
|
|
157
|
+
}
|
|
158
|
+
sim.alpha(Math.max(sim.alpha(), opts.alpha));
|
|
159
|
+
}
|
|
160
|
+
publishEdges();
|
|
161
|
+
applyPositions();
|
|
162
|
+
if (sim.alpha() >= sim.alphaMin()) startTickLoop();
|
|
163
|
+
}
|
|
164
|
+
function setSpacing(spacing, reheat = 0) {
|
|
165
|
+
if (!sim) {
|
|
166
|
+
currentSpacing = spacing;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
currentSpacing = spacing;
|
|
170
|
+
applySpacingToSim();
|
|
171
|
+
if (reheat > 0) {
|
|
172
|
+
isSettled.value = false;
|
|
173
|
+
sim.alpha(Math.max(sim.alpha(), reheat));
|
|
174
|
+
startTickLoop();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function setFixed(id, x, y) {
|
|
178
|
+
const n = mirrorById.get(id);
|
|
179
|
+
if (n) {
|
|
180
|
+
n.fx = x;
|
|
181
|
+
n.fy = y;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function setFixedMany(entries) {
|
|
185
|
+
for (const entry of entries) {
|
|
186
|
+
const n = mirrorById.get(entry.id);
|
|
187
|
+
if (n) {
|
|
188
|
+
n.fx = entry.x;
|
|
189
|
+
n.fy = entry.y;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function restart(alphaValue) {
|
|
194
|
+
if (!sim) return;
|
|
195
|
+
isSettled.value = false;
|
|
196
|
+
for (const n of sim.nodes()) {
|
|
197
|
+
n.vx = 0;
|
|
198
|
+
n.vy = 0;
|
|
199
|
+
}
|
|
200
|
+
sim.alpha(Math.max(sim.alpha(), alphaValue));
|
|
201
|
+
startTickLoop();
|
|
202
|
+
}
|
|
203
|
+
function stop() {
|
|
204
|
+
stopTickLoop();
|
|
205
|
+
if (sim) sim.alpha(0);
|
|
206
|
+
}
|
|
207
|
+
function destroy() {
|
|
208
|
+
stopTickLoop();
|
|
209
|
+
if (sim) sim.stop();
|
|
210
|
+
sim = null;
|
|
211
|
+
mirrorNodes = [];
|
|
212
|
+
mirrorById.clear();
|
|
213
|
+
resolvedEdges.value = [];
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
renderTick,
|
|
217
|
+
isSettled,
|
|
218
|
+
alpha,
|
|
219
|
+
resolvedEdges,
|
|
220
|
+
bindD3,
|
|
221
|
+
init,
|
|
222
|
+
patch,
|
|
223
|
+
setSpacing,
|
|
224
|
+
setFixed,
|
|
225
|
+
setFixedMany,
|
|
226
|
+
restart,
|
|
227
|
+
stop,
|
|
228
|
+
destroy,
|
|
229
|
+
getMirrorNodes: () => mirrorNodes
|
|
230
|
+
};
|
|
231
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface FormulaCell {
|
|
2
|
+
key: string;
|
|
3
|
+
colIdx: number;
|
|
4
|
+
rowIdx: number;
|
|
5
|
+
formula: string;
|
|
6
|
+
}
|
|
7
|
+
/** A formula cell with its precedent cell keys resolved (ranges expanded). */
|
|
8
|
+
export interface ResolvedFormulaCell extends FormulaCell {
|
|
9
|
+
precedents: string[];
|
|
10
|
+
}
|
|
11
|
+
/** Expand a formula's referenced cells/ranges into individual `col:row` keys. */
|
|
12
|
+
export declare function precedentKeys(formula: string): string[];
|
|
13
|
+
/** Attach resolved precedent keys to each formula cell. */
|
|
14
|
+
export declare function resolvePrecedents(cells: FormulaCell[]): ResolvedFormulaCell[];
|
|
15
|
+
/**
|
|
16
|
+
* Decide the recompute order for a set of formula cells.
|
|
17
|
+
*
|
|
18
|
+
* @param cells all formula cells (with resolved precedents)
|
|
19
|
+
* @param dirtyKeys keys of cells whose value just changed; `null` = recompute
|
|
20
|
+
* everything (used for structural ops where we can't cheaply
|
|
21
|
+
* scope the change).
|
|
22
|
+
* @returns ordered list of formula-cell keys to recompute. Cells in a reference
|
|
23
|
+
* cycle are placed last (in arbitrary order) — the evaluator's own
|
|
24
|
+
* cycle guard turns those into `#REF!`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function computeRecalcOrder(cells: ResolvedFormulaCell[], dirtyKeys: Set<string> | null): string[];
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { extractCellRefs } from "./useSheetsFormulas.js";
|
|
2
|
+
export function precedentKeys(formula) {
|
|
3
|
+
const out = [];
|
|
4
|
+
for (const r of extractCellRefs(formula)) {
|
|
5
|
+
if ("range" in r) {
|
|
6
|
+
const minC = Math.min(r.startCol, r.endCol);
|
|
7
|
+
const maxC = Math.max(r.startCol, r.endCol);
|
|
8
|
+
const minR = Math.min(r.startRow, r.endRow);
|
|
9
|
+
const maxR = Math.max(r.startRow, r.endRow);
|
|
10
|
+
for (let c = minC; c <= maxC; c++) {
|
|
11
|
+
for (let row = minR; row <= maxR; row++) out.push(`${c}:${row}`);
|
|
12
|
+
}
|
|
13
|
+
} else {
|
|
14
|
+
out.push(`${r.colIdx}:${r.rowIdx}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
export function resolvePrecedents(cells) {
|
|
20
|
+
return cells.map((c) => ({ ...c, precedents: precedentKeys(c.formula) }));
|
|
21
|
+
}
|
|
22
|
+
export function computeRecalcOrder(cells, dirtyKeys) {
|
|
23
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
24
|
+
for (const c of cells) byKey.set(c.key, c);
|
|
25
|
+
const dependents = /* @__PURE__ */ new Map();
|
|
26
|
+
for (const c of cells) {
|
|
27
|
+
for (const p of c.precedents) {
|
|
28
|
+
const list = dependents.get(p);
|
|
29
|
+
if (list) list.push(c.key);
|
|
30
|
+
else dependents.set(p, [c.key]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
let affected;
|
|
34
|
+
if (dirtyKeys === null) {
|
|
35
|
+
affected = new Set(byKey.keys());
|
|
36
|
+
} else {
|
|
37
|
+
affected = /* @__PURE__ */ new Set();
|
|
38
|
+
const queue = [...dirtyKeys];
|
|
39
|
+
while (queue.length) {
|
|
40
|
+
const k = queue.shift();
|
|
41
|
+
for (const dep of dependents.get(k) ?? []) {
|
|
42
|
+
if (!affected.has(dep)) {
|
|
43
|
+
affected.add(dep);
|
|
44
|
+
queue.push(dep);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (affected.size === 0) return [];
|
|
50
|
+
const indegree = /* @__PURE__ */ new Map();
|
|
51
|
+
for (const k of affected) indegree.set(k, 0);
|
|
52
|
+
for (const k of affected) {
|
|
53
|
+
const cell = byKey.get(k);
|
|
54
|
+
for (const p of cell.precedents) {
|
|
55
|
+
if (affected.has(p)) indegree.set(k, (indegree.get(k) ?? 0) + 1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const ready = [];
|
|
59
|
+
for (const [k, d] of indegree) if (d === 0) ready.push(k);
|
|
60
|
+
const order = [];
|
|
61
|
+
const seen = /* @__PURE__ */ new Set();
|
|
62
|
+
while (ready.length) {
|
|
63
|
+
const k = ready.shift();
|
|
64
|
+
if (seen.has(k)) continue;
|
|
65
|
+
seen.add(k);
|
|
66
|
+
order.push(k);
|
|
67
|
+
for (const dep of dependents.get(k) ?? []) {
|
|
68
|
+
if (!affected.has(dep) || seen.has(dep)) continue;
|
|
69
|
+
const d = (indegree.get(dep) ?? 0) - 1;
|
|
70
|
+
indegree.set(dep, d);
|
|
71
|
+
if (d <= 0) ready.push(dep);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const k of affected) if (!seen.has(k)) order.push(k);
|
|
75
|
+
return order;
|
|
76
|
+
}
|