@rhtml/modifiers 0.0.91 → 0.0.92

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.
@@ -1,6 +1,12 @@
1
- import { LitElement, TemplateResult } from '@rxdi/lit-html';
2
- export declare class FlexLayout extends LitElement {
1
+ import { LitElement, OnDestroy, OnUpdate, TemplateResult } from '@rxdi/lit-html';
2
+ export declare class FlexLayout extends LitElement implements OnUpdate, OnDestroy {
3
3
  child: LitElement;
4
+ private observables;
4
5
  OnUpdate(): void;
6
+ OnDestroy(): void;
7
+ private unsubscribe;
8
+ private updateAttributes;
9
+ private isFxLayout;
10
+ private subscribe;
5
11
  static modifier(template: TemplateResult): TemplateResult;
6
12
  }
@@ -13,12 +13,44 @@ exports.FlexLayout = void 0;
13
13
  const lit_html_1 = require("@rxdi/lit-html");
14
14
  const modifiers_1 = require("./modifiers");
15
15
  let FlexLayout = class FlexLayout extends lit_html_1.LitElement {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.observables = [];
19
+ }
16
20
  OnUpdate() {
21
+ this.updateAttributes();
22
+ }
23
+ OnDestroy() {
24
+ this.unsubscribe();
25
+ }
26
+ unsubscribe() {
27
+ for (const observable of this.observables) {
28
+ observable.disconnect();
29
+ }
30
+ this.observables = [];
31
+ }
32
+ updateAttributes() {
17
33
  const slot = this.shadowRoot.querySelector('slot');
18
- for (const div of [...slot === null || slot === void 0 ? void 0 : slot.assignedElements()]) {
19
- modifiers_1.recursion.call(this.child, div);
34
+ for (const element of [...slot === null || slot === void 0 ? void 0 : slot.assignedElements()]) {
35
+ if (this.isFxLayout(element)) {
36
+ this.unsubscribe();
37
+ this.subscribe(element);
38
+ }
39
+ modifiers_1.recursion.call(this.child, element);
20
40
  }
21
41
  }
42
+ isFxLayout(element) {
43
+ return element.getAttribute(modifiers_1.Attributes.FxLayout.toLowerCase());
44
+ }
45
+ subscribe(element) {
46
+ this.unsubscribe();
47
+ const observer = new MutationObserver(() => this.updateAttributes());
48
+ observer.observe(element, {
49
+ subtree: true,
50
+ childList: true
51
+ });
52
+ this.observables.push(observer);
53
+ }
22
54
  static modifier(template) {
23
55
  return lit_html_1.html `
24
56
  <flex-layout .child=${this}>${template}</flex-layout>
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAMwB;AAExB,2CAAwC;AAUxC,IAAa,UAAU,GAAvB,MAAa,UAAW,SAAQ,qBAAU;IAIxC,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,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,GAAY,CAAC,CAAC;SAC1C;IACH,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,QAAwB;QAC7C,OAAO,eAAI,CAAA;4BACa,IAAI,IAAI,QAAQ;KACvC,CAAC;IACJ,CAAC;CACF,CAAA;AAdC;IADC,mBAAQ,EAAE;8BACJ,qBAAU;yCAAC;AAFP,UAAU;IARtB,oBAAS,CAAC;QACT,QAAQ,EAAE,aAAa;QACvB,QAAQ;YACN,OAAO,eAAI,CAAA;;KAEV,CAAC;QACJ,CAAC;KACF,CAAC;GACW,UAAU,CAgBtB;AAhBY,gCAAU"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAQwB;AAExB,2CAAoD;AAUpD,IAAa,UAAU,GAAvB,MAAa,UAAW,SAAQ,qBAAU;IAA1C;;QAIU,gBAAW,GAAuB,EAAE,CAAC;IA+C/C,CAAC;IA7CC,QAAQ;QACN,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;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CAAC;CACF,CAAA;AAjDC;IADC,mBAAQ,EAAE;8BACJ,qBAAU;yCAAC;AAFP,UAAU;IARtB,oBAAS,CAAC;QACT,QAAQ,EAAE,aAAa;QACvB,QAAQ;YACN,OAAO,eAAI,CAAA;;KAEV,CAAC;QACJ,CAAC;KACF,CAAC;GACW,UAAU,CAmDtB;AAnDY,gCAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhtml/modifiers",
3
- "version": "0.0.91",
3
+ "version": "0.0.92",
4
4
  "description": "Reactive HyperText Markup Language",
5
5
  "scripts": {
6
6
  "start": "npx parcel ./examples/index.html --out-dir build/examples",
@@ -2,11 +2,13 @@ import {
2
2
  Component,
3
3
  html,
4
4
  LitElement,
5
+ OnDestroy,
6
+ OnUpdate,
5
7
  property,
6
8
  TemplateResult
7
9
  } from '@rxdi/lit-html';
8
10
 
9
- import { recursion } from './modifiers';
11
+ import { Attributes, recursion } from './modifiers';
10
12
 
11
13
  @Component({
12
14
  selector: 'flex-layout',
@@ -16,17 +18,52 @@ import { recursion } from './modifiers';
16
18
  `;
17
19
  }
18
20
  })
19
- export class FlexLayout extends LitElement {
21
+ export class FlexLayout extends LitElement implements OnUpdate, OnDestroy {
20
22
  @property()
21
23
  child: LitElement;
22
24
 
25
+ private observables: MutationObserver[] = [];
26
+
23
27
  OnUpdate(): void {
28
+ this.updateAttributes();
29
+ }
30
+
31
+ OnDestroy() {
32
+ this.unsubscribe();
33
+ }
34
+
35
+ private unsubscribe() {
36
+ for (const observable of this.observables) {
37
+ observable.disconnect();
38
+ }
39
+ this.observables = [];
40
+ }
41
+
42
+ private updateAttributes() {
24
43
  const slot = this.shadowRoot.querySelector('slot');
25
- for (const div of [...slot?.assignedElements()]) {
26
- recursion.call(this.child, div as never);
44
+ for (const element of [...slot?.assignedElements()]) {
45
+ if (this.isFxLayout(element)) {
46
+ this.unsubscribe();
47
+ this.subscribe(element);
48
+ }
49
+ recursion.call(this.child, element);
27
50
  }
28
51
  }
29
52
 
53
+ private isFxLayout(element: Element) {
54
+ return element.getAttribute(Attributes.FxLayout.toLowerCase());
55
+ }
56
+
57
+ private subscribe(element: Element) {
58
+ this.unsubscribe();
59
+ const observer = new MutationObserver(() => this.updateAttributes());
60
+ observer.observe(element, {
61
+ subtree: true,
62
+ childList: true
63
+ });
64
+ this.observables.push(observer);
65
+ }
66
+
30
67
  public static modifier(template: TemplateResult): TemplateResult {
31
68
  return html`
32
69
  <flex-layout .child=${this}>${template}</flex-layout>