mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: remove subtype render
This commit is contained in:
parent
d200371002
commit
eb97141859
@ -1,71 +1,78 @@
|
|||||||
{
|
{
|
||||||
"document": {
|
"document": {
|
||||||
"type": "editor",
|
"type": "editor",
|
||||||
"attributes": {},
|
"attributes": {},
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"delta": [
|
"delta": [
|
||||||
{ "insert": "👋 Welcome to AppFlowy!", "attributes": { "href": "https://www.appflowy.io/", "heading": "h1" } }
|
{
|
||||||
],
|
"insert": "👋 Welcome to AppFlowy!",
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"subtype": "with-heading",
|
"href": "https://www.appflowy.io/",
|
||||||
"heading": "h1"
|
"heading": "h1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
],
|
||||||
{
|
"attributes": {
|
||||||
"type": "text",
|
"heading": "h1"
|
||||||
"delta": [
|
|
||||||
{ "insert": "Here are the basics", "attributes": { "heading": "h2" } }
|
|
||||||
],
|
|
||||||
"attributes": {
|
|
||||||
"subtype": "with-heading",
|
|
||||||
"heading": "h2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "text",
|
|
||||||
"delta": [
|
|
||||||
{ "insert": "Click anywhere and just start typing." }
|
|
||||||
],
|
|
||||||
"attributes": {
|
|
||||||
"subtype": "with-checkbox",
|
|
||||||
"checkbox": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "text",
|
|
||||||
"delta": [
|
|
||||||
{ "insert": "Highlight", "attributes": { "highlight": "0xFFFFFF00" } },
|
|
||||||
{ "insert": " Click anywhere and just start typing" },
|
|
||||||
{ "insert": " any text, and use the menu at the bottom to " },
|
|
||||||
{ "insert": "style", "attributes": { "italic": true } },
|
|
||||||
{ "insert": " your ", "attributes": { "bold": true } },
|
|
||||||
{ "insert": "writing", "attributes": { "underline": true } },
|
|
||||||
{ "insert": " howeverv you like.", "attributes": { "strikethrough": true } }
|
|
||||||
],
|
|
||||||
"attributes": {
|
|
||||||
"subtype": "with-checkbox",
|
|
||||||
"checkbox": false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "text",
|
|
||||||
"delta": [
|
|
||||||
{ "insert": "Have a question? ", "attributes": { "heading": "h2" } }
|
|
||||||
],
|
|
||||||
"attributes": {
|
|
||||||
"subtype": "with-heading",
|
|
||||||
"heading": "h2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "text",
|
|
||||||
"delta": [
|
|
||||||
{ "insert": "Click the '?' at the bottom right for help and support."}
|
|
||||||
],
|
|
||||||
"attributes": {}
|
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
}
|
{
|
||||||
}
|
"type": "text",
|
||||||
|
"delta": [
|
||||||
|
{ "insert": "Here are the basics", "attributes": { "heading": "h2" } }
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"heading": "h2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"delta": [{ "insert": "Click anywhere and just start typing." }],
|
||||||
|
"attributes": {
|
||||||
|
"checkbox": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"delta": [
|
||||||
|
{
|
||||||
|
"insert": "Highlight",
|
||||||
|
"attributes": { "highlight": "0xFFFFFF00" }
|
||||||
|
},
|
||||||
|
{ "insert": " Click anywhere and just start typing" },
|
||||||
|
{ "insert": " any text, and use the menu at the bottom to " },
|
||||||
|
{ "insert": "style", "attributes": { "italic": true } },
|
||||||
|
{ "insert": " your ", "attributes": { "bold": true } },
|
||||||
|
{ "insert": "writing", "attributes": { "underline": true } },
|
||||||
|
{
|
||||||
|
"insert": " howeverv you like.",
|
||||||
|
"attributes": { "strikethrough": true }
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"checkbox": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"delta": [
|
||||||
|
{ "insert": "Have a question? ", "attributes": { "heading": "h2" } }
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"heading": "h2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"delta": [
|
||||||
|
{
|
||||||
|
"insert": "Click the '?' at the bottom right for help and support."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -20,6 +20,7 @@ class SelectedTextNodeBuilder extends NodeWidgetBuilder {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext buildContext) {
|
Widget build(BuildContext buildContext) {
|
||||||
|
print('key -> $key');
|
||||||
return _SelectedTextNodeWidget(
|
return _SelectedTextNodeWidget(
|
||||||
key: key,
|
key: key,
|
||||||
node: node,
|
node: node,
|
||||||
@ -100,9 +101,20 @@ class _SelectedTextNodeWidgetState extends State<_SelectedTextNodeWidget>
|
|||||||
// TODO: just handle upforward delete.
|
// TODO: just handle upforward delete.
|
||||||
if (textSelection != null) {
|
if (textSelection != null) {
|
||||||
if (textSelection.isCollapsed) {
|
if (textSelection.isCollapsed) {
|
||||||
TransactionBuilder(editorState)
|
print(node.toRawString());
|
||||||
..deleteText(node, textSelection.start - 1, 1)
|
print('is empty ${node.toRawString().isEmpty}');
|
||||||
..commit();
|
if (textSelection.baseOffset == 0 && node.toRawString().isEmpty) {
|
||||||
|
TransactionBuilder(editorState)
|
||||||
|
..deleteNode(node)
|
||||||
|
..commit();
|
||||||
|
} else {
|
||||||
|
TransactionBuilder(editorState)
|
||||||
|
..deleteText(node, textSelection.start - 1, 1)
|
||||||
|
..commit();
|
||||||
|
final rect = _computeCursorRect(textSelection.baseOffset - 1);
|
||||||
|
editorState.tapOffset = rect.center;
|
||||||
|
editorState.updateCursor();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
TransactionBuilder(editorState)
|
TransactionBuilder(editorState)
|
||||||
..deleteText(node, textSelection.start,
|
..deleteText(node, textSelection.start,
|
||||||
@ -117,6 +129,7 @@ class _SelectedTextNodeWidgetState extends State<_SelectedTextNodeWidget>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
print('text rebuild $this');
|
||||||
Widget richText;
|
Widget richText;
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
richText = DebuggableRichText(text: node.toTextSpan(), textKey: _textKey);
|
richText = DebuggableRichText(text: node.toTextSpan(), textKey: _textKey);
|
||||||
@ -127,7 +140,10 @@ class _SelectedTextNodeWidgetState extends State<_SelectedTextNodeWidget>
|
|||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
richText,
|
SizedBox(
|
||||||
|
width: MediaQuery.of(context).size.width,
|
||||||
|
child: richText,
|
||||||
|
),
|
||||||
if (node.children.isNotEmpty)
|
if (node.children.isNotEmpty)
|
||||||
...node.children.map(
|
...node.children.map(
|
||||||
(e) => editorState.renderPlugins.buildWidget(
|
(e) => editorState.renderPlugins.buildWidget(
|
||||||
@ -163,14 +179,18 @@ class _SelectedTextNodeWidgetState extends State<_SelectedTextNodeWidget>
|
|||||||
final position = TextPosition(offset: offset);
|
final position = TextPosition(offset: offset);
|
||||||
var cursorOffset = _renderParagraph.getOffsetForCaret(position, Rect.zero);
|
var cursorOffset = _renderParagraph.getOffsetForCaret(position, Rect.zero);
|
||||||
cursorOffset = _renderParagraph.localToGlobal(cursorOffset);
|
cursorOffset = _renderParagraph.localToGlobal(cursorOffset);
|
||||||
final cursorHeight = _renderParagraph.getFullHeightForCaret(position)!;
|
final cursorHeight = _renderParagraph.getFullHeightForCaret(position);
|
||||||
const cursorWidth = 2;
|
if (cursorHeight != null) {
|
||||||
return Rect.fromLTWH(
|
const cursorWidth = 2;
|
||||||
cursorOffset.dx - (cursorWidth / 2),
|
return Rect.fromLTWH(
|
||||||
cursorOffset.dy,
|
cursorOffset.dx - (cursorWidth / 2),
|
||||||
cursorWidth.toDouble(),
|
cursorOffset.dy,
|
||||||
cursorHeight.toDouble(),
|
cursorWidth.toDouble(),
|
||||||
);
|
cursorHeight.toDouble(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return Rect.zero;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,6 @@ class __TextNodeWidgetState extends State<_TextNodeWidget>
|
|||||||
textCapitalization: TextCapitalization.sentences,
|
textCapitalization: TextCapitalization.sentences,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
debugPrint('selection: $selection');
|
|
||||||
editorState.cursorSelection = _localSelectionToGlobal(node, selection);
|
editorState.cursorSelection = _localSelectionToGlobal(node, selection);
|
||||||
_textInputConnection
|
_textInputConnection
|
||||||
?..show()
|
?..show()
|
||||||
@ -182,9 +181,7 @@ class __TextNodeWidgetState extends State<_TextNodeWidget>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void performAction(TextInputAction action) {
|
void performAction(TextInputAction action) {}
|
||||||
debugPrint('action:$action');
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void performPrivateCommand(String action, Map<String, dynamic> data) {
|
void performPrivateCommand(String action, Map<String, dynamic> data) {
|
||||||
@ -207,13 +204,10 @@ class __TextNodeWidgetState extends State<_TextNodeWidget>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void updateEditingValue(TextEditingValue value) {
|
void updateEditingValue(TextEditingValue value) {}
|
||||||
debugPrint('offset: ${value.selection}');
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void updateEditingValueWithDeltas(List<TextEditingDelta> textEditingDeltas) {
|
void updateEditingValueWithDeltas(List<TextEditingDelta> textEditingDeltas) {
|
||||||
debugPrint(textEditingDeltas.toString());
|
|
||||||
for (final textDelta in textEditingDeltas) {
|
for (final textDelta in textEditingDeltas) {
|
||||||
if (textDelta is TextEditingDeltaInsertion) {
|
if (textDelta is TextEditingDeltaInsertion) {
|
||||||
TransactionBuilder(editorState)
|
TransactionBuilder(editorState)
|
||||||
|
@ -186,8 +186,6 @@ class TextNode extends Node {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
String toRawString() => _delta.operations
|
String toRawString() =>
|
||||||
.whereType<TextInsert>()
|
_delta.operations.whereType<TextInsert>().map((op) => op.content).join();
|
||||||
.map((op) => op.content)
|
|
||||||
.toString();
|
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,10 @@ class EditorState {
|
|||||||
List<OverlayEntry> selectionOverlays = [];
|
List<OverlayEntry> selectionOverlays = [];
|
||||||
|
|
||||||
void updateCursor() {
|
void updateCursor() {
|
||||||
|
selectionOverlays
|
||||||
|
..forEach((element) => element.remove())
|
||||||
|
..clear();
|
||||||
|
|
||||||
if (tapOffset == null) {
|
if (tapOffset == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ class RenderPlugins {
|
|||||||
_nodeWidgetBuilders.removeWhere((key, _) => key == name);
|
_nodeWidgetBuilders.removeWhere((key, _) => key == name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@protected
|
||||||
Widget buildWidget({
|
Widget buildWidget({
|
||||||
required NodeWidgetContext context,
|
required NodeWidgetContext context,
|
||||||
bool withSubtype = true,
|
bool withSubtype = true,
|
||||||
|
Loading…
Reference in New Issue
Block a user