@htmlplus/element 0.6.0 → 0.6.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.
@@ -138,6 +138,9 @@ export const customElement = (options) => {
138
138
  case 'TSStringKeyword':
139
139
  type |= CONSTANTS.TYPE_STRING;
140
140
  break;
141
+ case 'TSTupleType':
142
+ type |= CONSTANTS.TYPE_ARRAY;
143
+ break;
141
144
  case 'TSTypeLiteral':
142
145
  type |= CONSTANTS.TYPE_OBJECT;
143
146
  break;
@@ -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
  };
@@ -9,7 +9,7 @@ export const webTypes = (options) => {
9
9
  const finish = (global) => {
10
10
  var _a, _b, _c, _d, _e, _f, _g;
11
11
  const contexts = global.contexts.sort((a, b) => {
12
- return a.componentTag.toUpperCase() > b.componentTag.toUpperCase() ? -1 : +1;
12
+ return a.componentTag.toUpperCase() > b.componentTag.toUpperCase() ? +1 : -1;
13
13
  });
14
14
  const json = {
15
15
  '$schema': 'http://json.schemastore.org/web-types',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
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.",