@htmlplus/element 0.1.5 → 0.1.6

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.
@@ -64,24 +64,19 @@ export const attach = (options) => {
64
64
  ]))
65
65
  }))
66
66
  ]),
67
- t.tsInterfaceDeclaration(t.identifier(context.componentClassName), null, [], t.tsInterfaceBody([
68
- ...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
69
- optional: property.optional,
70
- leadingComments: property.leadingComments
71
- }))
72
- ])),
73
67
  t.tsInterfaceDeclaration(t.identifier('HTMLElementTagNameMap'), null, [], t.tsInterfaceBody([
74
- t.tSPropertySignature(t.stringLiteral(context.componentTag), t.tSTypeAnnotation(t.tSIntersectionType([t.tSTypeReference(t.identifier(context.componentClassName))])))
75
- ])),
76
- t.exportNamedDeclaration(t.tSModuleDeclaration(t.identifier('JSX'), t.tsModuleBlock([
77
- t.tsInterfaceDeclaration(t.identifier('IntrinsicElements'), undefined, undefined, t.tsInterfaceBody([
78
- t.tsPropertySignature(t.stringLiteral(context.componentTag), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(context.componentClassName))))
79
- ]))
80
- ])))
68
+ t.tSPropertySignature(t.stringLiteral(context.componentTag), t.tSTypeAnnotation(t.tSIntersectionType([t.tSTypeReference(t.identifier(context.componentInterfaceName))])))
69
+ ]))
81
70
  ])), {
82
71
  declare: true,
83
72
  global: true
84
73
  }));
74
+ path.node.body.push(t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(context.componentClassName + 'JSX'), null, [], t.tsInterfaceBody([
75
+ ...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
76
+ optional: property.optional,
77
+ leadingComments: property.leadingComments
78
+ }))
79
+ ]))));
85
80
  }
86
81
  });
87
82
  }
@@ -1,9 +1,11 @@
1
1
  export interface ReactProxyOptions {
2
+ compact?: boolean;
2
3
  dist: string;
3
- corePackageName: string;
4
- categorize?: boolean;
4
+ eventName?: (eventName: string) => string;
5
+ importerComponent?: (context: any) => string;
6
+ importerComponentType?: (context: any) => string;
5
7
  }
6
8
  export declare const reactProxy: (options: ReactProxyOptions) => {
7
9
  name: string;
8
- finish: (global: any) => Promise<void>;
10
+ finish: (global: any) => void;
9
11
  };
@@ -1,58 +1,117 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { __dirname, isDirectoryEmpty, renderTemplate } from '../../utils/index.js';
2
+ const defaults = {
3
+ compact: false,
4
+ dist: '',
5
+ eventName: undefined,
6
+ importerComponent(context) {
7
+ return `YOUR_CORE_PACKAGE_NAME#${context.componentClassName}`;
8
+ },
9
+ importerComponentType(context) {
10
+ return `YOUR_CORE_PACKAGE_NAME#JSX.${context.componentClassName}`;
11
+ }
12
+ };
11
13
  export const reactProxy = (options) => {
12
14
  const name = 'react-proxy';
13
- const finish = (global) => __awaiter(void 0, void 0, void 0, function* () {
15
+ const finish = (global) => {
16
+ options = Object.assign(Object.assign({}, defaults), options);
17
+ global = Object.assign(Object.assign({}, global), { options });
14
18
  const config = { cwd: __dirname(import.meta.url) };
15
- const component = 'templates/src/components/*fileName*';
16
- global = Object.assign({}, global, { options });
19
+ const isEmpty = isDirectoryEmpty(options.dist);
17
20
  const skip = [];
18
21
  const getKey = (component) => component.componentClassName;
19
- global.groups = Object.values(global.contexts)
20
- .sort((a, b) => getKey(b).length - getKey(a).length)
21
- .map((component, index, components) => ({
22
- key: getKey(component),
23
- components: components.filter((current) => getKey(current).startsWith(getKey(component)))
24
- }))
25
- .sort((a, b) => b.components.length - a.components.length)
26
- .filter((group) => {
27
- if (skip.includes(group.key))
28
- return;
29
- group.components.forEach((component) => skip.push(getKey(component)));
30
- return true;
31
- })
32
- .map((group) => {
33
- const root = group.components.find((component) => getKey(component) == group.key);
34
- const all = group.components
35
- .map((component) => (Object.assign(Object.assign({}, component), { componentClassNameInCategory: getKey(component).replace(group.key, '') })))
36
- .reverse();
37
- const filterd = all.filter((component) => getKey(component) != group.key);
38
- return {
39
- single: !filterd.length,
40
- root,
41
- all,
42
- filterd
22
+ for (const key in global.contexts) {
23
+ const context = global.contexts[key];
24
+ const parse = (input) => {
25
+ const [source, key] = input.split('#');
26
+ const [root, ...sub] = key.split('.');
27
+ const variable = ['Type', ...sub].join('.');
28
+ return {
29
+ source,
30
+ variable,
31
+ root
32
+ };
43
33
  };
44
- })
45
- .sort((a, b) => (getKey(a.root) < getKey(b.root) ? -1 : 0));
46
- if (yield isDirectoryEmpty(options.dist)) {
47
- renderTemplate(['templates/**', `!${component}`], options.dist, config)(global);
34
+ const classEvents = context.classEvents.map((classEvent) => {
35
+ return Object.assign(Object.assign({}, classEvent), { converted: options.eventName(classEvent.key.name) });
36
+ });
37
+ const fileName = context.fileName;
38
+ const importerComponent = parse(options.importerComponent(context));
39
+ const importerComponentType = parse(options.importerComponentType(context));
40
+ const state = Object.assign(Object.assign({}, context), { classEvents,
41
+ fileName,
42
+ importerComponent,
43
+ importerComponentType,
44
+ options });
45
+ const patterns = [
46
+ 'templates/src/components/*fileName*.ts.hbs',
47
+ '!templates/src/components/*fileName*.compact.ts.hbs'
48
+ ];
49
+ renderTemplate(patterns, options.dist, config)(state);
48
50
  }
49
- else {
50
- renderTemplate(['templates/src/proxy*', 'templates/src/components/index*'], options.dist, config)(global);
51
+ if (options.compact) {
52
+ global.groups = Object.values(global.contexts)
53
+ .sort((a, b) => getKey(b).length - getKey(a).length)
54
+ .map((component, index, components) => ({
55
+ key: getKey(component),
56
+ components: components.filter((current) => getKey(current).startsWith(getKey(component)))
57
+ }))
58
+ .sort((a, b) => b.components.length - a.components.length)
59
+ .filter((group) => {
60
+ if (skip.includes(group.key))
61
+ return;
62
+ group.components.forEach((component) => skip.push(getKey(component)));
63
+ return true;
64
+ })
65
+ .map((group) => {
66
+ const all = group.components.reverse().map((component, index) => {
67
+ const componentClassNameInCategory = getKey(component).replace(group.key, '');
68
+ const parse = (input) => {
69
+ const [source, key] = input.split('#');
70
+ const [root, ...sub] = key.split('.');
71
+ const local = root + (index + 1);
72
+ const variable = [local, ...sub].join('.');
73
+ return {
74
+ source,
75
+ variable,
76
+ root,
77
+ local
78
+ };
79
+ };
80
+ const importerComponent = parse(options.importerComponent(component));
81
+ const importerComponentType = parse(options.importerComponentType(component));
82
+ return Object.assign(Object.assign({}, component), { componentClassNameInCategory,
83
+ importerComponent,
84
+ importerComponentType });
85
+ });
86
+ return {
87
+ all,
88
+ filterd: all.slice(1),
89
+ root: all.at(0),
90
+ single: all.length == 1
91
+ };
92
+ })
93
+ .sort((a, b) => (getKey(a.root) < getKey(b.root) ? -1 : 0));
94
+ for (const group of global.groups) {
95
+ if (group.single)
96
+ continue;
97
+ const state = Object.assign({ fileName: group.root.fileName, options }, group);
98
+ const patterns = ['templates/src/components/*fileName*.compact.ts.hbs'];
99
+ renderTemplate(patterns, options.dist, config)(state);
100
+ }
51
101
  }
52
- for (const group of global.groups) {
53
- renderTemplate(component, options.dist, config)(Object.assign({ options, fileName: group.root.fileName }, group));
102
+ if (isEmpty) {
103
+ const patterns = [
104
+ 'templates/**',
105
+ '!templates/src/components/*fileName*.ts.hbs',
106
+ '!templates/src/components/*fileName*.compact.ts.hbs'
107
+ ];
108
+ renderTemplate(patterns, options.dist, config)(global);
54
109
  }
55
- });
110
+ if (!isEmpty) {
111
+ const patterns = ['templates/src/proxy*', 'templates/src/components/index*'];
112
+ renderTemplate(patterns, options.dist, config)(global);
113
+ }
114
+ };
56
115
  return {
57
116
  name,
58
117
  finish
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "your-react-package-name",
2
+ "name": "YOUR_REACT_PACKAGE_NAME",
3
3
  "version": "0.0.0",
4
4
  "type": "module",
5
5
  "description": "React output target for your custom element.",
@@ -14,13 +14,14 @@
14
14
  "dist"
15
15
  ],
16
16
  "dependencies": {
17
- "{{options.corePackageName}}": "latest",
17
+ "YOUR_CORE_PACKAGE_NAME": "latest",
18
18
  "change-case": "^4.1.2"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@rollup/plugin-commonjs": "^15.0.0",
22
22
  "@rollup/plugin-node-resolve": "^9.0.0",
23
23
  "@types/react": "^16.9.49",
24
+ "glob": "^7.2.0",
24
25
  "react": "^17.0.1",
25
26
  "react-dom": "^17.0.1",
26
27
  "rimraf": "^3.0.2",
@@ -1,20 +1,21 @@
1
1
  import commonjs from '@rollup/plugin-commonjs';
2
2
  import resolve from '@rollup/plugin-node-resolve';
3
+ import glob from 'glob';
3
4
  import peerDepsExternal from 'rollup-plugin-peer-deps-external';
4
5
  import typescript from 'rollup-plugin-typescript2';
5
6
 
6
7
  export default {
7
- input: 'src/index.ts',
8
+ input: glob.sync('src/**/*.ts'),
8
9
  output: [
9
10
  {
10
- dir: 'dist/components',
11
- format: 'esm'
12
- }
11
+ dir: 'dist',
12
+ format: 'esm',
13
+ },
13
14
  ],
14
15
  plugins: [
15
16
  peerDepsExternal(),
16
17
  resolve(),
17
18
  commonjs(),
18
- typescript()
19
- ]
19
+ typescript(),
20
+ ],
20
21
  };
@@ -1,3 +1,13 @@
1
+ {{#if options.compact}}
1
2
  {{#each groups}}
3
+ {{#if single}}
2
4
  export * from './{{root.fileName}}';
3
- {{/each}}
5
+ {{else}}
6
+ export * from './{{root.fileName}}.compact';
7
+ {{/if}}
8
+ {{/each}}
9
+ {{else}}
10
+ {{#each contexts}}
11
+ export * from './{{fileName}}';
12
+ {{/each}}
13
+ {{/if}}
@@ -0,0 +1,15 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+ /* auto-generated */
4
+
5
+ {{#each all}}
6
+ import { {{componentClassName}} } from './{{fileName}}';
7
+ {{/each}}
8
+
9
+ const All = /*@__PURE__*/ Object.assign({{root.componentClassName}}, {
10
+ {{#each filterd}}
11
+ {{componentClassNameInCategory}}: {{componentClassName}},
12
+ {{/each}}
13
+ });
14
+
15
+ export { All as {{root.componentClassName}} }
@@ -3,36 +3,21 @@
3
3
  /* auto-generated */
4
4
 
5
5
  import { proxy } from '../proxy';
6
- import type { JSX } from '{{options.corePackageName}}';
7
6
 
8
- {{#each all}}
9
- import {{componentClassName}} from '{{../options.corePackageName}}/{{fileName}}';
10
- {{/each}}
7
+ {{!-- import { {{importerComponent.root}} as Component } from '{{importerComponent.source}}'; --}}
8
+ import '{{importerComponent.source}}';
9
+ import type { {{importerComponentType.root}} as Type } from '{{importerComponentType.source}}';
11
10
 
12
- {{#each all}}
13
- const {{componentClassName}} = /*@__PURE__*/ proxy<{{componentInterfaceName}}, JSX.{{componentClassName}}>(
14
- '{{componentTag}}',
15
- [
16
- {{#each classProperties}}
17
- '{{key.name}}',
18
- {{/each}}
19
- ],
20
- [
21
- {{#each classEvents}}
22
- '{{key.name}}',
23
- {{/each}}
24
- ],
25
- );
11
+ type Rename<T, R extends { [K in keyof R]: K extends keyof T ? PropertyKey : "Error: key not in T" }> = { [P in keyof T as P extends keyof R ? R[P] : P]: T[P] }
26
12
 
27
- {{/each}}
28
- {{#if single}}
29
- export { {{root.componentClassName}} }
30
- {{else}}
31
- const All = /*@__PURE__*/ Object.assign({{root.componentClassName}}, {
32
- {{#each filterd}}
33
- {{componentClassNameInCategory}}: {{componentClassName}},
13
+ type Renamed = Rename<{{importerComponentType.variable}}, {
14
+ {{#each classEvents}}
15
+ {{key.name}}: '{{converted}}',
34
16
  {{/each}}
35
- });
17
+ }>
36
18
 
37
- export { All as {{root.componentClassName}} }
38
- {{/if}}
19
+ export const {{componentClassName}} = /*@__PURE__*/ proxy<{{componentInterfaceName}}, Renamed>(
20
+ '{{componentTag}}',
21
+ [{{#each classProperties}}'{{key.name}}', {{/each}}],
22
+ [{{#each classEvents}}'{{key.name}}', {{/each}}],
23
+ );
@@ -1 +1 @@
1
- export declare const isDirectoryEmpty: (directory: string) => Promise<boolean>;
1
+ export declare const isDirectoryEmpty: (directory: string) => boolean;
@@ -1,19 +1,10 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import fs from 'fs';
11
- export const isDirectoryEmpty = (directory) => __awaiter(void 0, void 0, void 0, function* () {
2
+ export const isDirectoryEmpty = (directory) => {
12
3
  try {
13
- const files = yield fs.readdirSync(directory);
4
+ const files = fs.readdirSync(directory);
14
5
  return !files.length;
15
6
  }
16
7
  catch (_a) {
17
8
  return true;
18
9
  }
19
- });
10
+ };
@@ -1 +1 @@
1
- export { html, render } from 'uhtml';
1
+ export { html } from 'uhtml';
@@ -1 +1,2 @@
1
- export { html, render } from 'uhtml';
1
+ export { html } from 'uhtml';
2
+ // export const html = (...args: any[]): any => {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "license": "MIT",
5
5
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
6
6
  "description": "Compiler of HTMLPlus",