feat: integrate into appflowy
This commit is contained in:
parent
14ca76611a
commit
77f549c4e9
5 changed files with 35 additions and 9 deletions
|
|
@ -2,6 +2,7 @@ import 'dart:collection';
|
|||
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nanoid/nanoid.dart';
|
||||
|
||||
/// [Node] represents a node in the document tree.
|
||||
///
|
||||
|
|
@ -20,6 +21,7 @@ import 'package:flutter/material.dart';
|
|||
class Node extends ChangeNotifier with LinkedListEntry<Node> {
|
||||
Node({
|
||||
required this.type,
|
||||
String? id,
|
||||
this.parent,
|
||||
Attributes attributes = const {},
|
||||
Iterable<Node> children = const [],
|
||||
|
|
@ -29,7 +31,8 @@ class Node extends ChangeNotifier with LinkedListEntry<Node> {
|
|||
(e) => e..unlink(),
|
||||
),
|
||||
), // unlink the given children to avoid the error of "node has already a parent"
|
||||
_attributes = attributes {
|
||||
_attributes = attributes,
|
||||
id = id ?? nanoid(10) {
|
||||
for (final child in this.children) {
|
||||
child.parent = this;
|
||||
}
|
||||
|
|
@ -54,11 +57,14 @@ class Node extends ChangeNotifier with LinkedListEntry<Node> {
|
|||
/// The type of the node.
|
||||
final String type;
|
||||
|
||||
/// The id of the node.
|
||||
final String id;
|
||||
|
||||
@Deprecated('Use type instead')
|
||||
String get subtype => type;
|
||||
|
||||
@Deprecated('Use type instead')
|
||||
String get id => type;
|
||||
// @Deprecated('Use type instead')
|
||||
// String get id => type;
|
||||
|
||||
/// The parent of the node.
|
||||
Node? parent;
|
||||
|
|
@ -111,8 +117,9 @@ class Node extends ChangeNotifier with LinkedListEntry<Node> {
|
|||
|
||||
Log.editor.debug('insert Node $entry at path ${path + [index]}}');
|
||||
|
||||
if (children.isEmpty) {
|
||||
entry.parent = this;
|
||||
|
||||
if (children.isEmpty) {
|
||||
_children.add(entry);
|
||||
notifyListeners();
|
||||
return;
|
||||
|
|
@ -160,6 +167,15 @@ class Node extends ChangeNotifier with LinkedListEntry<Node> {
|
|||
parent = null;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '''Node(id: $id,
|
||||
type: $type,
|
||||
attributes: $attributes,
|
||||
children: $children,
|
||||
)''';
|
||||
}
|
||||
|
||||
Delta? get delta {
|
||||
if (attributes['delta'] is List) {
|
||||
return Delta.fromJson(attributes['delta']);
|
||||
|
|
@ -186,11 +202,13 @@ class Node extends ChangeNotifier with LinkedListEntry<Node> {
|
|||
|
||||
Node copyWith({
|
||||
String? type,
|
||||
String? id,
|
||||
Iterable<Node>? children,
|
||||
Attributes? attributes,
|
||||
}) {
|
||||
final node = Node(
|
||||
type: type ?? this.type,
|
||||
id: id ?? this.id,
|
||||
attributes: attributes ?? {...this.attributes},
|
||||
children: children ?? [],
|
||||
);
|
||||
|
|
@ -224,6 +242,7 @@ class TextNode extends Node {
|
|||
type: 'text',
|
||||
children: children?.toList() ?? [],
|
||||
attributes: attributes ?? {},
|
||||
id: '',
|
||||
);
|
||||
|
||||
TextNode.empty({Attributes? attributes})
|
||||
|
|
@ -258,6 +277,7 @@ class TextNode extends Node {
|
|||
Iterable<Node>? children,
|
||||
Attributes? attributes,
|
||||
Delta? delta,
|
||||
String? id,
|
||||
}) {
|
||||
final textNode = TextNode(
|
||||
children: children ?? [],
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:appflowy_editor/src/editor/block_component/base_component/block_component_configuration.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
class HeadingBlockKeys {
|
||||
HeadingBlockKeys._();
|
||||
const HeadingBlockKeys._();
|
||||
|
||||
/// The level data of a heading block.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -13,11 +13,14 @@ Iterable<ThemeExtension<dynamic>> get darkEditorStyleExtension => [
|
|||
class EditorStyle extends ThemeExtension<EditorStyle> {
|
||||
// Editor styles
|
||||
final EdgeInsets? padding;
|
||||
final Color? backgroundColor;
|
||||
|
||||
final Color cursorColor;
|
||||
final Color selectionColor;
|
||||
final TextStyleConfiguration textStyleConfiguration;
|
||||
|
||||
@Deprecated('customize the editor\'s background color directly')
|
||||
final Color? backgroundColor;
|
||||
|
||||
// Text styles
|
||||
@Deprecated('customize the block component directly')
|
||||
final EdgeInsets? textPadding;
|
||||
|
|
@ -68,10 +71,10 @@ class EditorStyle extends ThemeExtension<EditorStyle> {
|
|||
|
||||
const EditorStyle({
|
||||
required this.padding,
|
||||
required this.backgroundColor,
|
||||
required this.cursorColor,
|
||||
required this.selectionColor,
|
||||
required this.textStyleConfiguration,
|
||||
required this.backgroundColor,
|
||||
required this.selectionMenuBackgroundColor,
|
||||
required this.selectionMenuItemTextColor,
|
||||
required this.selectionMenuItemIconColor,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class AppFlowyEditor extends StatefulWidget {
|
|||
ScrollController? scrollController,
|
||||
bool editable = true,
|
||||
bool autoFocus = false,
|
||||
Selection? focusedSelection,
|
||||
EditorStyle? editorStyle,
|
||||
Map<String, BlockComponentBuilder> blockComponentBuilders = const {},
|
||||
List<CharacterShortcutEvent> characterShortcutEvents = const [],
|
||||
|
|
@ -43,6 +44,7 @@ class AppFlowyEditor extends StatefulWidget {
|
|||
scrollController: scrollController,
|
||||
editable: editable,
|
||||
autoFocus: autoFocus,
|
||||
focusedSelection: focusedSelection,
|
||||
blockComponentBuilders: blockComponentBuilders,
|
||||
characterShortcutEvents: characterShortcutEvents,
|
||||
commandShortcutEvents: commandShortcutEvents,
|
||||
|
|
@ -56,6 +58,7 @@ class AppFlowyEditor extends StatefulWidget {
|
|||
ScrollController? scrollController,
|
||||
bool editable = true,
|
||||
bool autoFocus = false,
|
||||
Selection? focusedSelection,
|
||||
EditorStyle? editorStyle,
|
||||
}) : this(
|
||||
key: key,
|
||||
|
|
@ -63,6 +66,7 @@ class AppFlowyEditor extends StatefulWidget {
|
|||
scrollController: scrollController,
|
||||
editable: editable,
|
||||
autoFocus: autoFocus,
|
||||
focusedSelection: focusedSelection,
|
||||
blockComponentBuilders: standardBlockComponentBuilderMap,
|
||||
characterShortcutEvents: standardCharacterShortcutEvents,
|
||||
commandShortcutEvents: standardCommandShortcutEvents,
|
||||
|
|
@ -176,7 +180,6 @@ class _AppFlowyEditorState extends State<AppFlowyEditor> {
|
|||
key: editorState.service.scrollServiceKey,
|
||||
scrollController: widget.scrollController,
|
||||
child: Container(
|
||||
color: widget.editorStyle.backgroundColor,
|
||||
padding: widget.editorStyle.padding,
|
||||
child: SelectionServiceWidget(
|
||||
key: editorState.service.selectionServiceKey,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ dependencies:
|
|||
sdk: flutter
|
||||
tuple: ^2.0.1
|
||||
collection: ^1.17.0
|
||||
nanoid: ^1.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
|||
Loading…
Reference in a new issue