be-intl 0.0.8 → 0.0.10
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 +138 -138
- package/package.json +6 -6
package/be-intl.js
CHANGED
|
@@ -1,138 +1,138 @@
|
|
|
1
|
-
import { BE, propDefaults, propInfo } from 'be-enhanced/BE.js';
|
|
2
|
-
import { XE } from 'xtal-element/XE.js';
|
|
3
|
-
import { register } from 'be-hive/register.js';
|
|
4
|
-
export class BeIntl extends BE {
|
|
5
|
-
static get beConfig() {
|
|
6
|
-
return {
|
|
7
|
-
parse: true,
|
|
8
|
-
primaryProp: 'format',
|
|
9
|
-
primaryPropReq: true,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
async attach(enhancedElement, enhancementInfo) {
|
|
13
|
-
await super.attach(enhancedElement, enhancementInfo);
|
|
14
|
-
import('be-propagating/be-propagating.js');
|
|
15
|
-
const base = await enhancedElement.beEnhanced.whenResolved('be-propagating');
|
|
16
|
-
const propagator = base.propagators.get('self');
|
|
17
|
-
propagator.addEventListener('lang', e => {
|
|
18
|
-
this.locale = e.detail.newVal;
|
|
19
|
-
});
|
|
20
|
-
switch (enhancedElement.localName) {
|
|
21
|
-
case 'data':
|
|
22
|
-
case 'output':
|
|
23
|
-
{
|
|
24
|
-
propagator.addEventListener('value', e => {
|
|
25
|
-
const newVal = e.detail.newVal;
|
|
26
|
-
switch (typeof newVal) {
|
|
27
|
-
case 'string':
|
|
28
|
-
if (!newVal) {
|
|
29
|
-
this.value = 0;
|
|
30
|
-
}
|
|
31
|
-
break;
|
|
32
|
-
default:
|
|
33
|
-
this.value = newVal;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
const val = enhancedElement.value;
|
|
37
|
-
if (val !== '') {
|
|
38
|
-
this.value = JSON.parse(val);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
break;
|
|
42
|
-
case 'time':
|
|
43
|
-
{
|
|
44
|
-
propagator.addEventListener('dateTime', e => {
|
|
45
|
-
const newVal = e.detail.newVal;
|
|
46
|
-
switch (typeof newVal) {
|
|
47
|
-
case 'string':
|
|
48
|
-
try {
|
|
49
|
-
this.value = new Date(newVal);
|
|
50
|
-
}
|
|
51
|
-
catch (e) {
|
|
52
|
-
console.error(e);
|
|
53
|
-
}
|
|
54
|
-
default:
|
|
55
|
-
if (newVal instanceof Date) {
|
|
56
|
-
this.value = newVal;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
const val = enhancedElement.dateTime;
|
|
61
|
-
if (val !== '') {
|
|
62
|
-
try {
|
|
63
|
-
this.value = new Date(val);
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
console.error(e);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
this.locale = enhancedElement.lang || defaultLocale;
|
|
73
|
-
}
|
|
74
|
-
formatNumber(self) {
|
|
75
|
-
const { enhancedElement, value } = self;
|
|
76
|
-
if (value === undefined) {
|
|
77
|
-
enhancedElement.textContent = '';
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const { intlNumberFormat } = self;
|
|
81
|
-
enhancedElement.textContent = intlNumberFormat.format(value);
|
|
82
|
-
}
|
|
83
|
-
formatDate(self) {
|
|
84
|
-
const { enhancedElement, value, intlNumberFormat } = self;
|
|
85
|
-
enhancedElement.textContent = this.intlDateFormat.format(value);
|
|
86
|
-
}
|
|
87
|
-
onFormattingChange(self) {
|
|
88
|
-
const { enhancedElement, locale, format } = self;
|
|
89
|
-
switch (enhancedElement.localName) {
|
|
90
|
-
case 'time':
|
|
91
|
-
return {
|
|
92
|
-
intlDateFormat: new Intl.DateTimeFormat(locale, format),
|
|
93
|
-
resolved: true
|
|
94
|
-
};
|
|
95
|
-
default:
|
|
96
|
-
return {
|
|
97
|
-
intlNumberFormat: new Intl.NumberFormat(locale, format),
|
|
98
|
-
resolved: true
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
|
|
104
|
-
const tagName = 'be-intl';
|
|
105
|
-
const ifWantsToBe = 'intl';
|
|
106
|
-
const upgrade = 'data,time,output';
|
|
107
|
-
const xe = new XE({
|
|
108
|
-
config: {
|
|
109
|
-
tagName,
|
|
110
|
-
propDefaults: {
|
|
111
|
-
...propDefaults,
|
|
112
|
-
},
|
|
113
|
-
propInfo: {
|
|
114
|
-
...propInfo,
|
|
115
|
-
value: {
|
|
116
|
-
notify: {
|
|
117
|
-
dispatch: true
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
actions: {
|
|
122
|
-
formatNumber: {
|
|
123
|
-
ifKeyIn: ['value'],
|
|
124
|
-
ifAllOf: ['intlNumberFormat']
|
|
125
|
-
},
|
|
126
|
-
formatDate: {
|
|
127
|
-
ifKeyIn: ['value'],
|
|
128
|
-
ifAllOf: ['intlDateFormat']
|
|
129
|
-
},
|
|
130
|
-
onFormattingChange: {
|
|
131
|
-
ifAllOf: ['locale'],
|
|
132
|
-
ifKeyIn: ['format']
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
superclass: BeIntl
|
|
137
|
-
});
|
|
138
|
-
register(ifWantsToBe, upgrade, tagName);
|
|
1
|
+
import { BE, propDefaults, propInfo } from 'be-enhanced/BE.js';
|
|
2
|
+
import { XE } from 'xtal-element/XE.js';
|
|
3
|
+
import { register } from 'be-hive/register.js';
|
|
4
|
+
export class BeIntl extends BE {
|
|
5
|
+
static get beConfig() {
|
|
6
|
+
return {
|
|
7
|
+
parse: true,
|
|
8
|
+
primaryProp: 'format',
|
|
9
|
+
primaryPropReq: true,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
async attach(enhancedElement, enhancementInfo) {
|
|
13
|
+
await super.attach(enhancedElement, enhancementInfo);
|
|
14
|
+
import('be-propagating/be-propagating.js');
|
|
15
|
+
const base = await enhancedElement.beEnhanced.whenResolved('be-propagating');
|
|
16
|
+
const propagator = base.propagators.get('self');
|
|
17
|
+
propagator.addEventListener('lang', e => {
|
|
18
|
+
this.locale = e.detail.newVal;
|
|
19
|
+
});
|
|
20
|
+
switch (enhancedElement.localName) {
|
|
21
|
+
case 'data':
|
|
22
|
+
case 'output':
|
|
23
|
+
{
|
|
24
|
+
propagator.addEventListener('value', e => {
|
|
25
|
+
const newVal = e.detail.newVal;
|
|
26
|
+
switch (typeof newVal) {
|
|
27
|
+
case 'string':
|
|
28
|
+
if (!newVal) {
|
|
29
|
+
this.value = 0;
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
this.value = newVal;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const val = enhancedElement.value;
|
|
37
|
+
if (val !== '') {
|
|
38
|
+
this.value = JSON.parse(val);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
case 'time':
|
|
43
|
+
{
|
|
44
|
+
propagator.addEventListener('dateTime', e => {
|
|
45
|
+
const newVal = e.detail.newVal;
|
|
46
|
+
switch (typeof newVal) {
|
|
47
|
+
case 'string':
|
|
48
|
+
try {
|
|
49
|
+
this.value = new Date(newVal);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
console.error(e);
|
|
53
|
+
}
|
|
54
|
+
default:
|
|
55
|
+
if (newVal instanceof Date) {
|
|
56
|
+
this.value = newVal;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const val = enhancedElement.dateTime;
|
|
61
|
+
if (val !== '') {
|
|
62
|
+
try {
|
|
63
|
+
this.value = new Date(val);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
console.error(e);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
this.locale = enhancedElement.lang || defaultLocale;
|
|
73
|
+
}
|
|
74
|
+
formatNumber(self) {
|
|
75
|
+
const { enhancedElement, value } = self;
|
|
76
|
+
if (value === undefined) {
|
|
77
|
+
enhancedElement.textContent = '';
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const { intlNumberFormat } = self;
|
|
81
|
+
enhancedElement.textContent = intlNumberFormat.format(value);
|
|
82
|
+
}
|
|
83
|
+
formatDate(self) {
|
|
84
|
+
const { enhancedElement, value, intlNumberFormat } = self;
|
|
85
|
+
enhancedElement.textContent = this.intlDateFormat.format(value);
|
|
86
|
+
}
|
|
87
|
+
onFormattingChange(self) {
|
|
88
|
+
const { enhancedElement, locale, format } = self;
|
|
89
|
+
switch (enhancedElement.localName) {
|
|
90
|
+
case 'time':
|
|
91
|
+
return {
|
|
92
|
+
intlDateFormat: new Intl.DateTimeFormat(locale, format),
|
|
93
|
+
resolved: true
|
|
94
|
+
};
|
|
95
|
+
default:
|
|
96
|
+
return {
|
|
97
|
+
intlNumberFormat: new Intl.NumberFormat(locale, format),
|
|
98
|
+
resolved: true
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
|
|
104
|
+
const tagName = 'be-intl';
|
|
105
|
+
const ifWantsToBe = 'intl';
|
|
106
|
+
const upgrade = 'data,time,output';
|
|
107
|
+
const xe = new XE({
|
|
108
|
+
config: {
|
|
109
|
+
tagName,
|
|
110
|
+
propDefaults: {
|
|
111
|
+
...propDefaults,
|
|
112
|
+
},
|
|
113
|
+
propInfo: {
|
|
114
|
+
...propInfo,
|
|
115
|
+
value: {
|
|
116
|
+
notify: {
|
|
117
|
+
dispatch: true
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
actions: {
|
|
122
|
+
formatNumber: {
|
|
123
|
+
ifKeyIn: ['value'],
|
|
124
|
+
ifAllOf: ['intlNumberFormat']
|
|
125
|
+
},
|
|
126
|
+
formatDate: {
|
|
127
|
+
ifKeyIn: ['value'],
|
|
128
|
+
ifAllOf: ['intlDateFormat']
|
|
129
|
+
},
|
|
130
|
+
onFormattingChange: {
|
|
131
|
+
ifAllOf: ['locale'],
|
|
132
|
+
ifKeyIn: ['format']
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
superclass: BeIntl
|
|
137
|
+
});
|
|
138
|
+
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.10",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"web-components",
|
|
6
6
|
"web-component",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"safari": "npx playwright wk http://localhost:3030"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"be-enhanced": "0.0.
|
|
29
|
-
"be-hive": "0.0.
|
|
30
|
-
"be-propagating": "0.0.
|
|
31
|
-
"trans-render": "0.0.
|
|
32
|
-
"xtal-element": "0.0.
|
|
28
|
+
"be-enhanced": "0.0.33",
|
|
29
|
+
"be-hive": "0.0.109",
|
|
30
|
+
"be-propagating": "0.0.19",
|
|
31
|
+
"trans-render": "0.0.693",
|
|
32
|
+
"xtal-element": "0.0.571"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"may-it-serve": "0.0.5",
|