diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/elements/ImageElement.java b/domino-ui/src/main/java/org/dominokit/domino/ui/elements/ImageElement.java index 0231ea4fe..6db5ed674 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/elements/ImageElement.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/elements/ImageElement.java @@ -54,4 +54,15 @@ public static ImageElement of(HTMLImageElement e) { public ImageElement(HTMLImageElement element) { super(element); } + + /** + * Sets the src for the image element + * + * @param src String image source + * @return same component + */ + public ImageElement src(String src) { + setAttribute("src", src); + return this; + } } diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/Radio.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/Radio.java index beb23542f..d0b807525 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/Radio.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/Radio.java @@ -101,7 +101,6 @@ public Radio(T value, String label) { inputElement.addEventListener( "change", evt -> { - DomGlobal.console.info("CHANGEEEEEEEED.!"); if (isEnabled() && !isReadOnly()) { setChecked(isChecked(), isChangeListenersPaused()); } diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/icons/LabeledIcon.java b/domino-ui/src/main/java/org/dominokit/domino/ui/icons/LabeledIcon.java index b2ab41d13..44e615325 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/icons/LabeledIcon.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/icons/LabeledIcon.java @@ -22,6 +22,7 @@ import elemental2.dom.HTMLElement; import org.dominokit.domino.ui.elements.SpanElement; import org.dominokit.domino.ui.style.WavesElement; +import org.dominokit.domino.ui.utils.ChildHandler; /** * A component that combines an icon and a text label, allowing you to create labeled icons with @@ -30,6 +31,8 @@ public class LabeledIcon extends WavesElement { private final SpanElement element; + private final SpanElement textElement; + private final Icon icon; /** * Creates a labeled icon with the provided icon and text, positioned to the left. @@ -52,8 +55,9 @@ public LabeledIcon(Icon icon, String text, IconPosition position) { element = span() .addCss(dui_labeled_icon) - .appendChild(icon) - .appendChild(span().addCss(dui_icon_text, dui_text_ellipsis).textContent(text)); + .appendChild(this.icon = icon) + .appendChild( + textElement = span().addCss(dui_icon_text, dui_text_ellipsis).textContent(text)); init(this); position.apply(this); } @@ -82,6 +86,50 @@ public static LabeledIcon create(Icon icon, String text, IconPosition positio return new LabeledIcon(icon, text, position); } + /** + * Changes the text of the labeled icon + * + * @param text the new text. + * @return same component + */ + public LabeledIcon setText(String text) { + this.textElement.setTextContent(text); + return this; + } + + /** + * Apply a handler to the labeledIcon text element. + * + * @param handler the handler to be applied + * @return same component + */ + public LabeledIcon withTextElement(ChildHandler handler) { + handler.apply(this, textElement); + return this; + } + + /** + * Apply a handler to the labeledIcon icon element. + * + * @param handler the handler to be applied + * @return same component + */ + public LabeledIcon withIcon(ChildHandler> handler) { + handler.apply(this, icon); + return this; + } + + /** + * Applies a new position for the labeledIcon text. + * + * @param position The new position to be applied + * @return same component. + */ + public LabeledIcon setIconPosition(IconPosition position) { + position.apply(this); + return this; + } + /** @dominokit-site-ignore {@inheritDoc} */ @Override public HTMLElement element() { diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/BodyObserver.java b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/BodyObserver.java index f4b195222..e3479b497 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/BodyObserver.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/BodyObserver.java @@ -24,13 +24,16 @@ import elemental2.core.JsArray; import elemental2.dom.CustomEvent; import elemental2.dom.CustomEventInit; +import elemental2.dom.Element; import elemental2.dom.Event; import elemental2.dom.HTMLElement; import elemental2.dom.MutationObserver; import elemental2.dom.MutationObserverInit; import elemental2.dom.MutationRecord; import elemental2.dom.Node; +import java.util.HashSet; import java.util.List; +import java.util.Set; import jsinterop.base.Js; /** @@ -96,52 +99,64 @@ private static void observe() { private static void onElementsAppended(MutationRecord record) { List nodes = record.addedNodes.asList(); + Set processed = new HashSet<>(); for (int i = 0; i < nodes.size(); i++) { Node elementNode = Js.uncheckedCast(nodes.get(i)); if (Node.ELEMENT_NODE == elementNode.nodeType) { HTMLElement element = Js.uncheckedCast(elementNode); + List> childElements = + elements.elementOf(element).querySelectorAll("[" + ATTACH_UID_KEY + "]"); if (element.hasAttribute(ATTACH_UID_KEY)) { - element.dispatchEvent( - new CustomEvent<>(AttachDetachEventType.attachedType(elements.elementOf(element)))); + String type = AttachDetachEventType.attachedType(elements.elementOf(element)); + if (!processed.contains(type)) { + processed.add(type); + element.dispatchEvent(new CustomEvent<>(type)); + } } - elements - .elementOf(element) - .querySelectorAll("[" + ATTACH_UID_KEY + "]") - .forEach( - child -> { - CustomEventInit ceinit = CustomEventInit.create(); - ceinit.setDetail(record); - CustomEvent event = - new CustomEvent<>( - AttachDetachEventType.attachedType(elements.elementOf(child)), ceinit); - child.element().dispatchEvent(event); - }); + + childElements.forEach( + child -> { + CustomEventInit ceinit = CustomEventInit.create(); + ceinit.setDetail(record); + String type = AttachDetachEventType.attachedType(elements.elementOf(child)); + if (!processed.contains(type)) { + processed.add(type); + CustomEvent event = new CustomEvent<>(type, ceinit); + child.element().dispatchEvent(event); + } + }); } } } private static void onElementsRemoved(MutationRecord record) { List nodes = record.removedNodes.asList(); + Set processed = new HashSet<>(); for (int i = 0; i < nodes.size(); i++) { Node elementNode = Js.uncheckedCast(nodes.get(i)); if (Node.ELEMENT_NODE == elementNode.nodeType) { HTMLElement element = Js.uncheckedCast(elementNode); + List> childElements = + elements.elementOf(element).querySelectorAll("[" + DETACH_UID_KEY + "]"); if (element.hasAttribute(DETACH_UID_KEY)) { - element.dispatchEvent( - new Event(AttachDetachEventType.detachedType(elements.elementOf(element)))); + String type = AttachDetachEventType.detachedType(elements.elementOf(element)); + if (!processed.contains(type)) { + processed.add(type); + element.dispatchEvent(new Event(type)); + } } - elements - .elementOf(element) - .querySelectorAll("[" + DETACH_UID_KEY + "]") - .forEach( - child -> { - CustomEventInit ceinit = CustomEventInit.create(); - ceinit.setDetail(record); - CustomEvent event = - new CustomEvent<>( - AttachDetachEventType.detachedType(elements.elementOf(child)), ceinit); - child.element().dispatchEvent(event); - }); + + childElements.forEach( + child -> { + String type = AttachDetachEventType.detachedType(elements.elementOf(child)); + if (!processed.contains(type)) { + processed.add(type); + CustomEventInit ceinit = CustomEventInit.create(); + ceinit.setDetail(record); + CustomEvent event = new CustomEvent<>(type, ceinit); + child.element().dispatchEvent(event); + } + }); } } } diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/Clipboard.java b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/Clipboard.java index 4b716e44d..04045061d 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/Clipboard.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/Clipboard.java @@ -16,10 +16,13 @@ package org.dominokit.domino.ui.utils; import elemental2.core.JsArray; +import elemental2.dom.DomGlobal; import elemental2.promise.Promise; +import jsinterop.annotations.JsOverlay; import jsinterop.annotations.JsPackage; import jsinterop.annotations.JsType; import jsinterop.base.Any; +import jsinterop.base.Js; /** * A class for interacting with the clipboard to read and write data. @@ -59,4 +62,24 @@ public class Clipboard { * @return A promise that resolves when the text data is successfully written to the clipboard. */ public native Promise writeText(String text); + + @JsOverlay + public static Promise> get() { + return Js.uncheckedCast(DomGlobal.window.navigator).clipboard.read(); + } + + @JsOverlay + public static Promise getText() { + return Js.uncheckedCast(DomGlobal.window.navigator).clipboard.readText(); + } + + @JsOverlay + public static Promise put(ClipboardItem item) { + return Js.uncheckedCast(DomGlobal.window.navigator).clipboard.write(item); + } + + @JsOverlay + public static Promise put(String text) { + return Js.uncheckedCast(DomGlobal.window.navigator).clipboard.writeText(text); + } }