visual-space / visual-editor

Rich text editor for Flutter based on Delta format (Quill fork)
MIT License
280 stars 44 forks source link

Document - The ability to run DocumentController server side #246

Closed adrian-moisa closed 6 months ago

adrian-moisa commented 6 months ago

Edit Delta Docs In Dart Server

You can edit delta docs on the server side using DocumentController. This can come in handy for a couple of scenarios:

Importing Visual Editor Server By importing the server side library we ensure that no dart:ui dependencies are imported. Note that both the frontend and server versions of the library use the same code. They are just different export files.

import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:visual_editor/visual-editor-server.dart';

//...
// Convert delta text to plain text
final document = DeltaDocM.fromJson(jsonDecode(deltaText));
final plainText = DocumentController(document, null, null).toPlainText();
adrian-moisa commented 6 months ago

Took some effort, but now, thanks to the cleaned up code, it's completely possible to run DocumentController on the server side. Here's a snapshot from insomnia demonstrating a simple endpoint for converting delta docs to plain text.

image