@htmlplus/element 0.1.7 → 0.2.0

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,11 +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
- console.log(111, { constructor });
8
+ const members = getMembers(constructor);
9
9
  class Plus extends HTMLElement {
10
10
  constructor() {
11
11
  var _a;
@@ -16,15 +16,18 @@ export function Element(tag) {
16
16
  this.attachShadow({ mode: 'open' });
17
17
  }
18
18
  static get observedAttributes() {
19
- 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));
20
22
  }
21
23
  adoptedCallback() {
22
24
  call(this.plus, CONSTANTS.LIFECYCLE_ADOPTED);
23
25
  }
24
26
  attributeChangedCallback(name, prev, next) {
25
- const [type] = members[name];
27
+ const key = camelCase(name);
28
+ const [type] = members[key];
26
29
  const parsed = parseValue(next, type);
27
- this.plus[name] = parsed;
30
+ this.plus[key] = parsed;
28
31
  }
29
32
  connectedCallback() {
30
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,6 +1,8 @@
1
1
  import { html, render as renderer } from 'uhtml';
2
2
  import * as CONSTANTS from '../../configs/constants.js';
3
- import { call, getStyles, host } from '../utils/index.js';
3
+ import { call } from './call.js';
4
+ import { getStyles } from './get-styles.js';
5
+ import { host } from './host.js';
4
6
  export const render = (target) => {
5
7
  const element = host(target);
6
8
  renderer(element.shadowRoot, () => {
@@ -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)
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export const task = (options) => {
11
2
  let states, isPending, updatePromise;
12
3
  const run = (state) => {
@@ -18,10 +9,10 @@ export const task = (options) => {
18
9
  updatePromise = enqueue();
19
10
  return updatePromise;
20
11
  };
21
- const enqueue = () => __awaiter(void 0, void 0, void 0, function* () {
12
+ const enqueue = async () => {
22
13
  isPending = true;
23
14
  try {
24
- yield updatePromise;
15
+ await updatePromise;
25
16
  }
26
17
  catch (error) {
27
18
  Promise.reject(error);
@@ -41,6 +32,6 @@ export const task = (options) => {
41
32
  isPending = false;
42
33
  throw error;
43
34
  }
44
- });
35
+ };
45
36
  return run;
46
37
  };
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import logUpdate from 'log-update';
11
2
  const log = (namespace, message) => {
12
3
  logUpdate(`${new Date().toLocaleTimeString()} [@htmlplus/element]${namespace ? `[${namespace}]` : ''} ${message}`);
@@ -15,16 +6,16 @@ export default (...plugins) => {
15
6
  let global = {
16
7
  contexts: {}
17
8
  };
18
- const start = () => __awaiter(void 0, void 0, void 0, function* () {
9
+ const start = async () => {
19
10
  log(undefined, 'Starting.');
20
11
  for (const plugin of plugins) {
21
12
  if (!plugin.start)
22
13
  continue;
23
- global = (yield plugin.start(global)) || global;
14
+ global = (await plugin.start(global)) || global;
24
15
  log(plugin.name, 'Started successfully.');
25
16
  }
26
- });
27
- const next = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
17
+ };
18
+ const next = async (filePath) => {
28
19
  const key = filePath.split(/[\/|\\]/g).pop();
29
20
  let context = {
30
21
  filePath
@@ -32,22 +23,22 @@ export default (...plugins) => {
32
23
  for (const plugin of plugins) {
33
24
  if (!plugin.next)
34
25
  continue;
35
- context = (yield plugin.next(context, global)) || context;
26
+ context = (await plugin.next(context, global)) || context;
36
27
  log(`${key}:${plugin.name}`, 'Executed successfully.');
37
28
  }
38
29
  log(key, 'Executed successfully.');
39
30
  global.contexts[filePath] = context;
40
31
  return context;
41
- });
42
- const finish = () => __awaiter(void 0, void 0, void 0, function* () {
32
+ };
33
+ const finish = async () => {
43
34
  for (const plugin of plugins) {
44
35
  if (!plugin.finish)
45
36
  continue;
46
- global = (yield plugin.finish(global)) || global;
37
+ global = (await plugin.finish(global)) || global;
47
38
  log(plugin.name, 'Finished successfully.');
48
39
  }
49
40
  log(undefined, 'Finished.');
50
- });
41
+ };
51
42
  return {
52
43
  start,
53
44
  next,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "0.1.7",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
6
6
  "description": "Compiler of HTMLPlus",