Update attribute value to be private

pull/13/head
singerdmx 4 years ago
parent 26c0bea94e
commit 318d1b0962
  1. 25
      lib/models/documents/attribute.dart
  2. 4
      lib/models/documents/nodes/line.dart
  3. 4
      lib/models/documents/style.dart
  4. 2
      lib/models/rules/insert.dart
  5. 2
      lib/widgets/editor.dart
  6. 2
      lib/widgets/raw_editor.dart
  7. 2
      lib/widgets/text_block.dart

@ -9,9 +9,12 @@ enum AttributeScope {
class Attribute<T> {
final String key;
final AttributeScope scope;
T value;
T _value;
Attribute(this.key, this.scope, this.value);
Attribute(this.key, this.scope, this._value);
T getValue() => _value;
setValue(T val) => _value = val;
static final Map<String, Attribute> _registry = {
Attribute.bold.key: Attribute.bold,
@ -49,10 +52,10 @@ class Attribute<T> {
static Attribute<int> get h3 => HeaderAttribute(level: 3);
// "attributes":{"list":"ordered"}
// "attributes":{"list":"bullet"}
static Attribute<String> get ul => ListAttribute('bullet');
// "attributes":{"list":"bullet"}
// "attributes":{"list":"ordered"}
static Attribute<String> get ol => ListAttribute('ordered');
bool get isInline => scope == AttributeScope.INLINE;
@ -60,7 +63,7 @@ class Attribute<T> {
bool get isBlockExceptHeader =>
scope == AttributeScope.BLOCK && key != Attribute.header.key;
Map<String, dynamic> toJson() => <String, dynamic>{key: value};
Map<String, dynamic> toJson() => <String, dynamic>{key: _value};
static Attribute fromKeyValue(String key, dynamic value) {
if (!_registry.containsKey(key)) {
@ -69,13 +72,13 @@ class Attribute<T> {
Attribute origin = _registry[key];
Attribute attribute = clone(origin);
if (value != null) {
attribute.value = value;
attribute.setValue(value);
}
return attribute;
}
static Attribute clone(Attribute origin) {
return Attribute(origin.key, origin.scope, origin.value);
return Attribute(origin.key, origin.scope, origin.getValue());
}
@override
@ -85,15 +88,15 @@ class Attribute<T> {
Attribute<T> typedOther = other;
return key == typedOther.key &&
scope == typedOther.scope &&
value == typedOther.value;
_value == typedOther._value;
}
@override
int get hashCode => hash3(key, scope, value);
int get hashCode => hash3(key, scope, _value);
@override
String toString() {
return 'Attribute{key: $key, scope: $scope, value: $value}';
return 'Attribute{key: $key, scope: $scope, value: $_value}';
}
}
@ -118,7 +121,7 @@ class LinkAttribute extends Attribute<String> {
}
class HeaderAttribute extends Attribute<int> {
HeaderAttribute({int level = null}) : super('header', AttributeScope.BLOCK, level);
HeaderAttribute({int level}) : super('header', AttributeScope.BLOCK, level);
}
class ListAttribute extends Attribute<String> {

@ -168,7 +168,7 @@ class Line extends Container<Leaf> {
if (parent is Block) {
Attribute parentStyle = (parent as Block).style.getBlockExceptHeader();
if (blockStyle.value == null) {
if (blockStyle.getValue() == null) {
_unwrap();
} else if (blockStyle != parentStyle) {
_unwrap();
@ -177,7 +177,7 @@ class Line extends Container<Leaf> {
_wrap(block);
block.adjust();
}
} else if (blockStyle.value != null) {
} else if (blockStyle.getValue() != null) {
Block block = Block();
block.applyAttribute(blockStyle);
_wrap(block);

@ -25,7 +25,7 @@ class Style {
Map<String, dynamic> toJson() => _attributes.isEmpty
? null
: _attributes.map<String, dynamic>((String _, Attribute value) =>
MapEntry<String, dynamic>(value.key, value.value));
MapEntry<String, dynamic>(value.key, value.getValue()));
Iterable<String> get keys => _attributes.keys;
@ -54,7 +54,7 @@ class Style {
Style merge(Attribute attribute) {
Map<String, Attribute> merged = Map<String, Attribute>.from(_attributes);
if (attribute.value == null) {
if (attribute.getValue() == null) {
merged.remove(attribute.key);
} else {
merged[attribute.key] = attribute;

@ -79,7 +79,7 @@ class PreserveBlockStyleOnInsertRule extends InsertRule {
return null;
}
var blockStyle = <String, dynamic>{attribute.key: attribute.value};
var blockStyle = <String, dynamic>{attribute.key: attribute.getValue()};
Map<String, dynamic> resetStyle;

@ -298,7 +298,7 @@ class _QuillEditorSelectionGestureDetectorBuilder
if (getEditor().widget.readOnly) {
getEditor()
.widget
.onLaunchUrl(segment.style.attributes[Attribute.link.key].value);
.onLaunchUrl(segment.style.attributes[Attribute.link.key].getValue());
}
}
}

@ -609,7 +609,7 @@ class RawEditorState extends EditorState
Line line, DefaultStyles defaultStyles) {
Map<String, Attribute> attrs = line.style.attributes;
if (attrs.containsKey(Attribute.header.key)) {
int level = attrs[Attribute.header.key].value;
int level = attrs[Attribute.header.key].getValue();
switch (level) {
case 1:
return defaultStyles.h1.verticalSpacing;

@ -145,7 +145,7 @@ class EditableTextBlock extends StatelessWidget {
Map<String, Attribute> attrs = block.style.attributes;
if (attrs.containsKey(Attribute.header.key)) {
int level = attrs[Attribute.header.key].value;
int level = attrs[Attribute.header.key].getValue();
switch (level) {
case 1:
top = defaultStyles.h1.verticalSpacing.item1;

Loading…
Cancel
Save