@htmlplus/element 0.1.8 → 0.1.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,10 +1,11 @@
1
+ import { camelCase, paramCase } from 'change-case';
1
2
  import * as CONSTANTS from '../../configs/constants.js';
2
- import { call, isServer, parseValue, request } from '../utils/index.js';
3
+ import { call, getMembers, isServer, parseValue, request } from '../utils/index.js';
3
4
  export function Element(tag) {
4
5
  return function (constructor) {
5
6
  if (isServer())
6
7
  return;
7
- const members = constructor[CONSTANTS.STATIC_MEMBERS];
8
+ const members = getMembers(constructor);
8
9
  class Plus extends HTMLElement {
9
10
  constructor() {
10
11
  var _a;
@@ -15,15 +16,18 @@ export function Element(tag) {
15
16
  this.attachShadow({ mode: 'open' });
16
17
  }
17
18
  static get observedAttributes() {
18
- return Object.keys(members).filter((key) => members[key][0] != CONSTANTS.TYPE_FUNCTION);
19
+ return Object.keys(members)
20
+ .filter((key) => members[key][0] != CONSTANTS.TYPE_FUNCTION)
21
+ .map((key) => paramCase(key));
19
22
  }
20
23
  adoptedCallback() {
21
24
  call(this.plus, CONSTANTS.LIFECYCLE_ADOPTED);
22
25
  }
23
26
  attributeChangedCallback(name, prev, next) {
24
- const [type] = members[name];
27
+ const key = camelCase(name);
28
+ const [type] = members[key];
25
29
  const parsed = parseValue(next, type);
26
- this.plus[name] = parsed;
30
+ this.plus[key] = parsed;
27
31
  }
28
32
  connectedCallback() {
29
33
  this.plus[CONSTANTS.API_READY] = true;
@@ -1,4 +1,4 @@
1
- import { defineProperty, getMembers, host, parseValue, request, updateAttribute, onReady } from '../utils/index.js';
1
+ import { defineProperty, getMembers, host, isReady, parseValue, request, updateAttribute, onReady } from '../utils/index.js';
2
2
  export function Property(options) {
3
3
  return function (target, propertyKey) {
4
4
  const values = new Map();
@@ -11,14 +11,20 @@ export function Property(options) {
11
11
  if (value === input)
12
12
  return;
13
13
  values.set(this, input);
14
+ // TODO
15
+ const ready = isReady(this);
14
16
  request(this, { [propertyKey]: [input, value] })
15
17
  .then((renderd) => {
18
+ const name = String(propertyKey);
19
+ const element = host(this);
20
+ const hasAttribute = element.hasAttribute(name);
21
+ // TODO
22
+ if ((options === null || options === void 0 ? void 0 : options.reflect) && !hasAttribute && !renderd && !ready)
23
+ updateAttribute(element, name, input);
16
24
  if (!renderd)
17
25
  return;
18
26
  if (!(options === null || options === void 0 ? void 0 : options.reflect))
19
27
  return;
20
- const element = host(this);
21
- const name = String(propertyKey);
22
28
  const raw = element.getAttribute(name);
23
29
  const [type] = getMembers(target)[propertyKey];
24
30
  const parsed = parseValue(raw, type);
@@ -6,6 +6,7 @@ export * from './get-members.js';
6
6
  export * from './get-styles.js';
7
7
  export * from './host.js';
8
8
  export * from './is-event.js';
9
+ export * from './is-ready.js';
9
10
  export * from './is-server.js';
10
11
  export * from './on-ready.js';
11
12
  export * from './parse-value.js';
@@ -6,6 +6,7 @@ export * from './get-members.js';
6
6
  export * from './get-styles.js';
7
7
  export * from './host.js';
8
8
  export * from './is-event.js';
9
+ export * from './is-ready.js';
9
10
  export * from './is-server.js';
10
11
  export * from './on-ready.js';
11
12
  export * from './parse-value.js';
@@ -0,0 +1,2 @@
1
+ import { PlusElement } from '../../types/index.js';
2
+ export declare const isReady: (target: PlusElement) => boolean;
@@ -0,0 +1,4 @@
1
+ import * as CONSTANTS from '../../configs/constants.js';
2
+ export const isReady = (target) => {
3
+ return target[CONSTANTS.API_READY];
4
+ };
@@ -1,8 +1,8 @@
1
1
  import * as CONSTANTS from '../../configs/constants.js';
2
- import { call, render, task } from '../utils/index.js';
2
+ import { call, isReady, render, task } from '../utils/index.js';
3
3
  const targets = new Map();
4
4
  export const request = (target, state) => {
5
- if (!target[CONSTANTS.API_READY])
5
+ if (!isReady(target))
6
6
  return Promise.resolve(false);
7
7
  let run = targets.get(target);
8
8
  if (run)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "license": "MIT",
5
5
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
6
6
  "description": "Compiler of HTMLPlus",