Skip to content
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
54 changes: 26 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.flowingcode.vaadin.addons</groupId>
<artifactId>lite-renderer-addon</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.1.0-SNAPSHOT</version>
<name>Lite Renderer Add-On</name>
<description>Lite Template Renderer for Vaadin Flow</description>
<url>https://www.flowingcode.com/en/open-source/</url>
Expand All @@ -18,8 +18,9 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<drivers.dir>${project.basedir}/drivers</drivers.dir>
<jetty.version>11.0.26</jetty.version>
<flowingcode.commons.demo.version>4.1.0</flowingcode.commons.demo.version>
<flowingcode.commons.demo.version>5.2.0</flowingcode.commons.demo.version>
<frontend.hotdeploy>true</frontend.hotdeploy>
<viritin.version>2.8.26</viritin.version>
</properties>

<organization>
Expand Down Expand Up @@ -75,33 +76,8 @@
<id>Vaadin Directory</id>
<url>https://maven.vaadin.com/vaadin-addons</url>
</repository>
<!-- Repository needed for prerelease versions of Vaadin -->
<repository>
<id>Vaadin prereleases</id>
<url>https://maven.vaadin.com/vaadin-prereleases</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<!-- Repository needed for prerelease versions of Vaadin -->
<pluginRepository>
<id>Vaadin prereleases</id>
<url>https://maven.vaadin.com/vaadin-prereleases</url>
</pluginRepository>
<pluginRepository>
<id>vaadin-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases><enabled>false</enabled></releases>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
Expand All @@ -114,6 +90,11 @@
<version>1.18.34</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.flowingcode.vaadin</groupId>
<artifactId>json-migration-helper</artifactId>
<version>0.9.2</version>
</dependency>
<dependency>
<groupId>com.flowingcode.vaadin.addons.demo</groupId>
<artifactId>commons-demo</artifactId>
Expand All @@ -129,7 +110,7 @@
<dependency>
<groupId>in.virit</groupId>
<artifactId>viritin</artifactId>
<version>2.8.26</version>
<version>${viritin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -522,6 +503,23 @@
</plugins>
</build>
</profile>

<profile>
<id>v25</id>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<vaadin.version>25.0.3</vaadin.version>
<viritin.version>3.1.3</viritin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-dev</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</profile>

</profiles>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Lite Renderer Add-On
* %%
* Copyright (C) 2024 Flowing Code
* Copyright (C) 2024 - 2026 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,23 +19,29 @@
*/
package com.flowingcode.vaadin.addons.litetemplate;

import com.flowingcode.vaadin.jsonmigration.JsonMigration;
import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.data.renderer.LitRenderer;
import com.vaadin.flow.dom.Element;
import com.vaadin.flow.function.SerializableBiConsumer;
import com.vaadin.flow.function.ValueProvider;
import com.vaadin.flow.server.Version;
import elemental.json.JsonArray;
import elemental.json.JsonBoolean;
import elemental.json.JsonNumber;
import elemental.json.JsonString;
import elemental.json.JsonValue;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import lombok.NonNull;
import lombok.SneakyThrows;

final class LitRendererBuilder<SOURCE> {

Expand Down Expand Up @@ -86,13 +92,38 @@ private LitRenderer<SOURCE> build(

String templateExpression = sb.toString() + "\n";
var renderer = LitRenderer.<SOURCE>of(templateExpression);
functions.forEach((n, v) -> renderer.withFunction(n, v));
functions.forEach((n, v) -> withFunction(renderer, n, v));
properties.forEach((n, v) -> renderer.withProperty(n, v));

setTemplateExpression.accept(templateExpression);
return renderer;
}

@SneakyThrows
private LitRenderer<SOURCE> withFunction(LitRenderer<SOURCE> renderer, String name,
SerializableBiConsumer<SOURCE, JsonArray> handler) {
SerializableBiConsumer<SOURCE, ?> c = handler;
if (Version.getMajorVersion() >= 25) {
c = (source, array) -> handler.accept(source,
(JsonArray) JsonMigration.convertToJsonValue(array));
}
return (LitRenderer<SOURCE>) LitRenderer_withFunction.invokeExact(renderer, name, c);
}

private static final MethodHandle LitRenderer_withFunction = lookup_withFunction();

@SneakyThrows
private static MethodHandle lookup_withFunction() {
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodType methodType = MethodType.methodType(
LitRenderer.class,
String.class,
SerializableBiConsumer.class
);

return lookup.findVirtual(LitRenderer.class, "withFunction", methodType);
}

private String addFunction(SerializableBiConsumer<SOURCE, JsonArray> handler) {
String name = "function" + functions.size();
functions.put(name, handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Lite Renderer Add-On
* %%
* Copyright (C) 2024 Flowing Code
* Copyright (C) 2024 - 2026 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
*/
package com.flowingcode.vaadin.addons.litetemplate;

import com.flowingcode.vaadin.jsonmigration.JsonMigration;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.ComponentEventBus;
import com.vaadin.flow.dom.Element;
Expand All @@ -31,6 +32,7 @@
import java.util.List;
import java.util.Map;
import lombok.NonNull;
import lombok.experimental.ExtensionMethod;

/**
* Wrapper around a {@code Component} that provides fluent methods for managing attributes,
Expand All @@ -40,6 +42,7 @@
* @author Javier Godoy
*/
@SuppressWarnings("serial")
@ExtensionMethod(value = JsonMigration.class, suppressBaseMethods = true)
public final class LiteComponent<COMPONENT extends Component> extends Component {

// The wrapped component that is being managed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Lite Renderer Add-On
* %%
* Copyright (C) 2024 Flowing Code
* Copyright (C) 2024 - 2026 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,12 +23,12 @@
}

.lite-renderer-demo-template img {
height: var(--lumo-size-m);
margin-right: var(--lumo-space-s);
height: var(--lumo-size-m, 36px);
margin-right: var(--lumo-space-s, var(--vaadin-padding-s));
aspect-ratio: 1;
}

.lite-renderer-demo-template div div {
font-size: var(--lumo-font-size-s);
color: var(--lumo-secondary-text-color);
font-size: var(--lumo-font-size-s, var(--aura-font-size-s));
color: var(--lumo-secondary-text-color, var(--vaadin-text-color-secondary));
}