@rhtml/decorators 0.0.101

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.
package/.eslintrc.js ADDED
@@ -0,0 +1,26 @@
1
+ module.exports = {
2
+ // Specifies the ESLint parser
3
+ parser: "@typescript-eslint/parser",
4
+ extends: [
5
+ // Uses the recommended rules from the @typescript-eslint/eslint-plugin
6
+ "plugin:@typescript-eslint/recommended",
7
+ // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
8
+ "prettier/@typescript-eslint",
9
+ // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
10
+ "plugin:prettier/recommended"
11
+ ],
12
+ parserOptions: {
13
+ // Allows for the parsing of modern ECMAScript features
14
+ ecmaVersion: 2018,
15
+ // Allows for the use of imports
16
+ sourceType: "module"
17
+ },
18
+ rules: {
19
+ "@typescript-eslint/explicit-function-return-type": 0,
20
+ "simple-import-sort/sort": "error",
21
+ "sort-imports": "off",
22
+ "import/order": "off",
23
+ "@typescript-eslint/camelcase": 0
24
+ },
25
+ plugins: ["simple-import-sort"]
26
+ };
package/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "printWidth": 80
4
+ }
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @rhtml/decorators
2
+
3
+ #### Installation
4
+
5
+ ```bash
6
+ npm i @rhtml/decorators
7
+ ```
8
+
9
+ #### Usage
10
+
11
+ ```typescript
12
+ import { Attribute, Options } from '@rhtml/custom-attributes';
13
+ import { Input, HostListener } from '@rhtml/decorators';
14
+
15
+ export class TestDirective extends Attribute {
16
+ @Input()
17
+ myProperty: string;
18
+
19
+ public static options(this: HTMLElement): Options {
20
+ return {
21
+ name: 'test'
22
+ };
23
+ }
24
+
25
+ @HostListener('mouseenter')
26
+ enter(event: Event) {
27
+ console.log('ENTER', this, event);
28
+ console.log(this.myProperty);
29
+ }
30
+
31
+ @HostListener('mouseleave')
32
+ leave(event: Event) {
33
+ console.log('LEAVE', this, event);
34
+ console.log(this.myProperty);
35
+ }
36
+ }
37
+ ```
38
+
39
+ ```html
40
+ <div test myProperty="12312">
41
+ 111
42
+ </div>
43
+ ```
44
+
45
+ #### Usage inside @rxdi/lit-html
46
+
47
+ ```typescript
48
+ import { Component, html, LitElement } from '@rxdi/lit-html';
49
+
50
+ import { HostListener } from '@rhtml/decorators';
51
+
52
+ /**
53
+ * @customElement home-component
54
+ */
55
+ @Component({
56
+ selector: 'home-component',
57
+ template(this) {
58
+ return html`
59
+ Home Component
60
+ `;
61
+ }
62
+ })
63
+ export class HomeComponent extends LitElement {
64
+ @HostListener('mouseenter') onEnter() {
65
+ console.log('Enter home');
66
+ }
67
+
68
+ @HostListener('mouseleave') onLeave() {
69
+ console.log('Leave home');
70
+ }
71
+ }
72
+ ```
@@ -0,0 +1,3 @@
1
+ export declare const HostListener: (event: keyof DocumentEventMap) => (target: unknown, key: string, propertyDescriptor: PropertyDescriptor) => {
2
+ get: () => (...args: unknown[]) => any;
3
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HostListener = void 0;
4
+ exports.HostListener = (event) => (target, key, propertyDescriptor) => {
5
+ const wrapper = function (...args) {
6
+ return propertyDescriptor.value.apply(this, args);
7
+ };
8
+ const OnInit = target['OnInit'] ||
9
+ function () {
10
+ /* */
11
+ };
12
+ const OnDestroy = target['OnDestroy'] ||
13
+ function () {
14
+ /* */
15
+ };
16
+ Object.defineProperty(target, 'OnInit', {
17
+ value: function (...args) {
18
+ var _a;
19
+ const element = (_a = this.element) !== null && _a !== void 0 ? _a : this;
20
+ element.addEventListener(event, (...args) => wrapper.apply(this, args));
21
+ return OnInit.apply(this, args);
22
+ },
23
+ configurable: true,
24
+ writable: true
25
+ });
26
+ Object.defineProperty(target, 'OnDestroy', {
27
+ value: function (...args) {
28
+ var _a;
29
+ const element = (_a = this.element) !== null && _a !== void 0 ? _a : this;
30
+ element.removeEventListener(event, (...args) => wrapper.apply(this, args));
31
+ return OnDestroy.apply(this, args);
32
+ },
33
+ configurable: true,
34
+ writable: true
35
+ });
36
+ return {
37
+ get: () => wrapper
38
+ };
39
+ };
40
+ //# sourceMappingURL=host-listener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-listener.js","sourceRoot":"","sources":["../src/host-listener.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,CAAC,KAA6B,EAAE,EAAE,CAAC,CAC7D,MAAe,EACf,GAAW,EACX,kBAAsC,EACtC,EAAE;IACF,MAAM,OAAO,GAAG,UAAS,GAAG,IAAe;QACzC,OAAO,kBAAkB,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC,CAAC;IACF,MAAM,MAAM,GACV,MAAM,CAAC,QAAQ,CAAC;QAChB;YACE,MAAM;QACR,CAAC,CAAC;IACJ,MAAM,SAAS,GACb,MAAM,CAAC,WAAW,CAAC;QACnB;YACE,MAAM;QACR,CAAC,CAAC;IAEJ,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE;QACtC,KAAK,EAAE,UAAS,GAAG,IAAe;;YAChC,MAAM,OAAO,SAAG,IAAI,CAAC,OAAO,mCAAI,IAAI,CAAC;YACrC,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,GAAG,IAAe,EAAE,EAAE,CACrD,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAC1B,CAAC;YACF,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClC,CAAC;QACD,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IAEH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;QACzC,KAAK,EAAE,UAAS,GAAG,IAAe;;YAChC,MAAM,OAAO,SAAG,IAAI,CAAC,OAAO,mCAAI,IAAI,CAAC;YACrC,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAC,GAAG,IAAe,EAAE,EAAE,CACxD,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAC1B,CAAC;YACF,OAAO,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACrC,CAAC;QACD,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IACH,OAAO;QACL,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO;KACnB,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './host-listener';
2
+ export * from './input';
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./host-listener"), exports);
14
+ __exportStar(require("./input"), exports);
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC;AAChC,0CAAwB"}
@@ -0,0 +1 @@
1
+ export declare const Input: () => (target: unknown, memberName: string) => void;
package/dist/input.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Input = void 0;
4
+ exports.Input = () => (target, memberName) => {
5
+ Object.defineProperty(target, memberName, {
6
+ get: function () {
7
+ return this.element.getAttribute(memberName.toLowerCase());
8
+ }
9
+ });
10
+ };
11
+ //# sourceMappingURL=input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.js","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":";;;AAAa,QAAA,KAAK,GAAG,GAAG,EAAE,CAAC,CAAC,MAAe,EAAE,UAAkB,EAAE,EAAE;IACjE,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE;QACxC,GAAG,EAAE;YACH,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;QAC7D,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
package/jest.config.js ADDED
@@ -0,0 +1,16 @@
1
+ module.exports = {
2
+ testEnvironment: 'node',
3
+ testPathIgnorePatterns: ['/node_modules/'],
4
+ coverageReporters: ['lcov', 'html'],
5
+ rootDir: './',
6
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'node'],
7
+ globals: {
8
+ __DEV__: true
9
+ },
10
+ transform: {
11
+ '\\.(ts|tsx)$': 'ts-jest'
12
+ },
13
+ testRegex: '/src/.*\\.spec.(ts|tsx|js)$',
14
+ verbose: true,
15
+ collectCoverage: true
16
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@rhtml/decorators",
3
+ "version": "0.0.101",
4
+ "description": "Reactive HyperText Markup Language",
5
+ "scripts": {
6
+ "start": "npx parcel ./examples/index.html --out-dir build/examples",
7
+ "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
8
+ "delete-dist": "rm -rf dist",
9
+ "clean": "git clean -dxf",
10
+ "lint": "npx eslint . --ext .ts",
11
+ "lint-fix": "npx eslint . --fix --ext .ts",
12
+ "build": "rm -rf dist && npx npx tsc"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git@github.com:rhtml/rhtml.git"
17
+ },
18
+ "devDependencies": {
19
+ "eslint": "^6.7.2",
20
+ "eslint-config-prettier": "^6.7.0",
21
+ "eslint-plugin-prettier": "^3.1.1",
22
+ "eslint-plugin-simple-import-sort": "^5.0.0",
23
+ "@typescript-eslint/eslint-plugin": "^2.10.0",
24
+ "@typescript-eslint/parser": "^2.10.0",
25
+ "prettier": "^1.19.1",
26
+ "ts-jest": "25.2.1"
27
+ },
28
+ "author": "Kristiyan Tachev",
29
+ "license": "MIT",
30
+ "browserslist": [
31
+ "last 1 chrome versions"
32
+ ],
33
+ "main": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "module": "./dist/index.js",
36
+ "typings": "./dist/index.d.ts"
37
+ }
@@ -0,0 +1,46 @@
1
+ export const HostListener = (event: keyof DocumentEventMap) => (
2
+ target: unknown,
3
+ key: string,
4
+ propertyDescriptor: PropertyDescriptor
5
+ ) => {
6
+ const wrapper = function(...args: unknown[]) {
7
+ return propertyDescriptor.value.apply(this, args);
8
+ };
9
+ const OnInit =
10
+ target['OnInit'] ||
11
+ function() {
12
+ /* */
13
+ };
14
+ const OnDestroy =
15
+ target['OnDestroy'] ||
16
+ function() {
17
+ /* */
18
+ };
19
+
20
+ Object.defineProperty(target, 'OnInit', {
21
+ value: function(...args: unknown[]) {
22
+ const element = this.element ?? this;
23
+ element.addEventListener(event, (...args: unknown[]) =>
24
+ wrapper.apply(this, args)
25
+ );
26
+ return OnInit.apply(this, args);
27
+ },
28
+ configurable: true,
29
+ writable: true
30
+ });
31
+
32
+ Object.defineProperty(target, 'OnDestroy', {
33
+ value: function(...args: unknown[]) {
34
+ const element = this.element ?? this;
35
+ element.removeEventListener(event, (...args: unknown[]) =>
36
+ wrapper.apply(this, args)
37
+ );
38
+ return OnDestroy.apply(this, args);
39
+ },
40
+ configurable: true,
41
+ writable: true
42
+ });
43
+ return {
44
+ get: () => wrapper
45
+ };
46
+ };
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './host-listener';
2
+ export * from './input';
package/src/input.ts ADDED
@@ -0,0 +1,7 @@
1
+ export const Input = () => (target: unknown, memberName: string) => {
2
+ Object.defineProperty(target, memberName, {
3
+ get: function() {
4
+ return this.element.getAttribute(memberName.toLowerCase());
5
+ }
6
+ });
7
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "sourceMap": true,
5
+ "module": "commonjs",
6
+ "declaration": true,
7
+ "moduleResolution": "node",
8
+ "emitDecoratorMetadata": true,
9
+ "experimentalDecorators": true,
10
+ "esModuleInterop": true,
11
+ "target": "es6",
12
+ "outDir": "dist",
13
+ "typeRoots": ["node_modules/@types", "./typings.d.ts"],
14
+ "lib": [
15
+ "es2015",
16
+ "es2016",
17
+ "es6",
18
+ "esnext.asynciterable",
19
+ "dom.Iterable",
20
+ "es2017",
21
+ "dom"
22
+ ]
23
+ },
24
+ "include": ["./typings.d.ts", "src/**/*"]
25
+ }