be-intl 0.0.12 → 0.0.14

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 CHANGED
@@ -17,6 +17,8 @@ emits
17
17
  <data value=123456.789 lang="de-DE" be-intl='{ "style": "currency", "currency": "EUR" }'>123.456,79 €</data>
18
18
  ```
19
19
 
20
+ The output element provides identical support.
21
+
20
22
  ```html
21
23
  <time lang="ar-EG" datetime=2011-11-18T14:54:39.929Z be-intl='{ "weekday": "long", "year": "numeric", "month": "long", "day": "numeric" }'></time>
22
24
  ```
@@ -51,3 +53,4 @@ import 'be-intl/be-intl.js';
51
53
  import 'https://esm.run/be-intl';
52
54
  </script>
53
55
  ```
56
+
package/be-intl.js CHANGED
@@ -1,7 +1,7 @@
1
- import { BE, propDefaults, propInfo } from 'be-enhanced/BE.js';
2
1
  import { XE } from 'xtal-element/XE.js';
3
2
  import { register } from 'be-hive/register.js';
4
- export class BeIntl extends BE {
3
+ import { BeValueAdded, beValueAddedActions, beValueAddedPropDefaults, beValueAddedPropInfo } from 'be-value-added/be-value-added.js';
4
+ export class BeIntl extends BeValueAdded {
5
5
  static get beConfig() {
6
6
  return {
7
7
  parse: true,
@@ -9,67 +9,30 @@ export class BeIntl extends BE {
9
9
  primaryPropReq: true,
10
10
  };
11
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;
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);
71
27
  }
72
- this.locale = enhancedElement.lang || defaultLocale;
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();
73
36
  }
74
37
  formatNumber(self) {
75
38
  const { enhancedElement, value } = self;
@@ -108,17 +71,13 @@ const xe = new XE({
108
71
  config: {
109
72
  tagName,
110
73
  propDefaults: {
111
- ...propDefaults,
74
+ ...beValueAddedPropDefaults,
112
75
  },
113
76
  propInfo: {
114
- ...propInfo,
115
- value: {
116
- notify: {
117
- dispatch: true
118
- }
119
- }
77
+ ...beValueAddedPropInfo,
120
78
  },
121
79
  actions: {
80
+ ...beValueAddedActions,
122
81
  formatNumber: {
123
82
  ifKeyIn: ['value'],
124
83
  ifAllOf: ['intlNumberFormat']
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "be-intl",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "keywords": [
5
5
  "web-components",
6
6
  "web-component",
@@ -26,15 +26,16 @@
26
26
  "update": "ncu -u && npm install"
27
27
  },
28
28
  "dependencies": {
29
- "be-enhanced": "0.0.36",
30
- "be-hive": "0.0.115",
29
+ "be-enhanced": "0.0.38",
30
+ "be-hive": "0.0.116",
31
31
  "be-propagating": "0.0.21",
32
- "trans-render": "0.0.699",
33
- "xtal-element": "0.0.574"
32
+ "be-value-added": "0.0.1",
33
+ "trans-render": "0.0.701",
34
+ "xtal-element": "0.0.576"
34
35
  },
35
36
  "devDependencies": {
36
37
  "may-it-serve": "0.0.5",
37
- "@playwright/test": "1.36.1"
38
+ "@playwright/test": "1.37.0"
38
39
  },
39
40
  "author": "anderson.bruce.b@gmail.com",
40
41
  "license": "MIT"
package/types.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { ActionOnEventConfigs } from "trans-render/froop/types";
2
2
  import {IBE, Declarations} from 'be-enhanced/types';
3
+ import {BVAEndUserProps, BVAAllProps} from 'be-value-added/types';
3
4
 
4
- export interface EndUserProps extends IBE<HTMLDataElement | HTMLTimeElement | HTMLOutputElement>{
5
+ export interface EndUserProps extends BVAEndUserProps<HTMLDataElement | HTMLTimeElement, number | Date | boolean>{
5
6
  format?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions,
6
- value?: number | Date;
7
7
  locale?: string;
8
8
  }
9
9
 
10
- export interface AllProps extends EndUserProps{
10
+ export interface AllProps extends EndUserProps, BVAAllProps{
11
11
  intlDateFormat?: Intl.DateTimeFormat,
12
12
  intlNumberFormat?: Intl.NumberFormat,
13
13
  }