Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / go (Server) (push) Failing after 8m12s
CI / go (Web-App) (push) Successful in 11m16s
CI / frontend (push) Failing after 7m33s
CI / desktop (ubuntu-latest) (push) Successful in 1h25m49s
CI / mobile (push) Failing after 5m48s
CI / docker (push) Successful in 41m19s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
Phase D of docs/AFFINE.md (ADR-14).
The canvas lives in the page's Y.Doc next to its text, in
ydoc.getMap("surface"): one Y.Map per element, each field its own entry so
concurrent edits merge. The page's text is a note on the canvas bound to
the same "default" fragment, so typing on the canvas is typing in the page.
Canvas edits have their own undo history through a Y.UndoManager.
- New package @docwell/canvas: viewport with pan, zoom and pinch;
selection, marquee, snapping, resize and rotate; notes, text, shapes
(plain or scribbled), connectors (straight, curve, elbow, with arrowheads
and labels), pen and eraser, frames, groups, pictures, embeds and link
cards, and mind maps (right, left or both sides; Tab, Enter, arrows).
A style bar over the selection; the last style per kind is the default.
- Presentation through frames, stickers and templates, PNG and SVG export.
- Page/Edgeless switch in the header, ?mode= in page and share links, a
per-page default (pages.default_mode) and a per-device default for new
pages; share links show the canvas read-only.
- Server: yrs writes the canvas into the document JSON as "surface",
adds its text to search, and writes it back on restores and templates.
- Phone: the bridge draws the canvas read-only (protocol 3) and the page
screen has a canvas button.
Strings are translated into all five languages and the user guide covers
edgeless mode.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
104 lines
3.1 KiB
Dart
104 lines
3.1 KiB
Dart
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:docwell_mobile/editor/bridge.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
/// Decodes what the bridge asked the page to receive.
|
|
Map<String, dynamic> sentMessage(String script) {
|
|
final m = RegExp(
|
|
r'^window\.docwell\.receive\((.*)\)$',
|
|
dotAll: true,
|
|
).firstMatch(script)!;
|
|
return jsonDecode(jsonDecode(m[1]!) as String) as Map<String, dynamic>;
|
|
}
|
|
|
|
void main() {
|
|
const doc = {
|
|
'type': 'doc',
|
|
'content': [
|
|
{'type': 'paragraph'},
|
|
],
|
|
};
|
|
|
|
late List<Map<String, dynamic>> sent;
|
|
late EditorBridge bridge;
|
|
setUp(() {
|
|
sent = [];
|
|
bridge = EditorBridge(
|
|
content: doc,
|
|
evaluate: (js) async => sent.add(sentMessage(js)),
|
|
);
|
|
});
|
|
|
|
test('loads the content once the page is ready, only once', () async {
|
|
bridge.handleMessage('{"type":"ready","version":$editorProtocolVersion}');
|
|
bridge.handleMessage('{"type":"ready","version":$editorProtocolVersion}');
|
|
await bridge.ready;
|
|
expect(bridge.isReady, isTrue);
|
|
expect(sent, [
|
|
{'type': 'setContent', 'content': doc},
|
|
]);
|
|
});
|
|
|
|
test('refuses a page that speaks another protocol version', () {
|
|
bridge.handleMessage('{"type":"ready","version":99}');
|
|
expect(bridge.isReady, isFalse);
|
|
expect(bridge.error, contains('protocol 99'));
|
|
});
|
|
|
|
test('sends commands and tracks content and toolbar state', () async {
|
|
final changes = <Map<String, dynamic>>[];
|
|
bridge.changes.listen(changes.add);
|
|
|
|
await bridge.run(EditorCommand.bold);
|
|
bridge.handleMessage(
|
|
'{"type":"state","state":{"active":["bold","heading2","future"],'
|
|
'"canUndo":true,"canRedo":false,"focused":true}}',
|
|
);
|
|
bridge.handleMessage('{"type":"change","content":{"type":"doc"}}');
|
|
await Future<void>.delayed(Duration.zero);
|
|
|
|
expect(sent.last, {'type': 'command', 'command': 'bold'});
|
|
expect(bridge.state.active, {EditorCommand.bold, EditorCommand.heading2});
|
|
expect(bridge.state.canUndo, isTrue);
|
|
expect(bridge.content, {'type': 'doc'});
|
|
expect(changes, [
|
|
{'type': 'doc'},
|
|
]);
|
|
});
|
|
|
|
test("sends the page's width and font", () async {
|
|
await bridge.setLayout(fullWidth: true, font: 'serif');
|
|
expect(sent.last, {
|
|
'type': 'setLayout',
|
|
'fullWidth': true,
|
|
'font': 'serif',
|
|
});
|
|
});
|
|
|
|
test('switches between the text and the canvas', () async {
|
|
await bridge.setMode('edgeless');
|
|
expect(sent.last, {'type': 'setMode', 'mode': 'edgeless'});
|
|
});
|
|
|
|
test('tracks panels over the text and dismisses them', () async {
|
|
expect(bridge.overlayOpen, isFalse);
|
|
bridge.handleMessage('{"type":"overlay","open":true}');
|
|
expect(bridge.overlayOpen, isTrue);
|
|
await bridge.dismiss();
|
|
expect(sent.last, {'type': 'dismiss'});
|
|
bridge.handleMessage('{"type":"overlay","open":false}');
|
|
expect(bridge.overlayOpen, isFalse);
|
|
});
|
|
|
|
test('escapes content safely into the script', () async {
|
|
await bridge.setContent({
|
|
'type': 'doc',
|
|
'text': "it's \"quoted\" </script> \u2028",
|
|
});
|
|
expect(sent.last['content']['text'], "it's \"quoted\" </script> \u2028");
|
|
});
|
|
}
|