From 193dd68ccc9439c0fa880ebe33c27b7e25b9bfec Mon Sep 17 00:00:00 2001 From: X Code Date: Thu, 23 Dec 2021 17:28:26 -0800 Subject: [PATCH] Revert "Implements StyledNode" This reverts commit dfa623a4fdd477ad21a317bf14daaff93d530524. --- lib/src/models/documents/nodes/block.dart | 2 +- lib/src/models/documents/nodes/leaf.dart | 2 +- lib/src/models/documents/nodes/line.dart | 2 +- lib/src/models/documents/nodes/node.dart | 27 +++++++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/src/models/documents/nodes/block.dart b/lib/src/models/documents/nodes/block.dart index c69d6a8f..095f1183 100644 --- a/lib/src/models/documents/nodes/block.dart +++ b/lib/src/models/documents/nodes/block.dart @@ -13,7 +13,7 @@ import 'node.dart'; /// - Text Alignment /// - Text Direction /// - Code Block -class Block extends Container implements StyledNode { +class Block extends Container { /// Creates new unmounted [Block]. @override Node newInstance() => Block(); diff --git a/lib/src/models/documents/nodes/leaf.dart b/lib/src/models/documents/nodes/leaf.dart index 48817a10..3895fd62 100644 --- a/lib/src/models/documents/nodes/leaf.dart +++ b/lib/src/models/documents/nodes/leaf.dart @@ -7,7 +7,7 @@ import 'line.dart'; import 'node.dart'; /// A leaf in Quill document tree. -abstract class Leaf extends Node implements StyledNode { +abstract class Leaf extends Node { /// Creates a new [Leaf] with specified [data]. factory Leaf(Object data) { if (data is Embeddable) { diff --git a/lib/src/models/documents/nodes/line.dart b/lib/src/models/documents/nodes/line.dart index b0977500..bccd7fb8 100644 --- a/lib/src/models/documents/nodes/line.dart +++ b/lib/src/models/documents/nodes/line.dart @@ -17,7 +17,7 @@ import 'node.dart'; /// /// When a line contains an embed, it fully occupies the line, no other embeds /// or text nodes are allowed. -class Line extends Container implements StyledNode { +class Line extends Container { @override Leaf get defaultChild => Text(); diff --git a/lib/src/models/documents/nodes/node.dart b/lib/src/models/documents/nodes/node.dart index 090c1ba8..8863138a 100644 --- a/lib/src/models/documents/nodes/node.dart +++ b/lib/src/models/documents/nodes/node.dart @@ -127,6 +127,33 @@ abstract class StyledNode implements Node { Style get style; } +/// Mixin used by nodes that wish to implement [StyledNode] interface. +abstract class StyledNodeMixin implements StyledNode { + @override + Style get style => _style; + @override + Style _style = Style(); + + /// Applies style [attribute] to this node. + @override + void applyAttribute(Attribute attribute) { + _style = _style.merge(attribute); + } + + /// Applies new style [value] to this node. Provided [value] is merged + /// into current style. + @override + void applyStyle(Style value) { + _style = _style.mergeAll(value); + } + + /// Clears style of this node. + @override + void clearStyle() { + _style = Style(); + } +} + /// Root node of document tree. class Root extends Container> { @override