be-intl 0.0.17 → 0.0.18
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/README.md +2 -0
- package/be-intl.js +97 -97
- package/package.json +8 -8
- package/types.d.ts +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,8 @@ emits
|
|
|
29
29
|
<time lang="ar-EG" datetime="2011-11-18T14:54:39.929Z" be-intl="{ "weekday": "long", "year": "numeric", "month": "long", "day": "numeric" }">الجمعة، ١٨ نوفمبر ٢٠١١</time>
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
[TODO] Support [expanding out the attribute](https://github.com/bahrus/be-hive#behivior-aspects-untested) to avoid use of JSON
|
|
33
|
+
|
|
32
34
|
## Viewing Locally
|
|
33
35
|
|
|
34
36
|
Any web server than can serve static files will do, but...
|
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.18",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"web-components",
|
|
6
6
|
"web-component",
|
|
@@ -26,16 +26,16 @@
|
|
|
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.
|
|
33
|
-
"trans-render": "0.0.
|
|
34
|
-
"xtal-element": "0.0.
|
|
29
|
+
"be-enhanced": "0.0.56",
|
|
30
|
+
"be-hive": "0.0.127",
|
|
31
|
+
"be-propagating": "0.0.29",
|
|
32
|
+
"be-value-added": "0.0.17",
|
|
33
|
+
"trans-render": "0.0.707",
|
|
34
|
+
"xtal-element": "0.0.579"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"may-it-serve": "0.0.6",
|
|
38
|
-
"@playwright/test": "1.
|
|
38
|
+
"@playwright/test": "1.40.0"
|
|
39
39
|
},
|
|
40
40
|
"author": "anderson.bruce.b@gmail.com",
|
|
41
41
|
"license": "MIT"
|
package/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ActionOnEventConfigs } from "trans-render/froop/types";
|
|
|
2
2
|
import {IBE, Declarations} from 'be-enhanced/types';
|
|
3
3
|
import {BVAEndUserProps, BVAAllProps} from 'be-value-added/types';
|
|
4
4
|
|
|
5
|
-
export interface EndUserProps extends BVAEndUserProps
|
|
5
|
+
export interface EndUserProps extends BVAEndUserProps{
|
|
6
6
|
format?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions,
|
|
7
7
|
locale?: string;
|
|
8
8
|
}
|