feat(app): hubs, types and tags UI, themes, key bindings and slash commands

Settings screen (themes incl. Sweet, rebindable shortcuts), rich text escapes,
page sidebar with the local graph, sortable All pages, tree view changes and the
Type/Tags rows in the page header. Docs updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Sonnet 5.5 committed 2026-10-26 02:45:22 +01:00
1 parent e18fd2c27e
commit 88ef4a97a5
32 files changed
+5431 -375

No files matched your search

+195 -36
View File
@@ -1,5 +1,9 @@
import 'package:flutter/material.dart';
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:synapse/src/backend/graph_backend.dart';
import 'package:synapse/src/graph/graph_model.dart';
import 'package:synapse/src/graph/network_canvas.dart';
import 'package:synapse/src/graph/tree_canvas.dart';
@@ -99,10 +103,6 @@ void main() {
testWidgets('switches between every mode', (tester) async {
await pumpGraph(tester, demo());
await mode(tester, 'Local');
expect(find.byKey(const ValueKey('depth')), findsOneWidget);
expect(find.byType(NetworkCanvas), findsOneWidget);
await mode(tester, 'Synapses');
expect(find.text('Pulse'), findsOneWidget);
expect(find.byType(NetworkCanvas), findsOneWidget);
@@ -111,7 +111,7 @@ void main() {
await mode(tester, 'Clusters');
expect(find.byType(NetworkCanvas), findsOneWidget);
await mode(tester, 'Namespaces');
await mode(tester, 'Tree');
expect(find.byType(TreeCanvas), findsOneWidget);
expect(find.byType(NetworkCanvas), findsNothing);
@@ -123,43 +123,88 @@ void main() {
await tester.pump(const Duration(seconds: 1));
});
testWidgets('local mode follows the depth slider', (tester) async {
final b = demo();
// Chain Alpha – Beta – Gamma – Delta.
final g = b.createPage('Gamma');
b.seed(g.id, [(0, '[[Beta]] [[Delta]]')]);
await pumpGraph(tester, b);
await mode(tester, 'Local');
// Focus is the highest-degree page until the user picks one; pick Delta.
await tester.enterText(find.byType(TextField), 'Delta');
await tester.testTextInput.receiveAction(TextInputAction.done);
await settle(tester);
expect(
canvas(tester).nodeCount,
3,
reason: 'Delta, Gamma, Beta at depth 2',
);
final slider = tester.widget<Slider>(find.byKey(const ValueKey('depth')));
slider.onChanged!(1);
await settle(tester);
expect(canvas(tester).nodeCount, 2);
slider.onChanged!(3);
await settle(tester);
expect(canvas(tester).nodeCount, 5, reason: 'adds Alpha and topic');
});
test('namespace tree groups a/b titles and tags', () async {
test('tree groups a/b titles and tags', () async {
final model = GraphModel(await demo().graphData());
final root = buildNamespaceTree(model);
final labels = root.children.map((c) => c.label).toList();
expect(labels, ['Namespaces', 'Tags']);
expect(root.children[0].children.single.label, 'proj');
expect(root.children[0].children.single.children.single.label, 'one');
final topic = root.children[1].children.single;
TreeItem branch(String l) => root.children.firstWhere((c) => c.label == l);
// Hubs are covered by the hubs group below; notes in no hub hang off the centre.
// Namespaces have no node of their own: `proj` hangs off the centre.
expect(root.children.map((c) => c.label), [
'Alpha',
'Beta',
'Lonely',
'proj',
'Tags',
'topic',
]);
expect(branch('proj').children.single.label, 'one');
final topic = branch('Tags').children.single;
expect(topic.label, '#topic');
expect(topic.children.map((c) => c.label).toSet(), {'Alpha', 'Beta'});
});
test(
'tree centre carries the store name; sibling branches get distinct hues',
() async {
final model = GraphModel(await demo().graphData());
final root = buildNamespaceTree(model, name: 'Mi almacén');
expect(root.label, 'Mi almacén');
final arms = root.children;
expect(arms.length, greaterThan(1));
// Arms are evenly spread over the hue circle.
final gap = arms[1].hue - arms[0].hue;
expect(gap, closeTo(360 / arms.length, 1e-9));
// Children split their parent's sector evenly and stay inside it.
for (final a in arms) {
final k = a.children.length;
for (var j = 1; j < k; j++) {
expect(
a.children[j].hue - a.children[j - 1].hue,
closeTo(a.span / k, 1e-9),
);
}
for (final c in a.children) {
expect((c.hue - a.hue).abs(), lessThanOrEqualTo(a.span / 2));
}
}
},
);
test('tag grouping uses each page\'s most used tag', () {
GraphNode n(String t, List<String> tags) => GraphNode(
id: t,
title: t,
createdAt: 0,
degree: 1,
backlinks: 0,
cluster: 0,
isHub: false,
tags: tags,
);
final m = GraphModel(
GraphData(
nodes: [
n('a', ['Tecnología', 'idea']),
n('b', ['tecnología']),
n('c', ['idea', 'lugar']),
n('d', []),
],
sources: Uint32List(0),
targets: Uint32List(0),
kinds: Uint8List(0),
weights: Float32List(0),
seq: 0,
),
);
// Tie (two pages each): alphabetical.
expect(m.homeTag(0), 'idea');
expect(m.homeTag(2), 'idea');
expect(m.homeTag(3), isNull);
expect(m.tagGroups, ['idea', 'tecnología']);
expect(m.tagLabel('tecnología'), 'Tecnología');
expect(m.tagSprings([0, 1, 2, 3]).map((s) => (s.$1, s.$2)), [(2, 0)]);
});
test('filter by tag, query and min degree', () async {
final model = GraphModel(await demo().graphData());
String t(int i) => model.node(i).title;
@@ -212,4 +257,118 @@ void main() {
expect(hull.length, 4);
expect(hull.contains(const Offset(5, 5)), isFalse);
});
group('hubs', () {
// Media (hub) -> TV (hub) -> Anime (page); Media -> Books; Notes (page) in Media;
// a TV -> Media CONTAINS edge (a cycle the tree must survive); a journal (never a member).
GraphData hubData() {
GraphNode n(
String id,
String title, {
bool hub = false,
int? home,
String? journal,
}) => GraphNode(
id: id,
title: title,
journalDate: journal,
createdAt: 0,
degree: 1,
backlinks: 0,
cluster: 0,
isHub: hub,
homeHub: home,
tags: const [],
);
final nodes = [
n('0', 'Media', hub: true, home: 0),
n('1', 'TV', hub: true, home: 1),
n('2', 'Anime', home: 1),
n('3', 'Books', home: 0),
n('4', 'Notes', home: 0),
n('5', '2024-01-01', journal: '2024-01-01'),
];
// (source, target, kind)
final edges = [
(0, 1, 7), // Media contains TV
(0, 3, 7), // Media contains Books
(0, 4, 7), // Media contains Notes
(1, 2, 7), // TV contains Anime
(1, 0, 7), // TV contains Media (cycle)
(0, 5, 0), // Media -> journal link: a link never makes a member
];
return GraphData(
nodes: nodes,
sources: Uint32List.fromList([for (final e in edges) e.$1]),
targets: Uint32List.fromList([for (final e in edges) e.$2]),
kinds: Uint8List.fromList([for (final e in edges) e.$3]),
weights: Float32List.fromList([for (final _ in edges) 1.0]),
seq: 1,
);
}
GraphModel hubModel() => GraphModel(hubData());
test('hub members are the CONTAINS targets', () {
final m = hubModel();
expect(EdgeKind.values[7], EdgeKind.contains);
expect(EdgeKind.contains.structural, isTrue);
expect(EdgeKind.values[8], EdgeKind.tagged);
expect(const GraphFilter().kinds, contains(EdgeKind.tagged));
expect(m.hubMembers[0], {1, 3, 4});
expect(m.hubMembers[1], {2, 0});
expect(m.hubOrder.first, 0, reason: 'Media is home hub of most pages');
expect(m.hubRank[1], 1);
});
test('contains is a default filter kind', () {
expect(const GraphFilter().kinds, contains(EdgeKind.contains));
});
test('hub springs pull members to their home hub', () {
final m = hubModel();
expect(m.hubSprings([0, 1, 2, 3, 4, 5]), [
(2, 1, 0.6),
(3, 0, 0.6),
(4, 0, 0.6),
]);
});
test('tree hubs hang off the centre, cycle-safe', () {
final root = buildNamespaceTree(hubModel());
// Media is a member of TV and TV of Media: no root hub, both still placed once.
expect(root.children.where((c) => c.label == 'Hubs'), isEmpty);
final media = root.children.firstWhere((c) => c.label == 'Media');
expect(media.isHub, isTrue);
expect(media.children.map((c) => c.label).toSet(), {
'TV',
'Books',
'Notes',
});
final tv = media.children.firstWhere((c) => c.label == 'TV');
expect(tv.isHub, isTrue);
// Media already on the path: a leaf, not an endless loop.
expect(tv.children.map((c) => c.label).toSet(), {'Anime', 'Media'});
expect(
tv.children.firstWhere((c) => c.label == 'Media').children,
isEmpty,
);
});
testWidgets('clusters mode groups by hub by default', (tester) async {
await pumpGraph(tester, _HubBackend(hubData()));
await mode(tester, 'Clusters');
expect(find.byKey(const ValueKey('cluster-group')), findsOneWidget);
expect(find.text('Group: hubs'), findsOneWidget);
});
});
}
/// A memory backend whose graph data is fixed (so tests don't depend on its demo graph).
class _HubBackend extends MemoryBackend {
_HubBackend(this._data);
final GraphData _data;
@override
Future<GraphData> graphData() async => _data;
}