@taiga-ui/addon-commerce 4.52.0-canary.6ee9658 → 4.52.0-canary.811ffeb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/taiga-ui-addon-commerce-constants.mjs +1 -1
- package/fesm2022/taiga-ui-addon-commerce-constants.mjs.map +1 -1
- package/fesm2022/taiga-ui-addon-commerce-pipes-amount.mjs +23 -17
- package/fesm2022/taiga-ui-addon-commerce-pipes-amount.mjs.map +1 -1
- package/fesm2022/taiga-ui-addon-commerce-pipes-decimal.mjs +17 -10
- package/fesm2022/taiga-ui-addon-commerce-pipes-decimal.mjs.map +1 -1
- package/package.json +1 -1
- package/pipes/amount/amount.pipe.d.ts +5 -2
- package/pipes/decimal/decimal.pipe.d.ts +4 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taiga-ui-addon-commerce-constants.mjs","sources":["../../../projects/addon-commerce/constants/default-card-validator.ts","../../../projects/addon-commerce/constants/mask-card.ts","../../../projects/addon-commerce/constants/mask-card-holder.ts","../../../projects/addon-commerce/constants/mask-cvc.ts","../../../projects/addon-commerce/constants/mask-expire.ts","../../../projects/addon-commerce/constants/taiga-ui-addon-commerce-constants.ts"],"sourcesContent":["import {tuiIsCardLengthValid, tuiIsCardNumberValid} from '@taiga-ui/addon-commerce/utils';\nimport {type TuiBooleanHandler} from '@taiga-ui/cdk/types';\n\nexport const tuiDefaultCardValidator: TuiBooleanHandler<string> = (card) =>\n card.length > 11 && tuiIsCardLengthValid(card) && tuiIsCardNumberValid(card);\n","import {maskitoInitialCalibrationPlugin, type MaskitoOptions} from '@maskito/core';\nimport {CHAR_NO_BREAK_SPACE, TUI_DIGIT_REGEXP} from '@taiga-ui/cdk/constants';\n\nexport const TUI_MASK_CARD: MaskitoOptions = {\n plugins: [maskitoInitialCalibrationPlugin()],\n mask: Array.from({length: 23}).map((_, i) =>\n (i + 1) % 5 ? TUI_DIGIT_REGEXP : CHAR_NO_BREAK_SPACE,\n ),\n};\n","import {type MaskitoOptions} from '@maskito/core';\n\nconst MAP: Record<string, string> = {\n А: 'F',\n В: 'D',\n Г: 'U',\n Д: 'L',\n Е: 'T',\n З: 'P',\n И: 'B',\n Й: 'Q',\n К: 'R',\n Л: 'K',\n М: 'V',\n Н: 'Y',\n О: 'J',\n П: 'G',\n Р: 'H',\n С: 'C',\n Т: 'N',\n У: 'E',\n Ф: 'A',\n Ц: 'W',\n Ч: 'X',\n Ш: 'I',\n Щ: 'O',\n Ы: 'S',\n Ь: 'M',\n Я: 'Z',\n};\n\nfunction toEnglishUppercase(value: string): string {\n return value\n .toUpperCase()\n .split('')\n .map((char) => MAP[char] || char)\n .join('');\n}\n\nexport const TUI_MASK_CARD_HOLDER: MaskitoOptions = {\n mask: /^[a-z\\s]+$/i,\n preprocessors: [\n ({elementState, data}) => {\n const {value, selection} = elementState;\n\n return {\n elementState: {\n selection,\n value: toEnglishUppercase(value),\n },\n data: toEnglishUppercase(data),\n };\n },\n ],\n};\n","import {type MaskitoOptions} from '@maskito/core';\nimport {TUI_DIGIT_REGEXP} from '@taiga-ui/cdk/constants';\nimport {type TuiHandler} from '@taiga-ui/cdk/types';\n\nexport const TUI_MASK_CVC: TuiHandler<number, MaskitoOptions> = (length) => ({\n mask:
|
|
1
|
+
{"version":3,"file":"taiga-ui-addon-commerce-constants.mjs","sources":["../../../projects/addon-commerce/constants/default-card-validator.ts","../../../projects/addon-commerce/constants/mask-card.ts","../../../projects/addon-commerce/constants/mask-card-holder.ts","../../../projects/addon-commerce/constants/mask-cvc.ts","../../../projects/addon-commerce/constants/mask-expire.ts","../../../projects/addon-commerce/constants/taiga-ui-addon-commerce-constants.ts"],"sourcesContent":["import {tuiIsCardLengthValid, tuiIsCardNumberValid} from '@taiga-ui/addon-commerce/utils';\nimport {type TuiBooleanHandler} from '@taiga-ui/cdk/types';\n\nexport const tuiDefaultCardValidator: TuiBooleanHandler<string> = (card) =>\n card.length > 11 && tuiIsCardLengthValid(card) && tuiIsCardNumberValid(card);\n","import {maskitoInitialCalibrationPlugin, type MaskitoOptions} from '@maskito/core';\nimport {CHAR_NO_BREAK_SPACE, TUI_DIGIT_REGEXP} from '@taiga-ui/cdk/constants';\n\nexport const TUI_MASK_CARD: MaskitoOptions = {\n plugins: [maskitoInitialCalibrationPlugin()],\n mask: Array.from({length: 23}).map((_, i) =>\n (i + 1) % 5 ? TUI_DIGIT_REGEXP : CHAR_NO_BREAK_SPACE,\n ),\n};\n","import {type MaskitoOptions} from '@maskito/core';\n\nconst MAP: Record<string, string> = {\n А: 'F',\n В: 'D',\n Г: 'U',\n Д: 'L',\n Е: 'T',\n З: 'P',\n И: 'B',\n Й: 'Q',\n К: 'R',\n Л: 'K',\n М: 'V',\n Н: 'Y',\n О: 'J',\n П: 'G',\n Р: 'H',\n С: 'C',\n Т: 'N',\n У: 'E',\n Ф: 'A',\n Ц: 'W',\n Ч: 'X',\n Ш: 'I',\n Щ: 'O',\n Ы: 'S',\n Ь: 'M',\n Я: 'Z',\n};\n\nfunction toEnglishUppercase(value: string): string {\n return value\n .toUpperCase()\n .split('')\n .map((char) => MAP[char] || char)\n .join('');\n}\n\nexport const TUI_MASK_CARD_HOLDER: MaskitoOptions = {\n mask: /^[a-z\\s]+$/i,\n preprocessors: [\n ({elementState, data}) => {\n const {value, selection} = elementState;\n\n return {\n elementState: {\n selection,\n value: toEnglishUppercase(value),\n },\n data: toEnglishUppercase(data),\n };\n },\n ],\n};\n","import {type MaskitoOptions} from '@maskito/core';\nimport {TUI_DIGIT_REGEXP} from '@taiga-ui/cdk/constants';\nimport {type TuiHandler} from '@taiga-ui/cdk/types';\n\nexport const TUI_MASK_CVC: TuiHandler<number, MaskitoOptions> = (length) => ({\n mask: Array.from({length}, () => TUI_DIGIT_REGEXP),\n});\n","import {maskitoDateOptionsGenerator} from '@maskito/kit';\n\nexport const TUI_MASK_EXPIRE = maskitoDateOptionsGenerator({\n mode: 'mm/yy',\n separator: '/',\n});\n","/**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,IAAA,CAAC,EAAE,GAAG;CACT;AAED,SAAS,kBAAkB,CAAC,KAAa,EAAA;AACrC,IAAA,OAAO;AACF,SAAA,WAAW;SACX,KAAK,CAAC,EAAE;AACR,SAAA,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI;SAC/B,IAAI,CAAC,EAAE,CAAC;AACjB;AAEa,MAAA,oBAAoB,GAAmB;AAChD,IAAA,IAAI,EAAE,aAAa;AACnB,IAAA,aAAa,EAAE;AACX,QAAA,CAAC,EAAC,YAAY,EAAE,IAAI,EAAC,KAAI;AACrB,YAAA,MAAM,EAAC,KAAK,EAAE,SAAS,EAAC,GAAG,YAAY;YAEvC,OAAO;AACH,gBAAA,YAAY,EAAE;oBACV,SAAS;AACT,oBAAA,KAAK,EAAE,kBAAkB,CAAC,KAAK,CAAC;AACnC,iBAAA;AACD,gBAAA,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC;aACjC;SACJ;AACJ,KAAA;;;MCjDQ,YAAY,GAAuC,CAAC,MAAM,MAAM;AACzE,IAAA,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,EAAC,MAAM,EAAC,EAAE,MAAM,gBAAgB,CAAC;AACrD,CAAA;;ACJM,MAAM,eAAe,GAAG,2BAA2B,CAAC;AACvD,IAAA,IAAI,EAAE,OAAO;AACb,IAAA,SAAS,EAAE,GAAG;AACjB,CAAA;;ACLD;;AAEG;;;;"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { tuiCreateOptions } from '@taiga-ui/cdk/utils/di';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
|
-
import { inject, Pipe } from '@angular/core';
|
|
4
|
-
import { toObservable } from '@angular/core/rxjs-interop';
|
|
3
|
+
import { inject, signal, computed, untracked, Pipe } from '@angular/core';
|
|
5
4
|
import { tuiFormatCurrency } from '@taiga-ui/addon-commerce/utils';
|
|
6
5
|
import { CHAR_MINUS, CHAR_PLUS, CHAR_NO_BREAK_SPACE } from '@taiga-ui/cdk/constants';
|
|
7
6
|
import { TUI_NUMBER_FORMAT } from '@taiga-ui/core/tokens';
|
|
8
7
|
import { tuiFormatNumber } from '@taiga-ui/core/utils/format';
|
|
9
|
-
import { map } from 'rxjs';
|
|
10
8
|
|
|
11
9
|
const TUI_AMOUNT_DEFAULT_OPTIONS = {
|
|
12
10
|
currency: null,
|
|
@@ -29,35 +27,43 @@ const DEFAULT_PRECISION = 2;
|
|
|
29
27
|
class TuiAmountPipe {
|
|
30
28
|
constructor() {
|
|
31
29
|
this.options = inject(TUI_AMOUNT_OPTIONS);
|
|
32
|
-
this.format =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
30
|
+
this.format = inject(TUI_NUMBER_FORMAT);
|
|
31
|
+
this.value = signal(NaN);
|
|
32
|
+
this.currency = signal(this.options.currency);
|
|
33
|
+
this.currencyAlign = signal(this.options.currencyAlign);
|
|
34
|
+
this.formatted = computed(() => {
|
|
35
|
+
const format = this.format();
|
|
36
|
+
const currencySymbol = tuiFormatCurrency(this.currency());
|
|
37
|
+
const formatted = tuiFormatNumber(Math.abs(this.value()), {
|
|
38
38
|
...format,
|
|
39
39
|
precision: Number.isNaN(format.precision)
|
|
40
40
|
? DEFAULT_PRECISION
|
|
41
41
|
: format.precision,
|
|
42
42
|
});
|
|
43
|
-
const sign = formatted === '0'
|
|
44
|
-
? ''
|
|
45
|
-
: tuiFormatSignSymbol(value, this.options.sign);
|
|
43
|
+
const sign = formatted === '0' ? '' : tuiFormatSignSymbol(this.value(), this.options.sign);
|
|
46
44
|
const space = currencySymbol &&
|
|
47
|
-
(currencySymbol?.length > 1 || currencyAlign === 'right')
|
|
45
|
+
(currencySymbol?.length > 1 || this.currencyAlign() === 'right')
|
|
48
46
|
? CHAR_NO_BREAK_SPACE
|
|
49
47
|
: '';
|
|
50
|
-
return currencyAlign === 'right'
|
|
48
|
+
return this.currencyAlign() === 'right'
|
|
51
49
|
? `${sign}${formatted}${space}${currencySymbol}`
|
|
52
50
|
: `${sign}${currencySymbol}${space}${formatted}`;
|
|
53
|
-
})
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
transform(value, currency = this.options.currency, currencyAlign = this.options.currencyAlign) {
|
|
54
|
+
untracked(() => {
|
|
55
|
+
this.value.set(value);
|
|
56
|
+
this.currency.set(currency);
|
|
57
|
+
this.currencyAlign.set(currencyAlign);
|
|
58
|
+
});
|
|
59
|
+
return this.formatted();
|
|
54
60
|
}
|
|
55
61
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: TuiAmountPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
56
|
-
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.15", ngImport: i0, type: TuiAmountPipe, isStandalone: true, name: "tuiAmount" }); }
|
|
62
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.15", ngImport: i0, type: TuiAmountPipe, isStandalone: true, name: "tuiAmount", pure: false }); }
|
|
57
63
|
}
|
|
58
64
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: TuiAmountPipe, decorators: [{
|
|
59
65
|
type: Pipe,
|
|
60
|
-
args: [{ name: 'tuiAmount' }]
|
|
66
|
+
args: [{ name: 'tuiAmount', pure: false }]
|
|
61
67
|
}] });
|
|
62
68
|
|
|
63
69
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taiga-ui-addon-commerce-pipes-amount.mjs","sources":["../../../projects/addon-commerce/pipes/amount/amount.options.ts","../../../projects/addon-commerce/pipes/amount/amount.utils.ts","../../../projects/addon-commerce/pipes/amount/amount.pipe.ts","../../../projects/addon-commerce/pipes/amount/taiga-ui-addon-commerce-pipes-amount.ts"],"sourcesContent":["import {type TuiCurrencyVariants} from '@taiga-ui/addon-commerce/types';\nimport {tuiCreateOptions} from '@taiga-ui/cdk/utils/di';\nimport {type TuiHorizontalDirection} from '@taiga-ui/core/types';\n\nimport {type TuiAmountSign} from './amount.types';\n\nexport interface TuiAmountOptions {\n readonly currency: TuiCurrencyVariants;\n readonly currencyAlign: TuiHorizontalDirection;\n readonly sign: TuiAmountSign;\n}\n\nexport const TUI_AMOUNT_DEFAULT_OPTIONS: TuiAmountOptions = {\n currency: null,\n currencyAlign: 'left',\n sign: 'negative-only',\n};\n\nexport const [TUI_AMOUNT_OPTIONS, tuiAmountOptionsProvider] = tuiCreateOptions(\n TUI_AMOUNT_DEFAULT_OPTIONS,\n);\n","import {CHAR_MINUS, CHAR_PLUS} from '@taiga-ui/cdk/constants';\n\nimport {type TuiAmountSign, type TuiAmountSignSymbol} from './amount.types';\n\nexport function tuiFormatSignSymbol(\n value: number,\n sign: TuiAmountSign,\n): TuiAmountSignSymbol {\n if (sign === 'never' || !value || (sign === 'negative-only' && value > 0)) {\n return '';\n }\n\n if (sign === 'force-negative' || (value < 0 && sign !== 'force-positive')) {\n return CHAR_MINUS;\n }\n\n return CHAR_PLUS;\n}\n","import {inject
|
|
1
|
+
{"version":3,"file":"taiga-ui-addon-commerce-pipes-amount.mjs","sources":["../../../projects/addon-commerce/pipes/amount/amount.options.ts","../../../projects/addon-commerce/pipes/amount/amount.utils.ts","../../../projects/addon-commerce/pipes/amount/amount.pipe.ts","../../../projects/addon-commerce/pipes/amount/taiga-ui-addon-commerce-pipes-amount.ts"],"sourcesContent":["import {type TuiCurrencyVariants} from '@taiga-ui/addon-commerce/types';\nimport {tuiCreateOptions} from '@taiga-ui/cdk/utils/di';\nimport {type TuiHorizontalDirection} from '@taiga-ui/core/types';\n\nimport {type TuiAmountSign} from './amount.types';\n\nexport interface TuiAmountOptions {\n readonly currency: TuiCurrencyVariants;\n readonly currencyAlign: TuiHorizontalDirection;\n readonly sign: TuiAmountSign;\n}\n\nexport const TUI_AMOUNT_DEFAULT_OPTIONS: TuiAmountOptions = {\n currency: null,\n currencyAlign: 'left',\n sign: 'negative-only',\n};\n\nexport const [TUI_AMOUNT_OPTIONS, tuiAmountOptionsProvider] = tuiCreateOptions(\n TUI_AMOUNT_DEFAULT_OPTIONS,\n);\n","import {CHAR_MINUS, CHAR_PLUS} from '@taiga-ui/cdk/constants';\n\nimport {type TuiAmountSign, type TuiAmountSignSymbol} from './amount.types';\n\nexport function tuiFormatSignSymbol(\n value: number,\n sign: TuiAmountSign,\n): TuiAmountSignSymbol {\n if (sign === 'never' || !value || (sign === 'negative-only' && value > 0)) {\n return '';\n }\n\n if (sign === 'force-negative' || (value < 0 && sign !== 'force-positive')) {\n return CHAR_MINUS;\n }\n\n return CHAR_PLUS;\n}\n","import {\n computed,\n inject,\n Pipe,\n type PipeTransform,\n signal,\n untracked,\n} from '@angular/core';\nimport {type TuiCurrencyVariants} from '@taiga-ui/addon-commerce/types';\nimport {tuiFormatCurrency} from '@taiga-ui/addon-commerce/utils';\nimport {CHAR_NO_BREAK_SPACE} from '@taiga-ui/cdk/constants';\nimport {TUI_NUMBER_FORMAT} from '@taiga-ui/core/tokens';\nimport {type TuiHorizontalDirection} from '@taiga-ui/core/types';\nimport {tuiFormatNumber} from '@taiga-ui/core/utils/format';\n\nimport {TUI_AMOUNT_OPTIONS} from './amount.options';\nimport {tuiFormatSignSymbol} from './amount.utils';\n\nconst DEFAULT_PRECISION = 2;\n\n@Pipe({name: 'tuiAmount', pure: false})\nexport class TuiAmountPipe implements PipeTransform {\n private readonly options = inject(TUI_AMOUNT_OPTIONS);\n private readonly format = inject(TUI_NUMBER_FORMAT);\n\n private readonly value = signal(NaN);\n private readonly currency = signal(this.options.currency);\n private readonly currencyAlign = signal(this.options.currencyAlign);\n\n private readonly formatted = computed(() => {\n const format = this.format();\n const currencySymbol = tuiFormatCurrency(this.currency());\n const formatted = tuiFormatNumber(Math.abs(this.value()), {\n ...format,\n precision: Number.isNaN(format.precision)\n ? DEFAULT_PRECISION\n : format.precision,\n });\n const sign =\n formatted === '0' ? '' : tuiFormatSignSymbol(this.value(), this.options.sign);\n const space =\n currencySymbol &&\n (currencySymbol?.length > 1 || this.currencyAlign() === 'right')\n ? CHAR_NO_BREAK_SPACE\n : '';\n\n return this.currencyAlign() === 'right'\n ? `${sign}${formatted}${space}${currencySymbol}`\n : `${sign}${currencySymbol}${space}${formatted}`;\n });\n\n public transform(\n value: number,\n currency: TuiCurrencyVariants = this.options.currency,\n currencyAlign: TuiHorizontalDirection = this.options.currencyAlign,\n ): string {\n untracked(() => {\n this.value.set(value);\n this.currency.set(currency);\n this.currencyAlign.set(currencyAlign);\n });\n\n return this.formatted();\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;AAYa,MAAA,0BAA0B,GAAqB;AACxD,IAAA,QAAQ,EAAE,IAAI;AACd,IAAA,aAAa,EAAE,MAAM;AACrB,IAAA,IAAI,EAAE,eAAe;;AAGlB,MAAM,CAAC,kBAAkB,EAAE,wBAAwB,CAAC,GAAG,gBAAgB,CAC1E,0BAA0B;;ACfd,SAAA,mBAAmB,CAC/B,KAAa,EACb,IAAmB,EAAA;AAEnB,IAAA,IAAI,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,KAAK,IAAI,KAAK,eAAe,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;AACvE,QAAA,OAAO,EAAE;;AAGb,IAAA,IAAI,IAAI,KAAK,gBAAgB,KAAK,KAAK,GAAG,CAAC,IAAI,IAAI,KAAK,gBAAgB,CAAC,EAAE;AACvE,QAAA,OAAO,UAAU;;AAGrB,IAAA,OAAO,SAAS;AACpB;;ACCA,MAAM,iBAAiB,GAAG,CAAC;MAGd,aAAa,CAAA;AAD1B,IAAA,WAAA,GAAA;AAEqB,QAAA,IAAA,CAAA,OAAO,GAAG,MAAM,CAAC,kBAAkB,CAAC;AACpC,QAAA,IAAA,CAAA,MAAM,GAAG,MAAM,CAAC,iBAAi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AO,CAAC,QAAQ,EACrD,aAAwC,GAAA,IAAI,CAAC,OAAO,CAAC,aAAa,EAAA;QAElE,SAAS,CAAC,MAAK;AACX,YAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;AACrB,YAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC;AAC3B,YAAA,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC;AACzC,SAAC,CAAC;AAEF,QAAA,OAAO,IAAI,CAAC,SAAS,EAAE;;+GAzClB,aAAa,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,IAAA,EAAA,CAAA,CAAA;6GAAb,aAAa,EAAA,YAAA,EAAA,IAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAA,KAAA,EAAA,CAAA,CAAA;;4FAAb,aAAa,EAAA,UAAA,EAAA,CAAA;kBADzB,IAAI;AAAC,YAAA,IAAA,EAAA,CAAA,EAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAC;;;ACpBtC;;AAEG;;;;"}
|
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, Injector, INJECTOR, Pipe } from '@angular/core';
|
|
3
|
-
import { toObservable } from '@angular/core/rxjs-interop';
|
|
2
|
+
import { inject, Injector, INJECTOR, signal, computed, untracked, Pipe } from '@angular/core';
|
|
4
3
|
import { TuiAmountPipe } from '@taiga-ui/addon-commerce/pipes/amount';
|
|
5
4
|
import { TUI_NUMBER_FORMAT } from '@taiga-ui/core/tokens';
|
|
6
|
-
import { switchMap, map } from 'rxjs';
|
|
7
5
|
|
|
8
6
|
class TuiDecimalPipe {
|
|
9
7
|
constructor() {
|
|
10
|
-
this.format =
|
|
8
|
+
this.format = inject(TUI_NUMBER_FORMAT);
|
|
11
9
|
this.amountPipe = Injector.create({
|
|
12
10
|
providers: [{ provide: TuiAmountPipe }],
|
|
13
11
|
parent: inject(INJECTOR),
|
|
14
12
|
}).get(TuiAmountPipe);
|
|
13
|
+
this.value = signal(NaN);
|
|
14
|
+
this.currency = signal('');
|
|
15
|
+
this.formatted = computed(() => {
|
|
16
|
+
const format = this.format();
|
|
17
|
+
const amount = this.amountPipe.transform(this.value(), this.currency());
|
|
18
|
+
const [, decimal] = amount.split(format.decimalSeparator);
|
|
19
|
+
return decimal ? `${format.decimalSeparator}${decimal}` : '';
|
|
20
|
+
});
|
|
15
21
|
}
|
|
16
22
|
transform(value, currency = '') {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
})
|
|
23
|
+
untracked(() => {
|
|
24
|
+
this.value.set(value);
|
|
25
|
+
this.currency.set(currency);
|
|
26
|
+
});
|
|
27
|
+
return this.formatted();
|
|
21
28
|
}
|
|
22
29
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: TuiDecimalPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
23
|
-
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.15", ngImport: i0, type: TuiDecimalPipe, isStandalone: true, name: "tuiDecimal" }); }
|
|
30
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.15", ngImport: i0, type: TuiDecimalPipe, isStandalone: true, name: "tuiDecimal", pure: false }); }
|
|
24
31
|
}
|
|
25
32
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: TuiDecimalPipe, decorators: [{
|
|
26
33
|
type: Pipe,
|
|
27
|
-
args: [{ name: 'tuiDecimal' }]
|
|
34
|
+
args: [{ name: 'tuiDecimal', pure: false }]
|
|
28
35
|
}] });
|
|
29
36
|
|
|
30
37
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taiga-ui-addon-commerce-pipes-decimal.mjs","sources":["../../../projects/addon-commerce/pipes/decimal/decimal.pipe.ts","../../../projects/addon-commerce/pipes/decimal/taiga-ui-addon-commerce-pipes-decimal.ts"],"sourcesContent":["import {inject
|
|
1
|
+
{"version":3,"file":"taiga-ui-addon-commerce-pipes-decimal.mjs","sources":["../../../projects/addon-commerce/pipes/decimal/decimal.pipe.ts","../../../projects/addon-commerce/pipes/decimal/taiga-ui-addon-commerce-pipes-decimal.ts"],"sourcesContent":["import {\n computed,\n inject,\n INJECTOR,\n Injector,\n Pipe,\n type PipeTransform,\n signal,\n untracked,\n} from '@angular/core';\nimport {TuiAmountPipe} from '@taiga-ui/addon-commerce/pipes/amount';\nimport {type TuiCurrencyVariants} from '@taiga-ui/addon-commerce/types';\nimport {TUI_NUMBER_FORMAT} from '@taiga-ui/core/tokens';\n\n@Pipe({name: 'tuiDecimal', pure: false})\nexport class TuiDecimalPipe implements PipeTransform {\n private readonly format = inject(TUI_NUMBER_FORMAT);\n private readonly amountPipe = Injector.create({\n providers: [{provide: TuiAmountPipe}],\n parent: inject(INJECTOR),\n }).get(TuiAmountPipe);\n\n private readonly value = signal(NaN);\n private readonly currency = signal<TuiCurrencyVariants>('');\n\n private readonly formatted = computed(() => {\n const format = this.format();\n const amount = this.amountPipe.transform(this.value(), this.currency());\n\n const [, decimal] = amount.split(format.decimalSeparator);\n\n return decimal ? `${format.decimalSeparator}${decimal}` : '';\n });\n\n public transform(value: number, currency: TuiCurrencyVariants = ''): string {\n untracked(() => {\n this.value.set(value);\n this.currency.set(currency);\n });\n\n return this.formatted();\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;MAea,cAAc,CAAA;AAD3B,IAAA,WAAA,GAAA;AAEqB,QAAA,IAAA,CAAA,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC;AAClC,QAAA,IAAA,CAAA,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;AAC1C,YAAA,SAA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AA,EAAA,CAAA;kBAD1B,IAAI;AAAC,YAAA,IAAA,EAAA,CAAA,EAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAC;;;ACdvC;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { type PipeTransform } from '@angular/core';
|
|
2
2
|
import { type TuiCurrencyVariants } from '@taiga-ui/addon-commerce/types';
|
|
3
3
|
import { type TuiHorizontalDirection } from '@taiga-ui/core/types';
|
|
4
|
-
import { type Observable } from 'rxjs';
|
|
5
4
|
import * as i0 from "@angular/core";
|
|
6
5
|
export declare class TuiAmountPipe implements PipeTransform {
|
|
7
6
|
private readonly options;
|
|
8
7
|
private readonly format;
|
|
9
|
-
|
|
8
|
+
private readonly value;
|
|
9
|
+
private readonly currency;
|
|
10
|
+
private readonly currencyAlign;
|
|
11
|
+
private readonly formatted;
|
|
12
|
+
transform(value: number, currency?: TuiCurrencyVariants, currencyAlign?: TuiHorizontalDirection): string;
|
|
10
13
|
static ɵfac: i0.ɵɵFactoryDeclaration<TuiAmountPipe, never>;
|
|
11
14
|
static ɵpipe: i0.ɵɵPipeDeclaration<TuiAmountPipe, "tuiAmount", true>;
|
|
12
15
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type PipeTransform } from '@angular/core';
|
|
2
2
|
import { type TuiCurrencyVariants } from '@taiga-ui/addon-commerce/types';
|
|
3
|
-
import { type Observable } from 'rxjs';
|
|
4
3
|
import * as i0 from "@angular/core";
|
|
5
4
|
export declare class TuiDecimalPipe implements PipeTransform {
|
|
6
5
|
private readonly format;
|
|
7
6
|
private readonly amountPipe;
|
|
8
|
-
|
|
7
|
+
private readonly value;
|
|
8
|
+
private readonly currency;
|
|
9
|
+
private readonly formatted;
|
|
10
|
+
transform(value: number, currency?: TuiCurrencyVariants): string;
|
|
9
11
|
static ɵfac: i0.ɵɵFactoryDeclaration<TuiDecimalPipe, never>;
|
|
10
12
|
static ɵpipe: i0.ɵɵPipeDeclaration<TuiDecimalPipe, "tuiDecimal", true>;
|
|
11
13
|
}
|