Skip to content

Commit

Permalink
enhance mutation observer callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Dec 8, 2024
1 parent 71073b9 commit 4e46aab
Show file tree
Hide file tree
Showing 41 changed files with 342 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,20 @@ private void resetTimer() {
}

private void addDetachListener() {
ElementUtil.onDetach(
element(),
mutationRecord -> {
onDetached(
(Carousel, mutationRecord) -> {
this.attached = false;
this.stopAutoSlide();
});
}

private void addAttachListener() {
ElementUtil.onAttach(
this.element(),
mutationRecord -> {
onAttached(
(target, mutationRecord) -> {
this.attached = true;
if (autoSlide) {
timer.scheduleRepeating(autoSlideDuration);
}

addDetachListener();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ChipsGroup appendChild(Chip chip) {
chip.setSelectable(true);
chip.setRemovable(removable || chip.isRemovable());
chip.onDetached(
mutationRecord -> {
(target, mutationRecord) -> {
if (chip.isSelected()) {
chip.deselect();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void collapse(Element element) {
handlers.onCollapseCompleted().run();
} else {
self.onAttached(
mutationRecord -> {
(e, mutationRecord) -> {
this.target.setAttribute(DUI_EXPANDED_HEIGHT, "auto");
this.target.setCssProperty(this.heightVar, "auto");
this.handlers.onBeforeCollapse().run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void collapse(Element element) {
handlers.onCollapseCompleted().run();
} else {
self.onAttached(
mutationRecord -> {
(e, mutationRecord) -> {
this.handlers.onBeforeCollapse().run();
treeItem.addCss(dui_transition_none);
collapseElement(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public DataTable(TableConfig<T> tableConfig, DataStore<T> dataStore) {
initDynamicStyleSheet();
init();
onAttached(
mutationRecord -> {
(e, mutationRecord) -> {
DomGlobal.setTimeout(
p0 -> {
getDynamicStyleSheet().flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void init(DataTable<T> dataTable) {
"col-pin-" + col.getName().replace(" ", "_"));
});
}));
this.datatable.onAttached(mutationRecord -> pinColumns());
this.datatable.onAttached((e, mutationRecord) -> pinColumns());
}

/**
Expand Down Expand Up @@ -485,7 +485,7 @@ private void pinColumns() {
pinColumnsForAttachedTable();
} else {
datatable.onAttached(
mutationRecord -> DomGlobal.setTimeout(p0 -> pinColumnsForAttachedTable()));
(e, mutationRecord) -> DomGlobal.setTimeout(p0 -> pinColumnsForAttachedTable()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ public void onHeaderAdded(DataTable<T> dataTable, ColumnConfig<T> column) {
};

this.datatable.onAttached(
mutationRecord -> {
(e, mutationRecord) -> {
DominoDom.document.body.addEventListener(
EventType.mouseup.getName(), stopResizing);
});
this.datatable.onDetached(
mutationRecord -> {
(e, mutationRecord) -> {
resizeElement.removeEventListener(EventType.mouseup.getName(), stopResizing);
DominoDom.document.body.removeEventListener(
EventType.mouseup.getName(), stopResizing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public WeekDayHeader(IsCalendar calendar, int dayIndex) {
.textContent(
this.calendar.getDateTimeFormatInfo().weekdaysShort()[dayIndex]));
init(this);
onDetached(mutationRecord -> this.calendar.unbindCalenderViewListener(this));
onDetached((e, mutationRecord) -> this.calendar.unbindCalenderViewListener(this));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public DateBox(
popover -> {
withOpenOnFocusToggleListeners(false, field -> focus());
});
onDetached(mutationRecord -> popover.close());
onDetached((e, mutationRecord) -> popover.close());

getInputElement()
.onKeyDown(keyEvents -> keyEvents.onEnter(evt -> doOpen()).onSpace(evt -> doOpen()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public DateRangeBox(
popover -> {
withOpenOnFocusToggleListeners(false, field -> focus());
});
onDetached(mutationRecord -> popover.close());
onDetached((e, mutationRecord) -> popover.close());

getInputElement()
.onKeyDown(keyEvents -> keyEvents.onEnter(evt -> doOpen()).onSpace(evt -> doOpen()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.dominokit.domino.ui.utils.ApplyFunction;
import org.dominokit.domino.ui.utils.ChildHandler;
import org.dominokit.domino.ui.utils.DominoElement;
import org.dominokit.domino.ui.utils.ElementUtil;

/**
* An abstract base class for input form fields in Domino UI. InputFormField represents form fields
Expand Down Expand Up @@ -285,8 +284,12 @@ public void setValue(V value) {
public T focus() {
if (!isDisabled()) {
if (!isAttached()) {
ElementUtil.onAttach(
getInputElement(), mutationRecord -> getInputElement().element().focus());
getInputElement()
.onAttached(
(target, mutationRecord) -> {
getInputElement().element().focus();
});

} else {
getInputElement().element().focus();
}
Expand All @@ -302,11 +305,11 @@ public T focus() {
@Override
public T unfocus() {
if (!isAttached()) {
ElementUtil.onAttach(
getInputElement(),
mutationRecord -> {
getInputElement().element().blur();
});
getInputElement()
.onAttached(
(target, mutationRecord) -> {
getInputElement().element().blur();
});
} else {
getInputElement().element().blur();
}
Expand Down
17 changes: 10 additions & 7 deletions domino-ui/src/main/java/org/dominokit/domino/ui/forms/Radio.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,11 @@ public String getStringValue() {
public Radio<T> focus() {
if (!isDisabled()) {
if (!isAttached()) {
ElementUtil.onAttach(
getInputElement(), mutationRecord -> getInputElement().element().focus());
getInputElement()
.onAttached(
(target, mutationRecord) -> {
getInputElement().element().focus();
});
} else {
getInputElement().element().focus();
}
Expand All @@ -557,11 +560,11 @@ public Radio<T> focus() {
@Override
public Radio<T> unfocus() {
if (!isAttached()) {
ElementUtil.onAttach(
getInputElement(),
mutationRecord -> {
getInputElement().element().blur();
});
getInputElement()
.onAttached(
(target, mutationRecord) -> {
getInputElement().element().blur();
});
} else {
getInputElement().element().blur();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public TextAreaBox() {
header.appendChild(
headerFiller =
FillerElement.create().addCss(dui_form_text_area_header_filler, dui_order_30));
onAttached(mutationRecord -> adjustHeight());
onAttached((e, mutationRecord) -> adjustHeight());
setDefaultValue("");
getInputElement().addCss(dui_h_inherit).setAttribute("data-scroll", "0");
getInputElement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public TimeBox(Date date, DateTimeFormatInfo dateTimeFormatInfo) {
popover -> {
withOpenOnFocusToggleListeners(false, field -> focus());
});
onDetached(mutationRecord -> popover.close());
onDetached((e, mutationRecord) -> popover.close());

getInputElement()
.onKeyDown(keyEvents -> keyEvents.onEnter(evt -> doOpen()).onSpace(evt -> doOpen()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public AbstractSelect() {
.addOpenListener((menu) -> focus());

onAttached(
mutationRecord -> {
(e, mutationRecord) -> {
optionsMenu.setTargetElement(getWrapperElement());
});
getInputElement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public AbstractSuggestBox(SuggestionsStore<T, E, O> store) {
.setRemoveLoadingText(true);

onAttached(
mutationRecord -> {
(e, mutationRecord) -> {
optionsMenu.setTargetElement(getWrapperElement());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public AppLayout() {
init(this);

layout.onAttached(
mutationRecord ->
(e, mutationRecord) ->
layout
.parent()
.addClickListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ public void setLoadingText(String text) {
*/
@Override
public void setSize(String width, String height) {
onAttached(mutationRecord -> loader.setWidth(width).setHeight(height));
onAttached((e, mutationRecord) -> loader.setWidth(width).setHeight(height));
}

/** Removes the loading text from the loader. */
@Override
public void removeLoadingText() {
onAttached(mutationRecord -> loadingText.remove());
onAttached((e, mutationRecord) -> loadingText.remove());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ public void setLoadingText(String text) {
*/
@Override
public void setSize(String width, String height) {
onAttached(mutationRecord -> loader.setWidth(width).setHeight(height));
onAttached((e, mutationRecord) -> loader.setWidth(width).setHeight(height));
}

/** Removes the loading text from the loader. */
@Override
public void removeLoadingText() {
onAttached(mutationRecord -> loadingText.remove());
onAttached((e, mutationRecord) -> loadingText.remove());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ public void setLoadingText(String text) {
*/
@Override
public void setSize(String width, String height) {
onAttached(mutationRecord -> loader.setWidth(width).setHeight(height));
onAttached((e, mutationRecord) -> loader.setWidth(width).setHeight(height));
}

/** Removes the loading text from the loader. */
@Override
public void removeLoadingText() {
onAttached(mutationRecord -> loadingText.remove());
onAttached((e, mutationRecord) -> loadingText.remove());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ public void setLoadingText(String text) {
*/
@Override
public void setSize(String width, String height) {
onAttached(mutationRecord -> loader.setWidth(width).setHeight(height));
onAttached((e, mutationRecord) -> loader.setWidth(width).setHeight(height));
}

/** Removes the loading text from the loader. */
@Override
public void removeLoadingText() {
onAttached(mutationRecord -> loadingText.remove());
onAttached((e, mutationRecord) -> loadingText.remove());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void setSize(String width, String height) {}
/** Removes the loading text from the loader. */
@Override
public void removeLoadingText() {
onAttached(mutationRecord -> loadingText.remove());
onAttached((e, mutationRecord) -> loadingText.remove());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public void setLoadingText(String text) {
*/
@Override
public void setSize(String width, String height) {
onAttached(mutationRecord -> loader.setWidth(width).setHeight(height));
onAttached((e, mutationRecord) -> loader.setWidth(width).setHeight(height));
}

/** Removes the loading text from the loader. */
@Override
public void removeLoadingText() {
onAttached(mutationRecord -> loadingText.remove());
onAttached((e, mutationRecord) -> loadingText.remove());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ public void setLoadingText(String text) {
*/
@Override
public void setSize(String width, String height) {
onAttached(mutationRecord -> loader.setWidth(width).setHeight(height));
onAttached((e, mutationRecord) -> loader.setWidth(width).setHeight(height));
}

/** Removes the loading text from the loader. */
@Override
public void removeLoadingText() {
onAttached(mutationRecord -> loadingText.remove());
onAttached((e, mutationRecord) -> loadingText.remove());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ public void setLoadingText(String text) {
*/
@Override
public void setSize(String width, String height) {
onAttached(mutationRecord -> loader.setWidth(width).setHeight(height));
onAttached((e, mutationRecord) -> loader.setWidth(width).setHeight(height));
}

/** Removes the loading text from the loader. */
@Override
public void removeLoadingText() {
onAttached(mutationRecord -> loadingText.remove());
onAttached((e, mutationRecord) -> loadingText.remove());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ public void setLoadingText(String text) {
*/
@Override
public void setSize(String width, String height) {
onAttached(mutationRecord -> loader.setWidth(width).setHeight(height));
onAttached((e, mutationRecord) -> loader.setWidth(width).setHeight(height));
}

/** Removes the loading text from the loader. */
@Override
public void removeLoadingText() {
onAttached(mutationRecord -> loadingText.remove());
onAttached((e, mutationRecord) -> loadingText.remove());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ public void setLoadingText(String text) {
*/
@Override
public void setSize(String width, String height) {
onAttached(mutationRecord -> loader.setWidth(width).setHeight(height));
onAttached((e, mutationRecord) -> loader.setWidth(width).setHeight(height));
}

/** Removes the loading text from the loader. */
@Override
public void removeLoadingText() {
onAttached(mutationRecord -> loadingText.remove());
onAttached((e, mutationRecord) -> loadingText.remove());
}

/**
Expand Down
Loading

0 comments on commit 4e46aab

Please sign in to comment.