@htmlplus/element 0.5.9 → 0.6.1

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.
@@ -9,4 +9,5 @@ export * from './read.js';
9
9
  export * from './readme.js';
10
10
  export * from './style.js';
11
11
  export * from './validate.js';
12
+ export * from './visualStudioCode.js';
12
13
  export * from './webTypes.js';
@@ -9,4 +9,5 @@ export * from './read.js';
9
9
  export * from './readme.js';
10
10
  export * from './style.js';
11
11
  export * from './validate.js';
12
+ export * from './visualStudioCode.js';
12
13
  export * from './webTypes.js';
@@ -1,6 +1,8 @@
1
- import { Plugin } from '../../types';
1
+ import { Context, Plugin } from '../../types';
2
2
  export declare const VISUAL_STUDIO_CODE_OPTIONS: Partial<VisualStudioCodeOptions>;
3
3
  export interface VisualStudioCodeOptions {
4
4
  destination: string;
5
+ reference?: (context: Context) => string;
6
+ transformer?: (context: Context, component: any) => any;
5
7
  }
6
8
  export declare const visualStudioCode: (options: VisualStudioCodeOptions) => Plugin;
@@ -1,28 +1,77 @@
1
+ import { paramCase } from 'change-case';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import { getTags, getType, print } from '../utils/index.js';
1
5
  export const VISUAL_STUDIO_CODE_OPTIONS = {};
2
6
  export const visualStudioCode = (options) => {
3
7
  const name = 'visualStudioCode';
4
8
  options = Object.assign({}, VISUAL_STUDIO_CODE_OPTIONS, options);
5
9
  const finish = (global) => {
6
- // TODO
7
- // {
8
- // version: 1.1,
9
- // tags: [
10
- // {
11
- // name: context.componentKey,
12
- // description: {
13
- // kind: 'markdown',
14
- // value: description
15
- // },
16
- // attributes: properties,
17
- // references: [
18
- // {
19
- // name: 'Source code',
20
- // url: `https://github.com/htmlplus/core/tree/main/src/components/${context.directoryName}/${context.fileName}.tsx`
21
- // }
22
- // ]
23
- // }
24
- // ]
25
- // };
10
+ var _a, _b, _c, _d, _e;
11
+ const contexts = global.contexts.sort((a, b) => {
12
+ return a.componentTag.toUpperCase() > b.componentTag.toUpperCase() ? +1 : -1;
13
+ });
14
+ const json = {
15
+ $schema: 'TODO',
16
+ version: 1.1,
17
+ tags: []
18
+ };
19
+ for (const context of contexts) {
20
+ const description = (_a = getTags(context.class).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
21
+ const tag = {
22
+ name: context.componentTag,
23
+ description: description,
24
+ attributes: [],
25
+ references: [
26
+ {
27
+ name: 'Source code',
28
+ url: (_b = options.reference) === null || _b === void 0 ? void 0 : _b.call(options, context)
29
+ }
30
+ ]
31
+ };
32
+ for (const property of context.classProperties || []) {
33
+ const attribute = {
34
+ name: paramCase(property.key['name']),
35
+ description: (_c = getTags(property).find((tag) => !tag.key)) === null || _c === void 0 ? void 0 : _c.value,
36
+ values: []
37
+ };
38
+ const type = print(getType(context.fileAST, (_d = property.typeAnnotation) === null || _d === void 0 ? void 0 : _d['typeAnnotation'], {
39
+ directory: context.directoryPath
40
+ }));
41
+ const sections = type.split('|');
42
+ for (const section of sections) {
43
+ const trimmed = section.trim();
44
+ if (!trimmed)
45
+ continue;
46
+ const isBoolean = /bool|boolean|Boolean/.test(trimmed);
47
+ const isNumber = !isNaN(trimmed);
48
+ const isString = /^("|'|`)/.test(trimmed);
49
+ if (isBoolean) {
50
+ attribute.values.push({
51
+ name: 'false'
52
+ }, {
53
+ name: 'true'
54
+ });
55
+ }
56
+ else if (isNumber) {
57
+ attribute.values.push({
58
+ name: trimmed
59
+ });
60
+ }
61
+ else if (isString) {
62
+ attribute.values.push({
63
+ name: trimmed.slice(1, -1)
64
+ });
65
+ }
66
+ }
67
+ tag.attributes.push(attribute);
68
+ }
69
+ const transformed = ((_e = options.transformer) === null || _e === void 0 ? void 0 : _e.call(options, context, tag)) || tag;
70
+ json.tags.push(transformed);
71
+ }
72
+ const dirname = path.dirname(options.destination);
73
+ fs.ensureDirSync(dirname);
74
+ fs.writeJSONSync(options.destination, json, { encoding: 'utf8', spaces: 2 });
26
75
  };
27
76
  return { name, finish };
28
77
  };
@@ -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.1",
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.",