@htmlplus/element 0.1.2 → 0.1.5

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.
Files changed (66) hide show
  1. package/README.md +123 -25
  2. package/dist/client/decorators/bind.js +2 -1
  3. package/dist/client/decorators/element.js +113 -3
  4. package/dist/client/decorators/event.d.ts +19 -1
  5. package/dist/client/decorators/event.js +2 -2
  6. package/dist/client/decorators/index.js +0 -1
  7. package/dist/client/decorators/listen.d.ts +8 -1
  8. package/dist/client/decorators/method.js +2 -2
  9. package/dist/client/decorators/property.d.ts +11 -1
  10. package/dist/client/decorators/property.js +14 -5
  11. package/dist/client/decorators/state.js +8 -4
  12. package/dist/client/helpers/direction.d.ts +1 -1
  13. package/dist/client/helpers/slots.js +2 -1
  14. package/dist/client/services/link.js +3 -3
  15. package/dist/client/utils/api.d.ts +5 -1
  16. package/dist/client/utils/define-property.d.ts +1 -0
  17. package/dist/client/utils/define-property.js +1 -0
  18. package/dist/client/utils/host.js +1 -1
  19. package/dist/client/utils/index.d.ts +1 -1
  20. package/dist/client/utils/index.js +1 -1
  21. package/dist/compiler/compiler.js +3 -3
  22. package/dist/compiler/index.d.ts +1 -2
  23. package/dist/compiler/index.js +1 -2
  24. package/dist/compiler/plugins/attach.js +7 -10
  25. package/dist/compiler/plugins/docs.js +1 -0
  26. package/dist/compiler/plugins/extract.js +14 -2
  27. package/dist/compiler/plugins/index.d.ts +1 -0
  28. package/dist/compiler/plugins/index.js +1 -0
  29. package/dist/compiler/plugins/react.proxy/index.d.ts +1 -0
  30. package/dist/compiler/plugins/react.proxy/index.js +1 -0
  31. package/dist/compiler/plugins/react.proxy/react.proxy.d.ts +9 -0
  32. package/dist/compiler/plugins/react.proxy/react.proxy.js +60 -0
  33. package/dist/compiler/plugins/react.proxy/templates/README.md.hbs +1 -0
  34. package/dist/compiler/plugins/react.proxy/templates/_.gitignore.hbs +2 -0
  35. package/dist/compiler/plugins/react.proxy/templates/package.json.hbs +36 -0
  36. package/dist/compiler/plugins/react.proxy/templates/rollup.config.js.hbs +20 -0
  37. package/dist/compiler/plugins/react.proxy/templates/src/components/index.ts.hbs +3 -0
  38. package/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.ts.hbs +38 -0
  39. package/dist/compiler/plugins/react.proxy/templates/src/index.ts.hbs +1 -0
  40. package/dist/compiler/plugins/react.proxy/templates/src/proxy.ts.hbs +277 -0
  41. package/dist/compiler/plugins/react.proxy/templates/tsconfig.json.hbs +17 -0
  42. package/dist/compiler/utils/__dirname.d.ts +1 -0
  43. package/dist/compiler/utils/__dirname.js +5 -0
  44. package/dist/compiler/utils/index.d.ts +3 -0
  45. package/dist/compiler/utils/index.js +3 -0
  46. package/dist/compiler/utils/is-directory-empty.d.ts +1 -0
  47. package/dist/compiler/utils/is-directory-empty.js +19 -0
  48. package/dist/compiler/utils/render-template.d.ts +1 -0
  49. package/dist/compiler/utils/render-template.js +25 -0
  50. package/dist/types/context.d.ts +2 -0
  51. package/dist/types/index.d.ts +0 -5
  52. package/dist/types/index.js +0 -5
  53. package/dist/types/plugin.d.ts +4 -3
  54. package/package.json +10 -4
  55. package/dist/client/decorators/listen-options.d.ts +0 -2
  56. package/dist/client/decorators/listen-options.js +0 -2
  57. package/dist/types/api.d.ts +0 -5
  58. package/dist/types/api.js +0 -1
  59. package/dist/types/direction.d.ts +0 -1
  60. package/dist/types/direction.js +0 -1
  61. package/dist/types/event-options.d.ts +0 -18
  62. package/dist/types/event-options.js +0 -1
  63. package/dist/types/listen-options.d.ts +0 -7
  64. package/dist/types/listen-options.js +0 -1
  65. package/dist/types/property-options.d.ts +0 -10
  66. package/dist/types/property-options.js +0 -1
@@ -0,0 +1,19 @@
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
+ import fs from 'fs';
11
+ export const isDirectoryEmpty = (directory) => __awaiter(void 0, void 0, void 0, function* () {
12
+ try {
13
+ const files = yield fs.readdirSync(directory);
14
+ return !files.length;
15
+ }
16
+ catch (_a) {
17
+ return true;
18
+ }
19
+ });
@@ -0,0 +1 @@
1
+ export declare const renderTemplate: (source: string | Array<string>, destination: string, options?: any) => (context: any) => void;
@@ -0,0 +1,25 @@
1
+ import glob from 'fast-glob';
2
+ import fs from 'fs';
3
+ import handlebars from 'handlebars';
4
+ import path from 'path';
5
+ export const renderTemplate = (source, destination, options) => (context) => {
6
+ const files = glob.sync(source, options);
7
+ for (const file of files) {
8
+ const from = path.resolve((options === null || options === void 0 ? void 0 : options.cwd) || '', file);
9
+ const to = path.join(destination, path
10
+ .normalize(file)
11
+ .split(path.sep)
12
+ .slice(1)
13
+ .map((section) => handlebars.compile(section)(context))
14
+ .join(path.sep)
15
+ .replace('_.', '.')
16
+ .replace('.hbs', ''));
17
+ const directory = path.dirname(to);
18
+ const raw = fs.readFileSync(from, 'utf8');
19
+ const template = handlebars.compile(raw)(context);
20
+ if (!fs.existsSync(directory)) {
21
+ fs.mkdirSync(directory, { recursive: true });
22
+ }
23
+ fs.writeFileSync(to, template, 'utf8');
24
+ }
25
+ };
@@ -1,6 +1,8 @@
1
1
  import { ClassBody, ClassDeclaration, ClassMethod, ClassProperty, File } from '@babel/types';
2
2
  export interface Context {
3
3
  script?: string;
4
+ componentClassName?: string;
5
+ componentInterfaceName?: string;
4
6
  componentKey?: string;
5
7
  componentTag?: string;
6
8
  directoryName?: string;
@@ -1,8 +1,3 @@
1
- export * from './api.js';
2
1
  export * from './context.js';
3
- export * from './direction.js';
4
- export * from './event-options.js';
5
- export * from './listen-options.js';
6
2
  export * from './plugin.js';
7
3
  export * from './plus-element.js';
8
- export * from './property-options.js';
@@ -1,8 +1,3 @@
1
- export * from './api.js';
2
1
  export * from './context.js';
3
- export * from './direction.js';
4
- export * from './event-options.js';
5
- export * from './listen-options.js';
6
2
  export * from './plugin.js';
7
3
  export * from './plus-element.js';
8
- export * from './property-options.js';
@@ -1,7 +1,8 @@
1
1
  import { Context } from './context.js';
2
+ export declare type Return<T> = void | T | Promise<T>;
2
3
  export declare type Plugin = {
3
4
  name: string;
4
- start?: (global: any) => void;
5
- next?: (context: Context, global: any) => void | Context | Promise<Context>;
6
- finish?: (global: any) => void;
5
+ start?: (global: any) => Return<any>;
6
+ next?: (context: Context, global: any) => Return<Context>;
7
+ finish?: (global: any) => Return<any>;
7
8
  };
package/package.json CHANGED
@@ -1,16 +1,19 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "license": "MIT",
5
5
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
6
6
  "description": "Compiler of HTMLPlus",
7
7
  "type": "module",
8
8
  "scripts": {
9
- "build": "npm run clean && tsc",
9
+ "prebuild": "npm run clean",
10
+ "build": "tsc",
10
11
  "build:watch": "tsc -w",
12
+ "postbuild": "node scripts/build.post.js",
11
13
  "clean": "rimraf dist",
12
- "prettier": "prettier --write .",
13
- "start": "node src/dev/start.js"
14
+ "format": "prettier --write .",
15
+ "dev:start": "node src/dev/start.js",
16
+ "dev:build": "node src/dev/build.js"
14
17
  },
15
18
  "exports": {
16
19
  ".": {
@@ -78,6 +81,8 @@
78
81
  "@babel/types": "^7.16.0",
79
82
  "@types/node": "^16.11.11",
80
83
  "change-case": "^4.1.2",
84
+ "fast-glob": "^3.2.11",
85
+ "handlebars": "^4.7.7",
81
86
  "log-update": "^5.0.0",
82
87
  "sass": "^1.43.4",
83
88
  "ts-node": "^10.4.0",
@@ -86,6 +91,7 @@
86
91
  },
87
92
  "devDependencies": {
88
93
  "@trivago/prettier-plugin-sort-imports": "^3.1.1",
94
+ "cpy": "^9.0.0",
89
95
  "prettier": "^2.5.0",
90
96
  "rimraf": "^3.0.2",
91
97
  "vite": "^2.7.10"
@@ -1,2 +0,0 @@
1
- import { ListenOptions as ListenOptionsBase } from '../../types/index.js';
2
- export declare function ListenOptions(options?: Omit<ListenOptionsBase, 'target'>): void;
@@ -1,2 +0,0 @@
1
- // TODO
2
- export function ListenOptions(options = {}) { }
@@ -1,5 +0,0 @@
1
- export interface Api {
2
- ready: boolean;
3
- host(): HTMLElement;
4
- request(states?: any): void;
5
- }
package/dist/types/api.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export declare type Direction = 'ltr' | 'rtl';
@@ -1 +0,0 @@
1
- export {};
@@ -1,18 +0,0 @@
1
- export interface EventOptions {
2
- /**
3
- * A string custom event name to override the default.
4
- */
5
- name?: string;
6
- /**
7
- * A Boolean indicating whether the event bubbles up through the DOM or not. default is `false`.
8
- */
9
- bubbles?: boolean;
10
- /**
11
- * A Boolean indicating whether the event is cancelable. default is `false`.
12
- */
13
- cancelable?: boolean;
14
- /**
15
- * A Boolean value indicating whether or not the event can bubble across the boundary between the shadow DOM and the regular DOM. The default is false.
16
- */
17
- composed?: boolean;
18
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- export interface ListenOptions {
2
- target?: 'host' | 'body' | 'document' | 'window';
3
- once?: boolean;
4
- passive?: boolean;
5
- signal?: AbortSignal;
6
- capture?: boolean;
7
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- export interface PropertyOptions {
2
- /**
3
- * TODO
4
- */
5
- attribute?: boolean | string;
6
- /**
7
- * Whether property value is reflected back to the associated attribute. default is `false`.
8
- */
9
- reflect?: boolean;
10
- }
@@ -1 +0,0 @@
1
- export {};