2023-04-25 14:45:36 +08:00
|
|
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
2023-04-21 21:03:35 +08:00
|
|
|
|
2023-04-26 14:57:18 +08:00
|
|
|
import 'typedef_util.dart';
|
2023-04-21 21:03:35 +08:00
|
|
|
|
2023-04-25 14:45:36 +08:00
|
|
|
extension NodeExtension on Node {
|
2023-04-26 14:57:18 +08:00
|
|
|
void addParagraphs(
|
2023-04-25 14:45:36 +08:00
|
|
|
int count, {
|
2023-04-28 10:54:21 +08:00
|
|
|
TextBuilder? builder,
|
|
|
|
|
String? initialText,
|
2023-04-26 14:57:18 +08:00
|
|
|
NodeDecorator? decorator,
|
2023-04-25 14:45:36 +08:00
|
|
|
}) {
|
|
|
|
|
final builder0 = builder ??
|
2023-04-28 19:48:34 +08:00
|
|
|
(index) => Delta()
|
|
|
|
|
..insert(initialText ?? '🔥 $index. Welcome to AppFlowy Editor!');
|
2023-04-26 14:57:18 +08:00
|
|
|
final decorator0 = decorator ?? (index, node) {};
|
|
|
|
|
final nodes = List.generate(
|
2023-04-25 14:45:36 +08:00
|
|
|
count,
|
2023-04-26 14:57:18 +08:00
|
|
|
(index) {
|
|
|
|
|
final node = Node(type: 'paragraph');
|
|
|
|
|
decorator0(index, node);
|
|
|
|
|
node.updateAttributes({
|
2023-04-28 19:48:34 +08:00
|
|
|
'delta': builder0(index).toJson(),
|
2023-04-26 14:57:18 +08:00
|
|
|
});
|
2025-12-23 15:12:57 +08:00
|
|
|
|
2023-04-26 14:57:18 +08:00
|
|
|
return node;
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
nodes.forEach(insert);
|
2023-04-25 14:45:36 +08:00
|
|
|
}
|
2023-04-28 10:54:21 +08:00
|
|
|
|
|
|
|
|
void addParagraph({
|
|
|
|
|
TextBuilder? builder,
|
|
|
|
|
String? initialText,
|
|
|
|
|
NodeDecorator? decorator,
|
|
|
|
|
}) {
|
|
|
|
|
addParagraphs(
|
|
|
|
|
1,
|
|
|
|
|
builder: builder,
|
|
|
|
|
initialText: initialText,
|
|
|
|
|
decorator: decorator,
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-05-03 12:01:34 +08:00
|
|
|
|
|
|
|
|
bool everyAttributeValue(
|
|
|
|
|
Selection selection,
|
|
|
|
|
String key,
|
|
|
|
|
bool Function(dynamic value) test,
|
|
|
|
|
) {
|
|
|
|
|
return allSatisfyInSelection(
|
|
|
|
|
selection,
|
|
|
|
|
(delta) => delta.whereType<TextInsert>().every(
|
|
|
|
|
(element) => test(element.attributes?[key]),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool allBold(Selection selection) =>
|
|
|
|
|
everyAttributeValue(selection, 'bold', (value) => value == true);
|
|
|
|
|
bool allItalic(Selection selection) =>
|
|
|
|
|
everyAttributeValue(selection, 'italic', (value) => value == true);
|
|
|
|
|
bool allCode(Selection selection) =>
|
|
|
|
|
everyAttributeValue(selection, 'code', (value) => value == true);
|
|
|
|
|
bool allStrikethrough(Selection selection) =>
|
|
|
|
|
everyAttributeValue(selection, 'strikethrough', (value) => value == true);
|
|
|
|
|
bool allUnderline(Selection selection) =>
|
|
|
|
|
everyAttributeValue(selection, 'underline', (value) => value == true);
|
2023-04-25 14:45:36 +08:00
|
|
|
}
|