@htmlplus/element 0.6.6 → 0.6.7

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.
@@ -42,11 +42,17 @@ export function Element(tag) {
42
42
  }
43
43
  connectedCallback() {
44
44
  const instance = this[CONSTANTS.API_INSTANCE];
45
- instance[CONSTANTS.API_CONNECTED] = true;
46
- call(instance, CONSTANTS.LIFECYCLE_CONNECTED);
47
- request(instance, undefined, undefined, () => {
48
- call(instance, CONSTANTS.LIFECYCLE_LOADED);
49
- });
45
+ const connect = () => {
46
+ instance[CONSTANTS.API_CONNECTED] = true;
47
+ call(instance, CONSTANTS.LIFECYCLE_CONNECTED);
48
+ request(instance, undefined, undefined, () => {
49
+ call(instance, CONSTANTS.LIFECYCLE_LOADED);
50
+ });
51
+ };
52
+ const callback = call(instance, CONSTANTS.LIFECYCLE_CONNECT);
53
+ if (!(callback === null || callback === void 0 ? void 0 : callback.then))
54
+ return connect();
55
+ callback.then(() => connect());
50
56
  }
51
57
  disconnectedCallback() {
52
58
  call(this[CONSTANTS.API_INSTANCE], CONSTANTS.LIFECYCLE_DISCONNECTED);
@@ -107,6 +107,7 @@ export const customElement = (options) => {
107
107
  return;
108
108
  let type = 0;
109
109
  const extract = (input) => {
110
+ var _a;
110
111
  switch (input === null || input === void 0 ? void 0 : input.type) {
111
112
  case 'BooleanLiteral':
112
113
  type |= CONSTANTS.TYPE_BOOLEAN;
@@ -172,8 +173,18 @@ export const customElement = (options) => {
172
173
  input.types.forEach(extract);
173
174
  break;
174
175
  }
176
+ // TODO
177
+ if ((input === null || input === void 0 ? void 0 : input.type) == 'TSParenthesizedType' && ((_a = input === null || input === void 0 ? void 0 : input.typeAnnotation) === null || _a === void 0 ? void 0 : _a.type) == 'TSIntersectionType') {
178
+ let types = input.types || input.typeAnnotation.types;
179
+ if (types.length != 2)
180
+ return;
181
+ types = types.filter((type) => type.type != 'TSTypeLiteral');
182
+ if (types.length != 1)
183
+ return;
184
+ extract(types[0]);
185
+ }
175
186
  };
176
- extract(getType(ast, (_b = path.parentPath.node.typeAnnotation) === null || _b === void 0 ? void 0 : _b.typeAnnotation, { directory: context.directoryPath }));
187
+ extract(getType(context.directoryPath, ast, (_b = path.parentPath.node.typeAnnotation) === null || _b === void 0 ? void 0 : _b.typeAnnotation));
177
188
  if (!expression.arguments.length) {
178
189
  expression.arguments.push(t.objectExpression([]));
179
190
  }
@@ -35,9 +35,7 @@ export const visualStudioCode = (options) => {
35
35
  description: (_c = getTags(property).find((tag) => !tag.key)) === null || _c === void 0 ? void 0 : _c.value,
36
36
  values: []
37
37
  };
38
- const type = print(getType(context.fileAST, (_d = property.typeAnnotation) === null || _d === void 0 ? void 0 : _d['typeAnnotation'], {
39
- directory: context.directoryPath
40
- }));
38
+ const type = print(getType(context.directoryPath, context.fileAST, (_d = property.typeAnnotation) === null || _d === void 0 ? void 0 : _d['typeAnnotation']));
41
39
  const sections = type.split('|');
42
40
  for (const section of sections) {
43
41
  const trimmed = section.trim();
@@ -43,9 +43,7 @@ export const webTypes = (options) => {
43
43
  name: paramCase(property.key['name']),
44
44
  value: {
45
45
  // kind: TODO
46
- type: print(getType(context.fileAST, (_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a['typeAnnotation'], {
47
- directory: context.directoryPath
48
- }))
46
+ type: print(getType(context.directoryPath, context.fileAST, (_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a['typeAnnotation']))
49
47
  // required: TODO
50
48
  // default: TODO
51
49
  },
@@ -1,2 +1,2 @@
1
1
  import { File, Node } from '@babel/types';
2
- export declare const getType: (file: File, node: Node, options: any) => Node;
2
+ export declare const getType: (directory: string, file: File, node: Node) => Node;
@@ -4,12 +4,11 @@ import fs from 'fs-extra';
4
4
  import { dirname, resolve } from 'path';
5
5
  import { join } from 'path';
6
6
  import { visitor } from './visitor.js';
7
- export const getType = (file, node, options) => {
7
+ export const getType = (directory, file, node) => {
8
8
  if (!node)
9
9
  return node;
10
10
  if (node.type != 'TSTypeReference')
11
11
  return node;
12
- const { directory } = options;
13
12
  let result;
14
13
  visitor(file, {
15
14
  ClassDeclaration(path) {
@@ -48,9 +47,7 @@ export const getType = (file, node, options) => {
48
47
  plugins: ['typescript'],
49
48
  ranges: false
50
49
  }));
51
- result = getType(path.$ast, node, {
52
- directory: dirname(filePath)
53
- });
50
+ result = getType(dirname(filePath), path.$ast, node);
54
51
  }
55
52
  catch (_a) { }
56
53
  path.stop();
@@ -71,7 +68,7 @@ export const getType = (file, node, options) => {
71
68
  case 'TSUnionType':
72
69
  const types = [];
73
70
  for (const prev of result.types) {
74
- const next = getType(file, prev, options);
71
+ const next = getType(directory, file, prev);
75
72
  if (next.type == 'TSUnionType') {
76
73
  next.types.forEach((type) => types.push(type));
77
74
  }
@@ -82,7 +79,7 @@ export const getType = (file, node, options) => {
82
79
  result.types = types;
83
80
  break;
84
81
  default:
85
- result = getType(file, result, options);
82
+ result = getType(directory, file, result);
86
83
  break;
87
84
  }
88
85
  path.stop();
@@ -15,6 +15,7 @@ export declare const DECORATOR_PROPERTY = "Property";
15
15
  export declare const DECORATOR_STATE = "State";
16
16
  export declare const DECORATOR_METHOD = "Method";
17
17
  export declare const LIFECYCLE_ADOPTED = "adoptedCallback";
18
+ export declare const LIFECYCLE_CONNECT = "connectCallback";
18
19
  export declare const LIFECYCLE_CONNECTED = "connectedCallback";
19
20
  export declare const LIFECYCLE_DISCONNECTED = "disconnectedCallback";
20
21
  export declare const LIFECYCLE_LOADED = "loadedCallback";
@@ -19,6 +19,7 @@ export const DECORATOR_STATE = 'State';
19
19
  export const DECORATOR_METHOD = 'Method';
20
20
  // lifecycle
21
21
  export const LIFECYCLE_ADOPTED = 'adoptedCallback';
22
+ export const LIFECYCLE_CONNECT = 'connectCallback';
22
23
  export const LIFECYCLE_CONNECTED = 'connectedCallback';
23
24
  export const LIFECYCLE_DISCONNECTED = 'disconnectedCallback';
24
25
  export const LIFECYCLE_LOADED = 'loadedCallback';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "author": "Masood Abdolian <m.abdolian@gmail.com>",