@rhtml/modifiers 0.0.87

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,83 @@
1
+ # @rhtml/modifiers
2
+
3
+ #### Installation
4
+
5
+ ```bash
6
+ npm i @rhtml/modifiers
7
+ ```
8
+
9
+ #### Modifiers
10
+
11
+ What is a modifier ?
12
+
13
+ In order to apply some logic before current template is loaded like custom directives, we need to wrap current template and pass it along the actual modifier template
14
+
15
+ ```typescript
16
+ @Component({
17
+ selector: 'my-modifier',
18
+ template() {
19
+ return html`
20
+ <slot></slot>
21
+ `;
22
+ }
23
+ })
24
+ export class MyModifier extends LitElement {
25
+ OnUpdate() {
26
+ const slot = this.shadowRoot.querySelector('slot');
27
+ for (const element of [...slot.assignedElements()]) {
28
+ /// Do something here with element
29
+ }
30
+ }
31
+
32
+ public static html(template: TemplateResult) {
33
+ return html`
34
+ <my-modifier>${template}</my-modifier>
35
+ `;
36
+ }
37
+ }
38
+ ```
39
+
40
+ Another real example is to add FlexLayout modifier from `@rhtml/modifiers` which will apply useful directives
41
+ to be used inside of the html inspired from Angular flex-layout https://github.com/angular/flex-layout/wiki/Declarative-API-Overview
42
+
43
+ ```typescript
44
+ import { Component, css, html, LitElement } from '@rxdi/lit-html';
45
+
46
+ import { FlexLayout } from '@rhtml/modifiers';
47
+
48
+ /**
49
+ * @customElement home-component
50
+ */
51
+ @Component({
52
+ selector: 'home-component',
53
+ style: css`
54
+ .block {
55
+ background: red;
56
+ flex: 1;
57
+ }
58
+ .container {
59
+ height: 200px;
60
+ }
61
+ `,
62
+ modifiers: [FlexLayout],
63
+ template(this: HomeComponent) {
64
+ return html`
65
+ <div class="container" fxLayout="row" fxLayoutGap="10px">
66
+ <div>
67
+ <div class="block" fxLayoutAlign="center center" fxFlexFill>A</div>
68
+ </div>
69
+ <div>
70
+ <div class="block" fxLayoutAlign="center center" fxFlexFill>B</div>
71
+ </div>
72
+ <div>
73
+ <div class="block" fxLayoutAlign="center center" fxFlexFill>C</div>
74
+ </div>
75
+ <div>
76
+ <div class="block" fxLayoutAlign="center center" fxFlexFill>D</div>
77
+ </div>
78
+ </div>
79
+ `;
80
+ }
81
+ })
82
+ export class HomeComponent extends LitElement {}
83
+ ```
@@ -0,0 +1,12 @@
1
+ import { LitElement, TemplateResult } from '@rxdi/lit-html';
2
+ import { AsyncDirective } from '@rxdi/lit-html/dist/lit-html/async-directive';
3
+ import { AttributePart } from '@rxdi/lit-html/dist/lit-html/directive';
4
+ export declare class LayoutDirective extends AsyncDirective {
5
+ render(): symbol;
6
+ update(part: AttributePart): symbol;
7
+ }
8
+ export declare class FlexLayout extends LitElement {
9
+ OnUpdate(): void;
10
+ static modifier(template: TemplateResult): TemplateResult;
11
+ }
12
+ export declare const layout: import("@rxdi/lit-html/dist/lit-html/directive").DirectiveResult<typeof LayoutDirective>;
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.layout = exports.FlexLayout = exports.LayoutDirective = void 0;
10
+ const lit_html_1 = require("@rxdi/lit-html");
11
+ const async_directive_1 = require("@rxdi/lit-html/dist/lit-html/async-directive");
12
+ const directive_1 = require("@rxdi/lit-html/dist/lit-html/directive");
13
+ const modifiers_1 = require("./modifiers");
14
+ class LayoutDirective extends async_directive_1.AsyncDirective {
15
+ render() {
16
+ return lit_html_1.noChange;
17
+ }
18
+ update(part) {
19
+ const divs = [...part.element.children];
20
+ for (const div of divs) {
21
+ modifiers_1.recursion(div);
22
+ }
23
+ return this.render();
24
+ }
25
+ }
26
+ exports.LayoutDirective = LayoutDirective;
27
+ let FlexLayout = class FlexLayout extends lit_html_1.LitElement {
28
+ OnUpdate() {
29
+ const slot = this.shadowRoot.querySelector('slot');
30
+ for (const div of [...slot === null || slot === void 0 ? void 0 : slot.assignedElements()]) {
31
+ modifiers_1.recursion(div);
32
+ }
33
+ }
34
+ static modifier(template) {
35
+ return lit_html_1.html `
36
+ <flex-layout>${template}</flex-layout>
37
+ `;
38
+ }
39
+ };
40
+ FlexLayout = __decorate([
41
+ lit_html_1.Component({
42
+ selector: 'flex-layout',
43
+ template() {
44
+ return lit_html_1.html `
45
+ <slot></slot>
46
+ `;
47
+ }
48
+ })
49
+ ], FlexLayout);
50
+ exports.FlexLayout = FlexLayout;
51
+ exports.layout = directive_1.directive(LayoutDirective)();
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6CAMwB;AACxB,kFAA8E;AAC9E,sEAGgD;AAEhD,2CAAwC;AAExC,MAAa,eAAgB,SAAQ,gCAAc;IACjD,MAAM;QACJ,OAAO,mBAAQ,CAAC;IAClB,CAAC;IACD,MAAM,CAAC,IAAmB;QACxB,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAkB,CAAC;QACzD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,qBAAS,CAAC,GAAG,CAAC,CAAC;SAChB;QACD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF;AAXD,0CAWC;AAUD,IAAa,UAAU,GAAvB,MAAa,UAAW,SAAQ,qBAAU;IACxC,QAAQ;QACN,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACnD,KAAK,MAAM,GAAG,IAAI,CAAC,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,gBAAgB,EAAE,CAAC,EAAE;YAC/C,qBAAS,CAAC,GAAY,CAAC,CAAC;SACzB;IACH,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,QAAwB;QAC7C,OAAO,eAAI,CAAA;qBACM,QAAQ;KACxB,CAAC;IACJ,CAAC;CACF,CAAA;AAbY,UAAU;IARtB,oBAAS,CAAC;QACT,QAAQ,EAAE,aAAa;QACvB,QAAQ;YACN,OAAO,eAAI,CAAA;;KAEV,CAAC;QACJ,CAAC;KACF,CAAC;GACW,UAAU,CAatB;AAbY,gCAAU;AAeV,QAAA,MAAM,GAAG,qBAAS,CAAC,eAAe,CAAC,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare type FxLayout = 'row' | 'column' | 'row-reverse' | 'column-reverse';
2
+ export declare type MainAxis = 'start' | 'center' | 'end' | 'space-around' | 'space-between' | 'space-evenly';
3
+ export declare type CrossAxis = 'start' | 'center' | 'end' | 'stretch' | 'space-between' | 'space-around' | 'baseline';
4
+ export declare const isAttribute: (attr: string) => boolean | string;
5
+ export declare const setFxLayoutAlign: (element: HTMLElement) => (fxLayoutAlign?: string) => void;
6
+ export declare const setChildrensFlexFill: (div: HTMLElement) => void;
7
+ export declare const setChildrensFlex: (div: HTMLElement) => (fxFlex: string) => void;
8
+ export declare const setFxLayout: (element: HTMLElement) => (fxLayout?: string) => void;
9
+ export declare const recursion: (div: HTMLElement) => void;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.recursion = exports.setFxLayout = exports.setChildrensFlex = exports.setChildrensFlexFill = exports.setFxLayoutAlign = exports.isAttribute = void 0;
4
+ /* TODO we need to update to typescript 4 */
5
+ // export type FxLayoutAlign = `${MainAxis} ${CrossAxis}`;
6
+ exports.isAttribute = (attr) => typeof attr === 'string' && (attr || attr === '');
7
+ exports.setFxLayoutAlign = (element) => {
8
+ return (fxLayoutAlign = '') => {
9
+ const [mainAxis, crossAxis] = fxLayoutAlign.split(' ');
10
+ element.style['place-content'] = `${crossAxis} ${mainAxis}`;
11
+ element.style['align-items'] = crossAxis;
12
+ element.style['display'] = 'flex';
13
+ };
14
+ };
15
+ exports.setChildrensFlexFill = (div) => {
16
+ div.style['margin'] = '0';
17
+ div.style['width'] = '100%';
18
+ div.style['height'] = '100%';
19
+ div.style['min-width'] = '100%';
20
+ div.style['min-height '] = '100%';
21
+ };
22
+ exports.setChildrensFlex = (div) => {
23
+ return (fxFlex) => {
24
+ div.style['flex'] = '1 1 100%';
25
+ div.style['box-sizing'] = 'border-box';
26
+ if (fxFlex) {
27
+ div.style['max-width'] = fxFlex;
28
+ }
29
+ };
30
+ };
31
+ exports.setFxLayout = (element) => {
32
+ return (fxLayout = '') => {
33
+ // element.style['flex-direction'] = fxLayout;
34
+ element.style['box-sizing'] = 'flex';
35
+ element.style['display'] = 'flex';
36
+ element.style['flex-flow'] = `${fxLayout} wrap`;
37
+ };
38
+ };
39
+ exports.recursion = (div) => {
40
+ const fxFlex = div.getAttribute('fxFlex');
41
+ const fxFlexFill = div.getAttribute('fxFlexFill');
42
+ const fxLayout = div.getAttribute('fxLayout');
43
+ const fxLayoutAlign = div.getAttribute('fxLayoutAlign');
44
+ const fxLayoutGap = div.getAttribute('fxLayoutGap');
45
+ if (exports.isAttribute(fxFlex)) {
46
+ exports.setChildrensFlex(div)(fxFlex);
47
+ }
48
+ if (exports.isAttribute(fxFlexFill)) {
49
+ exports.setChildrensFlexFill(div);
50
+ }
51
+ if (exports.isAttribute(fxLayout)) {
52
+ exports.setFxLayout(div)(fxLayout);
53
+ }
54
+ if (exports.isAttribute(fxLayoutAlign)) {
55
+ exports.setFxLayoutAlign(div)(fxLayoutAlign);
56
+ }
57
+ if (exports.isAttribute(fxLayoutGap)) {
58
+ const divs = [...div.children];
59
+ for (const div of divs) {
60
+ div.style['padding'] = `0px ${fxLayoutGap} ${fxLayoutGap} 0px`;
61
+ div.style.flex = '1 1 25%';
62
+ }
63
+ }
64
+ const divs = [...div.children];
65
+ for (const div of divs) {
66
+ exports.recursion(div);
67
+ }
68
+ };
69
+ //# sourceMappingURL=modifiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modifiers.js","sourceRoot":"","sources":["../src/modifiers.ts"],"names":[],"mappings":";;;AAiBA,4CAA4C;AAC5C,0DAA0D;AAE7C,QAAA,WAAW,GAAG,CAAC,IAAY,EAAoB,EAAE,CAC5D,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC;AAEvC,QAAA,gBAAgB,GAAG,CAAC,OAAoB,EAAE,EAAE;IACvD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AAM,CAAC;YAC/D,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC;SAC5B;KACF;IAED,MAAM,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAkB,CAAC;IAChD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;QACtB,iBAAS,CAAC,GAAG,CAAC,CAAC;KAChB;AACH,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,40 @@
1
+ {
2
+ "name": "@rhtml/modifiers",
3
+ "version": "0.0.87",
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
+ "dependencies": {
19
+ "@rxdi/lit-html": "^0.7.133"
20
+ },
21
+ "devDependencies": {
22
+ "eslint": "^6.7.2",
23
+ "eslint-config-prettier": "^6.7.0",
24
+ "eslint-plugin-prettier": "^3.1.1",
25
+ "eslint-plugin-simple-import-sort": "^5.0.0",
26
+ "@typescript-eslint/eslint-plugin": "^2.10.0",
27
+ "@typescript-eslint/parser": "^2.10.0",
28
+ "prettier": "^1.19.1",
29
+ "ts-jest": "25.2.1"
30
+ },
31
+ "author": "Kristiyan Tachev",
32
+ "license": "MIT",
33
+ "browserslist": [
34
+ "last 1 chrome versions"
35
+ ],
36
+ "main": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
38
+ "module": "./dist/index.js",
39
+ "typings": "./dist/index.d.ts"
40
+ }
package/src/index.ts ADDED
@@ -0,0 +1,52 @@
1
+ import {
2
+ Component,
3
+ html,
4
+ LitElement,
5
+ noChange,
6
+ TemplateResult
7
+ } from '@rxdi/lit-html';
8
+ import { AsyncDirective } from '@rxdi/lit-html/dist/lit-html/async-directive';
9
+ import {
10
+ AttributePart,
11
+ directive
12
+ } from '@rxdi/lit-html/dist/lit-html/directive';
13
+
14
+ import { recursion } from './modifiers';
15
+
16
+ export class LayoutDirective extends AsyncDirective {
17
+ render(): symbol {
18
+ return noChange;
19
+ }
20
+ update(part: AttributePart): symbol {
21
+ const divs = [...part.element.children] as HTMLElement[];
22
+ for (const div of divs) {
23
+ recursion(div);
24
+ }
25
+ return this.render();
26
+ }
27
+ }
28
+
29
+ @Component({
30
+ selector: 'flex-layout',
31
+ template() {
32
+ return html`
33
+ <slot></slot>
34
+ `;
35
+ }
36
+ })
37
+ export class FlexLayout extends LitElement {
38
+ OnUpdate(): void {
39
+ const slot = this.shadowRoot.querySelector('slot');
40
+ for (const div of [...slot?.assignedElements()]) {
41
+ recursion(div as never);
42
+ }
43
+ }
44
+
45
+ public static modifier(template: TemplateResult): TemplateResult {
46
+ return html`
47
+ <flex-layout>${template}</flex-layout>
48
+ `;
49
+ }
50
+ }
51
+
52
+ export const layout = directive(LayoutDirective)();
@@ -0,0 +1,95 @@
1
+ export type FxLayout = 'row' | 'column' | 'row-reverse' | 'column-reverse';
2
+
3
+ export type MainAxis =
4
+ | 'start'
5
+ | 'center'
6
+ | 'end'
7
+ | 'space-around'
8
+ | 'space-between'
9
+ | 'space-evenly';
10
+ export type CrossAxis =
11
+ | 'start'
12
+ | 'center'
13
+ | 'end'
14
+ | 'stretch'
15
+ | 'space-between'
16
+ | 'space-around'
17
+ | 'baseline';
18
+ /* TODO we need to update to typescript 4 */
19
+ // export type FxLayoutAlign = `${MainAxis} ${CrossAxis}`;
20
+
21
+ export const isAttribute = (attr: string): boolean | string =>
22
+ typeof attr === 'string' && (attr || attr === '');
23
+
24
+ export const setFxLayoutAlign = (element: HTMLElement) => {
25
+ return (fxLayoutAlign = ''): void => {
26
+ const [mainAxis, crossAxis] = fxLayoutAlign.split(' ');
27
+ element.style['place-content'] = `${crossAxis} ${mainAxis}`;
28
+ element.style['align-items'] = crossAxis;
29
+ element.style['display'] = 'flex';
30
+ };
31
+ };
32
+
33
+ export const setChildrensFlexFill = (div: HTMLElement): void => {
34
+ div.style['margin'] = '0';
35
+ div.style['width'] = '100%';
36
+ div.style['height'] = '100%';
37
+ div.style['min-width'] = '100%';
38
+ div.style['min-height '] = '100%';
39
+ };
40
+
41
+ export const setChildrensFlex = (div: HTMLElement) => {
42
+ return (fxFlex: string): void => {
43
+ div.style['flex'] = '1 1 100%';
44
+ div.style['box-sizing'] = 'border-box';
45
+ if (fxFlex) {
46
+ div.style['max-width'] = fxFlex;
47
+ }
48
+ };
49
+ };
50
+
51
+ export const setFxLayout = (element: HTMLElement) => {
52
+ return (fxLayout = ''): void => {
53
+ // element.style['flex-direction'] = fxLayout;
54
+ element.style['box-sizing'] = 'flex';
55
+ element.style['display'] = 'flex';
56
+ element.style['flex-flow'] = `${fxLayout} wrap`;
57
+ };
58
+ };
59
+
60
+ export const recursion = (div: HTMLElement): void => {
61
+ const fxFlex = div.getAttribute('fxFlex');
62
+ const fxFlexFill = div.getAttribute('fxFlexFill');
63
+ const fxLayout = div.getAttribute('fxLayout');
64
+ const fxLayoutAlign = div.getAttribute('fxLayoutAlign');
65
+ const fxLayoutGap = div.getAttribute('fxLayoutGap');
66
+
67
+ if (isAttribute(fxFlex)) {
68
+ setChildrensFlex(div)(fxFlex);
69
+ }
70
+
71
+ if (isAttribute(fxFlexFill)) {
72
+ setChildrensFlexFill(div);
73
+ }
74
+
75
+ if (isAttribute(fxLayout)) {
76
+ setFxLayout(div)(fxLayout);
77
+ }
78
+
79
+ if (isAttribute(fxLayoutAlign)) {
80
+ setFxLayoutAlign(div)(fxLayoutAlign);
81
+ }
82
+
83
+ if (isAttribute(fxLayoutGap)) {
84
+ const divs = [...div.children] as HTMLElement[];
85
+ for (const div of divs) {
86
+ div.style['padding'] = `0px ${fxLayoutGap} ${fxLayoutGap} 0px`;
87
+ div.style.flex = '1 1 25%';
88
+ }
89
+ }
90
+
91
+ const divs = [...div.children] as HTMLElement[];
92
+ for (const div of divs) {
93
+ recursion(div);
94
+ }
95
+ };
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
+ }