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

v2.5.4 #34

Merged
merged 1 commit into from
Apr 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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 2.5.4

- New `UIComponentDOMContext`.

- `UIDOMGenerator`:
- Optimize `attachFutureElement` using `UIComponentDOMContext.uiComponent` to resolve `parentComponent`.

- mercury_client: ^2.2.2
- test: ^1.25.3
- test_api: ^0.7.1
- test_core: ^0.6.1
- build_web_compilers: ^4.0.10
- build_runner: ^2.4.9

## 2.5.3

- `testUI`:
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.3';
static const String version = '2.5.4';
}
66 changes: 40 additions & 26 deletions lib/src/bones_ui_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,9 @@
List<dynamic> toContentElements(dynamic rendered,
{bool append = false, bool parseAttributes = true}) {
try {
var list = _toContentElementsImpl(rendered, append);
var domContext = UIComponentDOMContext(this, domGenerator.domContext);

var list = _toContentElementsImpl(rendered, append, domContext);

if (parseAttributes) {
_parseAttributes(content!.children);
Expand Down Expand Up @@ -1450,7 +1452,8 @@

static final _listDynamicRuntimeType = <dynamic>[].runtimeType;

List<dynamic>? toRenderableList(Object? list) {
List<dynamic>? toRenderableList(Object? list,
[DOMContext<UINode>? domContext]) {
if (list == null) return null;

List<dynamic> renderableList;
Expand Down Expand Up @@ -1483,8 +1486,9 @@
return renderableList;
}

List<dynamic> _toContentElementsImpl(Object? rendered, bool append) {
var renderableList = toRenderableList(rendered);
List<dynamic> _toContentElementsImpl(
Object? rendered, bool append, DOMContext<UINode>? domContext) {
var renderableList = toRenderableList(rendered, domContext);

var content = this.content!;

Expand All @@ -1499,14 +1503,14 @@
if (isListOfStrings(renderableList)) {
var html = renderableList.join('\n');

var values = _normalizeRenderListValue(content, html);
var values = _normalizeRenderListValue(content, html, domContext);

var nodes = (values is List
? values
: (values is Iterable ? values.toList() : [values]))
.expand((e) => e is List ? e : [e])
.map((e) {
return _normalizeRenderListValue(content, e);
return _normalizeRenderListValue(content, e, domContext);
})
.cast<UINode>()
.toList();
Expand Down Expand Up @@ -1534,22 +1538,27 @@
var prevElemIndex = -1;

for (var value in renderableList) {
prevElemIndex = _buildRenderList(value, renderedList2, prevElemIndex);
prevElemIndex =
_buildRenderList(value, renderedList2, prevElemIndex, domContext);
}

return renderedList2;
}
}

dynamic _normalizeRenderListValue(UIElement? content, value) {
dynamic _normalizeRenderListValue(
UIElement? content, value, DOMContext<UINode>? domContext) {
if (value is DOMNode) {
return value.buildDOM(generator: domGenerator, parent: content);
return value.buildDOM(
generator: domGenerator, parent: content, context: domContext);
} else if (value is AsDOMElement) {
var element = value.asDOMElement;
return element.buildDOM(generator: domGenerator, parent: content);
return element.buildDOM(
generator: domGenerator, parent: content, context: domContext);

Check warning on line 1557 in lib/src/bones_ui_component.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_ui_component.dart#L1556-L1557

Added lines #L1556 - L1557 were not covered by tests
} else if (value is AsDOMNode) {
var node = value.asDOMNode;
return node.buildDOM(generator: domGenerator, parent: content);
return node.buildDOM(
generator: domGenerator, parent: content, context: domContext);

Check warning on line 1561 in lib/src/bones_ui_component.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_ui_component.dart#L1561

Added line #L1561 was not covered by tests
} else if (value is String) {
var nodes = $html(value);
return nodes;
Expand Down Expand Up @@ -1579,12 +1588,12 @@
}
}

int _buildRenderList(
dynamic value, List<dynamic> renderedList, int prevElemIndex) {
int _buildRenderList(dynamic value, List<dynamic> renderedList,
int prevElemIndex, DOMContext<UINode>? domContext) {
if (value == null) return prevElemIndex;
var content = this.content;

value = _normalizeRenderListValue(content, value);
value = _normalizeRenderListValue(content, value, domContext);

if (value is UINode) {
prevElemIndex =
Expand All @@ -1596,17 +1605,19 @@
prevElemIndex = _addElementToRenderList(
value, value.content!, renderedList, prevElemIndex);
} else if (value is UIAsyncContent) {
prevElemIndex =
_addUIAsyncContentToRenderList(value, renderedList, prevElemIndex);
prevElemIndex = _addUIAsyncContentToRenderList(
value, renderedList, prevElemIndex, domContext);
} else if (value is List) {
for (var elem in value) {
prevElemIndex = _buildRenderList(elem, renderedList, prevElemIndex);
prevElemIndex =
_buildRenderList(elem, renderedList, prevElemIndex, domContext);
}
} else if (value is Function) {
try {
// ignore: avoid_dynamic_calls
var result = value();
prevElemIndex = _buildRenderList(result, renderedList, prevElemIndex);
prevElemIndex =
_buildRenderList(result, renderedList, prevElemIndex, domContext);
} catch (e, s) {
UIConsole.error('Error calling function: $value', e, s);
}
Expand Down Expand Up @@ -1643,7 +1654,8 @@

bool get isLoadingUIAsyncContent => _loadingAsyncContents.isNotEmpty;

void _resolveUIAsyncContentLoaded(UIAsyncContent asyncContent) {
void _resolveUIAsyncContentLoaded(
UIAsyncContent asyncContent, DOMContext<UINode>? domContext) {
if (!asyncContent.isLoaded) return;

if (asyncContent.isLoaded && !asyncContent.hasAutoRefresh) {
Expand Down Expand Up @@ -1693,7 +1705,8 @@

var renderedList = [];
if (maxContentIdx == null || maxContentIdx >= content!.nodes.length) {
_buildRenderList(loadedContent, renderedList, content!.nodes.length - 1);
_buildRenderList(
loadedContent, renderedList, content!.nodes.length - 1, domContext);

_renderedElements!.addAll(renderedList);
} else {
Expand All @@ -1702,7 +1715,8 @@
content!.nodes.remove(e);
}

_buildRenderList(loadedContent, renderedList, content!.nodes.length - 1);
_buildRenderList(

Check warning on line 1718 in lib/src/bones_ui_component.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_ui_component.dart#L1718

Added line #L1718 was not covered by tests
loadedContent, renderedList, content!.nodes.length - 1, domContext);

if (tail.isNotEmpty) {
var renderedComponents = renderedList
Expand Down Expand Up @@ -1734,14 +1748,14 @@
_callPosAsyncRender();
}

int _addUIAsyncContentToRenderList(
UIAsyncContent asyncContent, List renderedList, int prevElemIndex) {
int _addUIAsyncContentToRenderList(UIAsyncContent asyncContent,
List renderedList, int prevElemIndex, DOMContext<UINode>? domContext) {
if (!asyncContent.isLoaded ||
asyncContent.isExpired ||
asyncContent.hasAutoRefresh) {
_loadingAsyncContents.add(asyncContent);
asyncContent.onLoadContent.listen((c) {
_resolveUIAsyncContentLoaded(asyncContent);
_resolveUIAsyncContentLoaded(asyncContent, domContext);
}, singletonIdentifier: this);
}

Expand All @@ -1755,8 +1769,8 @@

var renderIdx = renderedList.length;

prevElemIndex =
_buildRenderList(asyncContent.content, renderedList, prevElemIndex);
prevElemIndex = _buildRenderList(
asyncContent.content, renderedList, prevElemIndex, domContext);

var rendered = renderedList.sublist(renderIdx).toList();

Expand Down
22 changes: 20 additions & 2 deletions lib/src/bones_ui_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,18 @@
}
}

class UIComponentDOMContext extends DOMContext<UINode> {
final UIComponent uiComponent;

UIComponentDOMContext(this.uiComponent, DOMContext<UINode>? parent)
: super(parent: parent, intlMessageResolver: parent?.intlMessageResolver);

@override
String toString() {

Check warning on line 310 in lib/src/bones_ui_generator.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_ui_generator.dart#L310

Added line #L310 was not covered by tests
return 'UIComponentDOMContext{viewport: $viewport, resolveCSSViewportUnit: $resolveCSSViewportUnit resolveCSSURL: $resolveCSSURL}@$uiComponent';
}

Check warning on line 312 in lib/src/bones_ui_generator.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_ui_generator.dart#L312

Added line #L312 was not covered by tests
}

/// A [DOMGenerator] (from package `dom_builder`)
/// able to generate [UIElement] (from `dart:html`).
class UIDOMGenerator extends DOMGeneratorDartHTMLImpl {
Expand Down Expand Up @@ -438,8 +450,14 @@
futureElementResolved, treeMap, context);

if (futureElementResolved is UIElement) {
var parentComponent =
UIRoot.getInstance()!.findUIComponentByChild(futureElementResolved);
UIComponent? parentComponent;

if (context is UIComponentDOMContext) {
parentComponent = context.uiComponent;

Check warning on line 456 in lib/src/bones_ui_generator.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_ui_generator.dart#L456

Added line #L456 was not covered by tests
} else {
parentComponent =
UIRoot.getInstance()!.findUIComponentByChild(futureElementResolved);

Check warning on line 459 in lib/src/bones_ui_generator.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_ui_generator.dart#L459

Added line #L459 was not covered by tests
}

if (parentComponent != null) {
parentComponent.componentInternals
Expand Down
14 changes: 7 additions & 7 deletions 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.3
version: 2.5.4
homepage: https://github.com/Colossus-Services/bones_ui

environment:
Expand All @@ -18,7 +18,7 @@ dependencies:
json_object_mapper: ^2.0.1
swiss_knife: ^3.2.0
statistics: ^1.1.0
mercury_client: ^2.2.1
mercury_client: ^2.2.2
dynamic_call: ^2.0.1
project_template: ^1.1.0
resource_portable: ^3.1.0
Expand All @@ -33,16 +33,16 @@ dependencies:
args: ^2.4.2
logging: ^1.2.0
path: ^1.9.0
test: ^1.25.2
test_api: ^0.7.0
test_core: ^0.6.0
test: ^1.25.3
test_api: ^0.7.1
test_core: ^0.6.1
stream_channel: ^2.1.2
stack_trace: ^1.11.1


dev_dependencies:
build_web_compilers: ^4.0.9
build_runner: ^2.4.8
build_web_compilers: ^4.0.10
build_runner: ^2.4.9
lints: ^3.0.0
dependency_validator: ^3.2.3

Expand Down
Loading