@htmlplus/element 0.7.8 → 0.7.9

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.
@@ -1,6 +1,6 @@
1
1
  import { camelCase, paramCase } from 'change-case';
2
2
  import * as CONSTANTS from '../../constants/index.js';
3
- import { call, fromAttribute, getConfig, getMembers, getNamespace, getTag, isServer, request } from '../utils/index.js';
3
+ import { call, getConfig, getMembers, getNamespace, getTag, isServer, request, toProperty } from '../utils/index.js';
4
4
  export function Element() {
5
5
  return function (constructor) {
6
6
  if (isServer())
@@ -38,7 +38,7 @@ export function Element() {
38
38
  return;
39
39
  const name = camelCase(attribute);
40
40
  const type = (_a = members[name]) === null || _a === void 0 ? void 0 : _a.type;
41
- const value = fromAttribute(next, type);
41
+ const value = toProperty(next, type);
42
42
  if (instance[name] === value)
43
43
  return;
44
44
  instance[name] = value;
@@ -1,5 +1,5 @@
1
1
  import * as CONSTANTS from '../../constants/index.js';
2
- import { addMember, appendToMethod, defineProperty, host, request, updateAttribute } from '../utils/index.js';
2
+ import { addMember, appendToMethod, defineProperty, host, request, toProperty, updateAttribute } from '../utils/index.js';
3
3
  export function Property(options) {
4
4
  return function (target, propertyKey) {
5
5
  const name = String(propertyKey);
@@ -10,14 +10,15 @@ export function Property(options) {
10
10
  }
11
11
  function set(next) {
12
12
  const previous = this[symbol];
13
- if (next === previous)
13
+ const parsed = toProperty(next, options === null || options === void 0 ? void 0 : options.type);
14
+ if (parsed === previous)
14
15
  return;
15
- this[symbol] = next;
16
+ this[symbol] = parsed;
16
17
  request(this, name, previous, (skipped) => {
17
18
  if (!(options === null || options === void 0 ? void 0 : options.reflect) || skipped)
18
19
  return;
19
20
  target[CONSTANTS.API_LOCKED] = true;
20
- updateAttribute(host(this), name, next);
21
+ updateAttribute(host(this), name, parsed);
21
22
  target[CONSTANTS.API_LOCKED] = false;
22
23
  });
23
24
  }
@@ -7,7 +7,6 @@ export * from './config.js';
7
7
  export * from './defineProperty.js';
8
8
  export * from './direction.js';
9
9
  export * from './event.js';
10
- export * from './fromAttribute.js';
11
10
  export * from './getFramework.js';
12
11
  export * from './getMembers.js';
13
12
  export * from './getNamespace.js';
@@ -25,6 +24,7 @@ export * from './styles.js';
25
24
  export * from './task.js';
26
25
  export * from './toBoolean.js';
27
26
  export * from './toEvent.js';
27
+ export * from './toProperty.js';
28
28
  export * from './toUnit.js';
29
29
  export * from './typeOf.js';
30
30
  export * from './uhtml.js';
@@ -7,7 +7,6 @@ export * from './config.js';
7
7
  export * from './defineProperty.js';
8
8
  export * from './direction.js';
9
9
  export * from './event.js';
10
- export * from './fromAttribute.js';
11
10
  export * from './getFramework.js';
12
11
  export * from './getMembers.js';
13
12
  export * from './getNamespace.js';
@@ -25,6 +24,7 @@ export * from './styles.js';
25
24
  export * from './task.js';
26
25
  export * from './toBoolean.js';
27
26
  export * from './toEvent.js';
27
+ export * from './toProperty.js';
28
28
  export * from './toUnit.js';
29
29
  export * from './typeOf.js';
30
30
  export * from './uhtml.js';
@@ -0,0 +1 @@
1
+ export declare const toProperty: (input: any, type: number | undefined) => any;
@@ -1,6 +1,8 @@
1
1
  import * as CONSTANTS from '../../constants/index.js';
2
2
  import { typeOf } from './typeOf.js';
3
- export const fromAttribute = (input, type) => {
3
+ export const toProperty = (input, type) => {
4
+ if (type === undefined)
5
+ return input;
4
6
  const string = `${input}`;
5
7
  if (CONSTANTS.TYPE_BOOLEAN & type) {
6
8
  if (string === '')
@@ -38,7 +38,6 @@ export declare const TYPE_NUMBER: number;
38
38
  export declare const TYPE_OBJECT: number;
39
39
  export declare const TYPE_STRING: number;
40
40
  export declare const TYPE_UNDEFINED: number;
41
- export declare const TYPE_UNIT: number;
42
41
  export declare const UTILS_ATTRIBUTES_IMPORTED = "attributes";
43
42
  export declare const UTILS_ATTRIBUTES_LOCAL = "UTILS_ATTRIBUTES";
44
43
  export declare const UTILS_HOST_IMPORTED = "host";
@@ -46,7 +46,6 @@ export const TYPE_NUMBER = 2 ** 6;
46
46
  export const TYPE_OBJECT = 2 ** 7;
47
47
  export const TYPE_STRING = 2 ** 8;
48
48
  export const TYPE_UNDEFINED = 2 ** 9;
49
- export const TYPE_UNIT = 2 ** 10; // TODO
50
49
  // utils
51
50
  export const UTILS_ATTRIBUTES_IMPORTED = 'attributes';
52
51
  export const UTILS_ATTRIBUTES_LOCAL = 'UTILS_ATTRIBUTES';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "0.7.8",
3
+ "version": "0.7.9",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
@@ -1 +0,0 @@
1
- export declare const fromAttribute: (input: any, type: any) => any;