@bootkit/ng0 0.0.0-alpha.4 → 0.0.0-alpha.40
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/common/index.d.ts +263 -7
- package/components/accordion/index.d.ts +13 -3
- package/components/backdrop/index.d.ts +12 -0
- package/components/dropdown/index.d.ts +156 -0
- package/components/form-field/index.d.ts +24 -41
- package/components/list/index.d.ts +260 -0
- package/components/modal/index.d.ts +21 -3
- package/components/nav/index.d.ts +23 -19
- package/components/offcanvas/index.d.ts +13 -5
- package/components/pagination/index.d.ts +34 -8
- package/components/select/index.d.ts +160 -0
- package/components/sidenav/index.d.ts +125 -0
- package/components/table/index.d.ts +191 -59
- package/components/vertical-menu/index.d.ts +61 -0
- package/data/index.d.ts +103 -38
- package/date/index.d.ts +34 -0
- package/fesm2022/bootkit-ng0-common.mjs +289 -12
- package/fesm2022/bootkit-ng0-common.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-accordion.mjs +33 -26
- package/fesm2022/bootkit-ng0-components-accordion.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-backdrop.mjs +46 -0
- package/fesm2022/bootkit-ng0-components-backdrop.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-button.mjs +12 -12
- package/fesm2022/bootkit-ng0-components-button.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-card.mjs +12 -12
- package/fesm2022/bootkit-ng0-components-card.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-code.mjs +10 -10
- package/fesm2022/bootkit-ng0-components-code.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-collapse.mjs +16 -16
- package/fesm2022/bootkit-ng0-components-collapse.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-confirmation.mjs +13 -13
- package/fesm2022/bootkit-ng0-components-confirmation.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-dropdown.mjs +308 -0
- package/fesm2022/bootkit-ng0-components-dropdown.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-form-field.mjs +62 -84
- package/fesm2022/bootkit-ng0-components-form-field.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-list.mjs +564 -0
- package/fesm2022/bootkit-ng0-components-list.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-modal.mjs +41 -24
- package/fesm2022/bootkit-ng0-components-modal.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-nav.mjs +59 -60
- package/fesm2022/bootkit-ng0-components-nav.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-offcanvas.mjs +20 -13
- package/fesm2022/bootkit-ng0-components-offcanvas.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-overlay.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-pagination.mjs +59 -24
- package/fesm2022/bootkit-ng0-components-pagination.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-popover.mjs +11 -11
- package/fesm2022/bootkit-ng0-components-popover.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-select.mjs +447 -0
- package/fesm2022/bootkit-ng0-components-select.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-sidenav.mjs +290 -0
- package/fesm2022/bootkit-ng0-components-sidenav.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-components-stepper.mjs +14 -14
- package/fesm2022/bootkit-ng0-components-stepper.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-table.mjs +303 -159
- package/fesm2022/bootkit-ng0-components-table.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-toast.mjs +6 -6
- package/fesm2022/bootkit-ng0-components-toast.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-tooltip.mjs +9 -9
- package/fesm2022/bootkit-ng0-components-tooltip.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-components-vertical-menu.mjs +161 -0
- package/fesm2022/bootkit-ng0-components-vertical-menu.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-data.mjs +152 -39
- package/fesm2022/bootkit-ng0-data.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-date.mjs +50 -0
- package/fesm2022/bootkit-ng0-date.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-file.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-form.mjs +336 -264
- package/fesm2022/bootkit-ng0-form.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-http.mjs +40 -5
- package/fesm2022/bootkit-ng0-http.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-layouts-layout1.mjs +317 -0
- package/fesm2022/bootkit-ng0-layouts-layout1.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-localization-locales.mjs +101 -0
- package/fesm2022/bootkit-ng0-localization-locales.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-localization.mjs +431 -105
- package/fesm2022/bootkit-ng0-localization.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-platform-browser.mjs +179 -0
- package/fesm2022/bootkit-ng0-platform-browser.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-routing.mjs +80 -0
- package/fesm2022/bootkit-ng0-routing.mjs.map +1 -0
- package/fesm2022/bootkit-ng0-script.mjs +3 -3
- package/fesm2022/bootkit-ng0-script.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-security.mjs +16 -16
- package/fesm2022/bootkit-ng0-security.mjs.map +1 -1
- package/fesm2022/bootkit-ng0-utils.mjs +75 -0
- package/fesm2022/bootkit-ng0-utils.mjs.map +1 -0
- package/fesm2022/bootkit-ng0.mjs +2 -2
- package/fesm2022/bootkit-ng0.mjs.map +1 -1
- package/form/index.d.ts +94 -62
- package/http/index.d.ts +35 -4
- package/index.d.ts +2 -2
- package/layouts/layout1/index.d.ts +201 -0
- package/localization/index.d.ts +231 -42
- package/localization/locales/index.d.ts +7 -0
- package/package.json +66 -18
- package/platform/browser/index.d.ts +88 -0
- package/routing/index.d.ts +124 -0
- package/utils/index.d.ts +42 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, Pipe, NgModule, InjectionToken } from '@angular/core';
|
|
2
|
+
import { Injectable, Pipe, inject, runInInjectionContext, EnvironmentInjector, NgModule, InjectionToken } from '@angular/core';
|
|
3
3
|
import { Subject } from 'rxjs';
|
|
4
|
-
import { CommonModule } from '@angular/common';
|
|
5
4
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
6
5
|
|
|
7
6
|
/** Locale */
|
|
@@ -20,22 +19,36 @@ class Locale {
|
|
|
20
19
|
/**
|
|
21
20
|
* Translates a key in the dictionary
|
|
22
21
|
* @param key The key to look up
|
|
23
|
-
* @
|
|
22
|
+
* @param fallback Optional fallback value if the key is not found
|
|
23
|
+
* @returns The translated string or the fallbackValue if not found
|
|
24
24
|
*/
|
|
25
|
-
translate(key) {
|
|
26
|
-
return this.definition.dictionary?.[key] ??
|
|
25
|
+
translate(key, fallback) {
|
|
26
|
+
return this.definition.dictionary?.[key] ?? fallback;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Translates an enum value
|
|
30
30
|
* @param enumName The name of the enum
|
|
31
31
|
* @param enumValue The value of the enum to translate
|
|
32
|
+
* @param fallback
|
|
32
33
|
* @returns The translated string or the enum value itself if not found
|
|
33
34
|
*/
|
|
34
|
-
translateEnum(enumName, enumValue) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
translateEnum(enumName, enumValue, fallback) {
|
|
36
|
+
let e = this.definition.enums?.[enumName];
|
|
37
|
+
if (!e) {
|
|
38
|
+
return fallback || enumValue?.toString();
|
|
39
|
+
}
|
|
40
|
+
if (enumValue === null) {
|
|
41
|
+
return e['[null]'] || e['[empty]'];
|
|
42
|
+
}
|
|
43
|
+
else if (enumValue === undefined) {
|
|
44
|
+
return e['[undefined]'] || e['[empty]'];
|
|
45
|
+
}
|
|
46
|
+
else if (enumValue === '') {
|
|
47
|
+
return e['empty'];
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return e[enumValue] || e['[?]'] || fallback || enumValue?.toString();
|
|
51
|
+
}
|
|
39
52
|
}
|
|
40
53
|
/**
|
|
41
54
|
* Translates a form validation error
|
|
@@ -89,18 +102,8 @@ class Locale {
|
|
|
89
102
|
/**
|
|
90
103
|
* Clones and extends this object and returns a new Locale (without modifying this object).
|
|
91
104
|
*/
|
|
92
|
-
extend(
|
|
93
|
-
return new Locale({
|
|
94
|
-
name: this.definition.name,
|
|
95
|
-
rtl: this.definition.rtl,
|
|
96
|
-
dictionary: { ...this.definition.dictionary, ...values?.dictionary },
|
|
97
|
-
enums: { ...this.definition.enums, ...values?.enums },
|
|
98
|
-
form: {
|
|
99
|
-
validation: {
|
|
100
|
-
errors: { ...this.definition?.form?.validation?.errors, ...values?.form?.validation?.errors }
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
});
|
|
105
|
+
extend(definition) {
|
|
106
|
+
return new Locale({ ...this.definition, ...definition });
|
|
104
107
|
}
|
|
105
108
|
/**
|
|
106
109
|
*
|
|
@@ -110,8 +113,29 @@ class Locale {
|
|
|
110
113
|
formatDate(date, format) {
|
|
111
114
|
return date ? new Date(date).toLocaleDateString(this.definition.name, { hour: '2-digit', minute: '2-digit' }) : '';
|
|
112
115
|
}
|
|
116
|
+
format(object, formatterName, ...params) {
|
|
117
|
+
let formatter = this.definition.formatters?.[formatterName];
|
|
118
|
+
if (!formatter) {
|
|
119
|
+
throw Error(`The formatter "${formatterName}" is not defined in locale ${this.definition.name}`);
|
|
120
|
+
}
|
|
121
|
+
let formatterType = typeof formatter;
|
|
122
|
+
if (formatterType === 'function') {
|
|
123
|
+
return formatter(object, ...params);
|
|
124
|
+
}
|
|
125
|
+
else if (Array.isArray(formatter)) {
|
|
126
|
+
return formatter[+object];
|
|
127
|
+
}
|
|
128
|
+
else if (formatterType == 'object' && formatter != null) {
|
|
129
|
+
return formatter[object] || '';
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
throw Error(`Invalid locale formatter: ${formatterName}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
113
135
|
}
|
|
114
136
|
|
|
137
|
+
;
|
|
138
|
+
|
|
115
139
|
class LocalizationService {
|
|
116
140
|
_locales = [];
|
|
117
141
|
_activeLocale;
|
|
@@ -147,147 +171,449 @@ class LocalizationService {
|
|
|
147
171
|
get() {
|
|
148
172
|
return this._activeLocale;
|
|
149
173
|
}
|
|
150
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
151
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.
|
|
174
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
175
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizationService, providedIn: 'root' });
|
|
152
176
|
}
|
|
153
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
177
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizationService, decorators: [{
|
|
154
178
|
type: Injectable,
|
|
155
179
|
args: [{
|
|
156
180
|
providedIn: 'root'
|
|
157
181
|
}]
|
|
158
182
|
}], ctorParameters: () => [] });
|
|
159
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Pipe to translate a dictionary key into a localized string.
|
|
186
|
+
* It uses the LocalizationService to fetch the translation.
|
|
187
|
+
* If the translation is not found, it returns the fallback string if provided.
|
|
188
|
+
*/
|
|
160
189
|
class TranslatePipe {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
this._locale = x.new;
|
|
168
|
-
this._recompute = true;
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
transform(dictionaryKey, ...args) {
|
|
172
|
-
if (this._recompute) {
|
|
173
|
-
this._value = this._locale.translate(dictionaryKey);
|
|
174
|
-
this._recompute = false;
|
|
175
|
-
}
|
|
176
|
-
return this._value;
|
|
190
|
+
_ls;
|
|
191
|
+
constructor(_ls) {
|
|
192
|
+
this._ls = _ls;
|
|
193
|
+
}
|
|
194
|
+
transform(dictionaryKey, fallback) {
|
|
195
|
+
return this._ls.get()?.translate(dictionaryKey, fallback) || dictionaryKey;
|
|
177
196
|
}
|
|
178
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
179
|
-
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.
|
|
197
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: TranslatePipe, deps: [{ token: LocalizationService }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
198
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: TranslatePipe, isStandalone: true, name: "ng0Translate" });
|
|
180
199
|
}
|
|
181
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
200
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: TranslatePipe, decorators: [{
|
|
182
201
|
type: Pipe,
|
|
183
202
|
args: [{
|
|
184
203
|
name: 'ng0Translate',
|
|
185
204
|
standalone: true,
|
|
205
|
+
pure: true
|
|
206
|
+
}]
|
|
207
|
+
}], ctorParameters: () => [{ type: LocalizationService }] });
|
|
208
|
+
|
|
209
|
+
class TranslateEnumPipe {
|
|
210
|
+
_ls;
|
|
211
|
+
constructor(_ls) {
|
|
212
|
+
this._ls = _ls;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
*
|
|
216
|
+
* @param enumValue
|
|
217
|
+
* @param enumName
|
|
218
|
+
* @param nullValueKey
|
|
219
|
+
* @param returnEnumAsFallback
|
|
220
|
+
* @param fallbackKey
|
|
221
|
+
* @returns
|
|
222
|
+
*/
|
|
223
|
+
transform(enumValue, enumName, fallback) {
|
|
224
|
+
return this._ls.get()?.translateEnum(enumName, enumValue, fallback);
|
|
225
|
+
}
|
|
226
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: TranslateEnumPipe, deps: [{ token: LocalizationService }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
227
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: TranslateEnumPipe, isStandalone: true, name: "ng0TranslateEnum" });
|
|
228
|
+
}
|
|
229
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: TranslateEnumPipe, decorators: [{
|
|
230
|
+
type: Pipe,
|
|
231
|
+
args: [{
|
|
232
|
+
name: 'ng0TranslateEnum',
|
|
233
|
+
standalone: true,
|
|
234
|
+
pure: true
|
|
235
|
+
}]
|
|
236
|
+
}], ctorParameters: () => [{ type: LocalizationService }] });
|
|
237
|
+
|
|
238
|
+
class TranslateBooleanPipe {
|
|
239
|
+
localeProvider;
|
|
240
|
+
constructor(localeProvider) {
|
|
241
|
+
this.localeProvider = localeProvider;
|
|
242
|
+
}
|
|
243
|
+
transform(value, falseKey = 'true', trueKey = 'false') {
|
|
244
|
+
return this.localeProvider.get()?.translate(value ? trueKey : falseKey);
|
|
245
|
+
}
|
|
246
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: TranslateBooleanPipe, deps: [{ token: LocalizationService }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
247
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: TranslateBooleanPipe, isStandalone: true, name: "ng0TranslateBool" });
|
|
248
|
+
}
|
|
249
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: TranslateBooleanPipe, decorators: [{
|
|
250
|
+
type: Pipe,
|
|
251
|
+
args: [{
|
|
252
|
+
name: 'ng0TranslateBool',
|
|
253
|
+
standalone: true,
|
|
254
|
+
pure: true
|
|
255
|
+
}]
|
|
256
|
+
}], ctorParameters: () => [{ type: LocalizationService }] });
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Default object formatter function.
|
|
260
|
+
* @param value The item to format.
|
|
261
|
+
* @returns The formatted string.
|
|
262
|
+
*/
|
|
263
|
+
function defaultFormatter(obj) {
|
|
264
|
+
return obj?.toString() || '';
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Creates a field formatter that retrieves the value of a specified field from an object.
|
|
268
|
+
* @param field The field name to retrieve.
|
|
269
|
+
* @returns An ObjectFormatter function.
|
|
270
|
+
*/
|
|
271
|
+
function createFieldFormatter(field) {
|
|
272
|
+
return (obj) => obj?.[field];
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Creates an index formatter that retrieves the value at a specified index from an array.
|
|
276
|
+
* @param index The index to retrieve (number or boolean).
|
|
277
|
+
* @returns An ObjectFormatter function.
|
|
278
|
+
*/
|
|
279
|
+
function createIndexFormatter(index) {
|
|
280
|
+
return (obj) => {
|
|
281
|
+
if (Array.isArray(obj)) {
|
|
282
|
+
return obj[+index]; // use + to cast boolean values to numbers
|
|
283
|
+
}
|
|
284
|
+
throw Error('Object is not an array');
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Creates a number formatter.
|
|
289
|
+
* @param minimumIntegerDigits
|
|
290
|
+
* @param minimumFractionDigits
|
|
291
|
+
* @param maximumFractionDigits
|
|
292
|
+
* @param useGrouping
|
|
293
|
+
* @returns An ObjectFormatter function.
|
|
294
|
+
*/
|
|
295
|
+
function createNumberFormatter(minimumIntegerDigits, minimumFractionDigits, maximumFractionDigits, useGrouping = true) {
|
|
296
|
+
let locale = inject(LocalizationService, { optional: true })?.get();
|
|
297
|
+
const localeName = locale?.definition.name || 'en-US';
|
|
298
|
+
const f = new Intl.NumberFormat(localeName, {
|
|
299
|
+
minimumIntegerDigits,
|
|
300
|
+
minimumFractionDigits,
|
|
301
|
+
maximumFractionDigits,
|
|
302
|
+
useGrouping,
|
|
303
|
+
});
|
|
304
|
+
return (n) => Number.isFinite(n) ? f.format(n) : '';
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Creates a currency formatter.
|
|
308
|
+
* @param minFractions
|
|
309
|
+
* @param maxFractions
|
|
310
|
+
* @returns
|
|
311
|
+
*/
|
|
312
|
+
function createCurrencyFormatter(minFractions = 1, maxFractions = 2) {
|
|
313
|
+
return (n, minFractions, maxFractions) => Number.isFinite(n) ? n.toString() : '';
|
|
314
|
+
}
|
|
315
|
+
function createDateFormatter(options) {
|
|
316
|
+
let intlOptions;
|
|
317
|
+
if (options && (typeof options === 'object')) {
|
|
318
|
+
intlOptions = options;
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
intlOptions = {
|
|
322
|
+
dateStyle: arguments[0],
|
|
323
|
+
timeStyle: arguments[1],
|
|
324
|
+
timeZone: arguments[2]?.[0],
|
|
325
|
+
timeZoneName: arguments[2]?.[1],
|
|
326
|
+
calendar: arguments[3]
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
const locale = inject(LocalizationService, { optional: true })?.get();
|
|
330
|
+
let intlFormatter;
|
|
331
|
+
try {
|
|
332
|
+
intlFormatter = new Intl.DateTimeFormat(locale?.name, intlOptions);
|
|
333
|
+
return (d) => intlFormatter.format(new Date(d));
|
|
334
|
+
}
|
|
335
|
+
catch (err) {
|
|
336
|
+
console.warn('Invalid date format options:', intlOptions, err);
|
|
337
|
+
// Return a fallback formatter
|
|
338
|
+
return (d) => new Date(d).toLocaleString();
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Creates a locale-based formatter.
|
|
343
|
+
* @param locale The Locale object.
|
|
344
|
+
* @param formatterName The format string in the form of "formatterName:param1:param2:..."
|
|
345
|
+
* @returns A ValueFormatterFunction
|
|
346
|
+
* @private
|
|
347
|
+
*/
|
|
348
|
+
function createLocaleFormatter(formatterName) {
|
|
349
|
+
let locale = inject(LocalizationService, { optional: true })?.get();
|
|
350
|
+
if (locale == null) {
|
|
351
|
+
throw Error('For using locale formatters, provide a Locale object.');
|
|
352
|
+
}
|
|
353
|
+
let formatter = locale.definition.formatters?.[formatterName];
|
|
354
|
+
let formatterType = typeof formatter;
|
|
355
|
+
if (!formatter) {
|
|
356
|
+
console.warn(`The formatter "${formatterName}" is not defined in locale ${locale.definition.name}`);
|
|
357
|
+
return defaultFormatter;
|
|
358
|
+
}
|
|
359
|
+
if (formatterType === 'function') {
|
|
360
|
+
return formatter;
|
|
361
|
+
}
|
|
362
|
+
else if (Array.isArray(formatter)) {
|
|
363
|
+
return (index) => formatter[+index];
|
|
364
|
+
}
|
|
365
|
+
else if (formatterType == 'object' && formatter != null) {
|
|
366
|
+
return (value) => formatter[value] || '';
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
throw Error(`Invalid locale formatter: ${formatterName}`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Creates a composite formatter that applies multiple formatters in sequence.
|
|
374
|
+
* @param formatters The list of ObjectFormatterLike values to compose.
|
|
375
|
+
* @returns An ObjectFormatter function.
|
|
376
|
+
*/
|
|
377
|
+
function createCompositeFormatter(...formatters) {
|
|
378
|
+
const formattersFuncs = formatters.map(item => createObjectFormatter(item));
|
|
379
|
+
return (obj) => formattersFuncs.reduce((previous, current, index) => index == 0 ? current(obj) : current(previous));
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Creates an ObjectFormatter from various ObjectFormatterLike types.
|
|
383
|
+
* @param formatter The ObjectFormatterLike value to convert.
|
|
384
|
+
* @param locale Optional locale object for locale-based formatting.
|
|
385
|
+
* @param params Additional parameters for the formatter.
|
|
386
|
+
* @returns An ObjectFormatter function.
|
|
387
|
+
*/
|
|
388
|
+
function createObjectFormatter(formatter, ...params) {
|
|
389
|
+
switch (typeof formatter) {
|
|
390
|
+
case 'function':
|
|
391
|
+
return formatter.bind(null, ...params);
|
|
392
|
+
case 'number':
|
|
393
|
+
return createIndexFormatter(formatter);
|
|
394
|
+
case 'string':
|
|
395
|
+
switch (formatter[0]) {
|
|
396
|
+
case '#':
|
|
397
|
+
return createNumberFormatter(...params);
|
|
398
|
+
case '$':
|
|
399
|
+
return createCurrencyFormatter(...params);
|
|
400
|
+
case '@':
|
|
401
|
+
return createDateFormatter(...params);
|
|
402
|
+
case '*':
|
|
403
|
+
return createLocaleFormatter(formatter.substring(1));
|
|
404
|
+
default:
|
|
405
|
+
return createFieldFormatter(formatter);
|
|
406
|
+
}
|
|
407
|
+
case 'object':
|
|
408
|
+
if (Array.isArray(formatter) && formatter.length > 0) {
|
|
409
|
+
if (formatter[0] == 'C') {
|
|
410
|
+
return createCompositeFormatter(formatter.slice(1));
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
return createObjectFormatter(formatter[0], ...formatter.slice(1));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
throw Error('invalid formatter', { cause: formatter });
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Creates a transform function that converts a ObjectFormatterLike value into a ObjectFormatter.
|
|
422
|
+
* @param injector The EnvironmentInjector to use for dependency injection.
|
|
423
|
+
* @returns A function that takes a ObjectFormatterLike and returns a ObjectFormatter.
|
|
424
|
+
*/
|
|
425
|
+
function objectFormatterAttribute(injector) {
|
|
426
|
+
return (x) => runInInjectionContext(injector, createObjectFormatter.bind(null, x));
|
|
427
|
+
}
|
|
428
|
+
;
|
|
429
|
+
|
|
430
|
+
class DatePipe {
|
|
431
|
+
_injector = inject(EnvironmentInjector);
|
|
432
|
+
transform(value, ...options) {
|
|
433
|
+
const formatter = runInInjectionContext(this._injector, createDateFormatter.bind(null, ...options));
|
|
434
|
+
return formatter(value);
|
|
435
|
+
}
|
|
436
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: DatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
437
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: DatePipe, isStandalone: true, name: "ng0Date" });
|
|
438
|
+
}
|
|
439
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: DatePipe, decorators: [{
|
|
440
|
+
type: Pipe,
|
|
441
|
+
args: [{
|
|
442
|
+
name: 'ng0Date',
|
|
443
|
+
standalone: true,
|
|
444
|
+
pure: true
|
|
445
|
+
}]
|
|
446
|
+
}] });
|
|
447
|
+
|
|
448
|
+
class LocalizePipe {
|
|
449
|
+
_ls;
|
|
450
|
+
constructor(_ls) {
|
|
451
|
+
this._ls = _ls;
|
|
452
|
+
}
|
|
453
|
+
transform(dictionaryKey) {
|
|
454
|
+
return this._ls.get()?.translate(dictionaryKey);
|
|
455
|
+
}
|
|
456
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizePipe, deps: [{ token: LocalizationService }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
457
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: LocalizePipe, isStandalone: true, name: "ng0Localize", pure: false });
|
|
458
|
+
}
|
|
459
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizePipe, decorators: [{
|
|
460
|
+
type: Pipe,
|
|
461
|
+
args: [{
|
|
462
|
+
name: 'ng0Localize',
|
|
463
|
+
standalone: true,
|
|
186
464
|
pure: false
|
|
187
465
|
}]
|
|
188
466
|
}], ctorParameters: () => [{ type: LocalizationService }] });
|
|
189
467
|
|
|
190
|
-
class
|
|
191
|
-
|
|
468
|
+
class LocalizeEnumPipe {
|
|
469
|
+
_ls;
|
|
192
470
|
_recompute = true;
|
|
193
471
|
_value;
|
|
194
|
-
constructor(
|
|
195
|
-
this.
|
|
196
|
-
|
|
197
|
-
this._locale = x.new;
|
|
198
|
-
this._recompute = true;
|
|
199
|
-
});
|
|
472
|
+
constructor(_ls) {
|
|
473
|
+
this._ls = _ls;
|
|
474
|
+
_ls.change.pipe(takeUntilDestroyed()).subscribe(x => this._recompute = true);
|
|
200
475
|
}
|
|
201
|
-
|
|
476
|
+
/**
|
|
477
|
+
*
|
|
478
|
+
* @param enumValue
|
|
479
|
+
* @param enumName
|
|
480
|
+
* @param nullValueKey
|
|
481
|
+
* @param returnEnumAsFallback
|
|
482
|
+
* @param fallbackKey
|
|
483
|
+
* @returns
|
|
484
|
+
*/
|
|
485
|
+
transform(enumValue, enumName, fallback) {
|
|
202
486
|
if (this._recompute) {
|
|
203
|
-
|
|
204
|
-
var nullDictionaryKey = args[1];
|
|
205
|
-
this._value = enumValue ?
|
|
206
|
-
(this._locale.translateEnum(enumName, enumValue) ?? enumValue) :
|
|
207
|
-
(nullDictionaryKey ? this._locale.translate(nullDictionaryKey) : '');
|
|
487
|
+
this._value = this._ls.get()?.translateEnum(enumName, enumValue, fallback);
|
|
208
488
|
this._recompute = false;
|
|
209
489
|
}
|
|
210
490
|
return this._value;
|
|
211
491
|
}
|
|
212
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
213
|
-
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.
|
|
492
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizeEnumPipe, deps: [{ token: LocalizationService }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
493
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: LocalizeEnumPipe, isStandalone: true, name: "ng0LocalizeEnum", pure: false });
|
|
214
494
|
}
|
|
215
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
495
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizeEnumPipe, decorators: [{
|
|
216
496
|
type: Pipe,
|
|
217
497
|
args: [{
|
|
218
|
-
name: '
|
|
498
|
+
name: 'ng0LocalizeEnum',
|
|
219
499
|
standalone: true,
|
|
220
500
|
pure: false
|
|
221
501
|
}]
|
|
222
502
|
}], ctorParameters: () => [{ type: LocalizationService }] });
|
|
223
503
|
|
|
224
|
-
class
|
|
225
|
-
|
|
226
|
-
constructor(
|
|
227
|
-
this.
|
|
504
|
+
class LocalizeBooleanPipe {
|
|
505
|
+
_ls;
|
|
506
|
+
constructor(_ls) {
|
|
507
|
+
this._ls = _ls;
|
|
228
508
|
}
|
|
229
509
|
transform(value, falseKey = 'true', trueKey) {
|
|
230
|
-
return this.
|
|
510
|
+
return this._ls.get()?.translate(value ? trueKey : falseKey);
|
|
231
511
|
}
|
|
232
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
233
|
-
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.
|
|
512
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizeBooleanPipe, deps: [{ token: LocalizationService }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
513
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: LocalizeBooleanPipe, isStandalone: true, name: "ng0LocalizeBool", pure: false });
|
|
234
514
|
}
|
|
235
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
515
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizeBooleanPipe, decorators: [{
|
|
236
516
|
type: Pipe,
|
|
237
517
|
args: [{
|
|
238
|
-
name: '
|
|
518
|
+
name: 'ng0LocalizeBool',
|
|
239
519
|
standalone: true,
|
|
520
|
+
pure: false
|
|
240
521
|
}]
|
|
241
522
|
}], ctorParameters: () => [{ type: LocalizationService }] });
|
|
242
523
|
|
|
243
|
-
class
|
|
244
|
-
|
|
524
|
+
class LocalizeDatePipe {
|
|
525
|
+
_ls;
|
|
245
526
|
_value;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
});
|
|
527
|
+
_recompute = true;
|
|
528
|
+
constructor(_ls) {
|
|
529
|
+
this._ls = _ls;
|
|
530
|
+
_ls.change.pipe(takeUntilDestroyed()).subscribe(x => this._recompute = true);
|
|
251
531
|
}
|
|
252
|
-
transform(value) {
|
|
253
|
-
|
|
532
|
+
transform(value, format) {
|
|
533
|
+
if (this._recompute) {
|
|
534
|
+
this._value = this._ls.get()?.formatDate(value, format);
|
|
535
|
+
this._recompute = false;
|
|
536
|
+
}
|
|
537
|
+
return this._value;
|
|
254
538
|
}
|
|
255
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
256
|
-
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.
|
|
539
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizeDatePipe, deps: [{ token: LocalizationService }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
540
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: LocalizeDatePipe, isStandalone: true, name: "ng0LocalizeDate", pure: false });
|
|
257
541
|
}
|
|
258
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
542
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizeDatePipe, decorators: [{
|
|
259
543
|
type: Pipe,
|
|
260
544
|
args: [{
|
|
261
|
-
name: '
|
|
262
|
-
standalone: true
|
|
545
|
+
name: 'ng0LocalizeDate',
|
|
546
|
+
standalone: true,
|
|
547
|
+
pure: false
|
|
263
548
|
}]
|
|
264
549
|
}], ctorParameters: () => [{ type: LocalizationService }] });
|
|
265
550
|
|
|
266
|
-
|
|
551
|
+
/**
|
|
552
|
+
* Format pipe to format objects using various formatter types.
|
|
553
|
+
*/
|
|
554
|
+
class FormatPipe {
|
|
555
|
+
_injector = inject(EnvironmentInjector);
|
|
556
|
+
transform(obj, formatter, ...params) {
|
|
557
|
+
const frmtFunc = runInInjectionContext(this._injector, createObjectFormatter.bind(null, formatter, ...params));
|
|
558
|
+
return frmtFunc(obj);
|
|
559
|
+
}
|
|
560
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: FormatPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
561
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: FormatPipe, isStandalone: true, name: "ng0Format" });
|
|
562
|
+
}
|
|
563
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: FormatPipe, decorators: [{
|
|
564
|
+
type: Pipe,
|
|
565
|
+
args: [{
|
|
566
|
+
name: 'ng0Format',
|
|
567
|
+
standalone: true,
|
|
568
|
+
pure: true
|
|
569
|
+
}]
|
|
570
|
+
}] });
|
|
571
|
+
|
|
572
|
+
const Declares = [
|
|
573
|
+
// Pure pipes
|
|
267
574
|
TranslatePipe,
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
DatePipe
|
|
575
|
+
TranslateEnumPipe,
|
|
576
|
+
TranslateBooleanPipe,
|
|
577
|
+
DatePipe,
|
|
578
|
+
FormatPipe,
|
|
579
|
+
// Impure pipes
|
|
580
|
+
LocalizePipe,
|
|
581
|
+
LocalizeEnumPipe,
|
|
582
|
+
LocalizeBooleanPipe,
|
|
583
|
+
LocalizeDatePipe
|
|
271
584
|
];
|
|
272
585
|
class LocalizationModule {
|
|
273
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.
|
|
274
|
-
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
586
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
587
|
+
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: LocalizationModule, imports: [
|
|
588
|
+
// Pure pipes
|
|
589
|
+
TranslatePipe,
|
|
590
|
+
TranslateEnumPipe,
|
|
591
|
+
TranslateBooleanPipe,
|
|
592
|
+
DatePipe,
|
|
593
|
+
FormatPipe,
|
|
594
|
+
// Impure pipes
|
|
595
|
+
LocalizePipe,
|
|
596
|
+
LocalizeEnumPipe,
|
|
597
|
+
LocalizeBooleanPipe,
|
|
598
|
+
LocalizeDatePipe], exports: [
|
|
599
|
+
// Pure pipes
|
|
600
|
+
TranslatePipe,
|
|
601
|
+
TranslateEnumPipe,
|
|
602
|
+
TranslateBooleanPipe,
|
|
603
|
+
DatePipe,
|
|
604
|
+
FormatPipe,
|
|
605
|
+
// Impure pipes
|
|
606
|
+
LocalizePipe,
|
|
607
|
+
LocalizeEnumPipe,
|
|
608
|
+
LocalizeBooleanPipe,
|
|
609
|
+
LocalizeDatePipe] });
|
|
610
|
+
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizationModule });
|
|
282
611
|
}
|
|
283
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.
|
|
612
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: LocalizationModule, decorators: [{
|
|
284
613
|
type: NgModule,
|
|
285
614
|
args: [{
|
|
286
|
-
imports:
|
|
287
|
-
|
|
288
|
-
Declarables
|
|
289
|
-
],
|
|
290
|
-
exports: Declarables
|
|
615
|
+
imports: Declares,
|
|
616
|
+
exports: Declares
|
|
291
617
|
}]
|
|
292
618
|
}] });
|
|
293
619
|
|
|
@@ -297,5 +623,5 @@ const LOCALE = new InjectionToken('LOCALE');
|
|
|
297
623
|
* Generated bundle index. Do not edit.
|
|
298
624
|
*/
|
|
299
625
|
|
|
300
|
-
export {
|
|
626
|
+
export { DatePipe, FormatPipe, LOCALE, Locale, LocalizationModule, LocalizationService, LocalizeBooleanPipe, LocalizeDatePipe, LocalizeEnumPipe, LocalizePipe, TranslateBooleanPipe, TranslateEnumPipe, TranslatePipe, createCompositeFormatter, createCurrencyFormatter, createDateFormatter, createFieldFormatter, createIndexFormatter, createLocaleFormatter, createNumberFormatter, createObjectFormatter, defaultFormatter, objectFormatterAttribute };
|
|
301
627
|
//# sourceMappingURL=bootkit-ng0-localization.mjs.map
|