@htmlplus/element 0.1.1 → 0.1.2

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.
Files changed (45) hide show
  1. package/dist/client/decorators/attributes.js +5 -8
  2. package/dist/client/decorators/bind.d.ts +4 -1
  3. package/dist/client/decorators/bind.js +2 -4
  4. package/dist/client/decorators/element.js +5 -2
  5. package/dist/client/decorators/event.d.ts +2 -2
  6. package/dist/client/decorators/event.js +6 -6
  7. package/dist/client/decorators/listen.d.ts +4 -1
  8. package/dist/client/decorators/listen.js +5 -10
  9. package/dist/client/decorators/method.d.ts +2 -1
  10. package/dist/client/decorators/method.js +9 -13
  11. package/dist/client/decorators/property.d.ts +2 -2
  12. package/dist/client/decorators/property.js +14 -16
  13. package/dist/client/decorators/state.d.ts +2 -1
  14. package/dist/client/decorators/state.js +14 -16
  15. package/dist/client/decorators/watch.js +3 -4
  16. package/dist/client/helpers/direction.js +1 -1
  17. package/dist/client/helpers/index.d.ts +1 -3
  18. package/dist/client/helpers/index.js +1 -3
  19. package/dist/client/helpers/query-all.js +1 -1
  20. package/dist/client/helpers/query.js +1 -1
  21. package/dist/client/helpers/slots.js +1 -2
  22. package/dist/client/services/link.js +1 -1
  23. package/dist/client/utils/append-to-method.d.ts +1 -0
  24. package/dist/client/utils/append-to-method.js +7 -0
  25. package/dist/client/{helpers → utils}/event.d.ts +0 -0
  26. package/dist/client/{helpers → utils}/event.js +0 -0
  27. package/dist/client/{helpers → utils}/host.d.ts +0 -0
  28. package/dist/client/{helpers → utils}/host.js +0 -0
  29. package/dist/client/utils/index.d.ts +4 -4
  30. package/dist/client/utils/index.js +4 -4
  31. package/dist/client/utils/on-ready.d.ts +1 -0
  32. package/dist/client/utils/on-ready.js +4 -0
  33. package/dist/client/utils/proxy.js +65 -25
  34. package/dist/client/utils/sync.js +3 -2
  35. package/package.json +1 -1
  36. package/dist/client/helpers/is-server.d.ts +0 -1
  37. package/dist/client/helpers/is-server.js +0 -1
  38. package/dist/client/utils/decorator.d.ts +0 -5
  39. package/dist/client/utils/decorator.js +0 -14
  40. package/dist/client/utils/define-element.d.ts +0 -1
  41. package/dist/client/utils/define-element.js +0 -7
  42. package/dist/client/utils/define-method.d.ts +0 -1
  43. package/dist/client/utils/define-method.js +0 -7
  44. package/dist/client/utils/define-property.d.ts +0 -1
  45. package/dist/client/utils/define-property.js +0 -1
@@ -1,16 +1,13 @@
1
1
  import * as CONSTANTS from '../../configs/constants.js';
2
- import { host } from '../helpers/index.js';
3
- import { defineMethod, sync } from '../utils/index.js';
2
+ import { appendToMethod, host, sync } from '../utils/index.js';
4
3
  export function Attributes() {
5
4
  return function (target, propertyKey) {
6
5
  let update;
7
- defineMethod(target, CONSTANTS.TOKEN_LIFECYCLE_CONNECTED, function (instance, callback, args) {
8
- update = sync(host(instance));
9
- return callback === null || callback === void 0 ? void 0 : callback(...args);
6
+ appendToMethod(target, CONSTANTS.TOKEN_LIFECYCLE_CONNECTED, function () {
7
+ update = sync(host(this));
10
8
  });
11
- defineMethod(target, CONSTANTS.TOKEN_LIFECYCLE_UPDATED, function (instance, callback, args) {
12
- update(instance[propertyKey]);
13
- return callback === null || callback === void 0 ? void 0 : callback(...args);
9
+ appendToMethod(target, CONSTANTS.TOKEN_LIFECYCLE_UPDATED, function () {
10
+ update(this[propertyKey]);
14
11
  });
15
12
  };
16
13
  }
@@ -1 +1,4 @@
1
- export declare function Bind(): (target: Object, propertyKey: PropertyKey, descriptor?: PropertyDescriptor | undefined) => import("../utils/decorator.js").DecoratorSetupReturn | undefined;
1
+ export declare function Bind(): (target: Object, propertyKey: PropertyKey, descriptor: PropertyDescriptor) => {
2
+ configurable: boolean;
3
+ get(): any;
4
+ };
@@ -1,11 +1,10 @@
1
- import { decorator, defineProperty } from '../utils/index.js';
2
1
  export function Bind() {
3
- const setup = (target, propertyKey, descriptor) => {
2
+ return function (target, propertyKey, descriptor) {
4
3
  return {
5
4
  configurable: true,
6
5
  get() {
7
6
  const value = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value.bind(this);
8
- defineProperty(this, propertyKey, {
7
+ Object.defineProperty(this, propertyKey, {
9
8
  value,
10
9
  configurable: true,
11
10
  writable: true
@@ -14,5 +13,4 @@ export function Bind() {
14
13
  }
15
14
  };
16
15
  };
17
- return decorator(setup);
18
16
  }
@@ -1,6 +1,9 @@
1
- import { defineElement, proxy } from '../utils/index.js';
1
+ import { isServer, proxy } from '../utils/index.js';
2
2
  export function Element(tag) {
3
3
  return function (constructor) {
4
- defineElement(tag, proxy(constructor));
4
+ if (isServer())
5
+ return;
6
+ // TODO: remove as any
7
+ customElements.define(tag, proxy(constructor));
5
8
  };
6
9
  }
@@ -1,3 +1,3 @@
1
- import { EventOptions } from '../../types/index.js';
1
+ import { EventOptions, PlusElement } from '../../types/index.js';
2
2
  export declare type EventEmitter<T = any> = (data?: T) => CustomEvent<T>;
3
- export declare function Event<T = any>(options?: EventOptions): (target: Object, propertyKey: PropertyKey, descriptor?: PropertyDescriptor | undefined) => import("../utils/decorator.js").DecoratorSetupReturn | undefined;
3
+ export declare function Event<T = any>(options?: EventOptions): (target: PlusElement, propertyKey: PropertyKey) => void;
@@ -1,18 +1,18 @@
1
- import { host } from '../helpers/index.js';
2
- import { decorator } from '../utils/index.js';
1
+ import { host } from '../utils/index.js';
3
2
  // TODO: add global hook
4
3
  export function Event(options = {}) {
5
- const setup = (target, propertyKey) => {
6
- return {
4
+ return function (target, propertyKey) {
5
+ Object.defineProperty(target, propertyKey, {
7
6
  get() {
8
7
  return (detail) => {
8
+ var _a;
9
+ (_a = options.bubbles) !== null && _a !== void 0 ? _a : (options.bubbles = false);
9
10
  const name = options.name || String(propertyKey);
10
11
  const event = new CustomEvent(name, Object.assign(Object.assign({}, options), { detail }));
11
12
  host(this).dispatchEvent(event);
12
13
  return event;
13
14
  };
14
15
  }
15
- };
16
+ });
16
17
  };
17
- return decorator(setup);
18
18
  }
@@ -1,2 +1,5 @@
1
1
  import { ListenOptions, PlusElement } from '../../types/index.js';
2
- export declare function Listen(name: string, options?: ListenOptions): (target: PlusElement, propertyKey: PropertyKey, descriptor: PropertyDescriptor) => import("../utils/decorator.js").DecoratorSetupReturn | undefined;
2
+ export declare function Listen(name: string, options?: ListenOptions): (target: PlusElement, propertyKey: PropertyKey, descriptor: PropertyDescriptor) => {
3
+ configurable: boolean;
4
+ get(): any;
5
+ };
@@ -1,6 +1,5 @@
1
1
  import * as CONSTANTS from '../../configs/constants.js';
2
- import { host } from '../helpers/index.js';
3
- import { defineMethod } from '../utils/index.js';
2
+ import { appendToMethod, host, on, off } from '../utils/index.js';
4
3
  import { Bind } from './bind.js';
5
4
  const defaults = {
6
5
  target: 'host'
@@ -20,15 +19,11 @@ export function Listen(name, options = defaults) {
20
19
  return host(instance);
21
20
  }
22
21
  };
23
- defineMethod(target, CONSTANTS.TOKEN_LIFECYCLE_CONNECTED, function (instance, callback, args) {
24
- var _a;
25
- (_a = element(instance)) === null || _a === void 0 ? void 0 : _a.addEventListener(name, instance[propertyKey], options);
26
- return callback === null || callback === void 0 ? void 0 : callback(...args);
22
+ appendToMethod(target, CONSTANTS.TOKEN_LIFECYCLE_CONNECTED, function () {
23
+ on(element(this), name, this[propertyKey], options);
27
24
  });
28
- defineMethod(target, CONSTANTS.TOKEN_LIFECYCLE_DISCONNECTED, function (instance, callback, args) {
29
- var _a;
30
- (_a = element(instance)) === null || _a === void 0 ? void 0 : _a.removeEventListener(name, instance[propertyKey], options);
31
- return callback === null || callback === void 0 ? void 0 : callback(...args);
25
+ appendToMethod(target, CONSTANTS.TOKEN_LIFECYCLE_DISCONNECTED, function () {
26
+ off(element(this), name, this[propertyKey], options);
32
27
  });
33
28
  return Bind()(target, propertyKey, descriptor);
34
29
  };
@@ -1 +1,2 @@
1
- export declare function Method(): (target: Object, propertyKey: PropertyKey, descriptor?: PropertyDescriptor | undefined) => import("../utils/decorator.js").DecoratorSetupReturn | undefined;
1
+ import { PlusElement } from '../../types/index.js';
2
+ export declare function Method(): (target: PlusElement, propertyKey: PropertyKey) => void;
@@ -1,16 +1,12 @@
1
- import { host } from '../helpers/index.js';
2
- import { decorator, defineProperty } from '../utils/index.js';
1
+ import { host, onReady } from '../utils/index.js';
3
2
  export function Method() {
4
- const setup = (target, propertyKey) => {
5
- return {
6
- onReady() {
7
- defineProperty(host(this), propertyKey, {
8
- get: () => {
9
- return this[propertyKey].bind(this);
10
- }
11
- });
12
- }
13
- };
3
+ return function (target, propertyKey) {
4
+ onReady(target, function () {
5
+ Object.defineProperty(host(this), propertyKey, {
6
+ get: () => {
7
+ return this[propertyKey].bind(this);
8
+ }
9
+ });
10
+ });
14
11
  };
15
- return decorator(setup);
16
12
  }
@@ -1,2 +1,2 @@
1
- import { PropertyOptions } from '../../types/index.js';
2
- export declare function Property(options?: PropertyOptions): (target: Object, propertyKey: PropertyKey, descriptor?: PropertyDescriptor | undefined) => import("../utils/decorator.js").DecoratorSetupReturn | undefined;
1
+ import { PlusElement, PropertyOptions } from '../../types/index.js';
2
+ export declare function Property(options?: PropertyOptions): (target: PlusElement, propertyKey: PropertyKey) => void;
@@ -1,10 +1,9 @@
1
1
  import * as CONSTANTS from '../../configs/constants.js';
2
- import { host } from '../helpers/index.js';
3
- import { api, decorator, defineProperty, parseValue, updateAttribute } from '../utils/index.js';
2
+ import { api, host, onReady, parseValue, updateAttribute } from '../utils/index.js';
4
3
  export function Property(options) {
5
- const setup = (target, propertyKey) => {
4
+ return function (target, propertyKey) {
6
5
  let prev, next;
7
- return {
6
+ Object.defineProperty(target, propertyKey, {
8
7
  get() {
9
8
  return next;
10
9
  },
@@ -26,18 +25,17 @@ export function Property(options) {
26
25
  updateAttribute(element, name, next);
27
26
  api(this).request({ [propertyKey]: [next, prev] });
28
27
  prev = next;
29
- },
30
- onReady() {
31
- defineProperty(host(this), propertyKey, {
32
- get: () => {
33
- return this[propertyKey];
34
- },
35
- set: (value) => {
36
- this[propertyKey] = value;
37
- }
38
- });
39
28
  }
40
- };
29
+ });
30
+ onReady(target, function () {
31
+ Object.defineProperty(host(this), propertyKey, {
32
+ get: () => {
33
+ return this[propertyKey];
34
+ },
35
+ set: (value) => {
36
+ this[propertyKey] = value;
37
+ }
38
+ });
39
+ });
41
40
  };
42
- return decorator(setup);
43
41
  }
@@ -1 +1,2 @@
1
- export declare function State(): (target: Object, propertyKey: PropertyKey, descriptor?: PropertyDescriptor | undefined) => import("../utils/decorator.js").DecoratorSetupReturn | undefined;
1
+ import { PlusElement } from '../../types/index.js';
2
+ export declare function State(): (target: PlusElement, propertyKey: PropertyKey) => void;
@@ -1,9 +1,8 @@
1
- import { host } from '../helpers/index.js';
2
- import { api, decorator, defineProperty } from '../utils/index.js';
1
+ import { api, host, onReady } from '../utils/index.js';
3
2
  export function State() {
4
- const setup = (target, propertyKey) => {
3
+ return function (target, propertyKey) {
5
4
  let prev, next;
6
- return {
5
+ Object.defineProperty(target, propertyKey, {
7
6
  get() {
8
7
  return next;
9
8
  },
@@ -16,18 +15,17 @@ export function State() {
16
15
  return;
17
16
  api(this).request({ [propertyKey]: [next, prev] });
18
17
  prev = next;
19
- },
20
- onReady() {
21
- defineProperty(host(this), propertyKey, {
22
- get: () => {
23
- return this[propertyKey];
24
- },
25
- set: (value) => {
26
- this[propertyKey] = value;
27
- }
28
- });
29
18
  }
30
- };
19
+ });
20
+ onReady(target, function () {
21
+ Object.defineProperty(host(this), propertyKey, {
22
+ get: () => {
23
+ return this[propertyKey];
24
+ },
25
+ set: (value) => {
26
+ this[propertyKey] = value;
27
+ }
28
+ });
29
+ });
31
30
  };
32
- return decorator(setup);
33
31
  }
@@ -1,18 +1,17 @@
1
1
  import * as CONSTANTS from '../../configs/constants.js';
2
- import { defineMethod } from '../utils/index.js';
2
+ import { appendToMethod } from '../utils/index.js';
3
3
  // TODO: support * key
4
4
  export function Watch(...keys) {
5
5
  return function (target, propertyKey) {
6
6
  if (!keys.length)
7
7
  return;
8
- defineMethod(target, CONSTANTS.TOKEN_LIFECYCLE_UPDATED, function (instance, callback, args) {
8
+ appendToMethod(target, CONSTANTS.TOKEN_LIFECYCLE_UPDATED, function (args) {
9
9
  const [states] = args;
10
10
  for (const key of keys) {
11
11
  if (states === null || states === void 0 ? void 0 : states[key]) {
12
- instance[propertyKey](...states[key], key);
12
+ this[propertyKey](...states[key], key);
13
13
  }
14
14
  }
15
- return callback === null || callback === void 0 ? void 0 : callback(...args);
16
15
  });
17
16
  };
18
17
  }
@@ -1,4 +1,4 @@
1
- import { host } from './host.js';
1
+ import { host } from '../utils/index.js';
2
2
  export const direction = (target) => {
3
3
  return getComputedStyle(host(target)).getPropertyValue('direction').toLowerCase();
4
4
  };
@@ -1,11 +1,9 @@
1
1
  export * from './classes.js';
2
2
  export * from './direction.js';
3
- export * from './event.js';
4
- export * from './host.js';
5
3
  export * from './is-rtl.js';
6
- export * from './is-server.js';
7
4
  export * from './query.js';
8
5
  export * from './query-all.js';
9
6
  export * from './slots.js';
10
7
  export * from './styles.js';
11
8
  export * from './to-unit.js';
9
+ export { host, isServer, on, off } from '../utils/index.js';
@@ -1,11 +1,9 @@
1
1
  export * from './classes.js';
2
2
  export * from './direction.js';
3
- export * from './event.js';
4
- export * from './host.js';
5
3
  export * from './is-rtl.js';
6
- export * from './is-server.js';
7
4
  export * from './query.js';
8
5
  export * from './query-all.js';
9
6
  export * from './slots.js';
10
7
  export * from './styles.js';
11
8
  export * from './to-unit.js';
9
+ export { host, isServer, on, off } from '../utils/index.js';
@@ -1,4 +1,4 @@
1
- import { host } from './host.js';
1
+ import { host } from '../utils/index.js';
2
2
  export function queryAll(target, selectors) {
3
3
  var _a, _b;
4
4
  return (_b = (_a = host(target)) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelectorAll(selectors);
@@ -1,4 +1,4 @@
1
- import { host } from './host.js';
1
+ import { host } from '../utils/index.js';
2
2
  export function query(target, selectors) {
3
3
  var _a, _b;
4
4
  return (_b = (_a = host(target)) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector(selectors);
@@ -1,11 +1,10 @@
1
- import { defineProperty } from '../utils/index.js';
2
1
  import { queryAll } from './query-all.js';
3
2
  export const slots = (target) => {
4
3
  var _a;
5
4
  const result = {};
6
5
  (_a = queryAll(target, 'slot')) === null || _a === void 0 ? void 0 : _a.forEach((slot) => {
7
6
  const name = slot.name || 'default';
8
- defineProperty(result, name, {
7
+ Object.defineProperty(result, name, {
9
8
  get() {
10
9
  return !!slot.assignedNodes().filter((node) => { var _a; return node.nodeName != '#text' || ((_a = node.nodeValue) === null || _a === void 0 ? void 0 : _a.trim()); }).length;
11
10
  }
@@ -1,4 +1,4 @@
1
- import { host } from '../helpers/index.js';
1
+ import { host } from '../utils/index.js';
2
2
  const links = new Map();
3
3
  // TODO: return type
4
4
  export const createLink = (namespace) => {
@@ -0,0 +1 @@
1
+ export declare const appendToMethod: (target: any, propertyKey: PropertyKey, handler: (this: any, args: Array<any>) => void) => void;
@@ -0,0 +1,7 @@
1
+ export const appendToMethod = (target, propertyKey, handler) => {
2
+ const callback = target[propertyKey];
3
+ target[propertyKey] = function () {
4
+ handler.bind(this)(Array.from(arguments));
5
+ return callback === null || callback === void 0 ? void 0 : callback.bind(this)(arguments);
6
+ };
7
+ };
File without changes
File without changes
File without changes
File without changes
@@ -1,10 +1,10 @@
1
1
  export * from './api.js';
2
- export * from './decorator.js';
3
- export * from './define-element.js';
4
- export * from './define-method.js';
5
- export * from './define-property.js';
2
+ export * from './append-to-method.js';
3
+ export * from './event.js';
4
+ export * from './host.js';
6
5
  export * from './is-event.js';
7
6
  export * from './is-server.js';
7
+ export * from './on-ready.js';
8
8
  export * from './parse-value.js';
9
9
  export * from './proxy.js';
10
10
  export * from './sync.js';
@@ -1,10 +1,10 @@
1
1
  export * from './api.js';
2
- export * from './decorator.js';
3
- export * from './define-element.js';
4
- export * from './define-method.js';
5
- export * from './define-property.js';
2
+ export * from './append-to-method.js';
3
+ export * from './event.js';
4
+ export * from './host.js';
6
5
  export * from './is-event.js';
7
6
  export * from './is-server.js';
7
+ export * from './on-ready.js';
8
8
  export * from './parse-value.js';
9
9
  export * from './proxy.js';
10
10
  export * from './sync.js';
@@ -0,0 +1 @@
1
+ export declare function onReady(target: any, callback: (this: any) => void): void;
@@ -0,0 +1,4 @@
1
+ export function onReady(target, callback) {
2
+ var _a;
3
+ ((_a = target['setup']) !== null && _a !== void 0 ? _a : (target['setup'] = [])).push(callback);
4
+ }
@@ -1,3 +1,12 @@
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
+ };
1
10
  import { html, render } from 'uhtml';
2
11
  import * as CONSTANTS from '../../configs/constants.js';
3
12
  import { isServer } from './is-server.js';
@@ -9,6 +18,60 @@ export const proxy = (Class) => {
9
18
  };
10
19
  let host, instance;
11
20
  const members = Class[CONSTANTS.TOKEN_STATIC_MEMBERS] || {};
21
+ // TODO
22
+ let states;
23
+ let isPending = false;
24
+ let updatePromise;
25
+ const request = (state) => {
26
+ if (!true /*hasChange*/)
27
+ return;
28
+ states = Object.assign(Object.assign({}, (states || {})), state);
29
+ if (isPending)
30
+ return;
31
+ updatePromise = enqueue();
32
+ };
33
+ const enqueue = () => __awaiter(void 0, void 0, void 0, function* () {
34
+ isPending = true;
35
+ try {
36
+ yield updatePromise;
37
+ }
38
+ catch (error) {
39
+ Promise.reject(error);
40
+ }
41
+ const result = perform();
42
+ if (result != null)
43
+ yield result;
44
+ return !isPending;
45
+ });
46
+ const perform = () => {
47
+ if (!isPending)
48
+ return;
49
+ try {
50
+ if (true /*shouldUpdate*/) {
51
+ // TODO
52
+ // call(CONSTANTS.TOKEN_LIFECYCLE_UPDATE, [allStates]);
53
+ render(host.shadowRoot, () => {
54
+ const markup = call(CONSTANTS.TOKEN_METHOD_RENDER);
55
+ const styles = Class[CONSTANTS.TOKEN_STATIC_STYLES];
56
+ if (!styles && !markup)
57
+ return html ``;
58
+ if (!styles)
59
+ return markup;
60
+ if (!markup)
61
+ return html `<style>${styles}</style>`;
62
+ return html `<style>${styles}</style>${markup}`;
63
+ });
64
+ // TODO
65
+ call(CONSTANTS.TOKEN_LIFECYCLE_UPDATED, [states]);
66
+ states = undefined;
67
+ }
68
+ isPending = false;
69
+ }
70
+ catch (error) {
71
+ isPending = false;
72
+ throw error;
73
+ }
74
+ };
12
75
  const call = (key, args) => {
13
76
  var _a;
14
77
  return (_a = instance[key]) === null || _a === void 0 ? void 0 : _a.apply(instance, args);
@@ -19,30 +82,6 @@ export const proxy = (Class) => {
19
82
  const set = (key, value) => {
20
83
  instance[CONSTANTS.TOKEN_API][key] = value;
21
84
  };
22
- // TODO
23
- let timeout, allStates;
24
- const request = (states) => {
25
- clearTimeout(timeout);
26
- allStates = Object.assign(Object.assign({}, (allStates || {})), states);
27
- timeout = setTimeout(() => {
28
- // TODO
29
- // call(CONSTANTS.TOKEN_LIFECYCLE_UPDATE, [allStates]);
30
- render(host.shadowRoot, () => {
31
- const markup = call(CONSTANTS.TOKEN_METHOD_RENDER);
32
- const styles = Class[CONSTANTS.TOKEN_STATIC_STYLES];
33
- if (!styles && !markup)
34
- return html ``;
35
- if (!styles)
36
- return markup;
37
- if (!markup)
38
- return html `<style>${styles}</style>`;
39
- return html `<style>${styles}</style>${markup}`;
40
- });
41
- // TODO
42
- call(CONSTANTS.TOKEN_LIFECYCLE_UPDATED, [allStates]);
43
- allStates = undefined;
44
- });
45
- };
46
85
  return class extends HTMLElement {
47
86
  constructor() {
48
87
  var _a, _b;
@@ -74,7 +113,8 @@ export const proxy = (Class) => {
74
113
  connectedCallback() {
75
114
  call(CONSTANTS.TOKEN_LIFECYCLE_CONNECTED);
76
115
  request();
77
- call(CONSTANTS.TOKEN_LIFECYCLE_LOADED);
116
+ // TODO
117
+ setTimeout(() => call(CONSTANTS.TOKEN_LIFECYCLE_LOADED));
78
118
  set(CONSTANTS.TOKEN_API_READY, true);
79
119
  }
80
120
  disconnectedCallback() {
@@ -1,3 +1,4 @@
1
+ import { on, off } from './event.js';
1
2
  import { isEvent } from './is-event.js';
2
3
  import { toEvent } from './to-event.js';
3
4
  import { updateAttribute } from './update-attribute.js';
@@ -16,12 +17,12 @@ export const sync = (node) => {
16
17
  if (prev.style || next.style)
17
18
  node.setAttribute('style', next.style || '');
18
19
  for (const key in prev)
19
- isEvent(key) && node.removeEventListener(toEvent(key), prev[key]);
20
+ isEvent(key) && off(node, toEvent(key), prev[key]);
20
21
  for (const key in next) {
21
22
  if (['class', 'style'].includes(key))
22
23
  continue;
23
24
  if (isEvent(key))
24
- node.addEventListener(toEvent(key), next[key]);
25
+ on(node, toEvent(key), next[key]);
25
26
  else
26
27
  updateAttribute(node, key, next[key]);
27
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "license": "MIT",
5
5
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
6
6
  "description": "Compiler of HTMLPlus",
@@ -1 +0,0 @@
1
- export { isServer } from '../utils/index.js';
@@ -1 +0,0 @@
1
- export { isServer } from '../utils/index.js';
@@ -1,5 +0,0 @@
1
- export declare type DecoratorSetup = (target: Object, propertyKey: PropertyKey, descriptor?: PropertyDescriptor) => DecoratorSetupReturn;
2
- export declare type DecoratorSetupReturn = PropertyDescriptor & {
3
- onReady?(): void;
4
- };
5
- export declare const decorator: (setup: DecoratorSetup) => (target: Object, propertyKey: PropertyKey, descriptor?: PropertyDescriptor | undefined) => DecoratorSetupReturn | undefined;
@@ -1,14 +0,0 @@
1
- import { defineProperty } from './define-property.js';
2
- export const decorator = (setup) => {
3
- return function (target, propertyKey, descriptor) {
4
- var _a;
5
- const options = setup(target, propertyKey, descriptor);
6
- // TODO
7
- if (options.onReady)
8
- ((_a = target['setup']) !== null && _a !== void 0 ? _a : (target['setup'] = [])).push(options.onReady);
9
- if (descriptor)
10
- return options;
11
- if (Object.keys(options).some((key) => ['configurable', 'enumerable', 'value', 'writable', 'get', 'set'].includes(key)))
12
- defineProperty(target, propertyKey, options);
13
- };
14
- };
@@ -1 +0,0 @@
1
- export declare const defineElement: (name: string, Class: any) => void;
@@ -1,7 +0,0 @@
1
- import { isServer } from './is-server.js';
2
- // TODO: Class type
3
- export const defineElement = (name, Class) => {
4
- if (isServer())
5
- return;
6
- window.customElements.define(name, Class);
7
- };
@@ -1 +0,0 @@
1
- export declare const defineMethod: <T>(target: T, propertyKey: PropertyKey, handler: any) => void;
@@ -1,7 +0,0 @@
1
- // TODO: handler type
2
- export const defineMethod = (target, propertyKey, handler) => {
3
- const callback = target[propertyKey];
4
- target[propertyKey] = function (...args) {
5
- return handler(this, callback === null || callback === void 0 ? void 0 : callback.bind(this), args);
6
- };
7
- };
@@ -1 +0,0 @@
1
- export declare const defineProperty: <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T;
@@ -1 +0,0 @@
1
- export const defineProperty = Object.defineProperty;