Skip to content

Commit

Permalink
v2.2.1
Browse files Browse the repository at this point in the history
- `DOMHtmlBrowser`:
  - Fix `toDOMElement` for `checkbox`.
- `$checkbox`: added parameter `checked`.
- `WithValue`:
  - Changed from interface to mixin.
  - Added `valueAsBool`, `valueAsInt`, `valueAsDouble`, `valueAsNum`.

- dependency_validator: ^3.2.3
  • Loading branch information
gmpassos committed Sep 28, 2023
1 parent f8452c5 commit 1cbc5dc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
- `DOMHtmlBrowser`:
- Fix `toDOMElement` for `checkbox`.
- `$checkbox`: added parameter `checked`.
- `WithValue`:
- Changed from interface to mixin.
- Added `valueAsBool`, `valueAsInt`, `valueAsDouble`, `valueAsNum`.

- dependency_validator: ^3.2.3

Expand Down
2 changes: 1 addition & 1 deletion lib/src/dom_builder_attribute.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'dom_builder_template.dart';
import 'dom_builder_treemap.dart';

/// Represents a [DOMElement] attribute entry (`name` and [DOMAttributeValue]).
class DOMAttribute implements WithValue {
class DOMAttribute with WithValue {
static final Set<String> _attributesValueAsBoolean = {
'checked',
'hidden',
Expand Down
24 changes: 18 additions & 6 deletions lib/src/dom_builder_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,22 @@ void domBuilderLog(String message,
}
}

abstract class WithValue {
mixin WithValue {
bool get hasValue;

String? get value;

/// Returns [value] as [bool].
bool? get valueAsBool => parseBool(value);

/// Returns [value] as [bool].
int? get valueAsInt => parseInt(value);

/// Returns [value] as [double].
double? get valueAsDouble => parseDouble(value);

/// Returns [value] as [num].
num? get valueAsNum => parseNum(value);
}

//
Expand Down Expand Up @@ -1194,7 +1206,7 @@ class DOMNode implements AsDOMNode {
}

/// Represents a text node in DOM.
class TextNode extends DOMNode implements WithValue {
class TextNode extends DOMNode with WithValue {
static DOMNode toTextNode(String? text) {
if (text == null || text.isEmpty) {
return TextNode('');
Expand Down Expand Up @@ -1334,7 +1346,7 @@ class TextNode extends DOMNode implements WithValue {
}

/// Represents a template node in DOM.
class TemplateNode extends DOMNode implements WithValue {
class TemplateNode extends DOMNode with WithValue {
DOMTemplateNode template;

TemplateNode(this.template) : super._(false, false);
Expand Down Expand Up @@ -2869,7 +2881,7 @@ class DIVElement extends DOMElement {
// INPUTElement:
//

class INPUTElement extends DOMElement implements WithValue {
class INPUTElement extends DOMElement with WithValue {
static INPUTElement? from(Object? entry) {
if (entry == null) return null;
if (_domHTML.isHtmlNode(entry)) {
Expand Down Expand Up @@ -3040,7 +3052,7 @@ class SELECTElement extends DOMElement {
// OPTIONElement:
//

class OPTIONElement extends DOMElement implements WithValue {
class OPTIONElement extends DOMElement with WithValue {
static List<OPTIONElement> toOptions(Object? options) {
if (options == null) return [];
if (options is OPTIONElement) return [options];
Expand Down Expand Up @@ -3178,7 +3190,7 @@ class OPTIONElement extends DOMElement implements WithValue {
// TEXTAREAElement:
//

class TEXTAREAElement extends DOMElement implements WithValue {
class TEXTAREAElement extends DOMElement with WithValue {
static TEXTAREAElement? from(Object? entry) {
if (entry == null) return null;
if (_domHTML.isHtmlNode(entry)) {
Expand Down

0 comments on commit 1cbc5dc

Please sign in to comment.