@rhtml/component 0.0.113 → 0.0.116
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/dist/index.d.ts +3 -3
- package/dist/index.js +13 -11
- package/dist/index.js.map +1 -1
- package/package.json +3 -12
- package/src/index.ts +45 -45
- package/.eslintrc.js +0 -26
- package/.prettierrc +0 -4
- package/jest.config.js +0 -16
- package/tslint.json +0 -113
package/dist/index.d.ts
CHANGED
|
@@ -6,11 +6,11 @@ export declare type Injection = {
|
|
|
6
6
|
has: <T>(d: T) => boolean;
|
|
7
7
|
get: <T>(d: T) => T;
|
|
8
8
|
};
|
|
9
|
-
export declare type Constructor<T =
|
|
9
|
+
export declare type Constructor<T = any> = new (...args: any[]) => T;
|
|
10
10
|
export declare type InstanceTypes<T> = {
|
|
11
11
|
[P in keyof T]: T[P] extends Constructor<infer U> ? U : never;
|
|
12
12
|
};
|
|
13
|
-
export declare const DefineDependencies: <T extends Constructor<
|
|
13
|
+
export declare const DefineDependencies: <T extends Constructor<any>[]>(...deps: T) => (injection: Injection) => InstanceTypes<T>;
|
|
14
14
|
export declare type StateToRender<S, D, K extends LitElement> = (this: K, deps: D) => Observable<S> | S | Promise<S>;
|
|
15
15
|
export declare type PossibleRender = TemplateResult | string | number | unknown;
|
|
16
16
|
export declare type RenderResult<S, D, K extends LitElement> = (deps: D) => (this: K, state: S, setState: (s: S) => void) => TemplateResult | string | number | unknown;
|
|
@@ -30,7 +30,7 @@ export declare const Partial: <S, D, K extends LitElement = LitElement>(options:
|
|
|
30
30
|
styles: import("@rxdi/lit-html").CSSResult[];
|
|
31
31
|
is(): string;
|
|
32
32
|
} & K_1;
|
|
33
|
-
export declare function Component<S, D, K extends LitElement = LitElement>({ Settings, Providers, State, Render, Loading, Error }: {
|
|
33
|
+
export declare function Component<S, D, K extends LitElement = LitElement>({ Settings, Providers, State, Render, Loading, Error, }: {
|
|
34
34
|
Settings: Options;
|
|
35
35
|
Providers?: D;
|
|
36
36
|
State?: StateToRender<S, D, K>;
|
package/dist/index.js
CHANGED
|
@@ -3,18 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Component = exports.Partial = exports.DefineDependencies = void 0;
|
|
4
4
|
require("@rhtml/renderer");
|
|
5
5
|
const lit_html_1 = require("@rxdi/lit-html");
|
|
6
|
-
|
|
6
|
+
const DefineDependencies = (...deps) => (injection) => {
|
|
7
7
|
for (const [index, dep] of deps.entries()) {
|
|
8
8
|
Object.defineProperty(deps, index, {
|
|
9
|
-
get: () => (injection && injection.has(dep) ? injection.get(dep) : dep)
|
|
9
|
+
get: () => (injection && injection.has(dep) ? injection.get(dep) : dep),
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
return deps;
|
|
13
13
|
};
|
|
14
|
-
exports.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
exports.DefineDependencies = DefineDependencies;
|
|
15
|
+
const Partial = (options) => (deps = []) => (state = () => ({})) => (loading) => (error) => (render = () => state) => (0, lit_html_1.Component)(Object.assign(Object.assign({}, options), { template() {
|
|
16
|
+
return (0, lit_html_1.html) `
|
|
17
|
+
<r-renderer
|
|
18
|
+
.options=${{
|
|
18
19
|
state: state.bind(this).call(this, deps),
|
|
19
20
|
loading,
|
|
20
21
|
error,
|
|
@@ -24,13 +25,14 @@ exports.Partial = (options) => (deps = []) => (state = () => ({})) => (loading)
|
|
|
24
25
|
return render(deps)
|
|
25
26
|
.bind(this)
|
|
26
27
|
.call(this, state, setState, shadowRoot);
|
|
27
|
-
}
|
|
28
|
+
},
|
|
28
29
|
}}
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
></r-renderer>
|
|
31
|
+
`;
|
|
31
32
|
} }));
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
exports.Partial = Partial;
|
|
34
|
+
function Component({ Settings, Providers, State, Render, Loading, Error, }) {
|
|
35
|
+
return (0, exports.Partial)(Settings)(Providers)(State)(Loading)(Error)(Render);
|
|
34
36
|
}
|
|
35
37
|
exports.Component = Component;
|
|
36
38
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2BAAyB;AAEzB,6CAMwB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2BAAyB;AAEzB,6CAMwB;AAiBjB,MAAM,kBAAkB,GAC7B,CAA0B,GAAG,IAAO,EAAE,EAAE,CACxC,CAAC,SAAoB,EAAoB,EAAE;IACzC,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE;QACzC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE;YACjC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;SACxE,CAAC,CAAC;KACJ;IACD,OAAO,IAAa,CAAC;AACvB,CAAC,CAAC;AATS,QAAA,kBAAkB,sBAS3B;AAsBG,MAAM,OAAO,GAClB,CAA0C,OAAgB,EAAE,EAAE,CAC9D,CAAC,OAAU,EAAW,EAAE,EAAE,CAC1B,CAAC,QAAgC,GAAG,EAAE,CAAC,CAAC,EAAY,CAAA,EAAE,EAAE,CACxD,CAAC,OAA6B,EAAE,EAAE,CAClC,CAAC,KAA6C,EAAE,EAAE,CAClD,CAAC,SAAgC,GAAG,EAAE,CAAC,KAAc,EAAE,EAAE,CACvD,IAAA,oBAAiB,kCACZ,OAAO,KACV,QAAQ;QACN,OAAO,IAAA,eAAI,EAAA;;uBAEI;YACT,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC;YACxC,OAAO;YACP,KAAK;YACL,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,MAAM,EAAE,CACN,KAAQ,EACR,QAAwB,EACxB,UAAsB,EACtB,EAAE;gBACF,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBACnC,OAAO,MAAM,CAAC,IAAI,CAAC;qBAChB,IAAI,CAAC,IAAI,CAAC;qBACV,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;YAC7C,CAAC;SACO;;SAEb,CAAC;IACJ,CAAC,IACD,CAAC;AA/BM,QAAA,OAAO,WA+Bb;AAEP,SAAgB,SAAS,CAA0C,EACjE,QAAQ,EACR,SAAS,EACT,KAAK,EACL,MAAM,EACN,OAAO,EACP,KAAK,GAQN;IACC,OAAO,IAAA,eAAO,EAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;AACrE,CAAC;AAhBD,8BAgBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhtml/component",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.116",
|
|
4
4
|
"description": "Reactive HyperText Markup Language",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "npx parcel ./examples/index.html --out-dir build/examples",
|
|
@@ -17,21 +17,12 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@rxdi/lit-html": "^0.7.133",
|
|
20
|
-
"@rhtml/renderer": "0.0.
|
|
20
|
+
"@rhtml/renderer": "0.0.116"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"rxjs": "^6.6.3"
|
|
24
24
|
},
|
|
25
|
-
"devDependencies": {
|
|
26
|
-
"eslint": "^6.7.2",
|
|
27
|
-
"eslint-config-prettier": "^6.7.0",
|
|
28
|
-
"eslint-plugin-prettier": "^3.1.1",
|
|
29
|
-
"eslint-plugin-simple-import-sort": "^5.0.0",
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^2.10.0",
|
|
31
|
-
"@typescript-eslint/parser": "^2.10.0",
|
|
32
|
-
"prettier": "^1.19.1",
|
|
33
|
-
"ts-jest": "25.2.1"
|
|
34
|
-
},
|
|
25
|
+
"devDependencies": {},
|
|
35
26
|
"author": "Kristiyan Tachev",
|
|
36
27
|
"license": "MIT",
|
|
37
28
|
"browserslist": [
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
CustomElementConfig,
|
|
6
6
|
html,
|
|
7
7
|
LitElement,
|
|
8
|
-
TemplateResult
|
|
8
|
+
TemplateResult,
|
|
9
9
|
} from '@rxdi/lit-html';
|
|
10
10
|
import { Observable } from 'rxjs';
|
|
11
11
|
|
|
@@ -17,22 +17,22 @@ export type Injection = {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
-
export type Constructor<T =
|
|
20
|
+
export type Constructor<T = any> = new (...args: any[]) => T;
|
|
21
21
|
|
|
22
22
|
export type InstanceTypes<T> = {
|
|
23
23
|
[P in keyof T]: T[P] extends Constructor<infer U> ? U : never;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
export const DefineDependencies =
|
|
27
|
-
|
|
28
|
-
): InstanceTypes<T> => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
26
|
+
export const DefineDependencies =
|
|
27
|
+
<T extends Constructor[]>(...deps: T) =>
|
|
28
|
+
(injection: Injection): InstanceTypes<T> => {
|
|
29
|
+
for (const [index, dep] of deps.entries()) {
|
|
30
|
+
Object.defineProperty(deps, index, {
|
|
31
|
+
get: () => (injection && injection.has(dep) ? injection.get(dep) : dep),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return deps as never;
|
|
35
|
+
};
|
|
36
36
|
|
|
37
37
|
export type StateToRender<S, D, K extends LitElement> = (
|
|
38
38
|
this: K,
|
|
@@ -54,38 +54,38 @@ export interface Options
|
|
|
54
54
|
deepCloneState?: boolean;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export const Partial =
|
|
58
|
-
options: Options
|
|
59
|
-
|
|
60
|
-
state: StateToRender<S, D, K> = () => ({} as never)
|
|
61
|
-
|
|
62
|
-
error: (e: Error | unknown) => PossibleRender
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
57
|
+
export const Partial =
|
|
58
|
+
<S, D, K extends LitElement = LitElement>(options: Options) =>
|
|
59
|
+
(deps: D = [] as never) =>
|
|
60
|
+
(state: StateToRender<S, D, K> = () => ({} as never)) =>
|
|
61
|
+
(loading: () => PossibleRender) =>
|
|
62
|
+
(error: (e: Error | unknown) => PossibleRender) =>
|
|
63
|
+
(render: RenderResult<S, D, K> = () => state as never) =>
|
|
64
|
+
OriginalComponent<K>({
|
|
65
|
+
...options,
|
|
66
|
+
template(this: K) {
|
|
67
|
+
return html`
|
|
68
|
+
<r-renderer
|
|
69
|
+
.options=${{
|
|
70
|
+
state: state.bind(this).call(this, deps),
|
|
71
|
+
loading,
|
|
72
|
+
error,
|
|
73
|
+
deepCloneState: options.deepCloneState,
|
|
74
|
+
render: (
|
|
75
|
+
state: S,
|
|
76
|
+
setState: (s: S) => void,
|
|
77
|
+
shadowRoot: ShadowRoot
|
|
78
|
+
) => {
|
|
79
|
+
this.shadowRoot.append(shadowRoot);
|
|
80
|
+
return render(deps)
|
|
81
|
+
.bind(this)
|
|
82
|
+
.call(this, state, setState, shadowRoot);
|
|
83
|
+
},
|
|
84
|
+
} as never}
|
|
85
|
+
></r-renderer>
|
|
86
|
+
`;
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
89
|
|
|
90
90
|
export function Component<S, D, K extends LitElement = LitElement>({
|
|
91
91
|
Settings,
|
|
@@ -93,7 +93,7 @@ export function Component<S, D, K extends LitElement = LitElement>({
|
|
|
93
93
|
State,
|
|
94
94
|
Render,
|
|
95
95
|
Loading,
|
|
96
|
-
Error
|
|
96
|
+
Error,
|
|
97
97
|
}: {
|
|
98
98
|
Settings: Options;
|
|
99
99
|
Providers?: D;
|
package/.eslintrc.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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
DELETED
package/jest.config.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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/tslint.json
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
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
|
-
}
|