diff --git a/README.md b/README.md index 01333c5..7c95075 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ This is the relevant dependency: pl.unforgiven superfields - 0.19.0 + 0.19.1 ``` @@ -65,10 +65,11 @@ The author of the majority of the code is me (Miki), but this project would not * Simon Martinelli * Dmitry Nazukin * Stefan Penndorf +* Sebastian Penttinen * Stuart Robinson * Kaspar Scherrer * Tomi Virkki -* Martin Vysny +* Martin Vyšný * Leif Åstrand ## Support diff --git a/demo-v24/pom.xml b/demo-v24/pom.xml index 0320f24..79aca05 100644 --- a/demo-v24/pom.xml +++ b/demo-v24/pom.xml @@ -4,11 +4,11 @@ superfields-parent pl.unforgiven - 0.19.0 + 0.19.1 superfields-demo-v24 - 0.19.0 + 0.19.1 V24+ demo app for SuperFields Showcase application for V24+ and SuperFields. war @@ -22,7 +22,7 @@ pl.unforgiven superfields - 0.19.0 + 0.19.1 jakarta.servlet @@ -136,11 +136,11 @@ build-frontend compile + + false + - - true - diff --git a/demo-v24/src/main/java/org/vaadin/miki/InfoPage.java b/demo-v24/src/main/java/org/vaadin/miki/InfoPage.java index 4783445..839104a 100644 --- a/demo-v24/src/main/java/org/vaadin/miki/InfoPage.java +++ b/demo-v24/src/main/java/org/vaadin/miki/InfoPage.java @@ -16,7 +16,7 @@ import java.io.IOException; import java.io.InputStream; -import java.util.Locale; +import java.util.Collection; /** * Information about the demo, its organisation and components. @@ -37,12 +37,14 @@ public InfoPage() { new Span("Bottom left corner of the browser window will show major notifications from each component - like value change notifications. Bottom right corner is reserved for secondary notifications, e.g. focus and blur events.") ); + final Collection> types = DemoComponentFactory.get().getDemoableComponentTypes(); final ItemGrid> grid = new ItemGrid>() - .withItems(DemoComponentFactory.get().getDemoableComponentTypes()) + .withItems(types) .withColumnCount(5) .withPaddingCellsClickable(false) .withCellGenerator(this::buildDisplayCell) - .withId("presentation-grid"); + .withId("presentation-grid") + .withLabel("There are %d components with demo pages:".formatted(types.size())); grid.addValueChangeListener(event -> this.getUI() .ifPresent(ui -> ui.navigate( @@ -65,16 +67,14 @@ private Component buildDisplayCell(Class type, int row, int final Div result = new Div(); result.add(new H3(type.getSimpleName())); - try (InputStream resource = this.getClass().getClassLoader().getResourceAsStream(type.getSimpleName().toLowerCase(Locale.ROOT) + ".md")) { + final String resourceName = "/" + type.getSimpleName() + ".md"; + try (InputStream resource = this.getClass().getClassLoader().getResourceAsStream(resourceName)) { if (resource != null) { - try { final Span desc = new Span(new String(resource.readAllBytes())); desc.addClassName("presentation-description"); result.add(desc); - } catch (IOException e) { - LOGGER.error("could not read description for component {}", type.getSimpleName(), e); - } } + else LOGGER.error("did not find resource {}", resourceName); } catch (IOException e) { LOGGER.error("could not open description for component {}", type.getSimpleName(), e); } diff --git a/pom.xml b/pom.xml index c0deaee..d204801 100644 --- a/pom.xml +++ b/pom.xml @@ -1,22 +1,24 @@ - + 4.0.0 pl.unforgiven superfields-parent - 0.19.0 + 0.19.1 superfields demo-v24 SuperFields - Root project for SuperFields - Root project for SuperFields. Includes basic dependencies, repositories and other configuration. + Root project for SuperFields. Includes basic dependencies, repositories and other configuration. + pom 17 17 UTF-8 - 24.3.0 + 24.3.12 \ No newline at end of file diff --git a/superfields/pom.xml b/superfields/pom.xml index 301fd32..c24e288 100644 --- a/superfields/pom.xml +++ b/superfields/pom.xml @@ -9,13 +9,13 @@ SuperFields Code for various Vaadin 24 fields and other components. https://www.unforgiven.pl/superfields - 0.19.0 + 0.19.1 17 17 UTF-8 - 24.3.0 + 24.3.12 3.1.2 3.4.1 diff --git a/superfields/release-notes.md b/superfields/release-notes.md index 0888176..fcd4638 100644 --- a/superfields/release-notes.md +++ b/superfields/release-notes.md @@ -1,3 +1,11 @@ +# 0.19.1 - Bug fixes +## New features and enhancements +(nothing reported) +## Changes to API +* \#514 - [Upgrade Vaadin to 24.3.12](https://github.com/vaadin-miki/super-fields/issues/514) +## Bug fixes +* \#511 - [AFTER_* label positions are incorrect for custom fields](https://github.com/vaadin-miki/super-fields/issues/511) +* \#513 - [SuperTextField.inputMode cannot be set inside a Grid.Column](https://github.com/vaadin-miki/super-fields/issues/513) # 0.19.0 - Component(Multi)Select and refreshed LazyLoad ## New features and enhancements * \#488 - [ComponentSelect (and ButtonSelect as an example)](https://github.com/vaadin-miki/super-fields/issues/488) diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/collections/MapField.java b/superfields/src/main/java/org/vaadin/miki/superfields/collections/MapField.java index be3470f..c4da264 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/collections/MapField.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/collections/MapField.java @@ -37,7 +37,7 @@ * @author miki * @since 2022-04-08 */ -@CssImport(value = "./styles/label-positions.css", themeFor = "vaadin-custom-field") +@CssImport(value = "./styles/label-positions.css", themeFor = "map-field") @Tag("map-field") @JsModule("./map-field.js") public class MapField extends CustomField> implements HasStyle, diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/object/ObjectField.java b/superfields/src/main/java/org/vaadin/miki/superfields/object/ObjectField.java index be8296b..0df1d67 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/object/ObjectField.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/object/ObjectField.java @@ -51,7 +51,7 @@ * @author miki * @since 2022-05-16 */ -@CssImport(value = "./styles/label-positions.css", themeFor = "vaadin-custom-field") +@CssImport(value = "./styles/label-positions.css", themeFor = "object-field") @Tag("object-field") @JsModule("./object-field.js") public class ObjectField extends CustomField diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/text/LabelField.java b/superfields/src/main/java/org/vaadin/miki/superfields/text/LabelField.java index 1e2e601..36cee0f 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/text/LabelField.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/text/LabelField.java @@ -24,7 +24,7 @@ * @author miki * @since 2022-04-08 */ -@CssImport(value = "./styles/label-positions.css", themeFor = "vaadin-custom-field") +@CssImport(value = "./styles/label-positions.css", themeFor = "label-field") @Tag("label-field") @JsModule("./label-field.js") public class LabelField extends CustomField implements HasStyle, WithLabelMixin>, diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextArea.java b/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextArea.java index bda8a00..f5cf3ec 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextArea.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextArea.java @@ -28,6 +28,7 @@ /** * An extension of {@link TextArea} with some useful features. + * * @author miki * @since 2020-06-01 */ @@ -36,105 +37,105 @@ @CssImport(value = "./styles/label-positions.css", themeFor = "super-text-area") @SuppressWarnings("squid:S110") // there is no way to reduce the number of parent classes public class SuperTextArea extends TextArea implements CanSelectText, TextSelectionNotifier, - CanModifyText, WithRequiredMixin, WithLabelPositionableMixin, - WithIdMixin, WithLabelMixin, WithPlaceholderMixin, - WithReceivingSelectionEventsFromClientMixin, WithClearButtonMixin, - WithHelperMixin, WithHelperPositionableMixin, - WithValueMixin, String, SuperTextArea>, WithTooltipMixin { - - private final TextModificationDelegate delegate = new TextModificationDelegate<>(this, this.getEventBus(), this::getValue); - - public SuperTextArea() { - } - - public SuperTextArea(String label) { - super(label); - } - - public SuperTextArea(String label, String placeholder) { - super(label, placeholder); - } - - public SuperTextArea(String label, String initialValue, String placeholder) { - super(label, initialValue, placeholder); - } - - public SuperTextArea(ValueChangeListener> listener) { - super(listener); - } - - public SuperTextArea(String label, ValueChangeListener> listener) { - super(label, listener); - } - - public SuperTextArea(String label, String initialValue, ValueChangeListener> listener) { - super(label, initialValue, listener); - } - - @Override - protected void onAttach(AttachEvent attachEvent) { - this.delegate.onAttach(attachEvent, super::onAttach); - } - - @Override - protected void onDetach(DetachEvent detachEvent) { - this.delegate.onDetach(detachEvent, super::onDetach); - } - - @Override - public boolean isReceivingSelectionEventsFromClient() { - return this.delegate.isReceivingSelectionEventsFromClient(); - } - - @Override - public void setReceivingSelectionEventsFromClient(boolean receivingSelectionEventsFromClient) { - this.delegate.setReceivingSelectionEventsFromClient(receivingSelectionEventsFromClient); - } - - @Override - public void selectAll() { - this.delegate.selectAll(); - } - - @Override - public void selectNone() { - this.delegate.selectNone(); - } - - @Override - public void select(int from, int to) { - this.delegate.select(from, to); - } - - @Override - public void modifyText(String replacement, int from, int to) { - this.delegate.modifyText(replacement, from, to); - } - - @Override - public Registration addTextSelectionListener(TextSelectionListener listener) { - return this.delegate.addTextSelectionListener(listener); - } - - @ClientCallable - private void selectionChanged(int start, int end, String selection) { - this.delegate.fireTextSelectionEvent(true, start, end, selection); - } - - @ClientCallable - private void reinitialiseListening() { - this.delegate.reinitialiseListeners(); - } - - @SuppressWarnings("squid:S1185") // removing this method makes the class impossible to compile due to missing methods - @Override - public void setClearButtonVisible(boolean clearButtonVisible) { - super.setClearButtonVisible(clearButtonVisible); - } - - @SuppressWarnings("squid:S1185") // same comment as above - @Override - public boolean isClearButtonVisible() { - return super.isClearButtonVisible(); - } + CanModifyText, WithRequiredMixin, WithLabelPositionableMixin, + WithIdMixin, WithLabelMixin, WithPlaceholderMixin, + WithReceivingSelectionEventsFromClientMixin, WithClearButtonMixin, + WithHelperMixin, WithHelperPositionableMixin, + WithValueMixin, String, SuperTextArea>, WithTooltipMixin { + + private final TextModificationDelegate delegate = new TextModificationDelegate<>(this, this.getEventBus(), this::getValue); + + public SuperTextArea() { + } + + public SuperTextArea(String label) { + super(label); + } + + public SuperTextArea(String label, String placeholder) { + super(label, placeholder); + } + + public SuperTextArea(String label, String initialValue, String placeholder) { + super(label, initialValue, placeholder); + } + + public SuperTextArea(ValueChangeListener> listener) { + super(listener); + } + + public SuperTextArea(String label, ValueChangeListener> listener) { + super(label, listener); + } + + public SuperTextArea(String label, String initialValue, ValueChangeListener> listener) { + super(label, initialValue, listener); + } + + @Override + protected void onAttach(AttachEvent attachEvent) { + this.delegate.onAttach(attachEvent, super::onAttach); + } + + @Override + protected void onDetach(DetachEvent detachEvent) { + this.delegate.onDetach(detachEvent, super::onDetach); + } + + @Override + public boolean isReceivingSelectionEventsFromClient() { + return this.delegate.isReceivingSelectionEventsFromClient(); + } + + @Override + public void setReceivingSelectionEventsFromClient(boolean receivingSelectionEventsFromClient) { + this.delegate.setReceivingSelectionEventsFromClient(receivingSelectionEventsFromClient); + } + + @Override + public void selectAll() { + this.delegate.selectAll(); + } + + @Override + public void selectNone() { + this.delegate.selectNone(); + } + + @Override + public void select(int from, int to) { + this.delegate.select(from, to); + } + + @Override + public void modifyText(String replacement, int from, int to) { + this.delegate.modifyText(replacement, from, to); + } + + @Override + public Registration addTextSelectionListener(TextSelectionListener listener) { + return this.delegate.addTextSelectionListener(listener); + } + + @ClientCallable + private void selectionChanged(int start, int end, String selection) { + this.delegate.fireTextSelectionEvent(true, start, end, selection); + } + + @ClientCallable + private void performDelayedInitialisation() { + this.delegate.reinitialiseListeners(); + } + + @SuppressWarnings("squid:S1185") // removing this method makes the class impossible to compile due to missing methods + @Override + public void setClearButtonVisible(boolean clearButtonVisible) { + super.setClearButtonVisible(clearButtonVisible); + } + + @SuppressWarnings("squid:S1185") // same comment as above + @Override + public boolean isClearButtonVisible() { + return super.isClearButtonVisible(); + } } diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextField.java b/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextField.java index 4cc9661..99d02f9 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextField.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextField.java @@ -33,6 +33,7 @@ /** * An extension of {@link TextField} with some useful (hopefully) features. + * * @author miki * @since 2020-05-29 */ @@ -41,142 +42,154 @@ @CssImport(value = "./styles/label-positions.css", themeFor = "super-text-field") @SuppressWarnings("squid:S110") // there is no way to reduce the number of parent classes public class SuperTextField extends TextField implements CanSelectText, TextSelectionNotifier, - CanModifyText, WithRequiredMixin, WithLabelPositionableMixin, - WithIdMixin, WithLabelMixin, WithPlaceholderMixin, - WithValueMixin, String, SuperTextField>, - WithHelperMixin, WithHelperPositionableMixin, - WithReceivingSelectionEventsFromClientMixin, WithClearButtonMixin, - WithTooltipMixin, WithTextInputModeMixin, - WithInvalidInputPreventionMixin { - - private final TextModificationDelegate delegate = new TextModificationDelegate<>(this, this.getEventBus(), this::getValue); - private TextInputMode textInputMode; - private boolean preventInvalidInput; - - public SuperTextField() { - super(); - } - - public SuperTextField(String label) { - super(label); - } - - public SuperTextField(String label, String placeholder) { - super(label, placeholder); - } - - public SuperTextField(String label, String initialValue, String placeholder) { - super(label, initialValue, placeholder); - } - - public SuperTextField(ValueChangeListener> listener) { - super(listener); - } - - public SuperTextField(String label, ValueChangeListener> listener) { - super(label, listener); - } - - public SuperTextField(String label, String initialValue, ValueChangeListener> listener) { - super(label, initialValue, listener); - } - - @Override - protected void onAttach(AttachEvent attachEvent) { - this.delegate.onAttach(attachEvent, super::onAttach); - } - - @Override - protected void onDetach(DetachEvent detachEvent) { - this.delegate.onDetach(detachEvent, super::onDetach); - } - - @Override - public Registration addTextSelectionListener(TextSelectionListener listener) { - return this.delegate.addTextSelectionListener(listener); - } - - @Override - public void selectAll() { - this.delegate.selectAll(); - } - - @Override - public void selectNone() { - this.delegate.selectNone(); - } - - @Override - public void select(int from, int to) { - this.delegate.select(from, to); - } - - @ClientCallable - private void selectionChanged(int start, int end, String selection) { - this.delegate.fireTextSelectionEvent(true, start, end, selection); - } - - @ClientCallable - private void reinitialiseListening() { - this.delegate.reinitialiseListeners(); - } - - @Override - public boolean isReceivingSelectionEventsFromClient() { - return this.delegate.isReceivingSelectionEventsFromClient(); - } - - @Override - public void setReceivingSelectionEventsFromClient(boolean receivingSelectionEventsFromClient) { - this.delegate.setReceivingSelectionEventsFromClient(receivingSelectionEventsFromClient); - } - - @Override - public void modifyText(String replacement, int from, int to) { - this.delegate.modifyText(replacement, from, to); - } - - @Override - public void setTextInputMode(TextInputMode inputMode) { - // only when there is a change - if(!Objects.equals(inputMode, this.getTextInputMode())) - this.getElement().getNode().runWhenAttached(ui -> ui.beforeClientResponse(this, context -> { - // js courtesy of the one and only JC, thank you! - if(inputMode != null) - this.getElement().executeJs("this.inputElement.inputMode = $0;", inputMode.name().toLowerCase()); - else this.getElement().executeJs("delete this.inputElement.inputMode;" ); - this.textInputMode = inputMode; - })); - } - - @Override - public TextInputMode getTextInputMode() { - return this.textInputMode; - } - - @Override - public void setPreventingInvalidInput(boolean prevent) { - this.preventInvalidInput = prevent; - this.getElement().getNode().runWhenAttached(ui -> ui.beforeClientResponse(this, context -> - this.getElement().callJsFunction("preventInvalidInput", prevent) - )); - } - - @Override - public boolean isPreventingInvalidInput() { - return this.preventInvalidInput; - } - - @SuppressWarnings("squid:S1185") // removing this method makes the class impossible to compile due to missing methods - @Override - public void setClearButtonVisible(boolean clearButtonVisible) { - super.setClearButtonVisible(clearButtonVisible); - } - - @SuppressWarnings("squid:S1185") // see above - @Override - public boolean isClearButtonVisible() { - return super.isClearButtonVisible(); - } + CanModifyText, WithRequiredMixin, WithLabelPositionableMixin, + WithIdMixin, WithLabelMixin, WithPlaceholderMixin, + WithValueMixin, String, SuperTextField>, + WithHelperMixin, WithHelperPositionableMixin, + WithReceivingSelectionEventsFromClientMixin, WithClearButtonMixin, + WithTooltipMixin, WithTextInputModeMixin, + WithInvalidInputPreventionMixin { + + private final TextModificationDelegate delegate = new TextModificationDelegate<>(this, this.getEventBus(), this::getValue); + private TextInputMode textInputMode; + private boolean preventInvalidInput; + + public SuperTextField() { + super(); + } + + public SuperTextField(String label) { + super(label); + } + + public SuperTextField(String label, String placeholder) { + super(label, placeholder); + } + + public SuperTextField(String label, String initialValue, String placeholder) { + super(label, initialValue, placeholder); + } + + public SuperTextField(ValueChangeListener> listener) { + super(listener); + } + + public SuperTextField(String label, ValueChangeListener> listener) { + super(label, listener); + } + + public SuperTextField(String label, String initialValue, ValueChangeListener> listener) { + super(label, initialValue, listener); + } + + @Override + protected void onAttach(AttachEvent attachEvent) { + this.delegate.onAttach(attachEvent, super::onAttach); + } + + @Override + protected void onDetach(DetachEvent detachEvent) { + this.delegate.onDetach(detachEvent, super::onDetach); + } + + @Override + public Registration addTextSelectionListener(TextSelectionListener listener) { + return this.delegate.addTextSelectionListener(listener); + } + + @Override + public void selectAll() { + this.delegate.selectAll(); + } + + @Override + public void selectNone() { + this.delegate.selectNone(); + } + + @Override + public void select(int from, int to) { + this.delegate.select(from, to); + } + + @ClientCallable + private void selectionChanged(int start, int end, String selection) { + this.delegate.fireTextSelectionEvent(true, start, end, selection); + } + + @ClientCallable + private void performDelayedInitialisation() { + // fixes #243 + this.delegate.reinitialiseListeners(); + // fixes #513 + this.doChangeTextInputMode(this.getTextInputMode()); + } + + @Override + public boolean isReceivingSelectionEventsFromClient() { + return this.delegate.isReceivingSelectionEventsFromClient(); + } + + @Override + public void setReceivingSelectionEventsFromClient(boolean receivingSelectionEventsFromClient) { + this.delegate.setReceivingSelectionEventsFromClient(receivingSelectionEventsFromClient); + } + + @Override + public void modifyText(String replacement, int from, int to) { + this.delegate.modifyText(replacement, from, to); + } + + @Override + public void setTextInputMode(TextInputMode inputMode) { + // only when there is a change + if (!Objects.equals(inputMode, this.getTextInputMode())) + this.doChangeTextInputMode(inputMode); + } + + /** + * Forces the change of the input mode. + * + * @param inputMode New input mode. + */ + protected void doChangeTextInputMode(TextInputMode inputMode) { + this.getElement().getNode().runWhenAttached(ui -> ui.beforeClientResponse(this, context -> { + // js courtesy of the one and only JC, thank you! + if (inputMode != null) + this.getElement().executeJs("if(this.inputElement !== undefined) {this.inputElement.inputMode = $0;}", inputMode.name().toLowerCase()); + else this.getElement().executeJs("delete this.inputElement.inputMode;"); + this.textInputMode = inputMode; + })); + } + + @Override + public TextInputMode getTextInputMode() { + return this.textInputMode; + } + + @Override + public void setPreventingInvalidInput(boolean prevent) { + this.preventInvalidInput = prevent; + this.getElement().getNode().runWhenAttached(ui -> ui.beforeClientResponse(this, context -> + this.getElement().callJsFunction("preventInvalidInput", prevent) + )); + } + + @Override + public boolean isPreventingInvalidInput() { + return this.preventInvalidInput; + } + + @SuppressWarnings("squid:S1185") // removing this method makes the class impossible to compile due to missing methods + @Override + public void setClearButtonVisible(boolean clearButtonVisible) { + super.setClearButtonVisible(clearButtonVisible); + } + + @SuppressWarnings("squid:S1185") // see above + @Override + public boolean isClearButtonVisible() { + return super.isClearButtonVisible(); + } } diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/variant/VariantField.java b/superfields/src/main/java/org/vaadin/miki/superfields/variant/VariantField.java index f4d1304..b95541b 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/variant/VariantField.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/variant/VariantField.java @@ -29,7 +29,7 @@ * @author miki * @since 2022-04-11 */ -@CssImport(value = "./styles/label-positions.css", themeFor = "vaadin-custom-field") +@CssImport(value = "./styles/label-positions.css", themeFor = "variant-field") @Tag("variant-field") @JsModule("./variant-field.js") public class VariantField extends CustomField implements HasStyle, diff --git a/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions.css b/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions.css index cfada9a..dacce6f 100644 --- a/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions.css +++ b/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions.css @@ -39,7 +39,8 @@ width: 100%; } -:host([data-label-position-details~="after"]) [class|="vaadin"] [part="input-field"] { +:host([data-label-position-details~="after"]) [class|="vaadin"] [part="input-field"], +:host([data-label-position-details~="after"]) [class|="vaadin"] [part="input-fields"] { order: -1; } :host([data-label-position-details~="after"][theme~="helper-above-field"]) [class|="vaadin"] [part="helper-text"] { diff --git a/superfields/src/main/resources/META-INF/resources/frontend/text-selection-mixin.js b/superfields/src/main/resources/META-INF/resources/frontend/text-selection-mixin.js index 4fe8806..aea5aca 100644 --- a/superfields/src/main/resources/META-INF/resources/frontend/text-selection-mixin.js +++ b/superfields/src/main/resources/META-INF/resources/frontend/text-selection-mixin.js @@ -10,14 +10,13 @@ export class TextSelectionMixin { data.startsAt = data.input.selectionStart; data.endsAt = data.input.selectionEnd; data.selection = data.input.value.substring(data.startsAt, data.endsAt); - } - else { + } else { data.startsAt = -1; data.endsAt = -1; data.selection = ''; } src.dataset.selectedText = data.selection; - if(data.callServer && (currentStart !== data.startsAt || currentEnd !== data.endsAt)) { + if (data.callServer && (currentStart !== data.startsAt || currentEnd !== data.endsAt)) { console.log('TSM: calling server'); src.$server.selectionChanged(data.startsAt, data.endsAt, data.selection); } @@ -36,7 +35,7 @@ export class TextSelectionMixin { } select(src, from, to) { - console.log('TSM: selecting from '+from+' to '+to); + console.log('TSM: selecting from ' + from + ' to ' + to); if (from <= to) { src.selectionMixin.input.selectionStart = from; src.selectionMixin.input.selectionEnd = to; @@ -45,7 +44,7 @@ export class TextSelectionMixin { } replaceText(src, text, from, to) { - console.log('TSM: replacing text '+text+' from '+from+' to '+to); + console.log('TSM: replacing text ' + text + ' from ' + from + ' to ' + to); if (from < 0) { from = src.selectionMixin.input.selectionStart; } @@ -55,21 +54,21 @@ export class TextSelectionMixin { src.selectionMixin.input.setRangeText(text, from, to); // the above code does not trigger value changes // so using the trick from clear-button handler - const inputEvent = new Event('input', { bubbles: true, composed: true }); - const changeEvent = new Event('change', { bubbles: !src._slottedInput }); + const inputEvent = new Event('input', {bubbles: true, composed: true}); + const changeEvent = new Event('change', {bubbles: !src._slottedInput}); src.selectionMixin.input.dispatchEvent(inputEvent); src.selectionMixin.input.dispatchEvent(changeEvent); } listenToEvents(inputComponent, webComponent, notifyServer) { - console.log('TSM: setting up text selection for component <'+webComponent.tagName+'>'); + console.log('TSM: setting up text selection for component <' + webComponent.tagName + '>'); if (inputComponent === undefined) { console.log('TSM: input component is undefined, attempting to find it from shadow root/input element'); inputComponent = webComponent.inputElement; if (inputComponent === undefined) { console.log('TSM: no input component, server will reinitialise this component shortly (probably used inside Grid, nothing to worry about)'); // this trick has been suggested by the magnificent Erik Lumme, thank you! - webComponent.$server.reinitialiseListening(); + webComponent.$server.performDelayedInitialisation(); } } if (inputComponent !== undefined) { diff --git a/superfields/src/main/resources/superdatepickeri18n_sv.properties b/superfields/src/main/resources/superdatepickeri18n_sv.properties new file mode 100644 index 0000000..37ec8fa --- /dev/null +++ b/superfields/src/main/resources/superdatepickeri18n_sv.properties @@ -0,0 +1,2 @@ +cancel=Avbryt +today=Idag \ No newline at end of file diff --git a/superfields/src/test/java/org/vaadin/miki/superfields/dates/DatePatternDelegateTest.java b/superfields/src/test/java/org/vaadin/miki/superfields/dates/DatePatternDelegateTest.java index 48bf954..9a2c219 100644 --- a/superfields/src/test/java/org/vaadin/miki/superfields/dates/DatePatternDelegateTest.java +++ b/superfields/src/test/java/org/vaadin/miki/superfields/dates/DatePatternDelegateTest.java @@ -12,38 +12,39 @@ public class DatePatternDelegateTest { - private SuperDatePicker datePicker; - - @Before - public void setUp() { - MockVaadin.setup(); - this.datePicker = new SuperDatePicker().withDatePattern(DatePatterns.YYYY_MM_DD).withLocale(new Locale("pl", "PL")); - } - - @After - public void tearDown() { - MockVaadin.tearDown(); - } - - @Test - public void testFormattedValue() { - LocalDate expected = LocalDate.of(1999, 5, 3); - this.datePicker.setValue(expected); - LocalDate value = this.datePicker.getValue(); - Assert.assertEquals(expected, value); - String raw = this.datePicker.getFormattedValue(); - Assert.assertEquals("1999-05-03", raw); - - // now server-side month formatting - this.datePicker.setDatePattern(DatePatterns.D_MMMM_YYYY); - raw = this.datePicker.getFormattedValue(); - Assert.assertEquals("3 maja 1999", raw); - - this.datePicker.setDatePattern(null); - - // now formatted according to locale - raw = this.datePicker.getFormattedValue(); - Assert.assertEquals("03.05.1999", raw); - } + private SuperDatePicker datePicker; + + @Before + public void setUp() { + MockVaadin.setup(); + this.datePicker = new SuperDatePicker().withDatePattern(DatePatterns.YYYY_MM_DD).withLocale(new Locale("pl", "PL")); + } + + @After + public void tearDown() { + MockVaadin.tearDown(); + } + + @Test + public void testFormattedValue() { + LocalDate expected = LocalDate.of(1999, 5, 3); + this.datePicker.setValue(expected); + LocalDate value = this.datePicker.getValue(); + Assert.assertEquals(expected, value); + String raw = this.datePicker.getFormattedValue(); + Assert.assertEquals("1999-05-03", raw); + + // now server-side month formatting + this.datePicker.setDatePattern(DatePatterns.D_MMMM_YYYY); + raw = this.datePicker.getFormattedValue(); + Assert.assertEquals("3 maja 1999", raw); + + this.datePicker.setLocale(new Locale("pl", "PL")); + this.datePicker.setDatePattern(null); + + // now formatted according to locale + raw = this.datePicker.getFormattedValue(); + Assert.assertEquals("03.05.1999", raw); + } } \ No newline at end of file