Skip to content

Commit

Permalink
Merge branch 'main' into feature/react19
Browse files Browse the repository at this point in the history
  • Loading branch information
mshabarov authored Oct 7, 2024
2 parents f5793c9 + 747f7fe commit 68fe339
Show file tree
Hide file tree
Showing 59 changed files with 1,452 additions and 203 deletions.
12 changes: 6 additions & 6 deletions flow-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dnd.internal.DndUtil;
import com.vaadin.flow.dom.Element;
import com.vaadin.flow.internal.nodefeature.VirtualChildrenList;
import com.vaadin.flow.shared.Registration;

/**
Expand Down Expand Up @@ -300,6 +301,96 @@ default EffectAllowed getEffectAllowed() {
.toUpperCase(Locale.ENGLISH)));
}

/**
* Sets the drag image for the current drag source element. The image is
* applied automatically in the next drag start event in the browser. Drag
* image is shown by default with zero offset which means that pointer
* location is in the top left corner of the image.
* <p>
* {@code com.vaadin.flow.component.html.Image} is fully supported as a drag
* image component. Other components can be used as well, but the support
* may vary between browsers. If given component is visible element in the
* viewport, browser can show it as a drag image.
*
* @see <a href=
* "https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/setDragImage">
* MDN web docs</a> for more information.
* @param dragImage
* the image to be used as drag image or null to remove it
*/
default void setDragImage(Component dragImage) {
setDragImage(dragImage, 0, 0);
}

/**
* Sets the drag image for the current drag source element. The image is
* applied automatically in the next drag start event in the browser.
* Coordinates define the offset of the pointer location from the top left
* corner of the image.
* <p>
* {@code com.vaadin.flow.component.html.Image} is fully supported as a drag
* image component. Other components can be used as well, but the support
* may vary between browsers. If given component is visible element in the
* viewport, browser can show it as a drag image.
*
* @see <a href=
* "https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/setDragImage">
* MDN web docs</a> for more information.
* @param dragImage
* the image to be used as drag image or null to remove it
* @param offsetX
* the x-offset of the drag image
* @param offsetY
* the y-offset of the drag image
*/
default void setDragImage(Component dragImage, int offsetX, int offsetY) {
if (getDragImage() != null && getDragImage() != dragImage) {
// Remove drag image from the virtual children list if it's there.
if (getDraggableElement().getNode()
.hasFeature(VirtualChildrenList.class)) {
VirtualChildrenList childrenList = getDraggableElement()
.getNode().getFeature(VirtualChildrenList.class);
// dodging exception with empty list
if (childrenList.size() > 0) {
getDraggableElement()
.removeVirtualChild(getDragImage().getElement());
}
}
}
if (dragImage != null && !dragImage.isAttached()) {
if (!getDragSourceComponent().isAttached()) {
getDragSourceComponent().addAttachListener(event -> {
if (!dragImage.isAttached()
&& dragImage.getParent().isEmpty()) {
getDraggableElement()
.appendVirtualChild(dragImage.getElement());
}
event.unregisterListener();
});
} else {
getDraggableElement()
.appendVirtualChild(dragImage.getElement());
}
}
ComponentUtil.setData(getDragSourceComponent(),
DndUtil.DRAG_SOURCE_IMAGE, dragImage);
getDraggableElement().executeJs(
"window.Vaadin.Flow.dndConnector.setDragImage($0, $1, $2, $3)",
dragImage, (dragImage == null ? 0 : offsetX),
(dragImage == null ? 0 : offsetY), getDraggableElement());
}

/**
* Get server side drag image. This image is applied automatically in the
* next drag start event in the browser.
*
* @return Server side drag image if set, otherwise {@literal null}.
*/
default Component getDragImage() {
return (Component) ComponentUtil.getData(getDragSourceComponent(),
DndUtil.DRAG_SOURCE_IMAGE);
}

/**
* Attaches dragstart listener for the current drag source. The listener is
* triggered when dragstart event happens on the client side.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public class DndUtil {
*/
public static final String DRAG_SOURCE_DATA_KEY = "drag-source-data";

/**
* Key for storing server side drag image for a
* {@link com.vaadin.flow.component.dnd.DragSource}.
*/
public static final String DRAG_SOURCE_IMAGE = "drag-source-image";

/**
* Key for storing an internal drag start listener registration for a
* {@link com.vaadin.flow.component.dnd.DragSource}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ window.Vaadin.Flow.dndConnector = {
}
event.currentTarget.classList.add('v-dragged');
}
if(event.currentTarget.__dragImage) {
event.dataTransfer.setDragImage(
event.currentTarget.__dragImage,
event.currentTarget.__dragImageOffsetX,
event.currentTarget.__dragImageOffsetY);
}
},

__dragendListener: function (event) {
Expand All @@ -106,5 +112,11 @@ window.Vaadin.Flow.dndConnector = {
element.removeEventListener('dragstart', this.__dragstartListener, false);
element.removeEventListener('dragend', this.__dragendListener, false);
}
},

setDragImage: function (dragImage, offsetX, offsetY, dragSource) {
dragSource.__dragImage = dragImage;
dragSource.__dragImageOffsetX = offsetX;
dragSource.__dragImageOffsetY = offsetY;
}
};
23 changes: 12 additions & 11 deletions flow-plugins/flow-gradle-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is the official Vaadin Gradle Plugin for Vaadin 19 and newer.
The implementation is based on `flow-plugin-base` which is also used by the Vaadin Maven plugin.

Prerequisites:
* Java 8 or higher
* Java 17 or higher
* node.js and npm. Vaadin will now automatically install node.js and npm, but you can also install those locally:
* Windows/Mac: [node.js Download site](https://nodejs.org/en/download/)
* Linux: Use package manager e.g. `sudo apt install npm`
Expand All @@ -23,7 +23,7 @@ You need to add the following lines to your `build.gradle` file

```
plugins {
id 'com.vaadin' version '0.8.0'
id 'com.vaadin'
}
```

Expand All @@ -32,16 +32,17 @@ plugins {
Please follow this chart to learn which Plugin version to use with particular Vaadin version.
Vaadin recommends using the latest Vaadin LTS (Long-Term Support) version.

| Vaadin Gradle Plugin version | Supports |
|------------------------------|----------|
| - | Vaadin 13 and lower are unsupported |
| 0.6.0 and lower | Vaadin 14.1.x LTS and lower |
| 0.7.0 | Vaadin 14.2.x LTS |
| Vaadin Gradle Plugin version | Supports |
|------------------------------|------------------------------------------------|
| - | Vaadin 13 and lower are unsupported |
| 0.6.0 and lower | Vaadin 14.1.x LTS and lower |
| 0.7.0 | Vaadin 14.2.x LTS |
| 0.14.3.7 | All other Vaadin 14 LTS versions (recommended) |
| - | Vaadin 15 and 16 are unsupported |
| 0.17.0.1 | Vaadin 17 and higher |
| 0.20.0.0.alpha3 | experimental support for Vaadin 19 and 20 |
| 20.0.0 | Vaadin 20 and higher |
| - | Vaadin 15 and 16 are unsupported |
| 0.17.0.1 | Vaadin 17 and higher |
| 0.20.0.0.alpha3 | experimental support for Vaadin 19 and 20 |
| 20.0.0 | Vaadin 20 and higher |
| 24.0.0 | Vaadin 24 and higher |

## Tasks

Expand Down
2 changes: 1 addition & 1 deletion flow-plugins/flow-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ publishing {
*
**********************************************************************************************************************/
wrapper {
gradleVersion = '8.5'
gradleVersion = '8.7'
distributionType = Wrapper.DistributionType.ALL
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ object OsUtils {
* Used to test the plugin. Contains helpful utility methods to manipulate folders
* and files in the project.
*/
class TestProject(val gradleVersion: String = if(JavaVersion.current().majorVersion.toInt() >= 20) "8.3" else VaadinPlugin.GRADLE_MINIMUM_SUPPORTED_VERSION) {
class TestProject(val gradleVersion: String = VaadinPlugin.GRADLE_MINIMUM_SUPPORTED_VERSION) {
/**
* The project root dir.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,26 +464,36 @@ class VaadinSmokeTest : AbstractGradleTest() {
setup()
}

for (supportedVersion in arrayOf(VaadinPlugin.GRADLE_MINIMUM_SUPPORTED_VERSION, "8.5", "8.6") ) {
for (supportedVersion in arrayOf(VaadinPlugin.GRADLE_MINIMUM_SUPPORTED_VERSION, "8.8", "8.10") ) {
setupProjectForGradleVersion(supportedVersion)
val result = testProject.build("vaadinClean")
result.expectTaskSucceded("vaadinClean")
}

for (unsupportedVersion in arrayOf("8.3")) {
for (unsupportedVersion in arrayOf("8.3", "8.4", "8.5", "8.6")) {
setupProjectForGradleVersion(unsupportedVersion)
val result = testProject.buildAndFail("vaadinClean")
assertContains(
result.output,
"requires Gradle ${VaadinPlugin.GRADLE_MINIMUM_SUPPORTED_VERSION} or later",
true,
"Expecting plugin execution to fail for version ${unsupportedVersion} " +
"as it is lower than the supported one (${VaadinPlugin.GRADLE_MINIMUM_SUPPORTED_VERSION})"
)
assertContains(
result.output,
"current version is ${unsupportedVersion}"
)
if (result.output.contains("Unsupported class file major version")) {
assertContains(
result.output,
Regex("Failed to process the entry 'META-INF/versions/(\\d+)/com/fasterxml/jackson/"),
"Expecting plugin execution to fail for version ${unsupportedVersion} " +
"as it is lower than the supported one (${VaadinPlugin.GRADLE_MINIMUM_SUPPORTED_VERSION}) " +
"and it is incompatible with Jackson library used by Flow"
)
} else {
assertContains(
result.output,
"requires Gradle ${VaadinPlugin.GRADLE_MINIMUM_SUPPORTED_VERSION} or later",
true,
"Expecting plugin execution to fail for version ${unsupportedVersion} " +
"as it is lower than the supported one (${VaadinPlugin.GRADLE_MINIMUM_SUPPORTED_VERSION})"
)
assertContains(
result.output,
"current version is ${unsupportedVersion}"
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.gradle.util.GradleVersion
*/
public class VaadinPlugin : Plugin<Project> {
public companion object {
public const val GRADLE_MINIMUM_SUPPORTED_VERSION: String = "8.4"
public const val GRADLE_MINIMUM_SUPPORTED_VERSION: String = "8.7"
}

override fun apply(project: Project) {
Expand Down
8 changes: 1 addition & 7 deletions flow-server/src/main/java/com/vaadin/flow/component/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2056,13 +2056,7 @@ private void handleNavigation(Location location,
} catch (Exception exception) {
handleExceptionNavigation(location, exception);
} finally {
if (getInternals().getSession().getConfiguration().isReactEnabled()
&& getInternals().getContinueNavigationAction() != null) {
getInternals().clearLastHandledNavigation();
} else {
getInternals().clearLastHandledNavigation();
}

getInternals().clearLastHandledNavigation();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ protected Optional<Integer> handleTriggeredBeforeEvent(

@Override
protected boolean shouldPushHistoryState(NavigationEvent event) {
if (event.getUI().getInternals().getSession().getConfiguration()
.isReactEnabled()) {
if (event.getUI().getInternals().getSession().getService()
.getDeploymentConfiguration().isReactEnabled()) {
return super.shouldPushHistoryState(event);
}
if (NavigationTrigger.CLIENT_SIDE.equals(event.getTrigger())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,8 @@ public void showRouteTarget(Location viewLocation, Component target,
}
previous = current;
}
if (getSession().getConfiguration().isReactEnabled()
if (getSession().getService().getDeploymentConfiguration()
.isReactEnabled()
&& getRouter().getRegistry()
.getNavigationTarget(viewLocation.getPath()).isEmpty()
&& target instanceof RouterLayout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public void pushState(JsonValue state, Location location,
location);
// Second parameter is title which is currently ignored according to
// https://developer.mozilla.org/en-US/docs/Web/API/History_API
if (ui.getSession().getConfiguration().isReactEnabled()) {
if (ui.getSession().getService().getDeploymentConfiguration()
.isReactEnabled()) {
ui.getPage().executeJs(
"window.dispatchEvent(new CustomEvent('vaadin-navigate', { detail: { state: $0, url: $1, replace: false, callback: $2 } }));",
state, pathWithQueryParameters, callback);
Expand Down Expand Up @@ -314,7 +315,8 @@ public void replaceState(JsonValue state, Location location,
location);
// Second parameter is title which is currently ignored according to
// https://developer.mozilla.org/en-US/docs/Web/API/History_API
if (ui.getSession().getConfiguration().isReactEnabled()) {
if (ui.getSession().getService().getDeploymentConfiguration()
.isReactEnabled()) {
ui.getPage().executeJs(
"window.dispatchEvent(new CustomEvent('vaadin-navigate', { detail: { state: $0, url: $1, replace: true, callback: $2 } }));",
state, pathWithQueryParameters, callback);
Expand Down
Loading

0 comments on commit 68fe339

Please sign in to comment.