@htmlplus/element 0.4.0 → 0.4.3

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/client/decorators/element.js +25 -18
  2. package/client/decorators/event.js +14 -3
  3. package/client/decorators/property.js +6 -5
  4. package/client/decorators/state.js +3 -3
  5. package/client/decorators/watch.js +7 -10
  6. package/client/helpers/classes.d.ts +1 -1
  7. package/client/utils/appendToMethod.d.ts +1 -2
  8. package/client/utils/call.d.ts +1 -2
  9. package/client/utils/config.d.ts +5 -0
  10. package/client/utils/config.js +7 -0
  11. package/client/utils/getFramework.d.ts +1 -0
  12. package/client/utils/getFramework.js +12 -0
  13. package/client/utils/getMemberType.d.ts +2 -0
  14. package/client/utils/getMemberType.js +5 -0
  15. package/client/utils/getMembersKey.d.ts +2 -0
  16. package/client/utils/getMembersKey.js +4 -0
  17. package/client/utils/index.d.ts +6 -2
  18. package/client/utils/index.js +6 -2
  19. package/client/utils/off.d.ts +1 -0
  20. package/client/utils/off.js +3 -0
  21. package/client/utils/on.d.ts +1 -0
  22. package/client/utils/on.js +3 -0
  23. package/client/utils/request.d.ts +1 -1
  24. package/client/utils/request.js +4 -2
  25. package/client/utils/sync.js +2 -1
  26. package/client/utils/task.js +1 -1
  27. package/compiler/compiler.js +4 -1
  28. package/compiler/plugins/customElement.d.ts +1 -1
  29. package/compiler/plugins/customElement.js +15 -1
  30. package/compiler/plugins/customElementReact/customElementReact.js +1 -1
  31. package/compiler/plugins/customElementReact/templates/package.json.hbs +2 -2
  32. package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +1 -4
  33. package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +1 -5
  34. package/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +3 -3
  35. package/compiler/plugins/extract.d.ts +1 -1
  36. package/compiler/plugins/extract.js +11 -1
  37. package/compiler/utils/tags.d.ts +2 -2
  38. package/constants/index.d.ts +1 -1
  39. package/constants/index.js +2 -1
  40. package/package.json +14 -16
  41. package/types/context.d.ts +1 -0
  42. package/client/utils/event.d.ts +0 -5
  43. package/client/utils/event.js +0 -9
  44. package/client/utils/getMembers.d.ts +0 -2
  45. package/client/utils/getMembers.js +0 -5
@@ -1,53 +1,60 @@
1
1
  import { camelCase, paramCase } from 'change-case';
2
2
  import * as CONSTANTS from '../../constants/index.js';
3
- import { call, getMembers, isServer, parseValue, request } from '../utils/index.js';
3
+ import { call, getMembersKey, getMemberType, isServer, parseValue, request } from '../utils/index.js';
4
4
  import * as uhtml from '../vendor/uhtml.js';
5
5
  export function Element(tag) {
6
6
  return function (constructor) {
7
7
  if (isServer())
8
8
  return;
9
- const members = getMembers(constructor);
9
+ if (customElements.get(tag))
10
+ return;
11
+ const instances = new Map();
10
12
  class Plus extends HTMLElement {
11
13
  constructor() {
12
14
  super();
13
15
  this.attachShadow({ mode: 'open' });
14
16
  // TODO
15
- this.plus = new constructor();
16
- this.plus[CONSTANTS.API_HOST] = () => this;
17
- this.plus['uhtml'] = uhtml;
18
- this.plus[CONSTANTS.API_READY] = true;
17
+ const instance = new constructor();
18
+ instances.set(this, instance);
19
+ instance[CONSTANTS.API_HOST] = () => this;
20
+ instance['uhtml'] = uhtml;
21
+ instance[CONSTANTS.API_STATUS] = 'initialize';
19
22
  }
20
23
  static get observedAttributes() {
21
- return Object.keys(members)
22
- .filter((key) => members[key][0] != CONSTANTS.TYPE_FUNCTION)
23
- .map((key) => paramCase(key));
24
+ // TODO: ignore functions
25
+ return getMembersKey(constructor).map((key) => paramCase(key));
24
26
  }
25
27
  adoptedCallback() {
26
- call(this.plus, CONSTANTS.LIFECYCLE_ADOPTED);
28
+ const instance = instances.get(this);
29
+ call(instance, CONSTANTS.LIFECYCLE_ADOPTED);
27
30
  }
28
31
  // TODO
29
32
  attributeChangedCallback(name, prev, next) {
33
+ const instance = instances.get(this);
30
34
  const key = camelCase(name);
31
- const [type] = members[key];
35
+ const type = getMemberType(instance, key);
32
36
  const parsed = parseValue(next, type);
33
- this.plus[key] = parsed;
37
+ instance[key] = parsed;
34
38
  }
35
39
  connectedCallback() {
36
- call(this.plus, CONSTANTS.LIFECYCLE_CONNECTED);
37
- request(this.plus)
40
+ const instance = instances.get(this);
41
+ instance[CONSTANTS.API_STATUS] = 'connected';
42
+ call(instance, CONSTANTS.LIFECYCLE_CONNECTED);
43
+ request(instance)
38
44
  .then(() => {
39
- call(this.plus, CONSTANTS.LIFECYCLE_LOADED);
45
+ instance[CONSTANTS.API_STATUS] = 'loaded';
46
+ call(instance, CONSTANTS.LIFECYCLE_LOADED);
40
47
  })
41
48
  .catch((error) => {
42
49
  throw error;
43
50
  });
44
51
  }
45
52
  disconnectedCallback() {
46
- call(this.plus, CONSTANTS.LIFECYCLE_DISCONNECTED);
53
+ const instance = instances.get(this);
54
+ instance[CONSTANTS.API_STATUS] = 'disconnected';
55
+ call(instance, CONSTANTS.LIFECYCLE_DISCONNECTED);
47
56
  }
48
57
  }
49
- if (customElements.get(tag))
50
- return;
51
58
  customElements.define(tag, Plus);
52
59
  };
53
60
  }
@@ -1,14 +1,25 @@
1
- import { defineProperty, dispatch, host } from '../utils/index.js';
1
+ import { paramCase, pascalCase } from 'change-case';
2
+ import { defineProperty, getFramework, host } from '../utils/index.js';
2
3
  export function Event(options = {}) {
3
4
  return function (target, propertyKey) {
4
5
  defineProperty(target, propertyKey, {
5
6
  get() {
6
7
  return (detail) => {
7
8
  var _a;
9
+ const element = host(this);
10
+ const framework = getFramework(element);
8
11
  (_a = options.bubbles) !== null && _a !== void 0 ? _a : (options.bubbles = false);
9
- const name = options.name || String(propertyKey);
12
+ let name = options.name || String(propertyKey);
13
+ switch (framework) {
14
+ case 'react':
15
+ name = pascalCase(name);
16
+ break;
17
+ default:
18
+ name = paramCase(name);
19
+ break;
20
+ }
10
21
  const event = new CustomEvent(name, Object.assign(Object.assign({}, options), { detail }));
11
- dispatch(host(this), event);
22
+ element.dispatchEvent(event);
12
23
  return event;
13
24
  };
14
25
  }
@@ -1,11 +1,11 @@
1
1
  import { paramCase } from 'change-case';
2
2
  import * as CONSTANTS from '../../constants/index.js';
3
- import { defineProperty, getMembers, host, parseValue, request, updateAttribute, appendToMethod } from '../utils/index.js';
3
+ import { defineProperty, getMemberType, host, parseValue, request, updateAttribute, appendToMethod } from '../utils/index.js';
4
4
  export function Property(options) {
5
5
  return function (target, propertyKey) {
6
6
  const name = String(propertyKey);
7
7
  const attribute = paramCase(name);
8
- const type = getMembers(target)[name].at(0);
8
+ const type = getMemberType(target, name);
9
9
  const values = new Map();
10
10
  function get() {
11
11
  return values.get(this);
@@ -15,8 +15,8 @@ export function Property(options) {
15
15
  if (input === value)
16
16
  return;
17
17
  values.set(this, input);
18
- const isReady = !!this[CONSTANTS.API_READY];
19
- request(this, { [name]: [input, value, !this[CONSTANTS.API_READY]] }).then(() => {
18
+ const isReady = this[CONSTANTS.API_STATUS] == 'initialize';
19
+ request(this, { [name]: [input, value] }).then(() => {
20
20
  const element = host(this);
21
21
  const has = element.hasAttribute(attribute);
22
22
  if (!isReady && has)
@@ -39,7 +39,8 @@ export function Property(options) {
39
39
  const set = (input) => {
40
40
  this[propertyKey] = input;
41
41
  };
42
- defineProperty(element, propertyKey, { get, set });
42
+ // TODO: configurable
43
+ defineProperty(element, propertyKey, { get, set, configurable: true });
43
44
  });
44
45
  };
45
46
  }
@@ -1,4 +1,3 @@
1
- import * as CONSTANTS from '../../constants/index.js';
2
1
  import { defineProperty, request } from '../utils/index.js';
3
2
  export function State() {
4
3
  return function (target, propertyKey) {
@@ -12,12 +11,13 @@ export function State() {
12
11
  if (input === value)
13
12
  return;
14
13
  values.set(this, input);
15
- request(this, { [name]: [input, value, !this[CONSTANTS.API_READY]] })
14
+ request(this, { [name]: [input, value] })
16
15
  .then(() => undefined)
17
16
  .catch((error) => {
18
17
  throw error;
19
18
  });
20
19
  }
21
- defineProperty(target, propertyKey, { get, set });
20
+ // TODO: configurable
21
+ defineProperty(target, propertyKey, { get, set, configurable: true });
22
22
  };
23
23
  }
@@ -10,21 +10,18 @@ export function Watch(keys, immediate) {
10
10
  return function (target, propertyKey) {
11
11
  // Registers a lifecycle to detect changes.
12
12
  appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATED, function ([states]) {
13
- // Gets all keys
14
- const keys = Object.keys(states);
15
13
  // Loops the keys
16
- for (const key of keys) {
17
- // Finds current key in keys
18
- const has = keys === null || keys === void 0 ? void 0 : keys.some((x) => x == key);
14
+ for (const key of Object.keys(states)) {
15
+ // TODO
16
+ if ((keys === null || keys === void 0 ? void 0 : keys.length) && !keys.includes(key))
17
+ continue;
19
18
  // Checks the existence of key
20
- if (!has && !!(keys === null || keys === void 0 ? void 0 : keys.length))
19
+ if ((keys === null || keys === void 0 ? void 0 : keys.length) && !(key in states))
21
20
  continue;
22
21
  // Gets the current state
23
- const state = states === null || states === void 0 ? void 0 : states[key];
24
- // Destructs the state
25
- const [next, prev, isInitial] = state;
22
+ const [next, prev] = states[key];
26
23
  // TODO
27
- if (!immediate && isInitial)
24
+ if (!immediate && this[CONSTANTS.API_STATUS] != 'loaded')
28
25
  continue;
29
26
  // Invokes the method with parameters.
30
27
  this[propertyKey](next, prev, key);
@@ -1 +1 @@
1
- export declare const classes: (input: any, smart?: boolean | undefined) => string;
1
+ export declare const classes: (input: any, smart?: boolean) => string;
@@ -1,2 +1 @@
1
- import { PlusElement } from '../../types/index.js';
2
- export declare const appendToMethod: (target: PlusElement, propertyKey: PropertyKey, handler: (this: any, args: Array<any>) => void) => void;
1
+ export declare const appendToMethod: (target: any, propertyKey: PropertyKey, handler: (this: any, args: Array<any>) => void) => void;
@@ -1,2 +1 @@
1
- import { PlusElement } from '../../types/index.js';
2
- export declare const call: (target: PlusElement, key: string, ...args: Array<any>) => any;
1
+ export declare const call: (target: any, key: string, ...args: Array<any>) => any;
@@ -0,0 +1,5 @@
1
+ interface Options {
2
+ }
3
+ export declare const getConfig: () => Options;
4
+ export declare const setConfig: (config: Options) => void;
5
+ export {};
@@ -0,0 +1,7 @@
1
+ let options = {};
2
+ export const getConfig = () => {
3
+ return options;
4
+ };
5
+ export const setConfig = (config) => {
6
+ options = config || {};
7
+ };
@@ -0,0 +1 @@
1
+ export declare const getFramework: (target: HTMLElement) => string | undefined;
@@ -0,0 +1,12 @@
1
+ export const getFramework = (target) => {
2
+ const keys = Object.keys(target);
3
+ const has = (key) => keys.some((key) => key.startsWith(key));
4
+ if (has('__zone_symbol__'))
5
+ return 'angular';
6
+ if (has('__react'))
7
+ return 'react';
8
+ if (has('__svelte'))
9
+ return 'svelte';
10
+ if (has('__vnode'))
11
+ return 'vue';
12
+ };
@@ -0,0 +1,2 @@
1
+ import { PlusElement } from '../../types/index.js';
2
+ export declare const getMemberType: (target: PlusElement, key: string) => string;
@@ -0,0 +1,5 @@
1
+ import * as CONSTANTS from '../../constants/index.js';
2
+ export const getMemberType = (target, key) => {
3
+ var _a;
4
+ return (_a = (target.constructor[CONSTANTS.STATIC_MEMBERS] || target[CONSTANTS.STATIC_MEMBERS] || {})[key]) === null || _a === void 0 ? void 0 : _a[0];
5
+ };
@@ -0,0 +1,2 @@
1
+ import { PlusElement } from '../../types/index.js';
2
+ export declare const getMembersKey: (target: PlusElement) => string[];
@@ -0,0 +1,4 @@
1
+ import * as CONSTANTS from '../../constants/index.js';
2
+ export const getMembersKey = (target) => {
3
+ return Object.keys(target.constructor[CONSTANTS.STATIC_MEMBERS] || target[CONSTANTS.STATIC_MEMBERS] || {});
4
+ };
@@ -1,12 +1,16 @@
1
1
  export * from './appendToMethod.js';
2
2
  export * from './call.js';
3
+ export * from './config.js';
3
4
  export * from './defineProperty.js';
4
- export * from './event.js';
5
- export * from './getMembers.js';
5
+ export * from './getFramework.js';
6
+ export * from './getMembersKey.js';
7
+ export * from './getMemberType.js';
6
8
  export * from './getStyles.js';
7
9
  export * from './host.js';
8
10
  export * from './isEvent.js';
9
11
  export * from './isServer.js';
12
+ export * from './off.js';
13
+ export * from './on.js';
10
14
  export * from './parseValue.js';
11
15
  export * from './request.js';
12
16
  export * from './sync.js';
@@ -1,12 +1,16 @@
1
1
  export * from './appendToMethod.js';
2
2
  export * from './call.js';
3
+ export * from './config.js';
3
4
  export * from './defineProperty.js';
4
- export * from './event.js';
5
- export * from './getMembers.js';
5
+ export * from './getFramework.js';
6
+ export * from './getMembersKey.js';
7
+ export * from './getMemberType.js';
6
8
  export * from './getStyles.js';
7
9
  export * from './host.js';
8
10
  export * from './isEvent.js';
9
11
  export * from './isServer.js';
12
+ export * from './off.js';
13
+ export * from './on.js';
10
14
  export * from './parseValue.js';
11
15
  export * from './request.js';
12
16
  export * from './sync.js';
@@ -0,0 +1 @@
1
+ export declare const off: (target: Window | Document | Element, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => void;
@@ -0,0 +1,3 @@
1
+ export const off = (target, type, handler, options) => {
2
+ target.removeEventListener(type, handler, options);
3
+ };
@@ -0,0 +1 @@
1
+ export declare const on: (target: Window | Document | Element, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void;
@@ -0,0 +1,3 @@
1
+ export const on = (target, type, handler, options) => {
2
+ target.addEventListener(type, handler, options);
3
+ };
@@ -1,4 +1,4 @@
1
1
  import { PlusElement } from '../../types/index.js';
2
2
  export declare const request: (target: PlusElement, state?: {
3
- [key: string]: [any, any, (boolean | undefined)?];
3
+ [key: string]: [any, any];
4
4
  } | undefined) => Promise<boolean>;
@@ -11,10 +11,12 @@ export const request = (target, state) => {
11
11
  return run(state);
12
12
  run = task({
13
13
  canStart: (states, state) => {
14
- return /* hasChange */ true;
14
+ // TODO: hasChange
15
+ return true;
15
16
  },
16
17
  canRun: (states) => {
17
- return /* shouldUpdate */ true;
18
+ // TODO: shouldUpdate
19
+ return true;
18
20
  },
19
21
  run: (states) => {
20
22
  call(target, CONSTANTS.LIFECYCLE_UPDATE, states);
@@ -1,5 +1,6 @@
1
- import { on, off } from './event.js';
2
1
  import { isEvent } from './isEvent.js';
2
+ import { off } from './off.js';
3
+ import { on } from './on.js';
3
4
  import { toEvent } from './toEvent.js';
4
5
  import { updateAttribute } from './updateAttribute.js';
5
6
  export const sync = (node) => {
@@ -1,5 +1,5 @@
1
1
  export const task = (options) => {
2
- let states, isPending, updatePromise;
2
+ let isPending, states, updatePromise;
3
3
  const run = (state) => {
4
4
  const newStates = Object.assign({}, states, state);
5
5
  if (options.canStart && !options.canStart(newStates, state))
@@ -24,11 +24,15 @@ export default (...plugins) => {
24
24
  let context = {
25
25
  filePath
26
26
  };
27
+ let timeout;
27
28
  for (const plugin of plugins) {
28
29
  if (!plugin.next)
29
30
  continue;
31
+ clearTimeout(timeout);
30
32
  logger.start(`Plugin '${plugin.name}' executing...`);
31
33
  const output = await plugin.next(context, global);
34
+ logger.start(`Plugin '${plugin.name}' executed successfully.`);
35
+ timeout = setTimeout(() => logger.stop(), 1500);
32
36
  // TODO
33
37
  if (output) {
34
38
  context.outputs = ((_a = context.outputs) !== null && _a !== void 0 ? _a : [])
@@ -44,7 +48,6 @@ export default (...plugins) => {
44
48
  output
45
49
  });
46
50
  }
47
- logger.start(`Plugin '${plugin.name}' executed successfully.`);
48
51
  global.contexts = global.contexts.filter((current) => current.filePath != context.filePath).concat(context);
49
52
  if (context.isInvalid)
50
53
  break;
@@ -2,7 +2,7 @@ import { Context } from '../../types/index.js';
2
2
  export interface CustomElementOptions {
3
3
  typings?: boolean;
4
4
  }
5
- export declare const customElement: (options?: CustomElementOptions | undefined) => {
5
+ export declare const customElement: (options?: CustomElementOptions) => {
6
6
  name: string;
7
7
  next: (context: Context) => void;
8
8
  };
@@ -4,6 +4,7 @@ import { print, visitor } from '../utils/index.js';
4
4
  const defaults = {
5
5
  typings: true
6
6
  };
7
+ // TODO: support {variable && jsxElement}
7
8
  export const customElement = (options) => {
8
9
  const name = 'customElement';
9
10
  options = Object.assign({}, defaults, options);
@@ -17,6 +18,17 @@ export const customElement = (options) => {
17
18
  path.node.body.body.unshift(t.classProperty(t.identifier('uhtml')));
18
19
  }
19
20
  });
21
+ // replace className
22
+ visitor(ast, {
23
+ JSXAttribute(path) {
24
+ if (path.node.name.name != 'className')
25
+ return;
26
+ const hasClass = path.parentPath.node.attributes.some((attribute) => attribute.name.name == 'class');
27
+ if (hasClass)
28
+ return path.remove();
29
+ path.replaceWith(t.jsxAttribute(t.jsxIdentifier('class'), path.node.value));
30
+ }
31
+ });
20
32
  // jsx to uhtml syntax
21
33
  visitor(ast, {
22
34
  JSXAttribute: {
@@ -105,7 +117,9 @@ export const customElement = (options) => {
105
117
  visitor(ast, {
106
118
  Program(path) {
107
119
  path.node.body.push(Object.assign(t.tsModuleDeclaration(t.identifier('global'), t.tsModuleBlock([
108
- t.tsInterfaceDeclaration(t.identifier(context.componentInterfaceName), null, [], t.tsInterfaceBody([
120
+ t.tsInterfaceDeclaration(t.identifier(context.componentInterfaceName), null, [
121
+ t.tSExpressionWithTypeArguments(t.identifier('HTMLElement')) // TODO
122
+ ], t.tsInterfaceBody([
109
123
  ...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
110
124
  optional: property.optional,
111
125
  leadingComments: property.leadingComments
@@ -96,7 +96,7 @@ export const customElementReact = (options) => {
96
96
  return {
97
97
  all,
98
98
  filterd: all.slice(1),
99
- root: all.at(0),
99
+ root: all[0],
100
100
  single: all.length == 1
101
101
  };
102
102
  })
@@ -31,7 +31,7 @@
31
31
  "typescript": "^4.0.2"
32
32
  },
33
33
  "peerDependencies": {
34
- "react": "^16.0.0 || ^17.0.0",
35
- "react-dom": "^16.0.0 || ^17.0.0"
34
+ "react": "^18.0.0",
35
+ "react-dom": "^18.0.0"
36
36
  }
37
37
  }
@@ -1,6 +1,3 @@
1
- /* eslint-disable */
2
- /* tslint:disable */
3
-
4
1
  /**************************************************
5
2
  * THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
6
3
  **************************************************/
@@ -9,7 +6,7 @@
9
6
  import { {{componentClassNamePrune}} } from './{{fileName}}';
10
7
  {{/each}}
11
8
 
12
- const All = /*@__PURE__*/ Object.assign({{root.componentClassNamePrune}}, {
9
+ const All = Object.assign({{root.componentClassNamePrune}}, {
13
10
  {{#each filterd}}
14
11
  {{componentClassNameInCategory}}: {{componentClassNamePrune}},
15
12
  {{/each}}
@@ -1,13 +1,9 @@
1
- /* eslint-disable */
2
- /* tslint:disable */
3
-
4
1
  /**************************************************
5
2
  * THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
6
3
  **************************************************/
7
4
 
8
5
  import { proxy } from '../proxy';
9
6
 
10
- {{!-- import { {{importerComponent.root}} as Component } from '{{importerComponent.source}}'; --}}
11
7
  import '{{importerComponent.source}}';
12
8
  import type { {{importerComponentType.root}} as Type } from '{{importerComponentType.source}}';
13
9
 
@@ -19,7 +15,7 @@ type Renamed = Rename<{{importerComponentType.variable}}, {
19
15
  {{/each}}
20
16
  }>
21
17
 
22
- export const {{componentClassNamePrune}} = /*@__PURE__*/ proxy<{{componentInterfaceName}}, Renamed>(
18
+ export const {{componentClassNamePrune}} = proxy<{{componentInterfaceName}}, Renamed>(
23
19
  '{{componentTag}}',
24
20
  [{{#each classProperties}}'{{key.name}}', {{/each}}],
25
21
  [{{#each classEvents}}'{{key.name}}', {{/each}}],
@@ -159,13 +159,13 @@ const setEvent = (element: Element, name: string, handler: EventHandlerType) =>
159
159
 
160
160
  const previous = events[name];
161
161
 
162
- previous && element.removeEventListener(name, previous);
162
+ previous && element.removeEventListener(paramCase(name), previous);
163
163
 
164
164
  function callback(event: Event) {
165
165
  handler && handler.call(this, event);
166
166
  }
167
167
 
168
- element.addEventListener(name, (events[name] = callback));
168
+ element.addEventListener(paramCase(name), (events[name] = callback));
169
169
  };
170
170
 
171
171
  const setProps = <ElementType>(element: ElementType, props: PropsType<ElementType>, extra: ExtraType) => {
@@ -243,7 +243,7 @@ export const proxy = <ElementType, PropType>(
243
243
  Object.keys(events).forEach((name) => {
244
244
  const handler = events[name];
245
245
 
246
- (this.element as any).removeEventListener(name, handler);
246
+ (this.element as any).removeEventListener(paramCase(name), handler);
247
247
  });
248
248
 
249
249
  delete this.element['$events'];
@@ -2,7 +2,7 @@ import { Context } from '../../types/index.js';
2
2
  export interface ExtractOptions {
3
3
  prefix?: string;
4
4
  }
5
- export declare const extract: (options?: ExtractOptions | undefined) => {
5
+ export declare const extract: (options?: ExtractOptions) => {
6
6
  name: string;
7
7
  next: (context: Context) => void;
8
8
  };
@@ -35,7 +35,17 @@ export const extract = (options) => {
35
35
  ])));
36
36
  return;
37
37
  }
38
- }
38
+ },
39
+ JSXElement(path) {
40
+ var _a;
41
+ const { openingElement } = path.node;
42
+ const name = openingElement.name.name;
43
+ if (!/-/g.test(name))
44
+ return;
45
+ (_a = context.customElementNames) !== null && _a !== void 0 ? _a : (context.customElementNames = []);
46
+ context.customElementNames.push(name);
47
+ context.customElementNames = context.customElementNames.filter((item, index, items) => items.indexOf(item) === index).sort();
48
+ },
39
49
  });
40
50
  context.directoryPath = path.dirname(context.filePath);
41
51
  context.directoryName = path.basename(context.directoryPath);
@@ -7,7 +7,7 @@ export interface TagParsed {
7
7
  name?: string;
8
8
  description?: string;
9
9
  }
10
- export declare const getTag: (node: Node, key?: string | undefined) => Tag | undefined;
11
- export declare const getTags: (node: Node, filter?: string | undefined) => Array<Tag>;
10
+ export declare const getTag: (node: Node, key?: string) => Tag | undefined;
11
+ export declare const getTags: (node: Node, filter?: string) => Array<Tag>;
12
12
  export declare const hasTag: (node: Node, name: string) => Boolean;
13
13
  export declare const parseTag: (tag: Tag, spliter?: string) => TagParsed;
@@ -1,6 +1,6 @@
1
1
  export declare const PACKAGE_NAME = "@htmlplus/element";
2
2
  export declare const API_HOST = "$host$";
3
- export declare const API_READY = "$ready$";
3
+ export declare const API_STATUS = "$status$";
4
4
  export declare const DECORATOR_ELEMENT = "Element";
5
5
  export declare const DECORATOR_EVENT = "Event";
6
6
  export declare const DECORATOR_PROPERTY = "Property";
@@ -1,7 +1,8 @@
1
1
  export const PACKAGE_NAME = '@htmlplus/element';
2
2
  // apis
3
3
  export const API_HOST = '$host$';
4
- export const API_READY = '$ready$';
4
+ // TODO
5
+ export const API_STATUS = '$status$';
5
6
  // decorators
6
7
  export const DECORATOR_ELEMENT = 'Element';
7
8
  export const DECORATOR_EVENT = 'Event';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "0.4.0",
3
+ "version": "0.4.3",
4
4
  "license": "MIT",
5
5
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
6
6
  "description": "Compiler of HTMLPlus",
@@ -32,28 +32,26 @@
32
32
  },
33
33
  "homepage": "https://github.com/htmlplus/element#readme",
34
34
  "dependencies": {
35
- "@babel/generator": "^7.16.0",
36
- "@babel/parser": "^7.16.4",
37
- "@babel/traverse": "^7.16.3",
38
- "@babel/types": "^7.16.0",
39
- "@types/node": "^16.11.11",
35
+ "@babel/generator": "^7.18.9",
36
+ "@babel/parser": "^7.18.9",
37
+ "@babel/traverse": "^7.18.9",
38
+ "@babel/types": "^7.18.9",
39
+ "@types/node": "^18.6.3",
40
40
  "change-case": "^4.1.2",
41
41
  "fast-glob": "^3.2.11",
42
42
  "fs-extra": "^10.1.0",
43
43
  "handlebars": "^4.7.7",
44
- "listr2": "^4.0.5",
45
- "log-update": "^5.0.0",
46
- "ora": "^6.1.0",
47
- "typescript": "^4.5.2",
48
- "uhtml": "^3.0.1"
44
+ "listr2": "^5.0.1",
45
+ "ora": "^6.1.2",
46
+ "typescript": "^4.7.4"
49
47
  },
50
48
  "devDependencies": {
51
- "@trivago/prettier-plugin-sort-imports": "^3.1.1",
49
+ "@trivago/prettier-plugin-sort-imports": "^3.3.0",
52
50
  "cpy": "^9.0.1",
53
- "nodemon": "^2.0.16",
54
- "prettier": "^2.5.0",
51
+ "nodemon": "^2.0.19",
52
+ "prettier": "^2.7.1",
55
53
  "rimraf": "^3.0.2",
56
- "ts-node": "^10.7.0",
57
- "vite": "^2.7.10"
54
+ "ts-node": "^10.9.1",
55
+ "vite": "^3.0.4"
58
56
  }
59
57
  }
@@ -1,5 +1,6 @@
1
1
  import { ClassBody, ClassDeclaration, ClassMethod, ClassProperty, File } from '@babel/types';
2
2
  export interface Context {
3
+ customElementNames?: Array<string>;
3
4
  dependencies?: Array<Context>;
4
5
  dependenciesUnresolved?: Array<string>;
5
6
  isInvalid?: boolean;
@@ -1,5 +0,0 @@
1
- declare type Target = Window | Document | Element;
2
- export declare const dispatch: (target: Target, event: Event) => boolean;
3
- export declare const on: (target: Target, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined) => void;
4
- export declare const off: (target: Target, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined) => void;
5
- export {};
@@ -1,9 +0,0 @@
1
- export const dispatch = (target, event) => {
2
- return target.dispatchEvent(event);
3
- };
4
- export const on = (target, type, handler, options) => {
5
- target.addEventListener(type, handler, options);
6
- };
7
- export const off = (target, type, handler, options) => {
8
- target.removeEventListener(type, handler, options);
9
- };
@@ -1,2 +0,0 @@
1
- import { PlusElement } from '../../types/index.js';
2
- export declare const getMembers: (target: PlusElement) => any;
@@ -1,5 +0,0 @@
1
- import * as CONSTANTS from '../../constants/index.js';
2
- export const getMembers = (target) => {
3
- var _a;
4
- return (_a = target.constructor[CONSTANTS.STATIC_MEMBERS]) !== null && _a !== void 0 ? _a : target[CONSTANTS.STATIC_MEMBERS];
5
- };