@rxdi/lit-html 0.7.135 → 0.7.138

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/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # lit-html hard fork prepared for bundlers with removed `.js` files from extensions
2
-
3
1
  #### Install
2
+
4
3
  ```bash
5
4
  npm i @rxdi/lit-html
6
5
  ```
7
6
 
8
7
  Example component
8
+
9
9
  ```typescript
10
10
  import { LitElement, Component, html, css } from '@rxdi/lit-html';
11
11
 
@@ -43,7 +43,79 @@ import { LitElement, Component, html, css } from '@rxdi/lit-html';
43
43
  <div class="border" part="border"></div>
44
44
  </div>
45
45
  `;
46
- }
46
+ },
47
47
  })
48
48
  export class DescriptionListComponent extends LitElement {}
49
- ```
49
+ ```
50
+
51
+ #### Modifiers
52
+
53
+ What is a modifier ?
54
+
55
+ 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
56
+
57
+ ```typescript
58
+ @Component({
59
+ selector: 'my-modifier',
60
+ template() {
61
+ return html`<slot></slot>`;
62
+ },
63
+ })
64
+ export class MyModifier extends LitElement {
65
+ OnUpdate() {
66
+ const slot = this.shadowRoot.querySelector('slot');
67
+ for (const element of [...slot.assignedElements()]) {
68
+ /// Do something here with element
69
+ }
70
+ }
71
+
72
+ public static modifier(template: TemplateResult) {
73
+ return html`<my-modifier>${template}</my-modifier>`;
74
+ }
75
+ }
76
+ ```
77
+
78
+ Another real example is to add FlexLayout modifier from `@rhtml/modifiers` which will apply useful directives
79
+ to be used inside of the html inspired from Angular flex-layout https://github.com/angular/flex-layout/wiki/Declarative-API-Overview
80
+
81
+ ```typescript
82
+ import { Component, css, html, LitElement } from '@rxdi/lit-html';
83
+
84
+ import { FlexLayout } from '@rhtml/modifiers';
85
+
86
+ /**
87
+ * @customElement home-component
88
+ */
89
+ @Component({
90
+ selector: 'home-component',
91
+ style: css`
92
+ .block {
93
+ background: red;
94
+ flex: 1;
95
+ }
96
+ .container {
97
+ height: 200px;
98
+ }
99
+ `,
100
+ modifiers: [FlexLayout],
101
+ template(this: HomeComponent) {
102
+ return html`
103
+ <div class="container" fxLayout="row" fxLayoutGap="10px">
104
+ <div>
105
+ <div class="block" fxLayoutAlign="center center" fxFlexFill>A</div>
106
+ </div>
107
+ <div>
108
+ <div class="block" fxLayoutAlign="center center" fxFlexFill>B</div>
109
+ </div>
110
+ <div>
111
+ <div class="block" fxLayoutAlign="center center" fxFlexFill>C</div>
112
+ </div>
113
+ <div>
114
+ <div class="block" fxLayoutAlign="center center" fxFlexFill>D</div>
115
+ </div>
116
+ </div>
117
+ `;
118
+ },
119
+ })
120
+ export class HomeComponent extends LitElement {}
121
+ ```
@@ -6,6 +6,9 @@ export interface CustomElementConfig<T> {
6
6
  style?: CSSResult;
7
7
  styles?: CSSResult[];
8
8
  extends?: string;
9
+ modifier?: (Function | {
10
+ html(template: TemplateResult): TemplateResult;
11
+ })[];
9
12
  /**
10
13
  * Intended only for first render inside the DOM
11
14
  * for example we want app-component to be rendered
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Component = void 0;
4
4
  const lit_html_1 = require("../lit-html/lit-html");
5
+ const helpers_1 = require("./helpers");
5
6
  const legacyCustomElement = (tagName, clazz, options) => {
6
7
  window.customElements.define(tagName, clazz, options);
7
8
  return clazz;
@@ -71,6 +72,10 @@ const customElement = (tag, config = {}) => (Base) => {
71
72
  OnInit.call(this);
72
73
  }
73
74
  render() {
75
+ var _a;
76
+ if ((_a = config.modifier) === null || _a === void 0 ? void 0 : _a.length) {
77
+ return (0, helpers_1.pipe)(...(config.modifier.map(v => v['html'])))(config.template.call(this));
78
+ }
74
79
  return config.template.call(this);
75
80
  }
76
81
  update() {
@@ -0,0 +1,2 @@
1
+ import { TemplateResult } from '../../lit-html/lit-html';
2
+ export declare const pipe: (...fns: Function[]) => (x: TemplateResult) => any;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pipe = void 0;
4
+ const pipe = (...fns) => (x) => fns.reduce((v, f) => f(v), x);
5
+ exports.pipe = pipe;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdi/lit-html",
3
- "version": "0.7.135",
3
+ "version": "0.7.138",
4
4
  "main": "./dist/index.js",
5
5
  "author": "Kristiyan Tachev",
6
6
  "license": "MIT",
@@ -9,7 +9,7 @@
9
9
  "url": "https://github.com/rxdi/lit-html"
10
10
  },
11
11
  "scripts": {
12
- "build": "tsc || true"
12
+ "build": "npx tsc || true"
13
13
  },
14
14
  "dependencies": {},
15
15
  "devDependencies": {