From 48cd36ee9309e781d91962509684da5fec657b38 Mon Sep 17 00:00:00 2001 From: jin Date: Fri, 22 Nov 2024 22:16:07 +0300 Subject: [PATCH 01/25] $mol_page - fixed focusability --- page/page.view.tree | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/page/page.view.tree b/page/page.view.tree index d383c52e94d..efbe615a1c8 100644 --- a/page/page.view.tree +++ b/page/page.view.tree @@ -1,6 +1,6 @@ $mol_page $mol_view dom_name \article - field * + attr * ^ tabIndex <= tabindex -1 sub / From ee0790c0558715096f69e0c770bbcc7ec22e3eb5 Mon Sep 17 00:00:00 2001 From: nin-jin Date: Fri, 22 Nov 2024 22:38:21 +0300 Subject: [PATCH 02/25] Update and rename deploy.yml to mol.yml --- .github/workflows/{deploy.yml => mol.yml} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename .github/workflows/{deploy.yml => mol.yml} (76%) diff --git a/.github/workflows/deploy.yml b/.github/workflows/mol.yml similarity index 76% rename from .github/workflows/deploy.yml rename to .github/workflows/mol.yml index 6e0b7fb043b..7a4f4187d8a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/mol.yml @@ -1,4 +1,4 @@ -name: Deploy +name: $mol on: workflow_dispatch: @@ -42,12 +42,12 @@ jobs: if: github.ref == 'refs/heads/master' runs-on: ubuntu-latest steps: - - env: - GITHUB_TOKEN: ${{ secrets.GH_PAT }} - INPUTS_CLIENT_PAYLOAD: '{"repository":${{ toJson(github.event.repository.name) }}}' - INPUTS_EVENT_TYPE: dependency_changed - INPUTS_REPOSITORY: ${{ matrix.repo }} - uses: rekgrpth/github-repository-dispatch-shell-action@v1 + - uses: peter-evans/repository-dispatch@v3 + with: + token: ${{ secrets.PAT }} + repository: ${{ matrix.repo }} + event-type: dependency_changed + client-payload: '{"repository":${{ toJson(github.event.repository.name) }}}' strategy: matrix: repo: From 849c99976eff595e68b02d20fef19fcfb951c205 Mon Sep 17 00:00:00 2001 From: nin-jin Date: Fri, 22 Nov 2024 22:44:36 +0300 Subject: [PATCH 03/25] Update mol.yml --- .github/workflows/mol.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mol.yml b/.github/workflows/mol.yml index 7a4f4187d8a..9a09ad4da5e 100644 --- a/.github/workflows/mol.yml +++ b/.github/workflows/mol.yml @@ -44,10 +44,10 @@ jobs: steps: - uses: peter-evans/repository-dispatch@v3 with: - token: ${{ secrets.PAT }} + # token: ${{ secrets.PAT }} repository: ${{ matrix.repo }} event-type: dependency_changed - client-payload: '{"repository":${{ toJson(github.event.repository.name) }}}' + # client-payload: '{"repository":${{ toJson(github.event.repository.name) }}}' strategy: matrix: repo: From 44c6c0646735217a20370450d5dff57040fcb43a Mon Sep 17 00:00:00 2001 From: nin-jin Date: Fri, 22 Nov 2024 22:46:13 +0300 Subject: [PATCH 04/25] Update mol.yml --- .github/workflows/mol.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mol.yml b/.github/workflows/mol.yml index 9a09ad4da5e..e825b239a6f 100644 --- a/.github/workflows/mol.yml +++ b/.github/workflows/mol.yml @@ -44,7 +44,7 @@ jobs: steps: - uses: peter-evans/repository-dispatch@v3 with: - # token: ${{ secrets.PAT }} + token: ${{ secrets.PAT }} repository: ${{ matrix.repo }} event-type: dependency_changed # client-payload: '{"repository":${{ toJson(github.event.repository.name) }}}' From ce4deabe1a410f3945f79e129393c64c7a8d2fe5 Mon Sep 17 00:00:00 2001 From: nin-jin Date: Fri, 22 Nov 2024 22:49:01 +0300 Subject: [PATCH 05/25] Update mol.yml --- .github/workflows/mol.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mol.yml b/.github/workflows/mol.yml index e825b239a6f..bd7bb9127eb 100644 --- a/.github/workflows/mol.yml +++ b/.github/workflows/mol.yml @@ -44,7 +44,7 @@ jobs: steps: - uses: peter-evans/repository-dispatch@v3 with: - token: ${{ secrets.PAT }} + token: ${{ secrets.GITHUB_TOKEN }} repository: ${{ matrix.repo }} event-type: dependency_changed # client-payload: '{"repository":${{ toJson(github.event.repository.name) }}}' From 6bab1c2fe88354e190e68fb1b1a99e1bfa6e5ab9 Mon Sep 17 00:00:00 2001 From: nin-jin Date: Fri, 22 Nov 2024 22:55:26 +0300 Subject: [PATCH 06/25] Update mol.yml --- .github/workflows/mol.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mol.yml b/.github/workflows/mol.yml index bd7bb9127eb..e825b239a6f 100644 --- a/.github/workflows/mol.yml +++ b/.github/workflows/mol.yml @@ -44,7 +44,7 @@ jobs: steps: - uses: peter-evans/repository-dispatch@v3 with: - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.PAT }} repository: ${{ matrix.repo }} event-type: dependency_changed # client-payload: '{"repository":${{ toJson(github.event.repository.name) }}}' From 7f349a67d89237538ef445a813804b7555ebd15b Mon Sep 17 00:00:00 2001 From: nin-jin Date: Fri, 22 Nov 2024 23:05:11 +0300 Subject: [PATCH 07/25] Update mol.yml --- .github/workflows/mol.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mol.yml b/.github/workflows/mol.yml index e825b239a6f..6c863a9ee87 100644 --- a/.github/workflows/mol.yml +++ b/.github/workflows/mol.yml @@ -44,10 +44,10 @@ jobs: steps: - uses: peter-evans/repository-dispatch@v3 with: - token: ${{ secrets.PAT }} + token: ${{ secrets.ПР_PAT }} repository: ${{ matrix.repo }} event-type: dependency_changed - # client-payload: '{"repository":${{ toJson(github.event.repository.name) }}}' + client-payload: '{"repository":${{ toJson(github.event.repository.name) }}}' strategy: matrix: repo: From 1059a019272fd4f8aefbf4c3f81f0ae95a4fffc6 Mon Sep 17 00:00:00 2001 From: nin-jin Date: Fri, 22 Nov 2024 23:05:57 +0300 Subject: [PATCH 08/25] Update mol.yml --- .github/workflows/mol.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mol.yml b/.github/workflows/mol.yml index 6c863a9ee87..985fe8e14a5 100644 --- a/.github/workflows/mol.yml +++ b/.github/workflows/mol.yml @@ -44,7 +44,7 @@ jobs: steps: - uses: peter-evans/repository-dispatch@v3 with: - token: ${{ secrets.ПР_PAT }} + token: ${{ secrets.GH_PAT }} repository: ${{ matrix.repo }} event-type: dependency_changed client-payload: '{"repository":${{ toJson(github.event.repository.name) }}}' From 98dd3825a8e44b2f75d8d8626e7afa1e9fa33ec4 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sat, 23 Nov 2024 20:50:37 +0300 Subject: [PATCH 09/25] $mol_number dot minus constraint --- number/number.view.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/number/number.view.ts b/number/number.view.ts index 90285bbf3d5..2a9399d20a0 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -7,7 +7,7 @@ namespace $.$$ { export class $mol_number extends $.$mol_number { value_limited( val? : number ) : number { - if (Number.isNaN( val )) return this.value(val) + if (Number.isNaN( val )) return this.value( val ) if ( val === undefined ) return this.value() const min = this.value_min() @@ -28,7 +28,7 @@ namespace $.$$ { } value_normalized(next?: string) { - const next_num = this.value_limited( next === undefined ? next : Number(next) ) + const next_num = this.value_limited( next === undefined ? next : Number(next || Number.NaN) ) if (Number.isNaN(next_num)) return '' @@ -48,13 +48,24 @@ namespace $.$$ { @ $mol_mem override value_string( next? : string ) { const current = this.value_normalized() + if (next === undefined) return current - if ( next !== undefined) this.value_normalized( next ) + const minus = next.includes('-') + next = next.replace(/[^\d\.]/g, '') + + if ( minus ) next = '-' + next + const dot_pos = next.indexOf('.') + + if (dot_pos !== -1) { + next = next.slice(0, dot_pos) + '.' + next.slice(dot_pos + 1).replace(/\./g, '') + } + + this.value_normalized( next ) return next ?? current } - + @ $mol_mem override dec_enabled() : boolean { return this.enabled() && ( From 9849191af8aaae4a94419127fac1543c702a8df3 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sun, 24 Nov 2024 01:37:44 +0300 Subject: [PATCH 10/25] $mol_number Intl.Numberformat --- number/number.view.tree | 4 +++- number/number.view.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/number/number.view.tree b/number/number.view.tree index 7e5abd1b909..219f33fb79d 100644 --- a/number/number.view.tree +++ b/number/number.view.tree @@ -6,7 +6,9 @@ $mol_number $mol_view value? +NaN enabled true sub / - <= String $mol_string + <= String $mol_format + allow \0123456789.- + mask* <= mask* \ - \ we don't want native number controls in mobile devices - \ https://stackoverflow.com/questions/3790935/can-i-hide-the-html5-number-input-s-spin-box type <= type \tel diff --git a/number/number.view.ts b/number/number.view.ts index 2a9399d20a0..dd3c9501aab 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -66,6 +66,18 @@ namespace $.$$ { } + @ $mol_mem + formatter() { + return new Intl.NumberFormat() + } + + override mask(val: string) { + if (! val) return '' + const current = Number(val.replace(/[^\d\.\-]/g, '')) + if (Number.isNaN(current)) return '' + return this.formatter().format(current).replace(/[^\s]/g, '_') + } + @ $mol_mem override dec_enabled() : boolean { return this.enabled() && ( From 29e7d0e5443f2c600c111c4a9cff1fb58bfa9577 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sun, 24 Nov 2024 02:21:29 +0300 Subject: [PATCH 11/25] $mol_number Intl en locale --- number/number.view.tree | 2 +- number/number.view.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/number/number.view.tree b/number/number.view.tree index 219f33fb79d..a2ac3979c6f 100644 --- a/number/number.view.tree +++ b/number/number.view.tree @@ -7,7 +7,7 @@ $mol_number $mol_view enabled true sub / <= String $mol_format - allow \0123456789.- + allow \0123456789,.- mask* <= mask* \ - \ we don't want native number controls in mobile devices - \ https://stackoverflow.com/questions/3790935/can-i-hide-the-html5-number-input-s-spin-box diff --git a/number/number.view.ts b/number/number.view.ts index dd3c9501aab..62085a60c70 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -51,7 +51,7 @@ namespace $.$$ { if (next === undefined) return current const minus = next.includes('-') - next = next.replace(/[^\d\.]/g, '') + next = next.replace(/,/g, '.').replace(/[^\d\.]/g, '') if ( minus ) next = '-' + next const dot_pos = next.indexOf('.') @@ -67,15 +67,17 @@ namespace $.$$ { } @ $mol_mem - formatter() { - return new Intl.NumberFormat() + static formatter() { + return new Intl.NumberFormat('en-EN') } + formatter() { return this.$.$mol_number.formatter() } + override mask(val: string) { if (! val) return '' - const current = Number(val.replace(/[^\d\.\-]/g, '')) + const current = Number(val.replace(/,/g, '.').replace(/[^\d\.\-]/g, '')) if (Number.isNaN(current)) return '' - return this.formatter().format(current).replace(/[^\s]/g, '_') + return this.formatter().format(current).replace(',', ' ').replace(/[^\s]/g, '_') } @ $mol_mem From dc71771f100e63cb0ae6032c2fb116dbe2dfcb07 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sun, 24 Nov 2024 15:59:32 +0300 Subject: [PATCH 12/25] $mol_number dynamic mask --- number/number.view.ts | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/number/number.view.ts b/number/number.view.ts index 62085a60c70..08bb9913299 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -66,18 +66,29 @@ namespace $.$$ { } - @ $mol_mem - static formatter() { - return new Intl.NumberFormat('en-EN') - } + format(num_str: string) { + let result = '' - formatter() { return this.$.$mol_number.formatter() } + for (let i = num_str.length - 1; i >= 0; i--) { + result += '_' + if ((i % 3) === 0) result += ' ' + } + return result.trim() + + } override mask(val: string) { - if (! val) return '' - const current = Number(val.replace(/,/g, '.').replace(/[^\d\.\-]/g, '')) - if (Number.isNaN(current)) return '' - return this.formatter().format(current).replace(',', ' ').replace(/[^\s]/g, '_') + // const str = val.replace(/,/g, '.').replace(/[^\d\.\-]/g, '') + // const [ main = '', frac = ''] = str.split('.') ?? [] + + const [_, main = '', frac = ''] = val.match(/(\-?\d+)(?:\.?(\d+))?/) ?? [] + + const prefix = this.format(main) + if (! frac) return prefix + + const suffix = this.format(frac).split('').reverse().join('') + + return prefix + '_' + suffix } @ $mol_mem From 92ad887d680ea25fafded319dd98a03dd6dad5c7 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sun, 24 Nov 2024 17:36:22 +0300 Subject: [PATCH 13/25] $mol_number dynamic mask --- number/number.view.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/number/number.view.ts b/number/number.view.ts index 08bb9913299..05d8f5a63b6 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -28,15 +28,19 @@ namespace $.$$ { } value_normalized(next?: string) { - const next_num = this.value_limited( next === undefined ? next : Number(next || Number.NaN) ) + const next_num = this.value_limited( + next === undefined + ? next + : next === '-' || next === '.' + ? $mol_wire_probe(() => this.value_limited()) ?? 0 + : Number(next || Number.NaN) + ) if (Number.isNaN(next_num)) return '' - - const precision_view = this.precision_view() - if( next_num === 0 ) return '0' if( !next_num ) return '' + const precision_view = this.precision_view() if( precision_view >= 1 ) { return ( next_num / precision_view ).toFixed() } else { @@ -78,9 +82,6 @@ namespace $.$$ { } override mask(val: string) { - // const str = val.replace(/,/g, '.').replace(/[^\d\.\-]/g, '') - // const [ main = '', frac = ''] = str.split('.') ?? [] - const [_, main = '', frac = ''] = val.match(/(\-?\d+)(?:\.?(\d+))?/) ?? [] const prefix = this.format(main) From cbb919b374656fbee8b1efb05696bdebd823b0a0 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sun, 24 Nov 2024 17:39:19 +0300 Subject: [PATCH 14/25] $mol_number fix leading zero format --- number/number.view.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/number/number.view.ts b/number/number.view.ts index 05d8f5a63b6..a435efee5cc 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -32,7 +32,7 @@ namespace $.$$ { next === undefined ? next : next === '-' || next === '.' - ? $mol_wire_probe(() => this.value_limited()) ?? 0 + ? $mol_wire_probe(() => this.value_limited()) : Number(next || Number.NaN) ) @@ -61,7 +61,7 @@ namespace $.$$ { const dot_pos = next.indexOf('.') if (dot_pos !== -1) { - next = next.slice(0, dot_pos) + '.' + next.slice(dot_pos + 1).replace(/\./g, '') + next = (next.slice(0, dot_pos) || '0') + '.' + next.slice(dot_pos + 1).replace(/\./g, '') } this.value_normalized( next ) From 609818c963bfdd2c38010ee042bead38e09d42c8 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sun, 24 Nov 2024 17:43:11 +0300 Subject: [PATCH 15/25] $mol_number fix remove leading zeroes > 1 of main part --- number/number.view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/number/number.view.ts b/number/number.view.ts index a435efee5cc..4a363878772 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -55,7 +55,7 @@ namespace $.$$ { if (next === undefined) return current const minus = next.includes('-') - next = next.replace(/,/g, '.').replace(/[^\d\.]/g, '') + next = next.replace(/,/g, '.').replace(/[^\d\.]/g, '').replace(/^0{2,}/, '0') if ( minus ) next = '-' + next const dot_pos = next.indexOf('.') From 3e1185fa0438d073bcd801c3c0437a5377268686 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sun, 24 Nov 2024 19:16:17 +0300 Subject: [PATCH 16/25] $mol_number refactor round --- number/number.view.ts | 56 +++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/number/number.view.ts b/number/number.view.ts index 4a363878772..a495c437700 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -27,47 +27,63 @@ namespace $.$$ { this.value_limited( ( this.value_limited() || 0 ) + this.precision_change() ) } - value_normalized(next?: string) { - const next_num = this.value_limited( - next === undefined - ? next - : next === '-' || next === '.' - ? $mol_wire_probe(() => this.value_limited()) - : Number(next || Number.NaN) - ) - - if (Number.isNaN(next_num)) return '' - if( next_num === 0 ) return '0' - if( !next_num ) return '' + round(val: number) { + if (Number.isNaN(val)) return '' + if( val === 0 ) return '0' + if( !val ) return '' const precision_view = this.precision_view() + + if (! precision_view) return val.toFixed() + if( precision_view >= 1 ) { - return ( next_num / precision_view ).toFixed() + return ( val / precision_view ).toFixed() } else { const fixed_number = Math.log10( 1 / precision_view ) - return next_num.toFixed( Math.ceil( fixed_number ) ) + return val.toFixed( Math.ceil( fixed_number ) ) } } @ $mol_mem - override value_string( next? : string ) { - const current = this.value_normalized() + override value_string( next? : string ): string { + // Вытягиваем value + // Если кто-то поменяет из вне value, value_string надо обновить + const current = this.round( this.value_limited() ) if (next === undefined) return current const minus = next.includes('-') + // Запятые меняем на точки, удаляем не-цифры и не-точки и лишние ноли в начале целой части. next = next.replace(/,/g, '.').replace(/[^\d\.]/g, '').replace(/^0{2,}/, '0') + // Второй минус не даем ввести. + // Если где-либо ввели минус, то ставим минус в начале, если его там нет if ( minus ) next = '-' + next - const dot_pos = next.indexOf('.') + + let dot_pos = next.indexOf('.') if (dot_pos !== -1) { - next = (next.slice(0, dot_pos) || '0') + '.' + next.slice(dot_pos + 1).replace(/\./g, '') + const prev = $mol_wire_probe(() => this.value_string()) ?? '' + const dot_pos_prev = prev.indexOf('.') + // Определяем где относительно предыдущей точки юзер поставил новую + if (dot_pos_prev === dot_pos) dot_pos = next.lastIndexOf('.') + + // Из частей до и после новой точки старую точку удаляем, отбрасываем значения больше + const frac = next.slice(dot_pos + 1).replace(/\./g, '') + + // Если точка идет первой, перед ней пишем 0, что бы форматирование выглядело нормально в mask + next = (next.slice(0, dot_pos) || '0').replace(/\./g, '') + '.' + frac } - this.value_normalized( next ) + // Оставляем старое значение в value есть сочетание, приводящие к NaN, например -. + if ( Number.isNaN(Number(next)) ) return next - return next ?? current + // Точку в конце поставить нельзя, если precision_view < 1, т.е. разрешены только целые числа. + if ( next.endsWith('.') && this.precision_view() < 1) return next + if ( next.endsWith('-') ) return next + // Если пустая строка - сетим NaN + // Применяем округления. + return this.round( this.value_limited(Number(next || Number.NaN)) ) } format(num_str: string) { From f504e62144e44f7395a25ffaf7c87f707a79da8e Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sun, 24 Nov 2024 19:19:10 +0300 Subject: [PATCH 17/25] $mol_number refactor fix comment --- number/number.view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/number/number.view.ts b/number/number.view.ts index a495c437700..ab0d9646b70 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -77,7 +77,7 @@ namespace $.$$ { // Оставляем старое значение в value есть сочетание, приводящие к NaN, например -. if ( Number.isNaN(Number(next)) ) return next - // Точку в конце поставить нельзя, если precision_view < 1, т.е. разрешены только целые числа. + // Точку в конце поставить нельзя, если precision_view >= 1, т.е. разрешены только целые числа. if ( next.endsWith('.') && this.precision_view() < 1) return next if ( next.endsWith('-') ) return next From 916d10ad2dc964fabe8755ebc1c276d3a4b1c745 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sun, 24 Nov 2024 19:30:04 +0300 Subject: [PATCH 18/25] $mol_number precision --- number/number.view.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/number/number.view.ts b/number/number.view.ts index ab0d9646b70..e482811e537 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -77,8 +77,9 @@ namespace $.$$ { // Оставляем старое значение в value есть сочетание, приводящие к NaN, например -. if ( Number.isNaN(Number(next)) ) return next - // Точку в конце поставить нельзя, если precision_view >= 1, т.е. разрешены только целые числа. - if ( next.endsWith('.') && this.precision_view() < 1) return next + const precision = this.precision_view() + // Точку в конце поставить нельзя, если precision_view целое число > 0 + if ( next.endsWith('.') && precision - Math.floor(precision) === 0) return next if ( next.endsWith('-') ) return next // Если пустая строка - сетим NaN From 704edcd944d0e2fce1e9cc229f6557bcb97d8e04 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sun, 24 Nov 2024 23:01:18 +0300 Subject: [PATCH 19/25] $mol_number review fixes --- number/number.view.tree | 2 +- number/number.view.ts | 51 ++++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/number/number.view.tree b/number/number.view.tree index a2ac3979c6f..3414d650959 100644 --- a/number/number.view.tree +++ b/number/number.view.tree @@ -7,7 +7,7 @@ $mol_number $mol_view enabled true sub / <= String $mol_format - allow \0123456789,.- + allow <= allow <= allow_default \0123456789,.- mask* <= mask* \ - \ we don't want native number controls in mobile devices - \ https://stackoverflow.com/questions/3790935/can-i-hide-the-html5-number-input-s-spin-box diff --git a/number/number.view.ts b/number/number.view.ts index e482811e537..75476034fc7 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -1,5 +1,17 @@ namespace $.$$ { + function format(num_str: string) { + let result = '' + + for (let i = num_str.length - 1; i >= 0; i--) { + result += '_' + if ((i % 3) === 0) result += ' ' + } + + return result.trim() + + } + /** * Component for entering, incrementing and decrementing numeric values. * @see https://mol.hyoo.ru/#!section=demos/demo=mol_number_demo @@ -43,7 +55,21 @@ namespace $.$$ { return val.toFixed( Math.ceil( fixed_number ) ) } } - + + override allow() { + let next = this.allow_default() + + const precision = this.precision_view() + + // Точку в конце поставить нельзя, если precision_view целое число > 0 + if ( precision - Math.floor(precision) === 0 ) next = next.replace(/[.,]/g, '') + + // Минус нельзя ввести, если минимальное значение >=0 + if (this.value_min() >= 0) next = next.replace('-', '') + + return next + } + @ $mol_mem override value_string( next? : string ): string { // Вытягиваем value @@ -67,7 +93,7 @@ namespace $.$$ { // Определяем где относительно предыдущей точки юзер поставил новую if (dot_pos_prev === dot_pos) dot_pos = next.lastIndexOf('.') - // Из частей до и после новой точки старую точку удаляем, отбрасываем значения больше + // Из частей до и после новой точки старую точку удаляем const frac = next.slice(dot_pos + 1).replace(/\./g, '') // Если точка идет первой, перед ней пишем 0, что бы форматирование выглядело нормально в mask @@ -77,9 +103,7 @@ namespace $.$$ { // Оставляем старое значение в value есть сочетание, приводящие к NaN, например -. if ( Number.isNaN(Number(next)) ) return next - const precision = this.precision_view() - // Точку в конце поставить нельзя, если precision_view целое число > 0 - if ( next.endsWith('.') && precision - Math.floor(precision) === 0) return next + if ( next.endsWith('.') ) return next if ( next.endsWith('-') ) return next // Если пустая строка - сетим NaN @@ -87,24 +111,13 @@ namespace $.$$ { return this.round( this.value_limited(Number(next || Number.NaN)) ) } - format(num_str: string) { - let result = '' - - for (let i = num_str.length - 1; i >= 0; i--) { - result += '_' - if ((i % 3) === 0) result += ' ' - } - return result.trim() - - } - override mask(val: string) { - const [_, main = '', frac = ''] = val.match(/(\-?\d+)(?:\.?(\d+))?/) ?? [] + const [_, minus, main = '', frac] = val.match(/(\-)?(\d+)(?:\.?(\d+))?/) ?? [] - const prefix = this.format(main) + const prefix = (minus ? '_' : '') + format(main) if (! frac) return prefix - const suffix = this.format(frac).split('').reverse().join('') + const suffix = format(frac).split('').reverse().join('') return prefix + '_' + suffix } From 3cbf0602ca26186f96524e761112e0766887f74e Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sun, 24 Nov 2024 23:09:59 +0300 Subject: [PATCH 20/25] $mol_number review fixes 2 --- number/number.view.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/number/number.view.ts b/number/number.view.ts index 75476034fc7..8e597c86a8c 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -77,13 +77,10 @@ namespace $.$$ { const current = this.round( this.value_limited() ) if (next === undefined) return current - const minus = next.includes('-') // Запятые меняем на точки, удаляем не-цифры и не-точки и лишние ноли в начале целой части. - next = next.replace(/,/g, '.').replace(/[^\d\.]/g, '').replace(/^0{2,}/, '0') - - // Второй минус не даем ввести. - // Если где-либо ввели минус, то ставим минус в начале, если его там нет - if ( minus ) next = '-' + next + // Минус получится ввести только в начале. + next = (next.startsWith('-') ? '-' : '') + + next.replace(/,/g, '.').replace(/[^\d\.]/g, '').replace(/^0{2,}/, '0') let dot_pos = next.indexOf('.') From 82035508c7e2c1ebdf1ca2f47a85b34692e72732 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Mon, 25 Nov 2024 15:22:57 +0300 Subject: [PATCH 21/25] $mol_format dynamic mask cursor fix --- format/format.view.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/format/format.view.ts b/format/format.view.ts index faf0eeb903e..ce4b4fb5fda 100644 --- a/format/format.view.ts +++ b/format/format.view.ts @@ -19,8 +19,11 @@ namespace $.$$ { const mask = this.mask( filtered ) if( ( prev?.[0] ?? 0 ) >= from ) return [ from, to ] - - const lastAllow = ( value.length - [ ... value ].reverse().findIndex( letter => allow.includes( letter ) ) )%(value.length+1) + + const lastAllow = ( + value.length - [ ... value ].reverse().findIndex( letter => allow.includes( letter ) ) + ) % ( value.length + 1 ) + if( lastAllow < from ) { from = to = lastAllow } @@ -29,9 +32,23 @@ namespace $.$$ { ++ from ++ to } - + + // Если по-сравнению с this.mask_prev в mask добавились/удалились не подчервивания слева от from + // То надо увеличить/уменьшить from и to, на кол-во добавленных/удаленных символов + const before = mask.slice(0, from).replace(/_/g, '').length + const before_prev = this.mask_prev.slice(0, from).replace(/_/g, '').length + let delta = before - before_prev + + from += delta + to += delta + + + this.mask_prev = mask + return [ from, to ] } + + protected mask_prev = '' @ $mol_mem value_changed( next?: string ) { From 597198692673c6cfa339ad8e980dc5d9ae8f013e Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Mon, 25 Nov 2024 21:41:43 +0300 Subject: [PATCH 22/25] $mol_number removed format --- format/format.view.ts | 14 -------------- number/number.view.tree | 4 +--- number/number.view.ts | 32 ++++++-------------------------- 3 files changed, 7 insertions(+), 43 deletions(-) diff --git a/format/format.view.ts b/format/format.view.ts index ce4b4fb5fda..a61ba819fa5 100644 --- a/format/format.view.ts +++ b/format/format.view.ts @@ -33,22 +33,8 @@ namespace $.$$ { ++ to } - // Если по-сравнению с this.mask_prev в mask добавились/удалились не подчервивания слева от from - // То надо увеличить/уменьшить from и to, на кол-во добавленных/удаленных символов - const before = mask.slice(0, from).replace(/_/g, '').length - const before_prev = this.mask_prev.slice(0, from).replace(/_/g, '').length - let delta = before - before_prev - - from += delta - to += delta - - - this.mask_prev = mask - return [ from, to ] } - - protected mask_prev = '' @ $mol_mem value_changed( next?: string ) { diff --git a/number/number.view.tree b/number/number.view.tree index 3414d650959..7e5abd1b909 100644 --- a/number/number.view.tree +++ b/number/number.view.tree @@ -6,9 +6,7 @@ $mol_number $mol_view value? +NaN enabled true sub / - <= String $mol_format - allow <= allow <= allow_default \0123456789,.- - mask* <= mask* \ + <= String $mol_string - \ we don't want native number controls in mobile devices - \ https://stackoverflow.com/questions/3790935/can-i-hide-the-html5-number-input-s-spin-box type <= type \tel diff --git a/number/number.view.ts b/number/number.view.ts index 8e597c86a8c..5145004856b 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -55,20 +55,6 @@ namespace $.$$ { return val.toFixed( Math.ceil( fixed_number ) ) } } - - override allow() { - let next = this.allow_default() - - const precision = this.precision_view() - - // Точку в конце поставить нельзя, если precision_view целое число > 0 - if ( precision - Math.floor(precision) === 0 ) next = next.replace(/[.,]/g, '') - - // Минус нельзя ввести, если минимальное значение >=0 - if (this.value_min() >= 0) next = next.replace('-', '') - - return next - } @ $mol_mem override value_string( next? : string ): string { @@ -77,9 +63,14 @@ namespace $.$$ { const current = this.round( this.value_limited() ) if (next === undefined) return current + const precision = this.precision_view() + + // Точку в конце поставить нельзя, если precision_view целое число > 0 + if ( precision - Math.floor(precision) === 0 ) next = next.replace(/[.,]/g, '') + // Запятые меняем на точки, удаляем не-цифры и не-точки и лишние ноли в начале целой части. // Минус получится ввести только в начале. - next = (next.startsWith('-') ? '-' : '') + next = (this.value_min() >= 0 && next.startsWith('-') ? '-' : '') + next.replace(/,/g, '.').replace(/[^\d\.]/g, '').replace(/^0{2,}/, '0') let dot_pos = next.indexOf('.') @@ -108,17 +99,6 @@ namespace $.$$ { return this.round( this.value_limited(Number(next || Number.NaN)) ) } - override mask(val: string) { - const [_, minus, main = '', frac] = val.match(/(\-)?(\d+)(?:\.?(\d+))?/) ?? [] - - const prefix = (minus ? '_' : '') + format(main) - if (! frac) return prefix - - const suffix = format(frac).split('').reverse().join('') - - return prefix + '_' + suffix - } - @ $mol_mem override dec_enabled() : boolean { return this.enabled() && ( From 9f7d7e17d4d103e8d1655237e292a69fddedff2c Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Mon, 25 Nov 2024 21:53:04 +0300 Subject: [PATCH 23/25] $mol_number fix minus --- number/number.view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/number/number.view.ts b/number/number.view.ts index 5145004856b..bdd7345bad4 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -70,7 +70,7 @@ namespace $.$$ { // Запятые меняем на точки, удаляем не-цифры и не-точки и лишние ноли в начале целой части. // Минус получится ввести только в начале. - next = (this.value_min() >= 0 && next.startsWith('-') ? '-' : '') + next = (this.value_min() < 0 && next.startsWith('-') ? '-' : '') + next.replace(/,/g, '.').replace(/[^\d\.]/g, '').replace(/^0{2,}/, '0') let dot_pos = next.indexOf('.') From bfbe8cb88d2012b13022eb439250e17e3467b2d9 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Mon, 25 Nov 2024 22:11:31 +0300 Subject: [PATCH 24/25] $mol_number remove format function --- number/number.view.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/number/number.view.ts b/number/number.view.ts index bdd7345bad4..177fd0ad108 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -1,17 +1,5 @@ namespace $.$$ { - function format(num_str: string) { - let result = '' - - for (let i = num_str.length - 1; i >= 0; i--) { - result += '_' - if ((i % 3) === 0) result += ' ' - } - - return result.trim() - - } - /** * Component for entering, incrementing and decrementing numeric values. * @see https://mol.hyoo.ru/#!section=demos/demo=mol_number_demo From 7fee62077de206f2da47a23186fb3bf528514800 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Mon, 25 Nov 2024 22:35:44 +0300 Subject: [PATCH 25/25] $mol_number fix negative value --- number/number.view.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/number/number.view.ts b/number/number.view.ts index 177fd0ad108..ba3e2a7d6e2 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -84,7 +84,11 @@ namespace $.$$ { // Если пустая строка - сетим NaN // Применяем округления. - return this.round( this.value_limited(Number(next || Number.NaN)) ) + this.value_limited(Number(next || Number.NaN)) + + // Возвращаем все-равно не нормализованное значение + // Иначе нельзя ввести будет 10, если min/max 5..10 + return next } @ $mol_mem