be-intl 0.0.16 → 0.0.17
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/be-intl.js +97 -97
- package/package.json +6 -6
package/be-intl.js
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
import { XE } from 'xtal-element/XE.js';
|
|
2
|
-
import { register } from 'be-hive/register.js';
|
|
3
|
-
import { BeValueAdded, beValueAddedActions, beValueAddedPropDefaults, beValueAddedPropInfo } from 'be-value-added/be-value-added.js';
|
|
4
|
-
export class BeIntl extends BeValueAdded {
|
|
5
|
-
static get beConfig() {
|
|
6
|
-
return {
|
|
7
|
-
parse: true,
|
|
8
|
-
primaryProp: 'format',
|
|
9
|
-
primaryPropReq: true,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
#langObserver;
|
|
13
|
-
hydrate(self) {
|
|
14
|
-
const { enhancedElement } = self;
|
|
15
|
-
const returnObj = super.hydrate(self);
|
|
16
|
-
const { observeAttr } = self;
|
|
17
|
-
if (observeAttr) {
|
|
18
|
-
const mutOptions = {
|
|
19
|
-
attributeFilter: ['lang'],
|
|
20
|
-
attributes: true
|
|
21
|
-
};
|
|
22
|
-
self.#langObserver = new MutationObserver(( /*mutations: MutationRecord[]*/) => {
|
|
23
|
-
self.locale = enhancedElement.lang || defaultLocale;
|
|
24
|
-
;
|
|
25
|
-
});
|
|
26
|
-
self.#langObserver.observe(enhancedElement, mutOptions);
|
|
27
|
-
}
|
|
28
|
-
returnObj.locale = enhancedElement.lang || defaultLocale;
|
|
29
|
-
delete returnObj.resolved;
|
|
30
|
-
return returnObj;
|
|
31
|
-
}
|
|
32
|
-
detach(detachedElement) {
|
|
33
|
-
super.detach(detachedElement);
|
|
34
|
-
if (this.#langObserver !== undefined)
|
|
35
|
-
this.#langObserver.disconnect();
|
|
36
|
-
}
|
|
37
|
-
formatNumber(self) {
|
|
38
|
-
const { enhancedElement, value } = self;
|
|
39
|
-
if (value === undefined) {
|
|
40
|
-
enhancedElement.textContent = '';
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const { intlNumberFormat } = self;
|
|
44
|
-
enhancedElement.textContent = intlNumberFormat.format(value);
|
|
45
|
-
}
|
|
46
|
-
formatDate(self) {
|
|
47
|
-
const { enhancedElement, value, intlNumberFormat } = self;
|
|
48
|
-
enhancedElement.textContent = this.intlDateFormat.format(value);
|
|
49
|
-
}
|
|
50
|
-
onFormattingChange(self) {
|
|
51
|
-
const { enhancedElement, locale, format } = self;
|
|
52
|
-
switch (enhancedElement.localName) {
|
|
53
|
-
case 'time':
|
|
54
|
-
return {
|
|
55
|
-
intlDateFormat: new Intl.DateTimeFormat(locale, format),
|
|
56
|
-
resolved: true
|
|
57
|
-
};
|
|
58
|
-
default:
|
|
59
|
-
return {
|
|
60
|
-
intlNumberFormat: new Intl.NumberFormat(locale, format),
|
|
61
|
-
resolved: true
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
|
|
67
|
-
const tagName = 'be-intl';
|
|
68
|
-
const ifWantsToBe = 'intl';
|
|
69
|
-
const upgrade = 'data,time,output';
|
|
70
|
-
const xe = new XE({
|
|
71
|
-
config: {
|
|
72
|
-
tagName,
|
|
73
|
-
propDefaults: {
|
|
74
|
-
...beValueAddedPropDefaults,
|
|
75
|
-
},
|
|
76
|
-
propInfo: {
|
|
77
|
-
...beValueAddedPropInfo,
|
|
78
|
-
},
|
|
79
|
-
actions: {
|
|
80
|
-
...beValueAddedActions,
|
|
81
|
-
formatNumber: {
|
|
82
|
-
ifKeyIn: ['value'],
|
|
83
|
-
ifAllOf: ['intlNumberFormat']
|
|
84
|
-
},
|
|
85
|
-
formatDate: {
|
|
86
|
-
ifKeyIn: ['value'],
|
|
87
|
-
ifAllOf: ['intlDateFormat']
|
|
88
|
-
},
|
|
89
|
-
onFormattingChange: {
|
|
90
|
-
ifAllOf: ['locale'],
|
|
91
|
-
ifKeyIn: ['format']
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
superclass: BeIntl
|
|
96
|
-
});
|
|
97
|
-
register(ifWantsToBe, upgrade, tagName);
|
|
1
|
+
import { XE } from 'xtal-element/XE.js';
|
|
2
|
+
import { register } from 'be-hive/register.js';
|
|
3
|
+
import { BeValueAdded, beValueAddedActions, beValueAddedPropDefaults, beValueAddedPropInfo } from 'be-value-added/be-value-added.js';
|
|
4
|
+
export class BeIntl extends BeValueAdded {
|
|
5
|
+
static get beConfig() {
|
|
6
|
+
return {
|
|
7
|
+
parse: true,
|
|
8
|
+
primaryProp: 'format',
|
|
9
|
+
primaryPropReq: true,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
#langObserver;
|
|
13
|
+
hydrate(self) {
|
|
14
|
+
const { enhancedElement } = self;
|
|
15
|
+
const returnObj = super.hydrate(self);
|
|
16
|
+
const { observeAttr } = self;
|
|
17
|
+
if (observeAttr) {
|
|
18
|
+
const mutOptions = {
|
|
19
|
+
attributeFilter: ['lang'],
|
|
20
|
+
attributes: true
|
|
21
|
+
};
|
|
22
|
+
self.#langObserver = new MutationObserver(( /*mutations: MutationRecord[]*/) => {
|
|
23
|
+
self.locale = enhancedElement.lang || defaultLocale;
|
|
24
|
+
;
|
|
25
|
+
});
|
|
26
|
+
self.#langObserver.observe(enhancedElement, mutOptions);
|
|
27
|
+
}
|
|
28
|
+
returnObj.locale = enhancedElement.lang || defaultLocale;
|
|
29
|
+
delete returnObj.resolved;
|
|
30
|
+
return returnObj;
|
|
31
|
+
}
|
|
32
|
+
detach(detachedElement) {
|
|
33
|
+
super.detach(detachedElement);
|
|
34
|
+
if (this.#langObserver !== undefined)
|
|
35
|
+
this.#langObserver.disconnect();
|
|
36
|
+
}
|
|
37
|
+
formatNumber(self) {
|
|
38
|
+
const { enhancedElement, value } = self;
|
|
39
|
+
if (value === undefined) {
|
|
40
|
+
enhancedElement.textContent = '';
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const { intlNumberFormat } = self;
|
|
44
|
+
enhancedElement.textContent = intlNumberFormat.format(value);
|
|
45
|
+
}
|
|
46
|
+
formatDate(self) {
|
|
47
|
+
const { enhancedElement, value, intlNumberFormat } = self;
|
|
48
|
+
enhancedElement.textContent = this.intlDateFormat.format(value);
|
|
49
|
+
}
|
|
50
|
+
onFormattingChange(self) {
|
|
51
|
+
const { enhancedElement, locale, format } = self;
|
|
52
|
+
switch (enhancedElement.localName) {
|
|
53
|
+
case 'time':
|
|
54
|
+
return {
|
|
55
|
+
intlDateFormat: new Intl.DateTimeFormat(locale, format),
|
|
56
|
+
resolved: true
|
|
57
|
+
};
|
|
58
|
+
default:
|
|
59
|
+
return {
|
|
60
|
+
intlNumberFormat: new Intl.NumberFormat(locale, format),
|
|
61
|
+
resolved: true
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
|
|
67
|
+
const tagName = 'be-intl';
|
|
68
|
+
const ifWantsToBe = 'intl';
|
|
69
|
+
const upgrade = 'data,time,output';
|
|
70
|
+
const xe = new XE({
|
|
71
|
+
config: {
|
|
72
|
+
tagName,
|
|
73
|
+
propDefaults: {
|
|
74
|
+
...beValueAddedPropDefaults,
|
|
75
|
+
},
|
|
76
|
+
propInfo: {
|
|
77
|
+
...beValueAddedPropInfo,
|
|
78
|
+
},
|
|
79
|
+
actions: {
|
|
80
|
+
...beValueAddedActions,
|
|
81
|
+
formatNumber: {
|
|
82
|
+
ifKeyIn: ['value'],
|
|
83
|
+
ifAllOf: ['intlNumberFormat']
|
|
84
|
+
},
|
|
85
|
+
formatDate: {
|
|
86
|
+
ifKeyIn: ['value'],
|
|
87
|
+
ifAllOf: ['intlDateFormat']
|
|
88
|
+
},
|
|
89
|
+
onFormattingChange: {
|
|
90
|
+
ifAllOf: ['locale'],
|
|
91
|
+
ifKeyIn: ['format']
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
superclass: BeIntl
|
|
96
|
+
});
|
|
97
|
+
register(ifWantsToBe, upgrade, tagName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "be-intl",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"web-components",
|
|
6
6
|
"web-component",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"update": "ncu -u && npm install"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"be-enhanced": "0.0.
|
|
30
|
-
"be-hive": "0.0.
|
|
31
|
-
"be-propagating": "0.0.
|
|
32
|
-
"be-value-added": "0.0.
|
|
29
|
+
"be-enhanced": "0.0.51",
|
|
30
|
+
"be-hive": "0.0.122",
|
|
31
|
+
"be-propagating": "0.0.24",
|
|
32
|
+
"be-value-added": "0.0.7",
|
|
33
33
|
"trans-render": "0.0.705",
|
|
34
34
|
"xtal-element": "0.0.578"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"may-it-serve": "0.0.
|
|
37
|
+
"may-it-serve": "0.0.6",
|
|
38
38
|
"@playwright/test": "1.37.1"
|
|
39
39
|
},
|
|
40
40
|
"author": "anderson.bruce.b@gmail.com",
|