@ibyar/core 0.8.5 → 1.0.0

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.
Files changed (134) hide show
  1. package/annotation/context.d.ts +41 -0
  2. package/annotation/context.d.ts.map +1 -0
  3. package/annotation/context.js +79 -0
  4. package/annotation/context.js.map +1 -0
  5. package/annotation/decorators.d.ts +20 -285
  6. package/annotation/decorators.d.ts.map +1 -0
  7. package/annotation/decorators.js +92 -84
  8. package/annotation/decorators.js.map +1 -1
  9. package/annotation/options.d.ts +275 -0
  10. package/annotation/options.d.ts.map +1 -0
  11. package/annotation/options.js +2 -0
  12. package/annotation/options.js.map +1 -0
  13. package/binding/binding.expressions.d.ts +1 -0
  14. package/binding/binding.expressions.d.ts.map +1 -0
  15. package/binding/binding.expressions.js +138 -125
  16. package/binding/binding.expressions.js.map +1 -1
  17. package/component/component.d.ts +16 -12
  18. package/component/component.d.ts.map +1 -0
  19. package/component/component.js +111 -52
  20. package/component/component.js.map +1 -1
  21. package/component/custom-element.d.ts +1 -0
  22. package/component/custom-element.d.ts.map +1 -0
  23. package/component/events.d.ts +1 -0
  24. package/component/events.d.ts.map +1 -0
  25. package/component/events.js +4 -3
  26. package/component/events.js.map +1 -1
  27. package/component/lifecycle.d.ts +1 -0
  28. package/component/lifecycle.d.ts.map +1 -0
  29. package/component/reflect.d.ts +12 -15
  30. package/component/reflect.d.ts.map +1 -0
  31. package/component/reflect.js +27 -47
  32. package/component/reflect.js.map +1 -1
  33. package/context/stack.d.ts +1 -0
  34. package/context/stack.d.ts.map +1 -0
  35. package/context/subscription.d.ts +1 -0
  36. package/context/subscription.d.ts.map +1 -0
  37. package/directive/directive.d.ts +1 -0
  38. package/directive/directive.d.ts.map +1 -0
  39. package/directive/directive.js +8 -0
  40. package/directive/directive.js.map +1 -1
  41. package/directive/parser.d.ts +1 -0
  42. package/directive/parser.d.ts.map +1 -0
  43. package/directive/parser.js +9 -7
  44. package/directive/parser.js.map +1 -1
  45. package/directive/providers.d.ts +1 -0
  46. package/directive/providers.d.ts.map +1 -0
  47. package/directive/providers.js +2 -1
  48. package/directive/providers.js.map +1 -1
  49. package/html/deserialize.d.ts +1 -0
  50. package/html/deserialize.d.ts.map +1 -0
  51. package/html/expression.d.ts +1 -0
  52. package/html/expression.d.ts.map +1 -0
  53. package/html/expression.js +2 -2
  54. package/html/expression.js.map +1 -1
  55. package/html/types.d.ts +1 -0
  56. package/html/types.d.ts.map +1 -0
  57. package/index.d.ts +2 -2
  58. package/index.d.ts.map +1 -0
  59. package/index.js +1 -2
  60. package/index.js.map +1 -1
  61. package/linker/change-detector-ref.d.ts +1 -0
  62. package/linker/change-detector-ref.d.ts.map +1 -0
  63. package/linker/template-ref.d.ts +1 -0
  64. package/linker/template-ref.d.ts.map +1 -0
  65. package/linker/template-ref.js +5 -0
  66. package/linker/template-ref.js.map +1 -1
  67. package/linker/view-container-ref.d.ts +4 -2
  68. package/linker/view-container-ref.d.ts.map +1 -0
  69. package/linker/view-container-ref.js +8 -7
  70. package/linker/view-container-ref.js.map +1 -1
  71. package/linker/view-ref.d.ts +1 -0
  72. package/linker/view-ref.d.ts.map +1 -0
  73. package/linker/view-ref.js +5 -2
  74. package/linker/view-ref.js.map +1 -1
  75. package/node.d.ts +1 -0
  76. package/node.d.ts.map +1 -0
  77. package/package.json +7 -8
  78. package/pipe/pipe.d.ts +1 -0
  79. package/pipe/pipe.d.ts.map +1 -0
  80. package/pipe/pipe.js +2 -1
  81. package/pipe/pipe.js.map +1 -1
  82. package/providers/provider.d.ts +15 -13
  83. package/providers/provider.d.ts.map +1 -0
  84. package/providers/provider.js +13 -16
  85. package/providers/provider.js.map +1 -1
  86. package/utils/elements-util.d.ts +1 -0
  87. package/utils/elements-util.d.ts.map +1 -0
  88. package/utils/path.d.ts +1 -0
  89. package/utils/path.d.ts.map +1 -0
  90. package/utils/typeof.d.ts +3 -0
  91. package/utils/typeof.d.ts.map +1 -0
  92. package/utils/typeof.js.map +1 -1
  93. package/utils/utils.d.ts +1 -0
  94. package/utils/utils.d.ts.map +1 -0
  95. package/view/base-view.d.ts +1 -0
  96. package/view/base-view.d.ts.map +1 -0
  97. package/view/base-view.js +34 -16
  98. package/view/base-view.js.map +1 -1
  99. package/view/form-view.d.ts +1 -0
  100. package/view/form-view.d.ts.map +1 -0
  101. package/view/form-view.js +70 -67
  102. package/view/form-view.js.map +1 -1
  103. package/view/mutation.d.ts +1 -0
  104. package/view/mutation.d.ts.map +1 -0
  105. package/view/mutation.js +37 -36
  106. package/view/mutation.js.map +1 -1
  107. package/view/render.d.ts +2 -2
  108. package/view/render.d.ts.map +1 -0
  109. package/view/render.js +21 -21
  110. package/view/render.js.map +1 -1
  111. package/view/utils.d.ts +4 -3
  112. package/view/utils.d.ts.map +1 -0
  113. package/view/utils.js.map +1 -1
  114. package/view/view.d.ts +5 -4
  115. package/view/view.d.ts.map +1 -0
  116. package/view/view.js +19 -3
  117. package/view/view.js.map +1 -1
  118. package/zone/bootstrap.d.ts +1 -0
  119. package/zone/bootstrap.d.ts.map +1 -0
  120. package/zone/proxy.d.ts +1 -0
  121. package/zone/proxy.d.ts.map +1 -0
  122. package/zone/proxy.js +1 -0
  123. package/zone/proxy.js.map +1 -1
  124. package/zone/task.d.ts +1 -0
  125. package/zone/task.d.ts.map +1 -0
  126. package/zone/task.js +11 -3
  127. package/zone/task.js.map +1 -1
  128. package/zone/zone.d.ts +1 -0
  129. package/zone/zone.d.ts.map +1 -0
  130. package/zone/zone.js +8 -6
  131. package/zone/zone.js.map +1 -1
  132. package/providers/injector.d.ts +0 -10
  133. package/providers/injector.js +0 -27
  134. package/providers/injector.js.map +0 -1
package/view/form-view.js CHANGED
@@ -3,6 +3,7 @@ import { baseFactoryView } from './base-view.js';
3
3
  import { ARIAMixinAttributes, isFormElement } from '@ibyar/elements';
4
4
  export const NOOP_CONTROL_CHANGE = () => { };
5
5
  export class NativeElementInternals {
6
+ el;
6
7
  constructor(input) {
7
8
  this.el = input;
8
9
  }
@@ -35,80 +36,82 @@ ARIAMixinAttributes.forEach(ariaName => {
35
36
  });
36
37
  });
37
38
  export function baseFormFactoryView(htmlElementType) {
38
- var _a;
39
39
  const baseViewClass = baseFactoryView(htmlElementType);
40
- return _a = class BaseFormView extends baseViewClass {
41
- constructor(componentRef, modelClass) {
42
- super(componentRef, modelClass);
43
- if (componentRef.extend.name && isFormElement(componentRef.extend.name)) {
44
- this._internals = new NativeElementInternals(this);
45
- }
46
- else {
47
- this._internals = this.attachInternals();
48
- }
49
- let valueControl;
50
- if (typeof componentRef.formAssociated === 'function') {
51
- if (this._model instanceof componentRef.formAssociated) {
52
- valueControl == this._model;
53
- }
54
- else {
55
- const args = [this]; /* resolve dependency injection*/
56
- ;
57
- valueControl = new componentRef.formAssociated(args);
58
- }
59
- }
60
- else if (componentRef.formAssociated === true && isValueControl(this._model)) {
61
- valueControl = this._model;
62
- }
63
- valueControl && this.registerValueControl(valueControl);
64
- const valueInput = componentRef.inputs.filter(input => input.viewAttribute === 'value').at(0);
65
- if (valueInput) {
66
- this._modelScope.subscribe(valueInput.modelProperty, (newValue, oldValue) => {
67
- if (newValue === oldValue) {
68
- return;
69
- }
70
- this.onValueControlChange(newValue);
71
- });
72
- }
73
- }
74
- get internals() {
75
- return this._internals;
76
- }
77
- get form() {
78
- return this._form;
40
+ return class BaseFormView extends baseViewClass {
41
+ /**
42
+ * Identify the element as a form-associated custom element
43
+ */
44
+ static formAssociated = true;
45
+ value;
46
+ _internals;
47
+ _form;
48
+ _valueControl;
49
+ constructor(componentRef, modelClass) {
50
+ super(componentRef, modelClass);
51
+ if (componentRef.extend.name && isFormElement(componentRef.extend.name)) {
52
+ this._internals = new NativeElementInternals(this);
79
53
  }
80
- get valueControl() {
81
- return this._valueControl;
54
+ else {
55
+ this._internals = this.attachInternals();
82
56
  }
83
- registerValueControl(valueControl) {
84
- if (this.valueControl) {
85
- this.valueControl.registerOnChange(NOOP_CONTROL_CHANGE);
57
+ let valueControl;
58
+ if (typeof componentRef.formAssociated === 'function') {
59
+ if (this._model instanceof componentRef.formAssociated) {
60
+ valueControl == this._model;
61
+ }
62
+ else {
63
+ const args = [this]; /* resolve dependency injection*/
64
+ ;
65
+ valueControl = new componentRef.formAssociated(args);
86
66
  }
87
- this._valueControl = valueControl;
88
- this._valueControl?.registerOnChange((value) => this.onValueControlChange(value));
89
- }
90
- onValueControlChange(value) {
91
- this._internals.setFormValue(value);
92
- this.value = value;
93
- this.dispatchEvent(new Event('change', { bubbles: true, cancelable: true, composed: true }));
94
- }
95
- formAssociatedCallback(form) {
96
- this._form = form;
97
67
  }
98
- formDisabledCallback(disabled) {
99
- this._valueControl?.setDisabledState?.(disabled);
68
+ else if (componentRef.formAssociated === true && isValueControl(this._model)) {
69
+ valueControl = this._model;
100
70
  }
101
- formResetCallback() {
102
- this._valueControl?.writeValue({ mode: 'reset' });
71
+ valueControl && this.registerValueControl(valueControl);
72
+ const valueInput = componentRef.inputs.filter(input => input.viewAttribute === 'value').at(0);
73
+ if (valueInput) {
74
+ this._modelScope.subscribe(valueInput.modelProperty, (newValue, oldValue) => {
75
+ if (newValue === oldValue) {
76
+ return;
77
+ }
78
+ this.onValueControlChange(newValue);
79
+ });
103
80
  }
104
- formStateRestoreCallback(value, mode) {
105
- this._valueControl?.writeValue({ value, mode });
81
+ }
82
+ get internals() {
83
+ return this._internals;
84
+ }
85
+ get form() {
86
+ return this._form;
87
+ }
88
+ get valueControl() {
89
+ return this._valueControl;
90
+ }
91
+ registerValueControl(valueControl) {
92
+ if (this.valueControl) {
93
+ this.valueControl.registerOnChange(NOOP_CONTROL_CHANGE);
106
94
  }
107
- },
108
- /**
109
- * Identify the element as a form-associated custom element
110
- */
111
- _a.formAssociated = true,
112
- _a;
95
+ this._valueControl = valueControl;
96
+ this._valueControl?.registerOnChange((value) => this.onValueControlChange(value));
97
+ }
98
+ onValueControlChange(value) {
99
+ this._internals.setFormValue(value);
100
+ this.value = value;
101
+ this.dispatchEvent(new Event('change', { bubbles: true, cancelable: true, composed: true }));
102
+ }
103
+ formAssociatedCallback(form) {
104
+ this._form = form;
105
+ }
106
+ formDisabledCallback(disabled) {
107
+ this._valueControl?.setDisabledState?.(disabled);
108
+ }
109
+ formResetCallback() {
110
+ this._valueControl?.writeValue({ mode: 'reset' });
111
+ }
112
+ formStateRestoreCallback(value, mode) {
113
+ this._valueControl?.writeValue({ value, mode });
114
+ }
115
+ };
113
116
  }
114
117
  //# sourceMappingURL=form-view.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"form-view.js","sourceRoot":"","sources":["../../../src/core/view/form-view.ts"],"names":[],"mappings":"AAEA,OAAO,EAIN,cAAc,GACd,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErE,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;AAM7C,MAAM,OAAO,sBAAsB;IAElC,YAAY,KAAwC;QACnD,IAAI,CAAC,EAAE,GAAG,KAAgC,CAAC;IAC5C,CAAC;IAED,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;IACrB,CAAC;IACD,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,EAAE,CAAC,MAAO,CAAC;IACxB,CAAC;IAED,IAAI,UAAU;QACb,OAAO,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED,IAAI,YAAY;QACf,OAAO,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,YAAY,CAAC,KAAiB,EAAE,KAAuC;QACtE,IAAI,CAAC,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CAED;AAED,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;IACtC,MAAM,CAAC,cAAc,CAAC,sBAAsB,CAAC,SAAS,E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,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC9F,CAAC;YAED,sBAAsB,CAAC,IAA4B;gBAClD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,oBAAoB,CAAC,QAAiB;gBACrC,IAAI,CAAC,aAAa,EAAE,gBAAgB,EAAE,CAAC,QAAQ,CAAC,CAAC;YAClD,CAAC;YACD,iBAAiB;gBAChB,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YACnD,CAAC;YACD,wBAAwB,CAAC,KAAU,EAAE,IAAgC;gBACpE,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACjD,CAAC;SACD;QA1EA;;WAEG;QACI,iBAAc,GAAG,IAAK;WAuE7B;AACF,CAAC","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport { ComponentRef } from '../component/component.js';\nimport {\n\tFormAssociatedCustomElement, HTMLFormElement,\n\tFormAssociatedComponent,\n\tValueControl,\n\tisValueControl,\n} from '../component/custom-element.js';\nimport { baseFactoryView } from './base-view.js';\nimport { ARIAMixinAttributes, isFormElement } from '@ibyar/elements';\n\nexport const NOOP_CONTROL_CHANGE = () => { };\n\nexport interface NativeElementInternals extends ElementInternals {\n\n}\n\nexport class NativeElementInternals implements ElementInternals {\n\tprivate el: HTMLInputElement;\n\tconstructor(input: FormAssociatedComponent<any, any>) {\n\t\tthis.el = input as any as HTMLInputElement;\n\t}\n\n\tget form() {\n\t\treturn this.el.form;\n\t}\n\tget labels() {\n\t\treturn this.el.labels!;\n\t}\n\n\tget shadowRoot() {\n\t\treturn this.el.shadowRoot;\n\t}\n\n\tget willValidate() {\n\t\treturn this.el.willValidate;\n\t}\n\n\tsetFormValue(value: any | null, state?: File | string | FormData | null): void {\n\t\tthis.el.value = value;\n\t}\n\n}\n\nARIAMixinAttributes.forEach(ariaName => {\n\tObject.defineProperty(NativeElementInternals.prototype, ariaName, {\n\t\tenumerable: true,\n\t\tconfigurable: true,\n\t\tget: function name(this: { el: HTMLInputElement }) {\n\t\t\treturn this.el[ariaName];\n\t\t},\n\t\tset: function name(this: { el: HTMLInputElement }, value: any) {\n\t\t\treturn this.el[ariaName] = value;\n\t\t},\n\t});\n});\n\nexport function baseFormFactoryView<T extends Object>(htmlElementType: TypeOf<HTMLElement>): TypeOf<FormAssociatedComponent<T, any>> {\n\tconst baseViewClass = baseFactoryView<T>(htmlElementType);\n\treturn class BaseFormView<T> extends baseViewClass implements FormAssociatedCustomElement {\n\n\t\t/**\n\t\t * Identify the element as a form-associated custom element\n\t\t */\n\t\tstatic formAssociated = true;\n\n\t\tvalue: any;\n\n\t\tprivate _internals: ElementInternals;\n\t\tprivate _form: HTMLFormElement | null;\n\t\tprivate _valueControl?: ValueControl<T>;\n\n\t\tconstructor(componentRef: ComponentRef<T>, modelClass: TypeOf<T>) {\n\t\t\tsuper(componentRef, modelClass);\n\t\t\tif (componentRef.extend.name && isFormElement(componentRef.extend.name)) {\n\t\t\t\tthis._internals = new NativeElementInternals(this);\n\t\t\t} else {\n\t\t\t\tthis._internals = this.attachInternals();\n\t\t\t}\n\t\t\tlet valueControl: ValueControl<any> | undefined;\n\t\t\tif (typeof componentRef.formAssociated === 'function') {\n\t\t\t\tif (this._model instanceof componentRef.formAssociated) {\n\t\t\t\t\tvalueControl == this._model;\n\t\t\t\t} else {\n\t\t\t\t\tconst args: any[] = [this]; /* resolve dependency injection*/;\n\t\t\t\t\tvalueControl = new componentRef.formAssociated(args);\n\t\t\t\t}\n\t\t\t} else if (componentRef.formAssociated === true && isValueControl(this._model)) {\n\t\t\t\tvalueControl = this._model;\n\t\t\t}\n\t\t\tvalueControl && this.registerValueControl(valueControl);\n\t\t\tconst valueInput = componentRef.inputs.filter(input => input.viewAttribute === 'value').at(0);\n\t\t\tif (valueInput) {\n\t\t\t\tthis._modelScope.subscribe(valueInput.modelProperty as any, (newValue, oldValue) => {\n\t\t\t\t\tif (newValue === oldValue) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tthis.onValueControlChange(newValue);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tget internals(): ElementInternals {\n\t\t\treturn this._internals;\n\t\t}\n\t\tget form(): HTMLFormElement | null {\n\t\t\treturn this._form;\n\t\t}\n\t\tget valueControl(): ValueControl<T> | undefined {\n\t\t\treturn this._valueControl;\n\t\t}\n\t\tregisterValueControl(valueControl: ValueControl): void {\n\t\t\tif (this.valueControl) {\n\t\t\t\tthis.valueControl.registerOnChange(NOOP_CONTROL_CHANGE);\n\t\t\t}\n\t\t\tthis._valueControl = valueControl;\n\t\t\tthis._valueControl?.registerOnChange((value: any) => this.onValueControlChange(value));\n\t\t}\n\t\tprivate onValueControlChange(value: any) {\n\t\t\tthis._internals.setFormValue(value);\n\t\t\tthis.value = value;\n\t\t\tthis.dispatchEvent(new Event('change', { bubbles: true, cancelable: true, composed: true }));\n\t\t}\n\n\t\tformAssociatedCallback(form: HTMLFormElement | null): void {\n\t\t\tthis._form = form;\n\t\t}\n\t\tformDisabledCallback(disabled: boolean): void {\n\t\t\tthis._valueControl?.setDisabledState?.(disabled);\n\t\t}\n\t\tformResetCallback(): void {\n\t\t\tthis._valueControl?.writeValue({ mode: 'reset' });\n\t\t}\n\t\tformStateRestoreCallback(value: any, mode: 'restore' | 'autocomplete'): void {\n\t\t\tthis._valueControl?.writeValue({ value, mode });\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"form-view.js","sourceRoot":"","sources":["../../../src/core/view/form-view.ts"],"names":[],"mappings":"AAEA,OAAO,EAIN,cAAc,GACd,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,C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AClD,CAAC;QACD,iBAAiB;YAChB,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QACnD,CAAC;QACD,wBAAwB,CAAC,KAAU,EAAE,IAAgC;YACpE,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACjD,CAAC;KACD,CAAA;AACF,CAAC","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport { ComponentRef } from '../component/component.js';\nimport {\n\tFormAssociatedCustomElement, HTMLFormElement,\n\tFormAssociatedComponent,\n\tValueControl,\n\tisValueControl,\n} from '../component/custom-element.js';\nimport { baseFactoryView } from './base-view.js';\nimport { ARIAMixinAttributes, isFormElement } from '@ibyar/elements';\n\nexport const NOOP_CONTROL_CHANGE = () => { };\n\nexport interface NativeElementInternals extends ElementInternals {\n\n}\n\nexport class NativeElementInternals implements ElementInternals {\n\tprivate el: HTMLInputElement;\n\tconstructor(input: FormAssociatedComponent<any, any>) {\n\t\tthis.el = input as any as HTMLInputElement;\n\t}\n\n\tget form() {\n\t\treturn this.el.form;\n\t}\n\tget labels() {\n\t\treturn this.el.labels!;\n\t}\n\n\tget shadowRoot() {\n\t\treturn this.el.shadowRoot;\n\t}\n\n\tget willValidate() {\n\t\treturn this.el.willValidate;\n\t}\n\n\tsetFormValue(value: any | null, state?: File | string | FormData | null): void {\n\t\tthis.el.value = value;\n\t}\n\n}\n\nARIAMixinAttributes.forEach(ariaName => {\n\tObject.defineProperty(NativeElementInternals.prototype, ariaName, {\n\t\tenumerable: true,\n\t\tconfigurable: true,\n\t\tget: function name(this: { el: HTMLInputElement }) {\n\t\t\treturn this.el[ariaName];\n\t\t},\n\t\tset: function name(this: { el: HTMLInputElement }, value: any) {\n\t\t\treturn this.el[ariaName] = value;\n\t\t},\n\t});\n});\n\nexport function baseFormFactoryView<T extends Object>(htmlElementType: TypeOf<HTMLElement>): TypeOf<FormAssociatedComponent<T, any>> {\n\tconst baseViewClass = baseFactoryView<T>(htmlElementType);\n\treturn class BaseFormView<T> extends baseViewClass implements FormAssociatedCustomElement {\n\n\t\t/**\n\t\t * Identify the element as a form-associated custom element\n\t\t */\n\t\tstatic formAssociated = true;\n\n\t\tvalue: any;\n\n\t\tprivate _internals: ElementInternals;\n\t\tprivate _form: HTMLFormElement | null;\n\t\tprivate _valueControl?: ValueControl<T>;\n\n\t\tconstructor(componentRef: ComponentRef<T>, modelClass: TypeOf<T>) {\n\t\t\tsuper(componentRef, modelClass);\n\t\t\tif (componentRef.extend.name && isFormElement(componentRef.extend.name)) {\n\t\t\t\tthis._internals = new NativeElementInternals(this);\n\t\t\t} else {\n\t\t\t\tthis._internals = this.attachInternals();\n\t\t\t}\n\t\t\tlet valueControl: ValueControl<any> | undefined;\n\t\t\tif (typeof componentRef.formAssociated === 'function') {\n\t\t\t\tif (this._model instanceof componentRef.formAssociated) {\n\t\t\t\t\tvalueControl == this._model;\n\t\t\t\t} else {\n\t\t\t\t\tconst args: any[] = [this]; /* resolve dependency injection*/;\n\t\t\t\t\tvalueControl = new componentRef.formAssociated(args);\n\t\t\t\t}\n\t\t\t} else if (componentRef.formAssociated === true && isValueControl(this._model)) {\n\t\t\t\tvalueControl = this._model;\n\t\t\t}\n\t\t\tvalueControl && this.registerValueControl(valueControl);\n\t\t\tconst valueInput = componentRef.inputs.filter(input => input.viewAttribute === 'value').at(0);\n\t\t\tif (valueInput) {\n\t\t\t\tthis._modelScope.subscribe(valueInput.modelProperty as any, (newValue, oldValue) => {\n\t\t\t\t\tif (newValue === oldValue) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tthis.onValueControlChange(newValue);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tget internals(): ElementInternals {\n\t\t\treturn this._internals;\n\t\t}\n\t\tget form(): HTMLFormElement | null {\n\t\t\treturn this._form;\n\t\t}\n\t\tget valueControl(): ValueControl<T> | undefined {\n\t\t\treturn this._valueControl;\n\t\t}\n\t\tregisterValueControl(valueControl: ValueControl): void {\n\t\t\tif (this.valueControl) {\n\t\t\t\tthis.valueControl.registerOnChange(NOOP_CONTROL_CHANGE);\n\t\t\t}\n\t\t\tthis._valueControl = valueControl;\n\t\t\tthis._valueControl?.registerOnChange((value: any) => this.onValueControlChange(value));\n\t\t}\n\t\tprivate onValueControlChange(value: any) {\n\t\t\tthis._internals.setFormValue(value);\n\t\t\tthis.value = value;\n\t\t\tthis.dispatchEvent(new Event('change', { bubbles: true, cancelable: true, composed: true }));\n\t\t}\n\n\t\tformAssociatedCallback(form: HTMLFormElement | null): void {\n\t\t\tthis._form = form;\n\t\t}\n\t\tformDisabledCallback(disabled: boolean): void {\n\t\t\tthis._valueControl?.setDisabledState?.(disabled);\n\t\t}\n\t\tformResetCallback(): void {\n\t\t\tthis._valueControl?.writeValue({ mode: 'reset' });\n\t\t}\n\t\tformStateRestoreCallback(value: any, mode: 'restore' | 'autocomplete'): void {\n\t\t\tthis._valueControl?.writeValue({ value, mode });\n\t\t}\n\t}\n}\n"]}
@@ -42,3 +42,4 @@ export declare class ElementMutation {
42
42
  disconnect(): void;
43
43
  }
44
44
  export {};
45
+ //# sourceMappingURL=mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutation.d.ts","sourceRoot":"","sources":["../../../src/core/view/mutation.ts"],"names":[],"mappings":"AAAA,UAAU,uBAAuB;IAChC,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;CACnC;AAED,UAAU,kBAAkB;IAC3B,IAAI,IAAI,CAAC;CACT;AAGD,qBAAa,kBAAkB;IAC9B,OAAO,CAAC,UAAU,CAAgD;IAClE,OAAO,CAAC,MAAM,CAA6C;IAC3D,OAAO,CAAC,MAAM,CAA6C;IAE3D,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAG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AAE,MAAM,EAAE,QAAQ,EAAE,uBAAuB,GAAG,oBAAoB;IAUvG,qBAAqB,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,kBAAkB,GAAG,oBAAoB;IAUnG,qBAAqB,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,kBAAkB,GAAG,oBAAoB;IAUnG,UAAU;CAKV"}
package/view/mutation.js CHANGED
@@ -1,9 +1,7 @@
1
1
  export class MutationObservable {
2
- constructor() {
3
- this.attributes = new Map();
4
- this.remove = new WeakMap();
5
- this.insert = new WeakMap();
6
- }
2
+ attributes = new Map();
3
+ remove = new WeakMap();
4
+ insert = new WeakMap();
7
5
  emit(attributeName, value, oldValue) {
8
6
  const calls = this.attributes.get(attributeName);
9
7
  calls?.forEach(callback => {
@@ -85,6 +83,10 @@ export class MutationObservable {
85
83
  }
86
84
  }
87
85
  export class MutationSubscription {
86
+ observable;
87
+ key;
88
+ callback;
89
+ type;
88
90
  constructor(observable, key, callback) {
89
91
  this.observable = observable;
90
92
  this.key = key;
@@ -103,33 +105,37 @@ export class MutationSubscription {
103
105
  }
104
106
  }
105
107
  }
106
- export class ElementMutation {
107
- constructor() {
108
- this.observables = new WeakMap();
109
- this.mutationCallback = (mutations, observer) => {
110
- mutations.forEach((mut) => {
111
- switch (mut.type) {
112
- case 'childList':
113
- {
114
- // insert/remove events
115
- if (mut.removedNodes.length > 0 && this.observables.has(mut.target)) {
116
- const observable = this.observables.get(mut.target);
117
- mut.removedNodes.forEach(node => observable.emitNodeRemove(node));
118
- }
119
- }
120
- break;
121
- case 'attributes':
122
- default:
123
- {
108
+ class ElementMutation {
109
+ static Mutation_OPTIONS = {
110
+ attributes: true,
111
+ childList: true,
112
+ subtree: true,
113
+ attributeOldValue: true,
114
+ };
115
+ observables = new WeakMap();
116
+ mutationCallback = (mutations, observer) => {
117
+ mutations.forEach((mut) => {
118
+ switch (mut.type) {
119
+ case 'childList':
120
+ {
121
+ // insert/remove events
122
+ if (mut.removedNodes.length > 0 && this.observables.has(mut.target)) {
124
123
  const observable = this.observables.get(mut.target);
125
- observable && observable.emit(mut.attributeName, mut.target.nodeValue, mut.oldValue);
124
+ mut.removedNodes.forEach(node => observable.emitNodeRemove(node));
126
125
  }
127
- break;
128
- }
129
- });
130
- };
131
- this.mutationObserver = new MutationObserver(this.mutationCallback);
132
- }
126
+ }
127
+ break;
128
+ case 'attributes':
129
+ default:
130
+ {
131
+ const observable = this.observables.get(mut.target);
132
+ observable && observable.emit(mut.attributeName, mut.target.nodeValue, mut.oldValue);
133
+ }
134
+ break;
135
+ }
136
+ });
137
+ };
138
+ mutationObserver = new MutationObserver(this.mutationCallback);
133
139
  subscribe(target, attributeName, callback) {
134
140
  let observable = this.observables.get(target);
135
141
  if (!observable) {
@@ -163,10 +169,5 @@ export class ElementMutation {
163
169
  this.mutationCallback(records, this.mutationObserver);
164
170
  }
165
171
  }
166
- ElementMutation.Mutation_OPTIONS = {
167
- attributes: true,
168
- childList: true,
169
- subtree: true,
170
- attributeOldValue: true,
171
- };
172
+ export { ElementMutation };
172
173
  //# sourceMappingURL=mutation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mutation.js","sourceRoot":"","sources":["../../../src/core/view/mutation.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,kBAAkB;IAA/B;QACS,eAAU,GAAG,IAAI,GAAG,EAAqC,CAAC;QAC1D,WAAM,GAAG,IAAI,OAAO,EAA8B,CAAC;QACnD,WAAM,GAAG,IAAI,OAAO,EAA8B,CAAC;IA8F5D,CAAC;IA5FA,IAAI,CAAC,aAAqB,EAAE,KAAU,EAAE,QAAc;QACrD,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAEjD,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE;YACzB,IAAI;gBACH,QAAQ,CAAC,KAAK,EAAE,QAAQ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IACb,iBAAiB,EAAE,IAAI;CACvB,CAAC","sourcesContent":["interface AttributeChangeCallback {\n\t(value: any, oldValue?: any): void;\n}\n\ninterface NodeRemoveCallback {\n\t(): void;\n}\n\n\nexport class MutationObservable {\n\tprivate attributes = new Map<string, AttributeChangeCallback[]>();\n\tprivate remove = new WeakMap<Node, NodeRemoveCallback[]>();\n\tprivate insert = new WeakMap<Node, NodeRemoveCallback[]>();\n\n\temit(attributeName: string, value: any, oldValue?: any): void {\n\t\tconst calls = this.attributes.get(attributeName);\n\n\t\tcalls?.forEach(callback => {\n\t\t\ttry {\n\t\t\t\tcallback(value, oldValue);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(error);\n\t\t\t}\n\t\t});\n\n\t}\n\n\temitNodeRemove(node: Node): void {\n\t\tthis.emitNode(this.remove, node);\n\t}\n\n\temitNodeInsert(node: Node): void {\n\t\tthis.emitNode(this.insert, node);\n\t}\n\n\tprivate emitNode(actionMap: WeakMap<Node, NodeRemoveCallback[]>, node: Node): void {\n\t\tconst calls = actionMap.get(node);\n\n\t\tcalls?.forEach(callback => {\n\t\t\ttry {\n\t\t\t\tcallback();\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(error);\n\t\t\t}\n\t\t});\n\t}\n\n\tsubscribe(attributeName: string, callback: AttributeChangeCallback): MutationSubscription {\n\t\tlet calls = this.attributes.get(attributeName);\n\t\tif (!calls) {\n\t\t\tcalls = [];\n\t\t\tthis.attributes.set(attributeName, calls);\n\t\t}\n\t\tcalls.push(callback);\n\t\treturn new MutationSubscription(this, attributeName, callback);\n\t}\n\n\tsubscribeOnRemoveNode(node: Node, callback: NodeRemoveCallback): MutationSubscription {\n\t\treturn this.subscribeNodeAction(this.remove, node, callback);\n\t}\n\n\tsubscribeOnInsertNode(node: Node, callback: NodeRemoveCallback): MutationSubscription {\n\t\treturn this.subscribeNodeAction(this.insert, node, callback);\n\t}\n\n\tprivate subscribeNodeAction(actionMap: WeakMap<Node, NodeRemoveCallback[]>, node: Node, callback: NodeRemoveCallback): MutationSubscription {\n\t\tlet calls = actionMap.get(node);\n\t\tif (!calls) {\n\t\t\tcalls = [];\n\t\t\tactionMap.set(node, calls);\n\t\t}\n\t\tcalls.push(callback);\n\t\treturn new MutationSubscription(this, new WeakRef(node), callback);\n\t}\n\n\tunsubscribe(eventName: string, callback: AttributeChangeCallback): void {\n\t\tconst calls = this.attributes.get(eventName);\n\t\tif (calls) {\n\t\t\tconst index = calls.indexOf(callback);\n\t\t\tif (index !== -1) {\n\t\t\t\tcalls.splice(index, 1);\n\t\t\t}\n\t\t}\n\t}\n\n\tunsubscribeOnRemoveNode(node: Node, callback: NodeRemoveCallback): void {\n\t\tthis.unsubscribeNodeAction(this.remove, node, callback);\n\t}\n\n\tunsubscribeOnInsertNode(node: Node, callback: NodeRemoveCallback): void {\n\t\tthis.unsubscribeNodeAction(this.insert, node, callback);\n\t}\n\n\tprivate unsubscribeNodeAction(actionMap: WeakMap<Node, NodeRemoveCallback[]>, node: Node, callback: NodeRemoveCallback): void {\n\t\tconst calls = actionMap.get(node);\n\t\tif (calls) {\n\t\t\tconst index = calls.indexOf(callback);\n\t\t\tif (index !== -1) {\n\t\t\t\tcalls.splice(index, 1);\n\t\t\t}\n\t\t}\n\t}\n\n\tdestroy() {\n\t\tthis.attributes.clear();\n\t}\n}\n\nexport class MutationSubscription {\n\n\tprivate type: 'attribute' | 'remove';\n\tconstructor(observable: MutationObservable, node: WeakRef<Node>, callback: NodeRemoveCallback);\n\tconstructor(observable: MutationObservable, attributeName: string, callback: AttributeChangeCallback);\n\n\tconstructor(private observable: MutationObservable, private key: string | WeakRef<Node>, private callback: AttributeChangeCallback | NodeRemoveCallback) {\n\t\tthis.type = typeof key === 'string' ? 'attribute' : 'remove';\n\t}\n\n\tunsubscribe() {\n\t\tif (this.type === 'attribute') {\n\t\t\tthis.observable.unsubscribe(this.key as string, this.callback as AttributeChangeCallback);\n\t\t} else {\n\t\t\tconst ref = (this.key as WeakRef<Node>).deref();\n\t\t\tif (ref) {\n\t\t\t\tthis.observable.unsubscribeOnRemoveNode(ref, this.callback as NodeRemoveCallback);\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n\nexport class ElementMutation {\n\n\tprivate static Mutation_OPTIONS: MutationObserverInit = {\n\t\tattributes: true,\n\t\tchildList: true,\n\t\tsubtree: true,\n\t\tattributeOldValue: true,\n\t};\n\n\tprivate observables: WeakMap<Node, MutationObservable> = new WeakMap();\n\tprivate mutationCallback: MutationCallback = (mutations: MutationRecord[], observer: MutationObserver) => {\n\t\tmutations.forEach((mut) => {\n\t\t\tswitch (mut.type) {\n\t\t\t\tcase 'childList':\n\t\t\t\t\t{\n\t\t\t\t\t\t// insert/remove events\n\t\t\t\t\t\tif (mut.removedNodes.length > 0 && this.observables.has(mut.target)) {\n\t\t\t\t\t\t\tconst observable = this.observables.get(mut.target)!;\n\t\t\t\t\t\t\tmut.removedNodes.forEach(node => observable.emitNodeRemove(node));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'attributes':\n\t\t\t\tdefault:\n\t\t\t\t\t{\n\t\t\t\t\t\tconst observable = this.observables.get(mut.target);\n\t\t\t\t\t\tobservable && observable.emit(mut.attributeName as string, mut.target.nodeValue, mut.oldValue);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t});\n\t};\n\tprivate mutationObserver: MutationObserver = new MutationObserver(this.mutationCallback);\n\n\tsubscribe(target: Node, attributeName: string, callback: AttributeChangeCallback): MutationSubscription {\n\t\tlet observable = this.observables.get(target);\n\t\tif (!observable) {\n\t\t\tobservable = new MutationObservable();\n\t\t\tthis.observables.set(target, observable);\n\t\t\tthis.mutationObserver.observe(target, ElementMutation.Mutation_OPTIONS);\n\t\t}\n\t\treturn observable.subscribe(attributeName, callback);\n\t}\n\n\tsubscribeOnRemoveNode(target: Node, node: Node, callback: NodeRemoveCallback): MutationSubscription {\n\t\tlet observable = this.observables.get(target);\n\t\tif (!observable) {\n\t\t\tobservable = new MutationObservable();\n\t\t\tthis.observables.set(target, observable);\n\t\t\tthis.mutationObserver.observe(target, ElementMutation.Mutation_OPTIONS);\n\t\t}\n\t\treturn observable.subscribeOnRemoveNode(node, callback);\n\t}\n\n\tsubscribeOnInsertNode(target: Node, node: Node, callback: NodeRemoveCallback): MutationSubscription {\n\t\tlet observable = this.observables.get(target);\n\t\tif (!observable) {\n\t\t\tobservable = new MutationObservable();\n\t\t\tthis.observables.set(target, observable);\n\t\t\tthis.mutationObserver.observe(target, ElementMutation.Mutation_OPTIONS);\n\t\t}\n\t\treturn observable.subscribeOnInsertNode(node, callback);\n\t}\n\n\tdisconnect() {\n\t\tconst records = this.mutationObserver.takeRecords();\n\t\tthis.mutationObserver.disconnect();\n\t\tthis.mutationCallback(records, this.mutationObserver);\n\t}\n}\n"]}
1
+ {"version":3,"file":"mutation.js","sourceRoot":"","sources":["../../../src/core/view/mutation.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,kBAAkB;IACtB,UAAU,GAAG,IAAI,GAAG,EAAqC,CAAC;IAC1D,MAAM,GAAG,IAAI,OAAO,EAA8B,CAAC;IACnD,MAAM,GAAG,IAAI,OAAO,EAA8B,CAAC;IAE3D,IAAI,CAAC,aAAqB,EAAE,KAAU,EAAE,QAAc;QACrD,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAEjD,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE;YACzB,IAAI;gBACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;aAC1B;YAAC,OAAO,KAAK,EAAE;gBACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aACrB;QACF,CAAC,CAAC,CAAC;IAEJ,CAAC;IAED,cAAc,CAAC,IAAU;QACxB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;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AAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,CAAC,UAAU,EAAE;YAChB,UAAU,GAAG,IAAI,kBAAkB,EAAE,CAAC;YACtC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;YACzC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAC;SACxE;QACD,OAAO,UAAU,CAAC,qBAAqB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC;IAED,qBAAqB,CAAC,MAAY,EAAE,IAAU,EAAE,QAA4B;QAC3E,IAAI,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,CAAC,UAAU,EAAE;YAChB,UAAU,GAAG,IAAI,kBAAkB,EAAE,CAAC;YACtC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;YACzC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAC;SACxE;QACD,OAAO,UAAU,CAAC,qBAAqB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC;IAED,UAAU;QACT,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC;QACpD,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC;QACnC,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACvD,CAAC;;SApEW,eAAe","sourcesContent":["interface AttributeChangeCallback {\n\t(value: any, oldValue?: any): void;\n}\n\ninterface NodeRemoveCallback {\n\t(): void;\n}\n\n\nexport class MutationObservable {\n\tprivate attributes = new Map<string, AttributeChangeCallback[]>();\n\tprivate remove = new WeakMap<Node, NodeRemoveCallback[]>();\n\tprivate insert = new WeakMap<Node, NodeRemoveCallback[]>();\n\n\temit(attributeName: string, value: any, oldValue?: any): void {\n\t\tconst calls = this.attributes.get(attributeName);\n\n\t\tcalls?.forEach(callback => {\n\t\t\ttry {\n\t\t\t\tcallback(value, oldValue);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(error);\n\t\t\t}\n\t\t});\n\n\t}\n\n\temitNodeRemove(node: Node): void {\n\t\tthis.emitNode(this.remove, node);\n\t}\n\n\temitNodeInsert(node: Node): void {\n\t\tthis.emitNode(this.insert, node);\n\t}\n\n\tprivate emitNode(actionMap: WeakMap<Node, NodeRemoveCallback[]>, node: Node): void {\n\t\tconst calls = actionMap.get(node);\n\n\t\tcalls?.forEach(callback => {\n\t\t\ttry {\n\t\t\t\tcallback();\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(error);\n\t\t\t}\n\t\t});\n\t}\n\n\tsubscribe(attributeName: string, callback: AttributeChangeCallback): MutationSubscription {\n\t\tlet calls = this.attributes.get(attributeName);\n\t\tif (!calls) {\n\t\t\tcalls = [];\n\t\t\tthis.attributes.set(attributeName, calls);\n\t\t}\n\t\tcalls.push(callback);\n\t\treturn new MutationSubscription(this, attributeName, callback);\n\t}\n\n\tsubscribeOnRemoveNode(node: Node, callback: NodeRemoveCallback): MutationSubscription {\n\t\treturn this.subscribeNodeAction(this.remove, node, callback);\n\t}\n\n\tsubscribeOnInsertNode(node: Node, callback: NodeRemoveCallback): MutationSubscription {\n\t\treturn this.subscribeNodeAction(this.insert, node, callback);\n\t}\n\n\tprivate subscribeNodeAction(actionMap: WeakMap<Node, NodeRemoveCallback[]>, node: Node, callback: NodeRemoveCallback): MutationSubscription {\n\t\tlet calls = actionMap.get(node);\n\t\tif (!calls) {\n\t\t\tcalls = [];\n\t\t\tactionMap.set(node, calls);\n\t\t}\n\t\tcalls.push(callback);\n\t\treturn new MutationSubscription(this, new WeakRef(node), callback);\n\t}\n\n\tunsubscribe(eventName: string, callback: AttributeChangeCallback): void {\n\t\tconst calls = this.attributes.get(eventName);\n\t\tif (calls) {\n\t\t\tconst index = calls.indexOf(callback);\n\t\t\tif (index !== -1) {\n\t\t\t\tcalls.splice(index, 1);\n\t\t\t}\n\t\t}\n\t}\n\n\tunsubscribeOnRemoveNode(node: Node, callback: NodeRemoveCallback): void {\n\t\tthis.unsubscribeNodeAction(this.remove, node, callback);\n\t}\n\n\tunsubscribeOnInsertNode(node: Node, callback: NodeRemoveCallback): void {\n\t\tthis.unsubscribeNodeAction(this.insert, node, callback);\n\t}\n\n\tprivate unsubscribeNodeAction(actionMap: WeakMap<Node, NodeRemoveCallback[]>, node: Node, callback: NodeRemoveCallback): void {\n\t\tconst calls = actionMap.get(node);\n\t\tif (calls) {\n\t\t\tconst index = calls.indexOf(callback);\n\t\t\tif (index !== -1) {\n\t\t\t\tcalls.splice(index, 1);\n\t\t\t}\n\t\t}\n\t}\n\n\tdestroy() {\n\t\tthis.attributes.clear();\n\t}\n}\n\nexport class MutationSubscription {\n\n\tprivate type: 'attribute' | 'remove';\n\tconstructor(observable: MutationObservable, node: WeakRef<Node>, callback: NodeRemoveCallback);\n\tconstructor(observable: MutationObservable, attributeName: string, callback: AttributeChangeCallback);\n\n\tconstructor(private observable: MutationObservable, private key: string | WeakRef<Node>, private callback: AttributeChangeCallback | NodeRemoveCallback) {\n\t\tthis.type = typeof key === 'string' ? 'attribute' : 'remove';\n\t}\n\n\tunsubscribe() {\n\t\tif (this.type === 'attribute') {\n\t\t\tthis.observable.unsubscribe(this.key as string, this.callback as AttributeChangeCallback);\n\t\t} else {\n\t\t\tconst ref = (this.key as WeakRef<Node>).deref();\n\t\t\tif (ref) {\n\t\t\t\tthis.observable.unsubscribeOnRemoveNode(ref, this.callback as NodeRemoveCallback);\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n\nexport class ElementMutation {\n\n\tprivate static Mutation_OPTIONS: MutationObserverInit = {\n\t\tattributes: true,\n\t\tchildList: true,\n\t\tsubtree: true,\n\t\tattributeOldValue: true,\n\t};\n\n\tprivate observables: WeakMap<Node, MutationObservable> = new WeakMap();\n\tprivate mutationCallback: MutationCallback = (mutations: MutationRecord[], observer: MutationObserver) => {\n\t\tmutations.forEach((mut) => {\n\t\t\tswitch (mut.type) {\n\t\t\t\tcase 'childList':\n\t\t\t\t\t{\n\t\t\t\t\t\t// insert/remove events\n\t\t\t\t\t\tif (mut.removedNodes.length > 0 && this.observables.has(mut.target)) {\n\t\t\t\t\t\t\tconst observable = this.observables.get(mut.target)!;\n\t\t\t\t\t\t\tmut.removedNodes.forEach(node => observable.emitNodeRemove(node));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'attributes':\n\t\t\t\tdefault:\n\t\t\t\t\t{\n\t\t\t\t\t\tconst observable = this.observables.get(mut.target);\n\t\t\t\t\t\tobservable && observable.emit(mut.attributeName as string, mut.target.nodeValue, mut.oldValue);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t});\n\t};\n\tprivate mutationObserver: MutationObserver = new MutationObserver(this.mutationCallback);\n\n\tsubscribe(target: Node, attributeName: string, callback: AttributeChangeCallback): MutationSubscription {\n\t\tlet observable = this.observables.get(target);\n\t\tif (!observable) {\n\t\t\tobservable = new MutationObservable();\n\t\t\tthis.observables.set(target, observable);\n\t\t\tthis.mutationObserver.observe(target, ElementMutation.Mutation_OPTIONS);\n\t\t}\n\t\treturn observable.subscribe(attributeName, callback);\n\t}\n\n\tsubscribeOnRemoveNode(target: Node, node: Node, callback: NodeRemoveCallback): MutationSubscription {\n\t\tlet observable = this.observables.get(target);\n\t\tif (!observable) {\n\t\t\tobservable = new MutationObservable();\n\t\t\tthis.observables.set(target, observable);\n\t\t\tthis.mutationObserver.observe(target, ElementMutation.Mutation_OPTIONS);\n\t\t}\n\t\treturn observable.subscribeOnRemoveNode(node, callback);\n\t}\n\n\tsubscribeOnInsertNode(target: Node, node: Node, callback: NodeRemoveCallback): MutationSubscription {\n\t\tlet observable = this.observables.get(target);\n\t\tif (!observable) {\n\t\t\tobservable = new MutationObservable();\n\t\t\tthis.observables.set(target, observable);\n\t\t\tthis.mutationObserver.observe(target, ElementMutation.Mutation_OPTIONS);\n\t\t}\n\t\treturn observable.subscribeOnInsertNode(node, callback);\n\t}\n\n\tdisconnect() {\n\t\tconst records = this.mutationObserver.takeRecords();\n\t\tthis.mutationObserver.disconnect();\n\t\tthis.mutationCallback(records, this.mutationObserver);\n\t}\n}\n"]}
package/view/render.d.ts CHANGED
@@ -15,7 +15,6 @@ export declare class ComponentRender<T extends object> {
15
15
  isTemplateRefName(template: DomNode): template is DomElementNode;
16
16
  initTemplateRefMap(domNode: DomNode): void;
17
17
  initViewBinding(): void;
18
- addNativeEventListener(source: HTMLElement | Window, eventName: string, funcCallback: Function): void;
19
18
  getElementByName(name: string): any;
20
19
  createStructuralDirective(directive: DomStructuralDirectiveNode, comment: Comment, directiveStack: Stack, subscriptions: ScopeSubscription<Context>[], parentNode: Node, host: HTMLComponent<any> | StructuralDirective): void;
21
20
  createComment(node: CommentNode): Comment;
@@ -47,5 +46,6 @@ export declare class ComponentRender<T extends object> {
47
46
  initHtmlElement(element: HTMLElement, node: DomElementNode, contextStack: Stack, subscriptions: ScopeSubscription<Context>[], host: HTMLComponent<any> | StructuralDirective): void;
48
47
  private initAttributeDirectives;
49
48
  initAttribute(element: HTMLElement, node: DomElementNode, contextStack: Stack): ScopeSubscription<Context>[];
50
- initStructuralDirective(directive: StructuralDirective | AttributeDirective | AttributeOnStructuralDirective, node: DomStructuralDirectiveNode | DomAttributeDirectiveNode, contextStack: Stack): ScopeSubscription<Context>[];
49
+ initDirective(directive: StructuralDirective | AttributeDirective | AttributeOnStructuralDirective, node: DomStructuralDirectiveNode | DomAttributeDirectiveNode, contextStack: Stack): ScopeSubscription<Context>[];
51
50
  }
51
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","s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,EAAE,EAAE,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,mBAAmB,GAAG,IAAI;IAqCnL,OAAO,CAAC,uBAAuB;IAyC/B,aAAa,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,KAAK,GAAG,iBAAiB,CAAC,OAAO,CAAC,EAAE;IAwE5G,aAAa,CACZ,SAAS,EAAE,mBAAmB,GAAG,kBAAkB,GAAG,8BAA8B,EACpF,IAAI,EAAE,0BAA0B,GAAG,yBAAyB,EAC5D,YAAY,EAAE,KAAK,GAAG,iBAAiB,CAAC,OAAO,CAAC,EAAE;CA6CnD"}
package/view/render.js CHANGED
@@ -22,10 +22,16 @@ function getChangeEventName(tagName) {
22
22
  }
23
23
  }
24
24
  export class ComponentRender {
25
+ view;
26
+ subscriptions;
27
+ componentRef;
28
+ template;
29
+ contextStack;
30
+ templateNameScope;
31
+ viewScope = new ReactiveScope({});
25
32
  constructor(view, subscriptions) {
26
33
  this.view = view;
27
34
  this.subscriptions = subscriptions;
28
- this.viewScope = new ReactiveScope({});
29
35
  this.componentRef = this.view.getComponentRef();
30
36
  this.contextStack = documentStack.copyStack();
31
37
  this.contextStack.pushScope(this.view._modelScope);
@@ -43,13 +49,8 @@ export class ComponentRender {
43
49
  }
44
50
  let rootRef;
45
51
  if (this.componentRef.isShadowDom) {
46
- if (this.view.shadowRoot /* OPEN MODE */) {
47
- rootRef = this.view.shadowRoot;
48
- }
49
- else /* CLOSED MODE*/ {
50
- rootRef = Reflect.get(this.view, '_shadowRoot');
51
- Reflect.deleteProperty(this.view, '_shadowRoot');
52
- }
52
+ rootRef = Reflect.get(this.view, '_shadowRoot');
53
+ Reflect.deleteProperty(this.view, '_shadowRoot');
53
54
  }
54
55
  else {
55
56
  rootRef = this.view;
@@ -88,15 +89,12 @@ export class ComponentRender {
88
89
  }
89
90
  }
90
91
  initViewBinding() {
91
- if (!this.componentRef.viewBindings) {
92
- return;
92
+ if (this.componentRef.viewBindings) {
93
+ this.initHtmlElement(this.view, this.componentRef.viewBindings, this.contextStack, this.subscriptions);
94
+ }
95
+ if (this.componentRef.windowBindings) {
96
+ this.subscriptions.push(...this.initAttribute(window, this.componentRef.windowBindings, this.contextStack));
93
97
  }
94
- this.initHtmlElement(this.view, this.componentRef.viewBindings, this.contextStack, this.subscriptions);
95
- }
96
- addNativeEventListener(source, eventName, funcCallback) {
97
- source.addEventListener(eventName, (event) => {
98
- this.view._zone.run(funcCallback, this.view._model);
99
- });
100
98
  }
101
99
  getElementByName(name) {
102
100
  return Reflect.get(this.view, name);
@@ -123,8 +121,7 @@ export class ComponentRender {
123
121
  templateRef.host = structural;
124
122
  const scope = ReactiveScope.readOnlyScopeForThis(structural);
125
123
  stack.pushScope(scope);
126
- const dSubs = this.initStructuralDirective(structural, directive, stack);
127
- subscriptions.push(...dSubs);
124
+ subscriptions.push(...this.initDirective(structural, directive, stack));
128
125
  if (isOnInit(structural)) {
129
126
  directiveZone.run(structural.onInit, structural);
130
127
  }
@@ -236,6 +233,7 @@ export class ComponentRender {
236
233
  const inputScope = elementScope.getInnerScope('this');
237
234
  const listener = (event) => inputScope.emit('value', element.value);
238
235
  element.addEventListener(changeEventName, listener);
236
+ subscriptions.push(createSubscriptionDestroyer(() => element.removeEventListener(changeEventName, listener)));
239
237
  }
240
238
  const templateRefName = node.templateRefName;
241
239
  if (templateRefName) {
@@ -267,7 +265,7 @@ export class ComponentRender {
267
265
  const directive = directiveZone.run(() => new directiveRef.modelClass(element, directiveZone));
268
266
  const stack = contextStack.copyStack();
269
267
  const thisScope = stack.pushReactiveScopeFor({ 'this': directive });
270
- const directiveSubscriptions = this.initStructuralDirective(directive, directiveNode, stack);
268
+ const directiveSubscriptions = this.initDirective(directive, directiveNode, stack);
271
269
  subscriptions.push(...directiveSubscriptions);
272
270
  if (isOnInit(directive)) {
273
271
  directiveZone.run(directive.onInit, directive);
@@ -352,6 +350,7 @@ export class ComponentRender {
352
350
  listener = event.value;
353
351
  }
354
352
  element.addEventListener(event.name, listener);
353
+ subscriptions.push(createSubscriptionDestroyer(() => element.removeEventListener(event.name, listener)));
355
354
  });
356
355
  }
357
356
  if (node.templateAttrs?.length) {
@@ -363,7 +362,7 @@ export class ComponentRender {
363
362
  }
364
363
  return subscriptions;
365
364
  }
366
- initStructuralDirective(directive, node, contextStack) {
365
+ initDirective(directive, node, contextStack) {
367
366
  const subscriptions = [];
368
367
  if (node.attributes?.length) {
369
368
  node.attributes.forEach(attr => Reflect.set(directive, attr.name, attr.value));
@@ -389,7 +388,8 @@ export class ComponentRender {
389
388
  stack.pushBlockScopeFor({ $event });
390
389
  this.view._zone.run(event.expression.get, event.expression, [stack]);
391
390
  };
392
- directive[event.name].subscribe(listener);
391
+ const subscription = directive[event.name].subscribe(listener);
392
+ subscriptions.push(createSubscriptionDestroyer(() => directive[event.name].remove(subscription)));
393
393
  });
394
394
  }
395
395
  if (node.templateAttrs?.length) {