@lapis-notes/graph 0.1.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/CHANGELOG.md +6 -0
- package/LICENSE.md +8 -0
- package/README.md +20 -0
- package/dist/embed.d.ts +5 -0
- package/dist/embed.js +4 -0
- package/dist/graph-build-generation.d.ts +6 -0
- package/dist/graph-build-generation.js +13 -0
- package/dist/graph-controls-overlay.svelte +840 -0
- package/dist/graph-controls-overlay.svelte.d.ts +30 -0
- package/dist/graph-data-coordinator.d.ts +41 -0
- package/dist/graph-data-coordinator.js +265 -0
- package/dist/graph-data.d.ts +23 -0
- package/dist/graph-data.js +493 -0
- package/dist/graph-embed.svelte +92 -0
- package/dist/graph-embed.svelte.d.ts +12 -0
- package/dist/graph-file-preview.svelte +115 -0
- package/dist/graph-file-preview.svelte.d.ts +12 -0
- package/dist/graph-hover-intent.d.ts +22 -0
- package/dist/graph-hover-intent.js +85 -0
- package/dist/graph-load-alignment.d.ts +2 -0
- package/dist/graph-load-alignment.js +3 -0
- package/dist/graph-navigation.d.ts +7 -0
- package/dist/graph-navigation.js +78 -0
- package/dist/graph-node-activation.d.ts +4 -0
- package/dist/graph-node-activation.js +16 -0
- package/dist/graph-plugin.d.ts +38 -0
- package/dist/graph-plugin.js +177 -0
- package/dist/graph-problems.d.ts +15 -0
- package/dist/graph-problems.js +46 -0
- package/dist/graph-query-resolution.d.ts +9 -0
- package/dist/graph-query-resolution.js +44 -0
- package/dist/graph-renderer.d.ts +226 -0
- package/dist/graph-renderer.js +1350 -0
- package/dist/graph-settings.d.ts +20 -0
- package/dist/graph-settings.js +125 -0
- package/dist/graph-types.d.ts +74 -0
- package/dist/graph-types.js +1 -0
- package/dist/graph-view.d.ts +62 -0
- package/dist/graph-view.js +553 -0
- package/dist/graph-viewport-alignment.d.ts +6 -0
- package/dist/graph-viewport-alignment.js +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8 -0
- package/dist/mount-local-component.svelte.d.ts +7 -0
- package/dist/mount-local-component.svelte.js +12 -0
- package/dist/public-components.d.ts +2 -0
- package/dist/public-components.js +2 -0
- package/dist/styles.css +441 -0
- package/manifest.json +30 -0
- package/package.json +84 -0
- package/styles.css +1 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GraphGroupRule, GraphSettings, GraphSettingsPatch } from "./graph-types";
|
|
2
|
+
export declare const DEFAULT_GRAPH_GROUPS: GraphGroupRule[];
|
|
3
|
+
export declare const GRAPH_SETTINGS_VERSION = 2;
|
|
4
|
+
export declare function graphForceSliderToStrength(value: number): number;
|
|
5
|
+
export declare function graphStrengthToForceSlider(value: number): number;
|
|
6
|
+
export declare function graphRepelForceMagnitude(value: number): number;
|
|
7
|
+
export declare const DEFAULT_GRAPH_CENTER_FORCE: number;
|
|
8
|
+
export declare const DEFAULT_GRAPH_SETTINGS: GraphSettings;
|
|
9
|
+
export type PersistedGraphSettings = GraphSettings & {
|
|
10
|
+
settingsVersion: number;
|
|
11
|
+
};
|
|
12
|
+
export type LoadedGraphSettings = {
|
|
13
|
+
settings: GraphSettings;
|
|
14
|
+
migrated: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function loadPersistedGraphSettings(stored: unknown): LoadedGraphSettings;
|
|
17
|
+
export declare function serializeGraphSettings(settings: GraphSettings): PersistedGraphSettings;
|
|
18
|
+
export declare function mergeGraphSettings(stored: Partial<GraphSettings> | null | undefined): GraphSettings;
|
|
19
|
+
export declare function patchGraphSettings(current: GraphSettings, patch: GraphSettingsPatch): GraphSettings;
|
|
20
|
+
export declare function moveGraphGroup(groups: GraphGroupRule[], index: number, delta: number): GraphGroupRule[];
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export const DEFAULT_GRAPH_GROUPS = [];
|
|
2
|
+
export const GRAPH_SETTINGS_VERSION = 2;
|
|
3
|
+
const GRAPH_FORCE_CURVE_BASE = 0.01;
|
|
4
|
+
export function graphForceSliderToStrength(value) {
|
|
5
|
+
const slider = Math.min(Math.max(Number.isFinite(value) ? value : 0, 0), 1);
|
|
6
|
+
return ((Math.pow(GRAPH_FORCE_CURVE_BASE, 1 - slider) - GRAPH_FORCE_CURVE_BASE) /
|
|
7
|
+
(1 - GRAPH_FORCE_CURVE_BASE));
|
|
8
|
+
}
|
|
9
|
+
export function graphStrengthToForceSlider(value) {
|
|
10
|
+
const strength = Math.min(Math.max(Number.isFinite(value) ? value : 0, 0), 1);
|
|
11
|
+
const curved = strength * (1 - GRAPH_FORCE_CURVE_BASE) + GRAPH_FORCE_CURVE_BASE;
|
|
12
|
+
return 1 - Math.log(curved) / Math.log(GRAPH_FORCE_CURVE_BASE);
|
|
13
|
+
}
|
|
14
|
+
export function graphRepelForceMagnitude(value) {
|
|
15
|
+
const slider = Math.min(Math.max(Number.isFinite(value) ? value : 0, 0), 20);
|
|
16
|
+
return Math.max(slider ** 3, 1);
|
|
17
|
+
}
|
|
18
|
+
export const DEFAULT_GRAPH_CENTER_FORCE = graphStrengthToForceSlider(0.1);
|
|
19
|
+
export const DEFAULT_GRAPH_SETTINGS = {
|
|
20
|
+
filters: {
|
|
21
|
+
searchQuery: "",
|
|
22
|
+
showTags: false,
|
|
23
|
+
showAttachments: false,
|
|
24
|
+
existingFilesOnly: true,
|
|
25
|
+
showOrphans: true,
|
|
26
|
+
},
|
|
27
|
+
display: {
|
|
28
|
+
showArrows: false,
|
|
29
|
+
textFadeThreshold: 0.8,
|
|
30
|
+
nodeSize: 8,
|
|
31
|
+
linkThickness: 1,
|
|
32
|
+
wheelZoomSensitivity: 1,
|
|
33
|
+
hoverActivationDelayMs: 500,
|
|
34
|
+
hoverReleaseDelayMs: 350,
|
|
35
|
+
},
|
|
36
|
+
forces: {
|
|
37
|
+
centerForce: DEFAULT_GRAPH_CENTER_FORCE,
|
|
38
|
+
repelForce: 10,
|
|
39
|
+
linkForce: 1,
|
|
40
|
+
linkDistance: 250,
|
|
41
|
+
},
|
|
42
|
+
localGraph: {
|
|
43
|
+
depth: 1,
|
|
44
|
+
},
|
|
45
|
+
groups: DEFAULT_GRAPH_GROUPS,
|
|
46
|
+
};
|
|
47
|
+
function isRecord(value) {
|
|
48
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
49
|
+
}
|
|
50
|
+
export function loadPersistedGraphSettings(stored) {
|
|
51
|
+
if (!isRecord(stored)) {
|
|
52
|
+
return {
|
|
53
|
+
settings: mergeGraphSettings(null),
|
|
54
|
+
migrated: false,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const settings = mergeGraphSettings(stored);
|
|
58
|
+
if (stored.settingsVersion === undefined) {
|
|
59
|
+
settings.forces = { ...DEFAULT_GRAPH_SETTINGS.forces };
|
|
60
|
+
return { settings, migrated: true };
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
settings,
|
|
64
|
+
migrated: stored.settingsVersion === 1,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function serializeGraphSettings(settings) {
|
|
68
|
+
return {
|
|
69
|
+
settingsVersion: GRAPH_SETTINGS_VERSION,
|
|
70
|
+
...mergeGraphSettings(settings),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function mergeGraphSettings(stored) {
|
|
74
|
+
return {
|
|
75
|
+
filters: {
|
|
76
|
+
...DEFAULT_GRAPH_SETTINGS.filters,
|
|
77
|
+
...stored?.filters,
|
|
78
|
+
},
|
|
79
|
+
display: {
|
|
80
|
+
...DEFAULT_GRAPH_SETTINGS.display,
|
|
81
|
+
...stored?.display,
|
|
82
|
+
},
|
|
83
|
+
forces: {
|
|
84
|
+
...DEFAULT_GRAPH_SETTINGS.forces,
|
|
85
|
+
...stored?.forces,
|
|
86
|
+
},
|
|
87
|
+
localGraph: {
|
|
88
|
+
...DEFAULT_GRAPH_SETTINGS.localGraph,
|
|
89
|
+
...stored?.localGraph,
|
|
90
|
+
},
|
|
91
|
+
groups: stored?.groups?.flatMap((group, index) => {
|
|
92
|
+
if (!isRecord(group))
|
|
93
|
+
return [];
|
|
94
|
+
const id = typeof group.id === "string" ? group.id : `group-${index}`;
|
|
95
|
+
const query = typeof group.query === "string" ? group.query : "";
|
|
96
|
+
const color = typeof group.color === "string" ? group.color : "#3b82f6";
|
|
97
|
+
return [{ id, query, color }];
|
|
98
|
+
}) ?? [],
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export function patchGraphSettings(current, patch) {
|
|
102
|
+
return mergeGraphSettings({
|
|
103
|
+
...current,
|
|
104
|
+
...patch,
|
|
105
|
+
filters: { ...current.filters, ...patch.filters },
|
|
106
|
+
display: { ...current.display, ...patch.display },
|
|
107
|
+
forces: { ...current.forces, ...patch.forces },
|
|
108
|
+
localGraph: { ...current.localGraph, ...patch.localGraph },
|
|
109
|
+
groups: patch.groups ?? current.groups,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
export function moveGraphGroup(groups, index, delta) {
|
|
113
|
+
const target = index + delta;
|
|
114
|
+
if (index < 0 ||
|
|
115
|
+
index >= groups.length ||
|
|
116
|
+
target < 0 ||
|
|
117
|
+
target >= groups.length) {
|
|
118
|
+
return groups.map((group) => ({ ...group }));
|
|
119
|
+
}
|
|
120
|
+
const next = groups.map((group) => ({ ...group }));
|
|
121
|
+
const [group] = next.splice(index, 1);
|
|
122
|
+
if (group)
|
|
123
|
+
next.splice(target, 0, group);
|
|
124
|
+
return next;
|
|
125
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { TFile } from "@lapis-notes/api";
|
|
2
|
+
export type GraphNodeType = "note" | "unresolved" | "tag" | "attachment";
|
|
3
|
+
export type GraphLinkType = "internal-link" | "embed" | "tag";
|
|
4
|
+
export interface GraphNode {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
path: string | null;
|
|
8
|
+
type: GraphNodeType;
|
|
9
|
+
exists: boolean;
|
|
10
|
+
refCount: number;
|
|
11
|
+
outgoingCount: number;
|
|
12
|
+
tags: string[];
|
|
13
|
+
groupIds: string[];
|
|
14
|
+
primaryColor?: string;
|
|
15
|
+
ctime?: number;
|
|
16
|
+
mtime?: number;
|
|
17
|
+
extension?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface GraphLink {
|
|
20
|
+
id: string;
|
|
21
|
+
source: string;
|
|
22
|
+
target: string;
|
|
23
|
+
count: number;
|
|
24
|
+
type: GraphLinkType;
|
|
25
|
+
directed: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface GraphData {
|
|
28
|
+
nodes: GraphNode[];
|
|
29
|
+
links: GraphLink[];
|
|
30
|
+
centerNodeId?: string | null;
|
|
31
|
+
}
|
|
32
|
+
export interface GraphGroupRule {
|
|
33
|
+
id: string;
|
|
34
|
+
query: string;
|
|
35
|
+
color: string;
|
|
36
|
+
}
|
|
37
|
+
export interface GraphSettings {
|
|
38
|
+
filters: {
|
|
39
|
+
searchQuery: string;
|
|
40
|
+
showTags: boolean;
|
|
41
|
+
showAttachments: boolean;
|
|
42
|
+
existingFilesOnly: boolean;
|
|
43
|
+
showOrphans: boolean;
|
|
44
|
+
};
|
|
45
|
+
display: {
|
|
46
|
+
showArrows: boolean;
|
|
47
|
+
textFadeThreshold: number;
|
|
48
|
+
nodeSize: number;
|
|
49
|
+
linkThickness: number;
|
|
50
|
+
wheelZoomSensitivity: number;
|
|
51
|
+
hoverActivationDelayMs: number;
|
|
52
|
+
hoverReleaseDelayMs: number;
|
|
53
|
+
};
|
|
54
|
+
forces: {
|
|
55
|
+
centerForce: number;
|
|
56
|
+
repelForce: number;
|
|
57
|
+
linkForce: number;
|
|
58
|
+
linkDistance: number;
|
|
59
|
+
};
|
|
60
|
+
localGraph: {
|
|
61
|
+
depth: number;
|
|
62
|
+
};
|
|
63
|
+
groups: GraphGroupRule[];
|
|
64
|
+
}
|
|
65
|
+
export interface GraphSettingsPatch {
|
|
66
|
+
filters?: Partial<GraphSettings["filters"]>;
|
|
67
|
+
display?: Partial<GraphSettings["display"]>;
|
|
68
|
+
forces?: Partial<GraphSettings["forces"]>;
|
|
69
|
+
localGraph?: Partial<GraphSettings["localGraph"]>;
|
|
70
|
+
groups?: GraphGroupRule[];
|
|
71
|
+
}
|
|
72
|
+
export interface GraphSearchAdapter {
|
|
73
|
+
matchesNode(query: string, node: GraphNode, file?: TFile | null): boolean | Promise<boolean>;
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ItemView, Menu, type WorkspaceLeaf } from "@lapis-notes/api";
|
|
2
|
+
import type { GraphPlugin } from "./graph-plugin";
|
|
3
|
+
import type { GraphData, GraphSettings } from "./graph-types";
|
|
4
|
+
export declare const GraphViewType = "graph";
|
|
5
|
+
export declare const LocalGraphViewType = "graph-local";
|
|
6
|
+
declare abstract class GraphViewBase extends ItemView {
|
|
7
|
+
protected readonly plugin: GraphPlugin;
|
|
8
|
+
protected readonly isLocal: boolean;
|
|
9
|
+
private renderer;
|
|
10
|
+
private overlay;
|
|
11
|
+
private settings;
|
|
12
|
+
private canonicalGraph;
|
|
13
|
+
private coordinatorGraphVersion;
|
|
14
|
+
private unsubscribeCoordinator;
|
|
15
|
+
private currentGraphPaths;
|
|
16
|
+
private unregisterView;
|
|
17
|
+
private readonly buildGeneration;
|
|
18
|
+
private readonly deriveGeneration;
|
|
19
|
+
private metadataFacetGeneration;
|
|
20
|
+
private filterSyntax;
|
|
21
|
+
private readonly scheduleRebuild;
|
|
22
|
+
private readonly scheduleDerive;
|
|
23
|
+
constructor(leaf: WorkspaceLeaf | undefined, plugin: GraphPlugin, isLocal: boolean);
|
|
24
|
+
protected onOpen(): Promise<void>;
|
|
25
|
+
protected onClose(): Promise<void>;
|
|
26
|
+
onload(): void;
|
|
27
|
+
private scheduleViewportRefreshWhenVisible;
|
|
28
|
+
onunload(): void;
|
|
29
|
+
onPaneMenu(menu: Menu): void;
|
|
30
|
+
focusActiveFile(): void;
|
|
31
|
+
applyGraphSettings(settings: GraphSettings): void;
|
|
32
|
+
protected abstract getGraphData(settings: GraphSettings): Promise<GraphData>;
|
|
33
|
+
private rebuild;
|
|
34
|
+
private applyCoordinatorState;
|
|
35
|
+
private deriveGraphFromSettings;
|
|
36
|
+
private renderGraph;
|
|
37
|
+
private shouldRebuildForMetadataPaths;
|
|
38
|
+
private getSurfaceEl;
|
|
39
|
+
private getStatsText;
|
|
40
|
+
private refreshFilterSyntaxFromVault;
|
|
41
|
+
private refreshMetadataFacets;
|
|
42
|
+
private updateLocalSettings;
|
|
43
|
+
private resetLocalSettings;
|
|
44
|
+
private resolveNavigationLeaf;
|
|
45
|
+
private openNode;
|
|
46
|
+
private showNodeMenu;
|
|
47
|
+
}
|
|
48
|
+
export declare class GraphView extends GraphViewBase {
|
|
49
|
+
constructor(leaf: WorkspaceLeaf | undefined, plugin: GraphPlugin);
|
|
50
|
+
getViewType(): string;
|
|
51
|
+
getDisplayText(): string;
|
|
52
|
+
getIcon(): string;
|
|
53
|
+
protected getGraphData(_settings: GraphSettings): Promise<GraphData>;
|
|
54
|
+
}
|
|
55
|
+
export declare class LocalGraphView extends GraphViewBase {
|
|
56
|
+
constructor(leaf: WorkspaceLeaf | undefined, plugin: GraphPlugin);
|
|
57
|
+
getViewType(): string;
|
|
58
|
+
getDisplayText(): string;
|
|
59
|
+
getIcon(): string;
|
|
60
|
+
protected getGraphData(settings: GraphSettings): Promise<GraphData>;
|
|
61
|
+
}
|
|
62
|
+
export {};
|