From d61fa5fbc2ad73c8cf504b594c8a0a10403c198b Mon Sep 17 00:00:00 2001 From: Meghea Iulian Date: Tue, 21 Nov 2023 13:33:35 +0200 Subject: [PATCH] feat: replace paper-input with cosmoz-input --- cosmoz-omnitable-column-amount.js | 84 ++++---- cosmoz-omnitable-column-autocomplete.js | 23 +-- cosmoz-omnitable-column-date.js | 6 +- cosmoz-omnitable-column-datetime.js | 2 +- cosmoz-omnitable-column-number.js | 66 ++++--- cosmoz-omnitable-column-time.js | 56 +++--- cosmoz-omnitable-column.js | 7 +- demo/editable-demo.html | 6 +- docs/documentation.md | 2 +- lib/cosmoz-omnitable-amount-range-input.js | 135 ++++++++----- lib/cosmoz-omnitable-date-range-input.js | 68 ++++--- lib/cosmoz-omnitable-datetime-range-input.js | 69 ++++--- lib/cosmoz-omnitable-number-range-input.js | 5 +- lib/cosmoz-omnitable-range-input-mixin.js | 4 +- lib/cosmoz-omnitable-time-range-input.js | 9 +- package-lock.json | 196 ++++++++----------- package.json | 2 - test/integration/column-number.test.js | 6 +- 18 files changed, 405 insertions(+), 341 deletions(-) diff --git a/cosmoz-omnitable-column-amount.js b/cosmoz-omnitable-column-amount.js index 8745676e..70ea9257 100644 --- a/cosmoz-omnitable-column-amount.js +++ b/cosmoz-omnitable-column-amount.js @@ -1,5 +1,5 @@ /* eslint-disable no-return-assign */ -import '@polymer/paper-input/paper-input'; +import '@neovici/cosmoz-input'; import '@polymer/paper-dropdown-menu/paper-dropdown-menu'; import './ui-helpers/cosmoz-clear-button'; @@ -9,7 +9,16 @@ import { html } from 'lit-html'; import { columnMixin } from './cosmoz-omnitable-column-mixin'; import { defaultComputeSource } from './lib/utils-data'; import './lib/cosmoz-omnitable-amount-range-input'; -import { getComparableValue, getCurrency, applySingleFilter, getString, getInputString, toAmount, toHashString, fromHashString } from './lib/utils-amount'; +import { + getComparableValue, + getCurrency, + applySingleFilter, + getString, + getInputString, + toAmount, + toHashString, + fromHashString, +} from './lib/utils-amount'; import { get } from '@polymer/polymer/lib/utils/path'; /** @@ -29,13 +38,12 @@ class OmnitableColumnAmount extends columnMixin(PolymerElement) { rates: { type: Object, notify: true }, width: { type: String, value: '70px' }, cellClass: { type: String, value: 'amount-cell align-right' }, - headerCellClass: { type: String, value: 'amount-header-cell' } + headerCellClass: { type: String, value: 'amount-header-cell' }, }; } getFilterFn(column, filter) { - const - min = getComparableValue({ ...column, valuePath: 'min' }, filter), + const min = getComparableValue({ ...column, valuePath: 'min' }, filter), max = getComparableValue({ ...column, valuePath: 'max' }, filter); if (min == null && max == null) { @@ -64,8 +72,7 @@ class OmnitableColumnAmount extends columnMixin(PolymerElement) { if (filter == null) { return; } - const - min = toAmount(rates, filter.min), + const min = toAmount(rates, filter.min), max = toAmount(rates, filter.max); if (min == null && max == null) { @@ -86,51 +93,52 @@ class OmnitableColumnAmount extends columnMixin(PolymerElement) { return { min: fromHashString(matches[1]), - max: fromHashString(matches[2]) + max: fromHashString(matches[2]), }; } renderCell(column, { item }) { - return html`${ column.getString(column, item) }`; + return html`${column.getString(column, item)}`; } renderEditCell(column, { item }, onItemChange) { - const onChange = event => onItemChange({ - amount: event.target.value, - currency: get(item, column.valuePath)?.currency - }); - - return html` -
${ getCurrency(column, item) }
-
`; + const onChange = (event) => + onItemChange({ + amount: event.target.value, + currency: get(item, column.valuePath)?.currency, + }); + + return html` +
${getCurrency(column, item)}
+
`; } renderHeader( - { title, - min, - max, - locale, - rates, - currency, - autoupdate, - autodetect }, + { title, min, max, locale, rates, currency, autoupdate, autodetect }, { filter }, setState, - source + source, ) { return html` setState(state => ({ ...state, filter: value })) } - @header-focused-changed=${ ({ detail: { value }}) => setState(state => ({ ...state, headerFocused: value })) } + .title=${title} + .filter=${filter} + .values=${source} + .rates=${rates} + .min=${min} + .max=${max} + .locale=${locale} + .currency=${currency} + .autoupdate=${autoupdate} + .autodetect=${autodetect} + @filter-changed=${({ detail: { value } }) => + setState((state) => ({ ...state, filter: value }))} + @header-focused-changed=${({ detail: { value } }) => + setState((state) => ({ ...state, headerFocused: value }))} >`; } diff --git a/cosmoz-omnitable-column-autocomplete.js b/cosmoz-omnitable-column-autocomplete.js index b8433203..bbc3c3d7 100644 --- a/cosmoz-omnitable-column-autocomplete.js +++ b/cosmoz-omnitable-column-autocomplete.js @@ -20,7 +20,7 @@ import { get } from '@polymer/polymer/lib/utils/path'; export const getComparableValue = ( { valuePath, textProperty, valueProperty }, - item + item, ) => { const property = textProperty ? strProp(textProperty) : prop(valueProperty), values = array(valuePath && get(item, valuePath)).map(property); @@ -33,7 +33,7 @@ export const getComparableValue = ( * @appliesMixin columnMixin */ class OmnitableColumnAutocomplete extends listColumnMixin( - columnMixin(PolymerElement) + columnMixin(PolymerElement), ) { static get properties() { return { @@ -63,12 +63,12 @@ class OmnitableColumnAutocomplete extends listColumnMixin( renderEditCell(column, { item }, onItemChange) { const onChange = (event) => onItemChange(event.target.value); - return html``; + >`; } renderHeader(column, { filter, query }, setState, source) { @@ -89,12 +89,13 @@ class OmnitableColumnAutocomplete extends listColumnMixin( .onText=${onText(setState)} >${when( column.loading, - () => html`` + () => + html``, )}`; } @@ -105,5 +106,5 @@ class OmnitableColumnAutocomplete extends listColumnMixin( } customElements.define( 'cosmoz-omnitable-column-autocomplete', - OmnitableColumnAutocomplete + OmnitableColumnAutocomplete, ); diff --git a/cosmoz-omnitable-column-date.js b/cosmoz-omnitable-column-date.js index d2ea9e0b..16c5c6c9 100644 --- a/cosmoz-omnitable-column-date.js +++ b/cosmoz-omnitable-column-date.js @@ -1,5 +1,5 @@ /* eslint-disable no-return-assign */ -import '@polymer/paper-input/paper-input'; +import '@neovici/cosmoz-input'; import '@polymer/paper-dropdown-menu/paper-dropdown-menu'; import './ui-helpers/cosmoz-clear-button'; @@ -88,12 +88,12 @@ class OmnitableColumnDate extends columnMixin(PolymerElement) { renderEditCell(column, { item }, onItemChange) { const onChange = event => onItemChange(fromInputString(event.target.value)); - return html``; + >`; } renderHeader( diff --git a/cosmoz-omnitable-column-datetime.js b/cosmoz-omnitable-column-datetime.js index 6e9fbcec..0b97d6ef 100644 --- a/cosmoz-omnitable-column-datetime.js +++ b/cosmoz-omnitable-column-datetime.js @@ -96,7 +96,7 @@ class OmnitableColumnDatetime extends columnMixin(PolymerElement) { renderEditCell(column, { item }, onItemChange) { const onChange = event => onItemChange(fromInputString(event.target.value)); - return html``; + return html``; } // eslint-disable-next-line max-lines-per-function diff --git a/cosmoz-omnitable-column-number.js b/cosmoz-omnitable-column-number.js index aa1a1830..396d339f 100644 --- a/cosmoz-omnitable-column-number.js +++ b/cosmoz-omnitable-column-number.js @@ -1,4 +1,4 @@ -import '@polymer/paper-input/paper-input'; +import '@neovici/cosmoz-input'; import '@polymer/paper-dropdown-menu/paper-dropdown-menu'; import './ui-helpers/cosmoz-clear-button'; @@ -9,10 +9,16 @@ import { columnMixin } from './cosmoz-omnitable-column-mixin'; import './lib/cosmoz-omnitable-number-range-input'; import { defaultComputeSource } from './lib/utils-data'; -import { applySingleFilter, getComparableValue, getInputString, getString, toHashString, toNumber } from './lib/utils-number'; +import { + applySingleFilter, + getComparableValue, + getInputString, + getString, + toHashString, + toNumber, +} from './lib/utils-number'; import { get } from '@polymer/polymer/lib/utils/path'; - /** * @polymer * @customElement @@ -30,13 +36,12 @@ class OmnitableColumnNumber extends columnMixin(PolymerElement) { minWidth: { type: String, value: '30px' }, headerCellClass: { type: String, value: 'number-header-cell' }, maximumFractionDigits: { type: Number, value: null }, - minimumFractionDigits: { type: Number, value: null } // browser default 0 for numbers, currency-specific or 2 for currency + minimumFractionDigits: { type: Number, value: null }, // browser default 0 for numbers, currency-specific or 2 for currency }; } getFilterFn(column, filter) { - const - min = getComparableValue({ ...column, valuePath: 'min' }, filter), + const min = getComparableValue({ ...column, valuePath: 'min' }, filter), max = getComparableValue({ ...column, valuePath: 'max' }, filter); if (min == null && max == null) { @@ -86,44 +91,55 @@ class OmnitableColumnNumber extends columnMixin(PolymerElement) { return { min: toNumber(matches[1]), - max: toNumber(matches[2]) + max: toNumber(matches[2]), }; } renderCell(column, { item }) { - return html`
${ getString(column, item) }
`; + return html`
+ ${getString(column, item)} +
`; } renderEditCell(column, { item }, onItemChange) { - const onChange = event => onItemChange(event.target.value); - - return html``; + const onChange = (event) => onItemChange(event.target.value); + + return html``; } renderHeader( - { title, + { + title, min, max, locale, maximumFractionDigits, minimumFractionDigits, - autoupdate }, + autoupdate, + }, { filter }, setState, - source + source, ) { return html` setState(state => ({ ...state, filter: value })) } - @header-focused-changed=${ ({ detail: { value }}) => setState(state => ({ ...state, headerFocused: value })) } + .title=${title} + .filter=${filter} + .values=${source} + .min=${min} + .max=${max} + .locale=${locale} + .maximumFractionDigits=${maximumFractionDigits} + .minimumFractionDigsits=${minimumFractionDigits} + .autoupdate=${autoupdate} + @filter-changed=${({ detail: { value } }) => + setState((state) => ({ ...state, filter: value }))} + @header-focused-changed=${({ detail: { value } }) => + setState((state) => ({ ...state, headerFocused: value }))} >`; } diff --git a/cosmoz-omnitable-column-time.js b/cosmoz-omnitable-column-time.js index b3a91b12..d9bf55fe 100644 --- a/cosmoz-omnitable-column-time.js +++ b/cosmoz-omnitable-column-time.js @@ -1,6 +1,6 @@ /* eslint-disable no-return-assign */ import '@polymer/paper-dropdown-menu/paper-dropdown-menu'; -import '@polymer/paper-input/paper-input'; +import '@neovici/cosmoz-input'; import './ui-helpers/cosmoz-clear-button'; @@ -8,7 +8,15 @@ import { PolymerElement } from '@polymer/polymer/polymer-element'; import { html } from 'lit-html'; import { columnMixin } from './cosmoz-omnitable-column-mixin'; -import { getComparableValue, getString, toXlsxValue, applySingleFilter, toDate, toHashString, fromHashString } from './lib/utils-time'; +import { + getComparableValue, + getString, + toXlsxValue, + applySingleFilter, + toDate, + toHashString, + fromHashString, +} from './lib/utils-time'; import './lib/cosmoz-omnitable-time-range-input'; import { defaultComputeSource } from './lib/utils-data'; @@ -32,13 +40,12 @@ class OmnitableColumnTime extends columnMixin(PolymerElement) { * 1 => full seconds * 0.1 => milliseconds */ - filterStep: { type: String, value: '1' } + filterStep: { type: String, value: '1' }, }; } getFilterFn(column, filter) { - const - min = getComparableValue({ ...column, valuePath: 'min' }, filter), + const min = getComparableValue({ ...column, valuePath: 'min' }, filter), max = getComparableValue({ ...column, valuePath: 'max' }, filter); if (min == null && max == null) { @@ -88,7 +95,7 @@ class OmnitableColumnTime extends columnMixin(PolymerElement) { return { min: fromHashString(matches[1]), - max: fromHashString(matches[2]) + max: fromHashString(matches[2]), }; } @@ -97,30 +104,33 @@ class OmnitableColumnTime extends columnMixin(PolymerElement) { } renderEditCell(column, { item }, onItemChange) { - const onChange = event => onItemChange(event.target.value); - return html``; + const onChange = (event) => onItemChange(event.target.value); + return html``; } renderHeader( - { title, - min, - max, - locale, - filterStep }, + { title, min, max, locale, filterStep }, { filter }, setState, - source + source, ) { return html` setState(state => ({ ...state, filter: value })) } - @header-focused-changed=${ ({ detail: { value }}) => setState(state => ({ ...state, headerFocused: value })) } + .title=${title} + .filter=${filter} + .values=${source} + .min=${min} + .max=${max} + .locale=${locale} + .filterStep=${filterStep} + @filter-changed=${({ detail: { value } }) => + setState((state) => ({ ...state, filter: value }))} + @header-focused-changed=${({ detail: { value } }) => + setState((state) => ({ ...state, headerFocused: value }))} >`; } diff --git a/cosmoz-omnitable-column.js b/cosmoz-omnitable-column.js index e652dd3f..200ef16a 100644 --- a/cosmoz-omnitable-column.js +++ b/cosmoz-omnitable-column.js @@ -1,6 +1,5 @@ /* eslint-disable no-return-assign */ -import '@polymer/iron-icon/iron-icon'; -import '@polymer/paper-input/paper-input'; +import '@neovici/cosmoz-input'; import './ui-helpers/cosmoz-clear-button'; import { @@ -13,7 +12,7 @@ import { html } from 'lit-html'; const onChange = (setState) => (event) => setState((state) => { - // skip the event emitted during paper-input initialization + // skip the event emitted during cosmoz-input initialization if (state.inputValue === undefined && event.target.value === '') { return state; } @@ -76,7 +75,7 @@ class OmnitableColumn extends columnMixin(PolymerElement) { renderHeader(column, { filter, inputValue, headerFocused }, setState) { return html`Cosmoz omnitable demo renderEditValue(column, { item }, onItemChange) { const onChange = (event) => onItemChange(event.target.value); - return html``; + >`; } } customElements.define(XPage.is, XPage); diff --git a/docs/documentation.md b/docs/documentation.md index d3eb2645..1a4d7915 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -134,7 +134,7 @@ For `cosmoz-omnitable-column` ```html ``` diff --git a/lib/cosmoz-omnitable-amount-range-input.js b/lib/cosmoz-omnitable-amount-range-input.js index b391ce53..d5bdd020 100644 --- a/lib/cosmoz-omnitable-amount-range-input.js +++ b/lib/cosmoz-omnitable-amount-range-input.js @@ -2,10 +2,13 @@ import { _ } from '@neovici/cosmoz-i18next'; import { PolymerElement } from '@polymer/polymer'; import { html } from 'lit-html'; import { ifDefined } from 'lit-html/directives/if-defined.js'; +import '@neovici/cosmoz-input'; import { rangeInputMixin } from './cosmoz-omnitable-range-input-mixin'; import { polymerHauntedRender } from './polymer-haunted-render-mixin'; -class AmountRangeInput extends rangeInputMixin(polymerHauntedRender(PolymerElement)) { +class AmountRangeInput extends rangeInputMixin( + polymerHauntedRender(PolymerElement), +) { static get properties() { return { /** @@ -25,19 +28,20 @@ class AmountRangeInput extends rangeInputMixin(polymerHauntedRender(PolymerEleme rates: { type: Object }, // trigger filter updates manually autoupdate: { type: String, value: false }, - _filterText: { type: String, computed: '_computeFilterText(filter.*, _formatters)' } + _filterText: { + type: String, + computed: '_computeFilterText(filter.*, _formatters)', + }, }; } static get observers() { - return [ - '_valuesChanged(autodetect, currency, values)' - ]; + return ['_valuesChanged(autodetect, currency, values)']; } // eslint-disable-next-line max-lines-per-function render() { - const onOpenedChanged = event => { + const onOpenedChanged = (event) => { this.headerFocused = event.detail.value; this._onDropdownOpenedChanged(event); }; @@ -49,46 +53,59 @@ class AmountRangeInput extends rangeInputMixin(polymerHauntedRender(PolymerEleme display: block; } - this.resetFilter() } ?visible=${ this.hasFilter() }> + this.resetFilter()} + ?visible=${this.hasFilter()} + > - `; @@ -136,12 +153,17 @@ class AmountRangeInput extends rangeInputMixin(polymerHauntedRender(PolymerEleme * @param {Function} limitFunc The function used to limit the number (Math.min|Math.max) * @returns {Object|void} Value converted to Number or void */ - toAmount(value, limit, limitFunc) { // eslint-disable-line max-statements + toAmount(value, limit, limitFunc) { + // eslint-disable-line max-statements if (value == null || value === '') { return; } - if (typeof value !== 'object' || value.currency == null || value.currency === '') { + if ( + typeof value !== 'object' || + value.currency == null || + value.currency === '' + ) { return null; } @@ -151,7 +173,7 @@ class AmountRangeInput extends rangeInputMixin(polymerHauntedRender(PolymerEleme } const amount = { currency: value.currency, - amount: number + amount: number, }; if (limitFunc == null || limit == null) { @@ -215,14 +237,14 @@ class AmountRangeInput extends rangeInputMixin(polymerHauntedRender(PolymerEleme getFormatter(currency, locale) { const id = locale ? locale : '', key = currency + id || '', - formatters = this._formatters = this._formatters || {}; + formatters = (this._formatters = this._formatters || {}); if (formatters[key]) { return formatters[key]; } formatters[key] = new Intl.NumberFormat(locale || undefined, { style: 'currency', - currency + currency, }); return formatters[key]; @@ -239,8 +261,7 @@ class AmountRangeInput extends rangeInputMixin(polymerHauntedRender(PolymerEleme if (amount == null) { return ''; } - return this.getFormatter(amount.currency, this.locale) - .format(value.amount); + return this.getFormatter(amount.currency, this.locale).format(value.amount); } _amountValueChanged(event) { @@ -251,11 +272,16 @@ class AmountRangeInput extends rangeInputMixin(polymerHauntedRender(PolymerEleme amountValue = Number(value), newValue = { amount: amountValue, - currency: originalValue.currency + currency: originalValue.currency, }; this.set(this.valuePath, newValue, item); - this._fireItemChangeEvent(item, this.valuePath, originalValue, this.renderValue.bind(this)); + this._fireItemChangeEvent( + item, + this.valuePath, + originalValue, + this.renderValue.bind(this), + ); } _toInputString(value) { @@ -275,7 +301,9 @@ class AmountRangeInput extends rangeInputMixin(polymerHauntedRender(PolymerEleme if (amount == null) { return null; } - const toCurrency = this.toNumber(amount.amount) * (rates[amount.currency] || 1) / (rates[this.currency] || 1); + const toCurrency = + (this.toNumber(amount.amount) * (rates[amount.currency] || 1)) / + (rates[this.currency] || 1); return toCurrency.toFixed(2); } @@ -286,10 +314,11 @@ class AmountRangeInput extends rangeInputMixin(polymerHauntedRender(PolymerEleme } return this.toValue({ amount: number, - currency: property && this.get(['filter', property, 'currency']) || this.currency + currency: + (property && this.get(['filter', property, 'currency'])) || + this.currency, }); } } - customElements.define('cosmoz-omnitable-amount-range-input', AmountRangeInput); diff --git a/lib/cosmoz-omnitable-date-range-input.js b/lib/cosmoz-omnitable-date-range-input.js index 5578d88a..14834c08 100644 --- a/lib/cosmoz-omnitable-date-range-input.js +++ b/lib/cosmoz-omnitable-date-range-input.js @@ -2,10 +2,13 @@ import { _ } from '@neovici/cosmoz-i18next'; import { PolymerElement } from '@polymer/polymer'; import { html } from 'lit-html'; import { ifDefined } from 'lit-html/directives/if-defined.js'; +import '@neovici/cosmoz-input'; import { dateInputMixin } from './cosmoz-omnitable-date-input-mixin'; import { polymerHauntedRender } from './polymer-haunted-render-mixin'; -class DateRangeInput extends dateInputMixin(polymerHauntedRender(PolymerElement)) { +class DateRangeInput extends dateInputMixin( + polymerHauntedRender(PolymerElement), +) { // eslint-disable-next-line max-lines-per-function render() { return html` @@ -15,36 +18,46 @@ class DateRangeInput extends dateInputMixin(polymerHauntedRender(PolymerElement) display: block; } - this.resetFilter() } ?visible=${ this.hasFilter() }> + this.resetFilter()} + ?visible=${this.hasFilter()} + > { - // TODO: check ots integration - this.headerFocused = event.detail.value; - } }> -