@htmlplus/element 0.5.9 → 0.6.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,13 +1,16 @@
1
1
  import { paramCase } from 'change-case';
2
2
  import fs from 'fs-extra';
3
3
  import path from 'path';
4
- import { getInitializer, getTags, hasTag, parseTag, print } from '../utils/index.js';
4
+ import { getInitializer, getTags, getType, hasTag, parseTag, print } from '../utils/index.js';
5
5
  export const WEB_TYPES_OPTIONS = {};
6
6
  export const webTypes = (options) => {
7
7
  const name = 'webTypes';
8
8
  options = Object.assign({}, WEB_TYPES_OPTIONS, options);
9
9
  const finish = (global) => {
10
10
  var _a, _b, _c, _d, _e, _f, _g;
11
+ const contexts = global.contexts.sort((a, b) => {
12
+ return a.componentTag.toUpperCase() > b.componentTag.toUpperCase() ? -1 : +1;
13
+ });
11
14
  const json = {
12
15
  '$schema': 'http://json.schemastore.org/web-types',
13
16
  'name': options.packageName,
@@ -33,27 +36,16 @@ export const webTypes = (options) => {
33
36
  experimental: hasTag(member, 'experimental')
34
37
  });
35
38
  };
36
- for (const context of global.contexts) {
39
+ for (const context of contexts) {
37
40
  const attributes = (_a = context.classProperties) === null || _a === void 0 ? void 0 : _a.map((property) => {
38
41
  var _a;
39
42
  return Object.assign(common(property), {
40
43
  name: paramCase(property.key['name']),
41
44
  value: {
42
45
  // kind: TODO
43
- /**
44
- * For Example
45
- * 01) type: "''"
46
- * 02) type: "null"
47
- * 03) type: "undefined"
48
- * 04) type: "boolean"
49
- * 05) type: "string"
50
- * 06) type: "number"
51
- * 07) type: "boolean | string | number"
52
- * 08) type: "string[]"
53
- * 09) type: "1 | 2 | 3"
54
- * 10) type: "'Value-1' | 'Value-2'"
55
- */
56
- type: print((_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a['typeAnnotation'])
46
+ type: print(getType(context.fileAST, (_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a['typeAnnotation'], {
47
+ directory: context.directoryPath
48
+ }))
57
49
  // required: TODO
58
50
  // default: TODO
59
51
  },
@@ -1,2 +1,2 @@
1
1
  import { File, Node } from '@babel/types';
2
- export declare const getType: (file: File, node: Node, options: any) => any;
2
+ export declare const getType: (file: File, node: Node, options: any) => Node;
@@ -4,7 +4,6 @@ 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
- // TODO: return type
8
7
  export const getType = (file, node, options) => {
9
8
  if (!node)
10
9
  return node;
@@ -68,6 +67,24 @@ export const getType = (file, node, options) => {
68
67
  if (path.node.id.name != node.typeName['name'])
69
68
  return;
70
69
  result = path.node.typeAnnotation;
70
+ switch (result.type) {
71
+ case 'TSUnionType':
72
+ const types = [];
73
+ for (const prev of result.types) {
74
+ const next = getType(file, prev, options);
75
+ if (next.type == 'TSUnionType') {
76
+ next.types.forEach((type) => types.push(type));
77
+ }
78
+ else {
79
+ types.push(next);
80
+ }
81
+ }
82
+ result.types = types;
83
+ break;
84
+ default:
85
+ result = getType(file, result, options);
86
+ break;
87
+ }
71
88
  path.stop();
72
89
  }
73
90
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "0.5.9",
3
+ "version": "0.6.0",
4
4
  "license": "MIT",
5
5
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
6
6
  "description": "A powerful library for building scalable, reusable, fast, tastable and lightweight design system for any web technologies. Powerd by Web Component.",