@rhtml/operators 0.0.81

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,32 @@
1
+ # @rhtml/operators
2
+
3
+ #### Installation
4
+
5
+ ```bash
6
+ npm i @rhtml/operators
7
+ ```
8
+
9
+ #### Usage
10
+
11
+ ```typescript
12
+ import { LitElement, Component, html } from '@rxdi/lit-html';
13
+
14
+ import '@rhtml/operators';
15
+
16
+ @Component({
17
+ selector: 'r-html-view',
18
+ template(this: RHtmlViewComponent) {
19
+ return html`
20
+ <r-for .of=${['IterableItem 1', 'Iterable Item 2']}>
21
+ <r-let .item=${v => html``}></r-let>
22
+ </r-for>
23
+
24
+ <r-let .data=${['IterableItem 1', 'Iterable Item 2']} .item=${v => html`
25
+ dadada
26
+ `}></r-let>
27
+ `;
28
+ }
29
+ })
30
+ export class RHtmlViewComponent extends LitElement {}
31
+
32
+ ```
package/dist/for.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { LitElement } from '@rxdi/lit-html';
2
+ /**
3
+ * @customElement r-for
4
+ */
5
+ export declare class ForOperator extends LitElement {
6
+ of: any;
7
+ OnUpdate(): void;
8
+ }
package/dist/for.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ForOperator = void 0;
13
+ /* eslint-disable @typescript-eslint/no-explicit-any */
14
+ const lit_html_1 = require("@rxdi/lit-html");
15
+ /**
16
+ * @customElement r-for
17
+ */
18
+ let ForOperator = class ForOperator extends lit_html_1.LitElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.of = [];
22
+ }
23
+ OnUpdate() {
24
+ const slotNodes = this.shadowRoot.querySelector('slot').assignedNodes();
25
+ if (slotNodes.length) {
26
+ const slotNode = slotNodes[0];
27
+ const letOperator = slotNode.nextSibling;
28
+ if (letOperator) {
29
+ letOperator.data = this.of;
30
+ }
31
+ }
32
+ }
33
+ };
34
+ __decorate([
35
+ lit_html_1.property({ type: Array }),
36
+ __metadata("design:type", Object)
37
+ ], ForOperator.prototype, "of", void 0);
38
+ ForOperator = __decorate([
39
+ lit_html_1.Component({
40
+ selector: 'r-for',
41
+ template() {
42
+ return lit_html_1.html `
43
+ <slot></slot>
44
+ `;
45
+ }
46
+ })
47
+ ], ForOperator);
48
+ exports.ForOperator = ForOperator;
49
+ //# sourceMappingURL=for.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"for.js","sourceRoot":"","sources":["../src/for.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAuD;AACvD,6CAAuE;AAGvE;;GAEG;AASH,IAAa,WAAW,GAAxB,MAAa,WAAY,SAAQ,qBAAU;IAA3C;;QAES,OAAE,GAAQ,EAAE,CAAC;IAWtB,CAAC;IAVC,QAAQ;QACN,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;QACxE,IAAI,SAAS,CAAC,MAAM,EAAE;YACpB,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YAC9B,MAAM,WAAW,GAAG,QAAQ,CAAC,WAA0B,CAAC;YACxD,IAAI,WAAW,EAAE;gBACf,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC;aAC5B;SACF;IACH,CAAC;CACF,CAAA;AAXC;IADC,mBAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;uCACN;AAFT,WAAW;IARvB,oBAAS,CAAC;QACT,QAAQ,EAAE,OAAO;QACjB,QAAQ;YACN,OAAO,eAAI,CAAA;;KAEV,CAAC;QACJ,CAAC;KACF,CAAC;GACW,WAAW,CAavB;AAbY,kCAAW"}
package/dist/if.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { LitElement } from '@rxdi/lit-html';
2
+ /**
3
+ * @customElement r-if
4
+ */
5
+ export declare class IfOperator extends LitElement {
6
+ exp: boolean;
7
+ }
package/dist/if.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.IfOperator = void 0;
13
+ const lit_html_1 = require("@rxdi/lit-html");
14
+ /**
15
+ * @customElement r-if
16
+ */
17
+ let IfOperator = class IfOperator extends lit_html_1.LitElement {
18
+ };
19
+ __decorate([
20
+ lit_html_1.property({ type: Boolean }),
21
+ __metadata("design:type", Boolean)
22
+ ], IfOperator.prototype, "exp", void 0);
23
+ IfOperator = __decorate([
24
+ lit_html_1.Component({
25
+ selector: 'r-if',
26
+ template() {
27
+ return lit_html_1.html `
28
+ ${this.exp
29
+ ? lit_html_1.html `
30
+ <slot></slot>
31
+ `
32
+ : ''}
33
+ `;
34
+ }
35
+ })
36
+ ], IfOperator);
37
+ exports.IfOperator = IfOperator;
38
+ //# sourceMappingURL=if.js.map
package/dist/if.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if.js","sourceRoot":"","sources":["../src/if.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAuE;AAEvE;;GAEG;AAaH,IAAa,UAAU,GAAvB,MAAa,UAAW,SAAQ,qBAAU;CAEzC,CAAA;AAD8B;IAA5B,mBAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;uCAAc;AAD/B,UAAU;IAZtB,oBAAS,CAAC;QACT,QAAQ,EAAE,MAAM;QAChB,QAAQ;YACN,OAAO,eAAI,CAAA;QACP,IAAI,CAAC,GAAG;gBACR,CAAC,CAAC,eAAI,CAAA;;WAEH;gBACH,CAAC,CAAC,EAAE;KACP,CAAC;QACJ,CAAC;KACF,CAAC;GACW,UAAU,CAEtB;AAFY,gCAAU"}
@@ -0,0 +1,14 @@
1
+ import '@rhtml/renderer';
2
+ import { ForOperator } from './for';
3
+ import { IfOperator } from './if';
4
+ import { LetOperator } from './let';
5
+ export * from './for';
6
+ export * from './let';
7
+ export * from './if';
8
+ declare global {
9
+ interface HTMLElementTagNameMap {
10
+ 'r-if': IfOperator;
11
+ 'r-let': LetOperator;
12
+ 'r-for': ForOperator;
13
+ }
14
+ }
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
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
+ require("@rhtml/renderer");
14
+ __exportStar(require("./for"), exports);
15
+ __exportStar(require("./let"), exports);
16
+ __exportStar(require("./if"), exports);
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2BAAyB;AAMzB,wCAAsB;AACtB,wCAAsB;AACtB,uCAAqB"}
@@ -0,0 +1 @@
1
+ export declare type Operators = 'r-let' | 'r-for';
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":""}
package/dist/let.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { LitElement } from '@rxdi/lit-html';
2
+ /**
3
+ * @customElement r-let
4
+ */
5
+ export declare class LetOperator extends LitElement {
6
+ data: any[];
7
+ item: (v: any) => import("lit-html").TemplateResult<1>;
8
+ private normalizeArray;
9
+ private isObservable;
10
+ private isFunction;
11
+ }
package/dist/let.js ADDED
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LetOperator = void 0;
13
+ const lit_html_1 = require("@rxdi/lit-html");
14
+ /**
15
+ * @customElement r-let
16
+ */
17
+ let LetOperator = class LetOperator extends lit_html_1.LitElement {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.data = [];
21
+ this.item = v => lit_html_1.html `
22
+ ${v}
23
+ `;
24
+ }
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ normalizeArray(state) {
27
+ if (!state || typeof state === 'string') {
28
+ return [];
29
+ }
30
+ if (typeof state === 'number') {
31
+ return Array.from(Array(state), (v, i) => i);
32
+ }
33
+ /* https://javascript.info/map-set */
34
+ if (state instanceof Map || state instanceof Set) {
35
+ return [...state.entries()];
36
+ }
37
+ if (!Array.isArray(state)) {
38
+ return Object.entries(state);
39
+ }
40
+ return state;
41
+ }
42
+ isObservable(value) {
43
+ return (value && this.isFunction(value.lift) && this.isFunction(value.subscribe));
44
+ }
45
+ isFunction(value) {
46
+ return typeof value === 'function';
47
+ }
48
+ };
49
+ __decorate([
50
+ lit_html_1.property({ type: Array }),
51
+ __metadata("design:type", Object)
52
+ ], LetOperator.prototype, "data", void 0);
53
+ __decorate([
54
+ lit_html_1.property({ type: Object }),
55
+ __metadata("design:type", Object)
56
+ ], LetOperator.prototype, "item", void 0);
57
+ LetOperator = __decorate([
58
+ lit_html_1.Component({
59
+ selector: 'r-let',
60
+ template() {
61
+ return lit_html_1.html `
62
+ ${this.isObservable(this.data)
63
+ ? lit_html_1.html `
64
+ <r-renderer
65
+ .options=${{
66
+ state: this.data,
67
+ render: s => this.normalizeArray(s).map(this.item)
68
+ }}
69
+ ></r-renderer>
70
+ `
71
+ : this.normalizeArray(this.data).map(this.item)}
72
+ `;
73
+ }
74
+ })
75
+ ], LetOperator);
76
+ exports.LetOperator = LetOperator;
77
+ //# sourceMappingURL=let.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"let.js","sourceRoot":"","sources":["../src/let.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAuE;AACvE;;GAEG;AAkBH,IAAa,WAAW,GAAxB,MAAa,WAAY,SAAQ,qBAAU;IAA3C;;QAES,SAAI,GAAG,EAAE,CAAC;QAGV,SAAI,GAAG,CAAC,CAAC,EAAE,CAChB,eAAI,CAAA;QACA,CAAC;KACJ,CAAC;IA4BN,CAAC;IA1BC,8DAA8D;IACtD,cAAc,CAAC,KAA0B;QAC/C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YACvC,OAAO,EAAE,CAAC;SACX;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;SAC9C;QACD,qCAAqC;QACrC,IAAI,KAAK,YAAY,GAAG,IAAI,KAAK,YAAY,GAAG,EAAE;YAChD,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;SAC7B;QACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACzB,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;SAC9B;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,YAAY,CAAC,KAAK;QACxB,OAAO,CACL,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CACzE,CAAC;IACJ,CAAC;IACO,UAAU,CAAC,KAAK;QACtB,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;IACrC,CAAC;CACF,CAAA;AAlCC;IADC,mBAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;yCACT;AAGjB;IADC,mBAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yCAIvB;AARO,WAAW;IAjBvB,oBAAS,CAAC;QACT,QAAQ,EAAE,OAAO;QACjB,QAAQ;YACN,OAAO,eAAI,CAAA;QACP,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;gBAC5B,CAAC,CAAC,eAAI,CAAA;;yBAEW;oBACT,KAAK,EAAE,IAAI,CAAC,IAAI;oBAChB,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;iBACnD;;WAEJ;gBACH,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;KAClD,CAAC;QACJ,CAAC;KACF,CAAC;GACW,WAAW,CAoCvB;AApCY,kCAAW"}
@@ -0,0 +1,7 @@
1
+ config:
2
+ app:
3
+ local:
4
+ INTROSPECTION_FOLDER: ./src/introspection/
5
+ schema:
6
+ introspectionEndpoint: https://countries.trevorblades.com/
7
+ introspectionOutputFolder: ./develop/src/introspection
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,41 @@
1
+ {
2
+ "name": "@rhtml/operators",
3
+ "version": "0.0.81",
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 && tsc"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git@github.com:rhtml/rhtml.git"
17
+ },
18
+ "author": "Kristiyan Tachev",
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "@rxdi/lit-html": "^0.7.119",
22
+ "@rhtml/renderer": "0.0.81"
23
+ },
24
+ "devDependencies": {
25
+ "eslint": "^6.7.2",
26
+ "eslint-config-prettier": "^6.7.0",
27
+ "eslint-plugin-prettier": "^3.1.1",
28
+ "eslint-plugin-simple-import-sort": "^5.0.0",
29
+ "@typescript-eslint/eslint-plugin": "^2.10.0",
30
+ "@typescript-eslint/parser": "^2.10.0",
31
+ "prettier": "^1.19.1",
32
+ "ts-jest": "25.2.1"
33
+ },
34
+ "browserslist": [
35
+ "last 1 chrome versions"
36
+ ],
37
+ "main": "./dist/index.js",
38
+ "types": "./dist/index.d.ts",
39
+ "module": "./dist/index.js",
40
+ "typings": "./dist/index.d.ts"
41
+ }
package/src/for.ts ADDED
@@ -0,0 +1,29 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { Component, html, LitElement, property } from '@rxdi/lit-html';
3
+
4
+ import { LetOperator } from './let';
5
+ /**
6
+ * @customElement r-for
7
+ */
8
+ @Component({
9
+ selector: 'r-for',
10
+ template() {
11
+ return html`
12
+ <slot></slot>
13
+ `;
14
+ }
15
+ })
16
+ export class ForOperator extends LitElement {
17
+ @property({ type: Array })
18
+ public of: any = [];
19
+ OnUpdate() {
20
+ const slotNodes = this.shadowRoot.querySelector('slot').assignedNodes();
21
+ if (slotNodes.length) {
22
+ const slotNode = slotNodes[0];
23
+ const letOperator = slotNode.nextSibling as LetOperator;
24
+ if (letOperator) {
25
+ letOperator.data = this.of;
26
+ }
27
+ }
28
+ }
29
+ }
package/src/if.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { Component, html, LitElement, property } from '@rxdi/lit-html';
2
+
3
+ /**
4
+ * @customElement r-if
5
+ */
6
+ @Component({
7
+ selector: 'r-if',
8
+ template(this: IfOperator) {
9
+ return html`
10
+ ${this.exp
11
+ ? html`
12
+ <slot></slot>
13
+ `
14
+ : ''}
15
+ `;
16
+ }
17
+ })
18
+ export class IfOperator extends LitElement {
19
+ @property({ type: Boolean }) exp: boolean;
20
+ }
package/src/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ import '@rhtml/renderer';
2
+
3
+ import { ForOperator } from './for';
4
+ import { IfOperator } from './if';
5
+ import { LetOperator } from './let';
6
+
7
+ export * from './for';
8
+ export * from './let';
9
+ export * from './if';
10
+
11
+ declare global {
12
+ interface HTMLElementTagNameMap {
13
+ 'r-if': IfOperator;
14
+ 'r-let': LetOperator;
15
+ 'r-for': ForOperator;
16
+ }
17
+ }
@@ -0,0 +1 @@
1
+ export type Operators = 'r-let' | 'r-for';
package/src/let.ts ADDED
@@ -0,0 +1,58 @@
1
+ import { Component, html, LitElement, property } from '@rxdi/lit-html';
2
+ /**
3
+ * @customElement r-let
4
+ */
5
+ @Component({
6
+ selector: 'r-let',
7
+ template(this: LetOperator) {
8
+ return html`
9
+ ${this.isObservable(this.data)
10
+ ? html`
11
+ <r-renderer
12
+ .options=${{
13
+ state: this.data,
14
+ render: s => this.normalizeArray(s).map(this.item)
15
+ }}
16
+ ></r-renderer>
17
+ `
18
+ : this.normalizeArray(this.data).map(this.item)}
19
+ `;
20
+ }
21
+ })
22
+ export class LetOperator extends LitElement {
23
+ @property({ type: Array })
24
+ public data = [];
25
+
26
+ @property({ type: Object })
27
+ public item = v =>
28
+ html`
29
+ ${v}
30
+ `;
31
+
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ private normalizeArray(state: Record<string, any>) {
34
+ if (!state || typeof state === 'string') {
35
+ return [];
36
+ }
37
+ if (typeof state === 'number') {
38
+ return Array.from(Array(state), (v, i) => i);
39
+ }
40
+ /* https://javascript.info/map-set */
41
+ if (state instanceof Map || state instanceof Set) {
42
+ return [...state.entries()];
43
+ }
44
+ if (!Array.isArray(state)) {
45
+ return Object.entries(state);
46
+ }
47
+ return state;
48
+ }
49
+
50
+ private isObservable(value) {
51
+ return (
52
+ value && this.isFunction(value.lift) && this.isFunction(value.subscribe)
53
+ );
54
+ }
55
+ private isFunction(value) {
56
+ return typeof value === 'function';
57
+ }
58
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
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
+ "es2017",
20
+ "dom"
21
+ ]
22
+ },
23
+ "include": [
24
+ "./typings.d.ts",
25
+ "src/**/*"
26
+ ]
27
+ }
package/tslint.json ADDED
@@ -0,0 +1,113 @@
1
+ {
2
+ "rules": {
3
+ "arrow-return-shorthand": true,
4
+ "callable-types": true,
5
+ "class-name": true,
6
+ "comment-format": [
7
+ true,
8
+ "check-space"
9
+ ],
10
+ "curly": true,
11
+ "eofline": true,
12
+ "forin": true,
13
+ "import-blacklist": [
14
+ true,
15
+ "rxjs/Rx"
16
+ ],
17
+ "import-spacing": true,
18
+ "indent": [
19
+ true,
20
+ "spaces"
21
+ ],
22
+ "interface-over-type-literal": true,
23
+ "label-position": true,
24
+ "max-line-length": [
25
+ true,
26
+ 140
27
+ ],
28
+ "member-access": false,
29
+ "member-ordering": [
30
+ true,
31
+ {
32
+ "order": [
33
+ "static-field",
34
+ "instance-field",
35
+ "static-method",
36
+ "instance-method"
37
+ ]
38
+ }
39
+ ],
40
+ "no-arg": true,
41
+ "no-bitwise": true,
42
+ "no-console": [
43
+ true,
44
+ "debug",
45
+ "info",
46
+ "time",
47
+ "timeEnd",
48
+ "trace"
49
+ ],
50
+ "no-construct": true,
51
+ "no-debugger": true,
52
+ "no-duplicate-super": true,
53
+ "no-empty": false,
54
+ "no-empty-interface": true,
55
+ "no-eval": true,
56
+ "no-inferrable-types": [
57
+ true,
58
+ "ignore-params"
59
+ ],
60
+ "no-misused-new": true,
61
+ "no-non-null-assertion": true,
62
+ "no-shadowed-variable": true,
63
+ "no-string-literal": false,
64
+ "no-string-throw": true,
65
+ "no-switch-case-fall-through": true,
66
+ "no-trailing-whitespace": true,
67
+ "no-unnecessary-initializer": true,
68
+ "no-unused-expression": true,
69
+ "no-var-keyword": true,
70
+ "object-literal-sort-keys": false,
71
+ "one-line": [
72
+ true,
73
+ "check-open-brace",
74
+ "check-catch",
75
+ "check-else",
76
+ "check-whitespace"
77
+ ],
78
+ "prefer-const": true,
79
+ "quotemark": [
80
+ true,
81
+ "single"
82
+ ],
83
+ "radix": true,
84
+ "semicolon": [
85
+ false,
86
+ "never"
87
+ ],
88
+ "triple-equals": [
89
+ true,
90
+ "allow-null-check"
91
+ ],
92
+ "typedef-whitespace": [
93
+ true,
94
+ {
95
+ "call-signature": "nospace",
96
+ "index-signature": "nospace",
97
+ "parameter": "nospace",
98
+ "property-declaration": "nospace",
99
+ "variable-declaration": "nospace"
100
+ }
101
+ ],
102
+ "unified-signatures": true,
103
+ "variable-name": false,
104
+ "whitespace": [
105
+ true,
106
+ "check-branch",
107
+ "check-decl",
108
+ "check-operator",
109
+ "check-separator",
110
+ "check-type"
111
+ ]
112
+ }
113
+ }