Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize resolve element value #36

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 2.5.6

- `ElementExtension`:
- `resolveElementValue`: optimize for `InputElement`.
- Added `resolveInputElementValue`.

- `UIComponent`:
- Added `selectElementsValues`

## 2.5.5

- New `UIRootComponent`:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bones_ui.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class BonesUI {
static const String version = '2.5.5';
static const String version = '2.5.6';
}
13 changes: 13 additions & 0 deletions lib/src/bones_ui_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,19 @@ abstract class UIComponent extends UIEventHandler {
List<T> selectElements<T extends UIElement>(String? selectors) =>
querySelectorAll(selectors);

/// Alias to [content.querySelectorAll].
Map<String, String?> selectElementsValues<T extends UIElement>(
String? selectors) {
var entries = selectElements<T>(selectors).map((e) {
var k = e.getAttribute('name')?.trim();
if (k == null || k.isEmpty) {
k = e.id.trim();
}
return MapEntry(k, e.elementValue);
});
return Map.fromEntries(entries);
}

bool clearContent() {
content!.nodes.clear();
return true;
Expand Down
22 changes: 17 additions & 5 deletions lib/src/bones_ui_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ extension ElementExtension on UIElement {
{UIComponent? parentUIComponent,
UIComponent? uiComponent,
bool allowTextAsValue = true}) {
var self = this;

if (self is InputElementBase ||
self is TextAreaElement ||
self is SelectElement) {
return resolveInputElementValue();
}

uiComponent ??= resolveUIComponent(parentUIComponent: parentUIComponent);

if (uiComponent != null) {
Expand All @@ -36,6 +44,14 @@ extension ElementExtension on UIElement {
}
}

var value = self.getAttribute('field_value');
if (isEmptyObject(value) && allowTextAsValue) {
value = self.text;
}
return value;
}

String? resolveInputElementValue() {
var self = this;

if (self is TextAreaElement) {
Expand All @@ -56,11 +72,7 @@ extension ElementExtension on UIElement {
return self.value;
}
} else {
var value = self.getAttribute('field_value');
if (isEmptyObject(value) && allowTextAsValue) {
value = self.text;
}
return value;
return null;
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bones_ui
description: Bones_UI - An intuitive and user-friendly Web User Interface framework for Dart.
version: 2.5.5
version: 2.5.6
homepage: https://github.com/Colossus-Services/bones_ui

environment:
Expand Down
Loading