@rxap/remote-method 12.0.9-next.0 → 13.0.0-next.1

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 (125) hide show
  1. package/directive/package.json +5 -5
  2. package/esm2020/directive/lib/error.mjs +7 -0
  3. package/esm2020/directive/lib/remote-method-template-collection.directive.mjs +333 -0
  4. package/esm2020/directive/lib/remote-method-template.directive.mjs +201 -0
  5. package/esm2020/directive/lib/remote-method.directive.mjs +165 -0
  6. package/esm2020/directive/lib/tokens.mjs +3 -0
  7. package/esm2020/directive/public_api.mjs +6 -0
  8. package/esm2020/directive/rxap-remote-method-directive.mjs +5 -0
  9. package/esm2020/http/directive/lib/contenteditable.directive.mjs +86 -0
  10. package/esm2020/http/directive/lib/http-remote-method.directive.mjs +79 -0
  11. package/esm2020/http/directive/public_api.mjs +3 -0
  12. package/esm2020/http/directive/rxap-remote-method-http-directive.mjs +5 -0
  13. package/esm2020/http/lib/base-http.remote-method.mjs +82 -0
  14. package/esm2020/http/lib/http-remote-method.loader.mjs +30 -0
  15. package/esm2020/http/lib/http.remote-method.mjs +45 -0
  16. package/esm2020/http/public_api.mjs +4 -0
  17. package/esm2020/http/rxap-remote-method-http.mjs +5 -0
  18. package/esm2020/index.mjs +6 -0
  19. package/esm2020/lib/base.remote-method.mjs +73 -0
  20. package/esm2020/lib/error.mjs +7 -0
  21. package/esm2020/lib/proxy.remote-method.mjs +29 -0
  22. package/esm2020/lib/remote-method-loader.mjs +17 -0
  23. package/esm2020/lib/tokens.mjs +4 -0
  24. package/esm2020/rxap-remote-method.mjs +5 -0
  25. package/esm2020/testing/lib/remote-method-testing-loader.mjs +47 -0
  26. package/esm2020/testing/public_api.mjs +2 -0
  27. package/esm2020/testing/rxap-remote-method-testing.mjs +5 -0
  28. package/fesm2015/rxap-remote-method-directive.mjs +712 -0
  29. package/fesm2015/rxap-remote-method-directive.mjs.map +1 -0
  30. package/fesm2015/rxap-remote-method-http-directive.mjs +172 -0
  31. package/fesm2015/rxap-remote-method-http-directive.mjs.map +1 -0
  32. package/fesm2015/rxap-remote-method-http.mjs +158 -0
  33. package/fesm2015/rxap-remote-method-http.mjs.map +1 -0
  34. package/fesm2015/{rxap-remote-method-testing.js → rxap-remote-method-testing.mjs} +1 -1
  35. package/fesm2015/rxap-remote-method-testing.mjs.map +1 -0
  36. package/fesm2015/{rxap-remote-method.js → rxap-remote-method.mjs} +35 -31
  37. package/fesm2015/rxap-remote-method.mjs.map +1 -0
  38. package/{fesm2015/rxap-remote-method-directive.js → fesm2020/rxap-remote-method-directive.mjs} +64 -72
  39. package/fesm2020/rxap-remote-method-directive.mjs.map +1 -0
  40. package/{fesm2015/rxap-remote-method-http-directive.js → fesm2020/rxap-remote-method-http-directive.mjs} +15 -15
  41. package/fesm2020/rxap-remote-method-http-directive.mjs.map +1 -0
  42. package/{fesm2015/rxap-remote-method-http.js → fesm2020/rxap-remote-method-http.mjs} +18 -16
  43. package/fesm2020/rxap-remote-method-http.mjs.map +1 -0
  44. package/{esm2015/testing/lib/remote-method-testing-loader.js → fesm2020/rxap-remote-method-testing.mjs} +18 -17
  45. package/fesm2020/rxap-remote-method-testing.mjs.map +1 -0
  46. package/fesm2020/rxap-remote-method.mjs +126 -0
  47. package/fesm2020/rxap-remote-method.mjs.map +1 -0
  48. package/http/directive/package.json +5 -5
  49. package/http/package.json +5 -5
  50. package/package.json +62 -14
  51. package/src/schematics/base/index.js +9 -9
  52. package/src/schematics/base/index.js.map +1 -1
  53. package/src/schematics/directive/index.js +6 -6
  54. package/src/schematics/directive/index.js.map +1 -1
  55. package/src/schematics/http/index.js +7 -7
  56. package/src/schematics/http/index.js.map +1 -1
  57. package/src/schematics/ng-add/index.js +1 -1
  58. package/src/schematics/ng-add/index.js.map +1 -1
  59. package/testing/package.json +5 -5
  60. package/bundles/rxap-remote-method-directive.umd.js +0 -1150
  61. package/bundles/rxap-remote-method-directive.umd.js.map +0 -1
  62. package/bundles/rxap-remote-method-http-directive.umd.js +0 -565
  63. package/bundles/rxap-remote-method-http-directive.umd.js.map +0 -1
  64. package/bundles/rxap-remote-method-http.umd.js +0 -520
  65. package/bundles/rxap-remote-method-http.umd.js.map +0 -1
  66. package/bundles/rxap-remote-method-testing.umd.js +0 -388
  67. package/bundles/rxap-remote-method-testing.umd.js.map +0 -1
  68. package/bundles/rxap-remote-method.umd.js +0 -527
  69. package/bundles/rxap-remote-method.umd.js.map +0 -1
  70. package/esm2015/directive/lib/error.js +0 -7
  71. package/esm2015/directive/lib/error.js.map +0 -1
  72. package/esm2015/directive/lib/remote-method-template-collection.directive.js +0 -333
  73. package/esm2015/directive/lib/remote-method-template-collection.directive.js.map +0 -1
  74. package/esm2015/directive/lib/remote-method-template.directive.js +0 -204
  75. package/esm2015/directive/lib/remote-method-template.directive.js.map +0 -1
  76. package/esm2015/directive/lib/remote-method.directive.js +0 -170
  77. package/esm2015/directive/lib/remote-method.directive.js.map +0 -1
  78. package/esm2015/directive/lib/tokens.js +0 -3
  79. package/esm2015/directive/lib/tokens.js.map +0 -1
  80. package/esm2015/directive/public_api.js +0 -6
  81. package/esm2015/directive/public_api.js.map +0 -1
  82. package/esm2015/directive/rxap-remote-method-directive.js +0 -5
  83. package/esm2015/directive/rxap-remote-method-directive.js.map +0 -1
  84. package/esm2015/http/directive/lib/contenteditable.directive.js +0 -86
  85. package/esm2015/http/directive/lib/contenteditable.directive.js.map +0 -1
  86. package/esm2015/http/directive/lib/http-remote-method.directive.js +0 -79
  87. package/esm2015/http/directive/lib/http-remote-method.directive.js.map +0 -1
  88. package/esm2015/http/directive/public_api.js +0 -3
  89. package/esm2015/http/directive/public_api.js.map +0 -1
  90. package/esm2015/http/directive/rxap-remote-method-http-directive.js +0 -5
  91. package/esm2015/http/directive/rxap-remote-method-http-directive.js.map +0 -1
  92. package/esm2015/http/lib/base-http.remote-method.js +0 -79
  93. package/esm2015/http/lib/base-http.remote-method.js.map +0 -1
  94. package/esm2015/http/lib/http-remote-method.loader.js +0 -30
  95. package/esm2015/http/lib/http-remote-method.loader.js.map +0 -1
  96. package/esm2015/http/lib/http.remote-method.js +0 -46
  97. package/esm2015/http/lib/http.remote-method.js.map +0 -1
  98. package/esm2015/http/public_api.js +0 -4
  99. package/esm2015/http/public_api.js.map +0 -1
  100. package/esm2015/http/rxap-remote-method-http.js +0 -5
  101. package/esm2015/http/rxap-remote-method-http.js.map +0 -1
  102. package/esm2015/index.js +0 -6
  103. package/esm2015/index.js.map +0 -1
  104. package/esm2015/lib/base.remote-method.js +0 -76
  105. package/esm2015/lib/base.remote-method.js.map +0 -1
  106. package/esm2015/lib/error.js +0 -7
  107. package/esm2015/lib/error.js.map +0 -1
  108. package/esm2015/lib/proxy.remote-method.js +0 -32
  109. package/esm2015/lib/proxy.remote-method.js.map +0 -1
  110. package/esm2015/lib/remote-method-loader.js +0 -20
  111. package/esm2015/lib/remote-method-loader.js.map +0 -1
  112. package/esm2015/lib/tokens.js +0 -4
  113. package/esm2015/lib/tokens.js.map +0 -1
  114. package/esm2015/rxap-remote-method.js +0 -5
  115. package/esm2015/rxap-remote-method.js.map +0 -1
  116. package/esm2015/testing/lib/remote-method-testing-loader.js.map +0 -1
  117. package/esm2015/testing/public_api.js +0 -2
  118. package/esm2015/testing/public_api.js.map +0 -1
  119. package/esm2015/testing/rxap-remote-method-testing.js +0 -5
  120. package/esm2015/testing/rxap-remote-method-testing.js.map +0 -1
  121. package/fesm2015/rxap-remote-method-directive.js.map +0 -1
  122. package/fesm2015/rxap-remote-method-http-directive.js.map +0 -1
  123. package/fesm2015/rxap-remote-method-http.js.map +0 -1
  124. package/fesm2015/rxap-remote-method-testing.js.map +0 -1
  125. package/fesm2015/rxap-remote-method.js.map +0 -1
@@ -1,333 +0,0 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import { Directive, TemplateRef, Inject, Input, Injector, INJECTOR, ViewContainerRef, ChangeDetectorRef, NgModule, isDevMode, IterableDiffers, NgZone, Optional, Self } from '@angular/core';
3
- import { RemoteMethodLoader } from '@rxap/remote-method';
4
- import { Required } from '@rxap/utilities';
5
- import { tap, take } from 'rxjs/operators';
6
- import { RXAP_REMOTE_METHOD_DIRECTIVE_TOKEN } from './tokens';
7
- import * as i0 from "@angular/core";
8
- import * as i1 from "@rxap/remote-method";
9
- export class RemoteMethodTemplateCollectionDirectiveContext {
10
- constructor($implicit, index, count) {
11
- this.$implicit = $implicit;
12
- this.index = index;
13
- this.count = count;
14
- }
15
- get first() {
16
- return this.index === 0;
17
- }
18
- get last() {
19
- return this.index === this.count - 1;
20
- }
21
- get even() {
22
- return this.index % 2 === 0;
23
- }
24
- get odd() {
25
- return !this.even;
26
- }
27
- }
28
- function getTypeName(type) {
29
- return type['name'] || typeof type;
30
- }
31
- class RecordViewTuple {
32
- constructor(record, view) {
33
- this.record = record;
34
- this.view = view;
35
- }
36
- }
37
- export class RemoteMethodTemplateCollectionDirective {
38
- constructor(template, remoteMethodLoader, injector, viewContainerRef, cdr, differs, zone, remoteMethodToken) {
39
- this.template = template;
40
- this.remoteMethodLoader = remoteMethodLoader;
41
- this.injector = injector;
42
- this.viewContainerRef = viewContainerRef;
43
- this.cdr = cdr;
44
- this.differs = differs;
45
- this.zone = zone;
46
- this.remoteMethodToken = remoteMethodToken;
47
- this.withoutParameters = false;
48
- this._differ = null;
49
- /**
50
- * Holds the data that should be displayed
51
- * @private
52
- */
53
- this._data = null;
54
- this._dirty = true;
55
- /**
56
- * Indicates that the remote method returned a empty collection
57
- *
58
- * true - is empty
59
- * false - is NOT empty
60
- * null - unknown
61
- *
62
- * @private
63
- */
64
- this._empty = null;
65
- /**
66
- * Holds the error that call of the remote method throws
67
- *
68
- * @private
69
- */
70
- this._error = null;
71
- /**
72
- * Holds the empty template view ref.
73
- *
74
- * Is used to determine if a empty template is added to the
75
- * view. And used to destruct the empty template if the remote method
76
- * changes from empty to not empty.
77
- *
78
- * @private
79
- */
80
- this._emptyTemplateViewRef = null;
81
- /**
82
- * Holds the error template view ref.
83
- *
84
- * Is used to determine if a error template is added to the
85
- * view. And used to destruct the error template if the remote method
86
- * is called again with an error.
87
- *
88
- * @private
89
- */
90
- this._errorTemplateViewRef = null;
91
- if (this.remoteMethodToken) {
92
- this._remoteMethodOrIdOrToken = this.remoteMethodToken;
93
- }
94
- }
95
- /**
96
- * Asserts the correct type of the context for the template that `NgForOf` will render.
97
- *
98
- * The presence of this method is a signal to the Ivy template type-check compiler that the
99
- * `NgForOf` structural directive renders its template with a specific context type.
100
- */
101
- static ngTemplateContextGuard(dir, ctx) {
102
- return true;
103
- }
104
- set remoteMethodOrIdOrToken(value) {
105
- if (value) {
106
- this._remoteMethodOrIdOrToken = value;
107
- }
108
- }
109
- /**
110
- * A function that defines how to track changes for items in the iterable.
111
- *
112
- * When items are added, moved, or removed in the iterable,
113
- * the directive must re-render the appropriate DOM nodes.
114
- * To minimize churn in the DOM, only nodes that have changed
115
- * are re-rendered.
116
- *
117
- * By default, the change detector assumes that
118
- * the object instance identifies the node in the iterable.
119
- * When this function is supplied, the directive uses
120
- * the result of calling this function to identify the item node,
121
- * rather than the identity of the object itself.
122
- *
123
- * The function receives two inputs,
124
- * the iteration index and the node object ID.
125
- */
126
- set trackBy(fn) {
127
- if (isDevMode() && fn != null && typeof fn !== 'function') {
128
- // TODO(vicb): use a log service once there is a public one available
129
- if (console && console.warn) {
130
- console.warn(`trackBy must be a function, but received ${JSON.stringify(fn)}. ` +
131
- `See https://angular.io/api/common/NgForOf#change-propagation for more information.`);
132
- }
133
- }
134
- this._trackByFn = fn;
135
- }
136
- get trackBy() {
137
- return this._trackByFn;
138
- }
139
- set data(data) {
140
- this._data = data;
141
- this._dirty = true;
142
- }
143
- ngOnChanges(changes) {
144
- const parametersChanges = changes.parameters;
145
- if (parametersChanges) {
146
- this.call(parametersChanges.currentValue);
147
- }
148
- }
149
- ngOnInit() {
150
- if (this.withoutParameters) {
151
- this.call();
152
- }
153
- }
154
- call(parameters) {
155
- this.zone.onStable.pipe(take(1), tap(() => {
156
- this.zone.run(() => {
157
- this.remoteMethodLoader
158
- .call$(this._remoteMethodOrIdOrToken, parameters, undefined, this.injector)
159
- .then(response => {
160
- this._empty = response.length === 0;
161
- this._data = response;
162
- this.cdr.detectChanges();
163
- })
164
- .catch(error => {
165
- this._error = error;
166
- this.cdr.detectChanges();
167
- });
168
- });
169
- })).subscribe();
170
- }
171
- applyChanges(changes) {
172
- const insertTuples = [];
173
- changes.forEachOperation((item, adjustedPreviousIndex, currentIndex) => {
174
- if (item.previousIndex == null) {
175
- // NgForOf is never "null" or "undefined" here because the differ detected
176
- // that a new item needs to be inserted from the iterable. This implies that
177
- // there is an iterable value for "_ngForOf".
178
- const view = this.viewContainerRef.createEmbeddedView(this.template, new RemoteMethodTemplateCollectionDirectiveContext(null, -1, -1), currentIndex === null ? undefined : currentIndex);
179
- const tuple = new RecordViewTuple(item, view);
180
- insertTuples.push(tuple);
181
- }
182
- else if (currentIndex == null) {
183
- this.viewContainerRef.remove(adjustedPreviousIndex === null ? undefined : adjustedPreviousIndex);
184
- }
185
- else if (adjustedPreviousIndex !== null) {
186
- const view = this.viewContainerRef.get(adjustedPreviousIndex);
187
- this.viewContainerRef.move(view, currentIndex);
188
- const tuple = new RecordViewTuple(item, view);
189
- insertTuples.push(tuple);
190
- }
191
- });
192
- for (let i = 0; i < insertTuples.length; i++) {
193
- this.perViewChange(insertTuples[i].view, insertTuples[i].record);
194
- }
195
- for (let i = 0, ilen = this.viewContainerRef.length; i < ilen; i++) {
196
- const viewRef = this.viewContainerRef.get(i);
197
- viewRef.context.index = i;
198
- viewRef.context.count = ilen;
199
- }
200
- changes.forEachIdentityChange((record) => {
201
- const viewRef = this.viewContainerRef.get(record.currentIndex);
202
- viewRef.context.$implicit = record.item;
203
- });
204
- }
205
- perViewChange(view, record) {
206
- view.context.$implicit = record.item;
207
- }
208
- /**
209
- * Applies the changes when needed.
210
- */
211
- ngDoCheck() {
212
- if (this._error !== null) {
213
- this.viewContainerRef.clear();
214
- this._differ = null;
215
- if (this.errorTemplate) {
216
- this._errorTemplateViewRef = this.viewContainerRef.createEmbeddedView(this.errorTemplate, { $implicit: this._error, message: this._error.message, name: this._error.name });
217
- }
218
- }
219
- else if (this._empty === true) {
220
- this.viewContainerRef.clear();
221
- this._differ = null;
222
- // attaches the empty template if the data source is empty
223
- if (this.emptyTemplate) {
224
- this._emptyTemplateViewRef = this.viewContainerRef.createEmbeddedView(this.emptyTemplate);
225
- }
226
- }
227
- else if (this._empty === false) {
228
- // detach and destroy the empty template if the data source is not
229
- // empty any more
230
- if (this._emptyTemplateViewRef) {
231
- this._emptyTemplateViewRef.detach();
232
- this._emptyTemplateViewRef.destroy();
233
- this._errorTemplateViewRef = null;
234
- }
235
- if (this._errorTemplateViewRef) {
236
- this._errorTemplateViewRef.detach();
237
- this._errorTemplateViewRef.destroy();
238
- this._errorTemplateViewRef = null;
239
- }
240
- if (this._data) {
241
- this._dirty = false;
242
- // React on ngForOf changes only once all inputs have been initialized
243
- const value = this._data;
244
- if (!this._differ && value) {
245
- try {
246
- this._differ = this.differs.find(value).create(this.trackBy);
247
- }
248
- catch (_a) {
249
- throw new Error(`Cannot find a differ supporting object '${value}' of type '${getTypeName(value)}'. NgFor only supports binding to Iterables such as Arrays.`);
250
- }
251
- }
252
- }
253
- if (this._differ) {
254
- const changes = this._differ.diff(this._data);
255
- if (changes) {
256
- this.applyChanges(changes);
257
- }
258
- }
259
- }
260
- }
261
- }
262
- RemoteMethodTemplateCollectionDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.1", ngImport: i0, type: RemoteMethodTemplateCollectionDirective, deps: [{ token: TemplateRef }, { token: RemoteMethodLoader }, { token: INJECTOR }, { token: ViewContainerRef }, { token: ChangeDetectorRef }, { token: IterableDiffers }, { token: NgZone }, { token: RXAP_REMOTE_METHOD_DIRECTIVE_TOKEN, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive });
263
- RemoteMethodTemplateCollectionDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.0.1", type: RemoteMethodTemplateCollectionDirective, selector: "[rxapRemoteMethodCollection]", inputs: { remoteMethodOrIdOrToken: ["rxapRemoteMethodCollectionCall", "remoteMethodOrIdOrToken"], trackBy: ["rxapRemoteMethodCollectionTrackBy", "trackBy"], parameters: ["rxapRemoteMethodCollectionParameters", "parameters"], emptyTemplate: ["rxapRemoteMethodCollectionEmpty", "emptyTemplate"], errorTemplate: ["rxapRemoteMethodCollectionError", "errorTemplate"], withoutParameters: ["rxapRemoteMethodCollectionWithoutParameters", "withoutParameters"] }, exportAs: ["rxapRemoteMethodCollection"], usesOnChanges: true, ngImport: i0 });
264
- __decorate([
265
- Required,
266
- __metadata("design:type", Object)
267
- ], RemoteMethodTemplateCollectionDirective.prototype, "_remoteMethodOrIdOrToken", void 0);
268
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.1", ngImport: i0, type: RemoteMethodTemplateCollectionDirective, decorators: [{
269
- type: Directive,
270
- args: [{
271
- selector: '[rxapRemoteMethodCollection]',
272
- exportAs: 'rxapRemoteMethodCollection'
273
- }]
274
- }], ctorParameters: function () { return [{ type: i0.TemplateRef, decorators: [{
275
- type: Inject,
276
- args: [TemplateRef]
277
- }] }, { type: i1.RemoteMethodLoader, decorators: [{
278
- type: Inject,
279
- args: [RemoteMethodLoader]
280
- }] }, { type: i0.Injector, decorators: [{
281
- type: Inject,
282
- args: [INJECTOR]
283
- }] }, { type: i0.ViewContainerRef, decorators: [{
284
- type: Inject,
285
- args: [ViewContainerRef]
286
- }] }, { type: i0.ChangeDetectorRef, decorators: [{
287
- type: Inject,
288
- args: [ChangeDetectorRef]
289
- }] }, { type: i0.IterableDiffers, decorators: [{
290
- type: Inject,
291
- args: [IterableDiffers]
292
- }] }, { type: i0.NgZone, decorators: [{
293
- type: Inject,
294
- args: [NgZone]
295
- }] }, { type: undefined, decorators: [{
296
- type: Optional
297
- }, {
298
- type: Self
299
- }, {
300
- type: Inject,
301
- args: [RXAP_REMOTE_METHOD_DIRECTIVE_TOKEN]
302
- }] }]; }, propDecorators: { remoteMethodOrIdOrToken: [{
303
- type: Input,
304
- args: ['rxapRemoteMethodCollectionCall']
305
- }], trackBy: [{
306
- type: Input,
307
- args: ['rxapRemoteMethodCollectionTrackBy']
308
- }], parameters: [{
309
- type: Input,
310
- args: ['rxapRemoteMethodCollectionParameters']
311
- }], emptyTemplate: [{
312
- type: Input,
313
- args: ['rxapRemoteMethodCollectionEmpty']
314
- }], errorTemplate: [{
315
- type: Input,
316
- args: ['rxapRemoteMethodCollectionError']
317
- }], withoutParameters: [{
318
- type: Input,
319
- args: ['rxapRemoteMethodCollectionWithoutParameters']
320
- }], _remoteMethodOrIdOrToken: [] } });
321
- export class RemoteMethodTemplateCollectionDirectiveModule {
322
- }
323
- RemoteMethodTemplateCollectionDirectiveModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.1", ngImport: i0, type: RemoteMethodTemplateCollectionDirectiveModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
324
- RemoteMethodTemplateCollectionDirectiveModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.1", ngImport: i0, type: RemoteMethodTemplateCollectionDirectiveModule, declarations: [RemoteMethodTemplateCollectionDirective], exports: [RemoteMethodTemplateCollectionDirective] });
325
- RemoteMethodTemplateCollectionDirectiveModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.1", ngImport: i0, type: RemoteMethodTemplateCollectionDirectiveModule });
326
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.1", ngImport: i0, type: RemoteMethodTemplateCollectionDirectiveModule, decorators: [{
327
- type: NgModule,
328
- args: [{
329
- declarations: [RemoteMethodTemplateCollectionDirective],
330
- exports: [RemoteMethodTemplateCollectionDirective]
331
- }]
332
- }] });
333
- //# sourceMappingURL=remote-method-template-collection.directive.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remote-method-template-collection.directive.js","sourceRoot":"","sources":["../../../../../../libs/remote-method/directive/src/lib/remote-method-template-collection.directive.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,SAAS,EACT,WAAW,EACX,MAAM,EACN,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EAKR,SAAS,EAET,eAAe,EAKf,MAAM,EACN,QAAQ,EACR,IAAI,EACL,MAAM,eAAe,CAAC;AACvB,OAAO,EAGL,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAEL,GAAG,EACH,IAAI,EACL,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAC;;;AAE9D,MAAM,OAAO,8CAA8C;IACzD,YACS,SAAqB,EACrB,KAAa,EACb,KAAa;QAFb,cAAS,GAAT,SAAS,CAAY;QACrB,UAAK,GAAL,KAAK,CAAQ;QACb,UAAK,GAAL,KAAK,CAAQ;IACnB,CAAC;IAEJ,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI,GAAG;QACL,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;IACpB,CAAC;CACF;AAQD,SAAS,WAAW,CAAC,IAAS;IAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,OAAO,IAAI,CAAC;AACrC,CAAC;AAED,MAAM,eAAe;IACnB,YAAmB,MAAW,EAAS,IAAwE;QAA5F,WAAM,GAAN,MAAM,CAAK;QA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BAAC,gCAAgC;gBAyBnC,OAAO;sBADV,KAAK;uBAAC,mCAAmC;gBAkBnC,UAAU;sBADhB,KAAK;uBAAC,sCAAsC;gBAItC,aAAa;sBADnB,KAAK;uBAAC,iCAAiC;gBAIjC,aAAa;sBADnB,KAAK;uBAAC,iCAAiC;gBAIjC,iBAAiB;sBADvB,KAAK;uBAAC,6CAA6C;gBAI1C,wBAAwB;AAgPpC,MAAM,OAAO,6CAA6C;;0IAA7C,6CAA6C;2IAA7C,6CAA6C,iBAtT7C,uCAAuC,aAAvC,uCAAuC;2IAsTvC,6CAA6C;2FAA7C,6CAA6C;kBAJzD,QAAQ;mBAAC;oBACR,YAAY,EAAE,CAAC,uCAAuC,CAAC;oBACvD,OAAO,EAAE,CAAC,uCAAuC,CAAC;iBACnD","sourcesContent":["import {\n Directive,\n TemplateRef,\n Inject,\n Input,\n Injector,\n INJECTOR,\n ViewContainerRef,\n ChangeDetectorRef,\n NgModule,\n SimpleChanges,\n OnChanges,\n EmbeddedViewRef,\n TrackByFunction,\n isDevMode,\n IterableDiffer,\n IterableDiffers,\n IterableChanges,\n IterableChangeRecord,\n DoCheck,\n OnInit,\n NgZone,\n Optional,\n Self\n} from '@angular/core';\nimport {\n BaseRemoteMethod,\n BaseRemoteMethodMetadata,\n RemoteMethodLoader\n} from '@rxap/remote-method';\nimport { Required } from '@rxap/utilities';\nimport { IdOrInstanceOrToken } from '@rxap/definition';\nimport {\n first,\n tap,\n take\n} from 'rxjs/operators';\nimport { RXAP_REMOTE_METHOD_DIRECTIVE_TOKEN } from './tokens';\n\nexport class RemoteMethodTemplateCollectionDirectiveContext<ReturnType = any> {\n constructor(\n public $implicit: ReturnType,\n public index: number,\n public count: number,\n ) {}\n\n get first(): boolean {\n return this.index === 0;\n }\n\n get last(): boolean {\n return this.index === this.count - 1;\n }\n\n get even(): boolean {\n return this.index % 2 === 0;\n }\n\n get odd(): boolean {\n return !this.even;\n }\n}\n\nexport interface RemoteMethodTemplateCollectionDirectiveErrorContext {\n $implicit: Error;\n message?: string;\n name?: string;\n}\n\nfunction getTypeName(type: any): string {\n return type['name'] || typeof type;\n}\n\nclass RecordViewTuple<T> {\n constructor(public record: any, public view: EmbeddedViewRef<RemoteMethodTemplateCollectionDirectiveContext<T>>) {}\n}\n\n@Directive({\n selector: '[rxapRemoteMethodCollection]',\n exportAs: 'rxapRemoteMethodCollection'\n})\nexport class RemoteMethodTemplateCollectionDirective<ReturnType = any,\n Parameters = any,\n Metadata extends BaseRemoteMethodMetadata = BaseRemoteMethodMetadata>\n implements OnChanges, DoCheck, OnInit {\n\n /**\n * Asserts the correct type of the context for the template that `NgForOf` will render.\n *\n * The presence of this method is a signal to the Ivy template type-check compiler that the\n * `NgForOf` structural directive renders its template with a specific context type.\n */\n static ngTemplateContextGuard<T>(dir: RemoteMethodTemplateCollectionDirective<T>, ctx: any):\n ctx is RemoteMethodTemplateCollectionDirectiveContext<T> {\n return true;\n }\n\n @Input('rxapRemoteMethodCollectionCall')\n public set remoteMethodOrIdOrToken(value: IdOrInstanceOrToken<BaseRemoteMethod<ReturnType[], Parameters, Metadata>>) {\n if (value) {\n this._remoteMethodOrIdOrToken = value;\n }\n }\n\n /**\n * A function that defines how to track changes for items in the iterable.\n *\n * When items are added, moved, or removed in the iterable,\n * the directive must re-render the appropriate DOM nodes.\n * To minimize churn in the DOM, only nodes that have changed\n * are re-rendered.\n *\n * By default, the change detector assumes that\n * the object instance identifies the node in the iterable.\n * When this function is supplied, the directive uses\n * the result of calling this function to identify the item node,\n * rather than the identity of the object itself.\n *\n * The function receives two inputs,\n * the iteration index and the node object ID.\n */\n @Input('rxapRemoteMethodCollectionTrackBy')\n set trackBy(fn: TrackByFunction<ReturnType>) {\n if (isDevMode() && fn != null && typeof fn !== 'function') {\n // TODO(vicb): use a log service once there is a public one available\n if (<any>console && <any>console.warn) {\n console.warn(\n `trackBy must be a function, but received ${JSON.stringify(fn)}. ` +\n `See https://angular.io/api/common/NgForOf#change-propagation for more information.`);\n }\n }\n this._trackByFn = fn;\n }\n\n get trackBy(): TrackByFunction<ReturnType> {\n return this._trackByFn;\n }\n\n @Input('rxapRemoteMethodCollectionParameters')\n public parameters?: Parameters;\n\n @Input('rxapRemoteMethodCollectionEmpty')\n public emptyTemplate?: TemplateRef<void>;\n\n @Input('rxapRemoteMethodCollectionError')\n public errorTemplate?: TemplateRef<RemoteMethodTemplateCollectionDirectiveErrorContext>;\n\n @Input('rxapRemoteMethodCollectionWithoutParameters')\n public withoutParameters: boolean = false;\n\n @Required\n protected _remoteMethodOrIdOrToken!: IdOrInstanceOrToken<BaseRemoteMethod<ReturnType[], Parameters, Metadata>>;\n\n protected set data(data: ReturnType[]) {\n this._data = data;\n this._dirty = true;\n }\n\n private _differ: IterableDiffer<ReturnType> | null = null;\n private _trackByFn!: TrackByFunction<ReturnType>;\n\n /**\n * Holds the data that should be displayed\n * @private\n */\n private _data: ReturnType[] | null = null;\n private _dirty = true;\n\n /**\n * Indicates that the remote method returned a empty collection\n *\n * true - is empty\n * false - is NOT empty\n * null - unknown\n *\n * @private\n */\n private _empty: boolean | null = null;\n\n /**\n * Holds the error that call of the remote method throws\n *\n * @private\n */\n private _error: Error | null = null;\n\n /**\n * Holds the empty template view ref.\n *\n * Is used to determine if a empty template is added to the\n * view. And used to destruct the empty template if the remote method\n * changes from empty to not empty.\n *\n * @private\n */\n private _emptyTemplateViewRef: EmbeddedViewRef<void> | null = null;\n\n /**\n * Holds the error template view ref.\n *\n * Is used to determine if a error template is added to the\n * view. And used to destruct the error template if the remote method\n * is called again with an error.\n *\n * @private\n */\n private _errorTemplateViewRef: EmbeddedViewRef<RemoteMethodTemplateCollectionDirectiveErrorContext> | null = null;\n\n constructor(\n @Inject(TemplateRef)\n private readonly template: TemplateRef<RemoteMethodTemplateCollectionDirectiveContext<ReturnType>>,\n @Inject(RemoteMethodLoader)\n protected readonly remoteMethodLoader: RemoteMethodLoader,\n @Inject(INJECTOR)\n private readonly injector: Injector,\n @Inject(ViewContainerRef)\n private readonly viewContainerRef: ViewContainerRef,\n @Inject(ChangeDetectorRef)\n protected readonly cdr: ChangeDetectorRef,\n @Inject(IterableDiffers)\n private readonly differs: IterableDiffers,\n @Inject(NgZone)\n private readonly zone: NgZone,\n @Optional()\n @Self()\n @Inject(RXAP_REMOTE_METHOD_DIRECTIVE_TOKEN)\n private readonly remoteMethodToken?: any\n ) {\n if (this.remoteMethodToken) {\n this._remoteMethodOrIdOrToken = this.remoteMethodToken;\n }\n }\n\n public ngOnChanges(changes: SimpleChanges) {\n const parametersChanges = changes.parameters;\n if (parametersChanges) {\n this.call(parametersChanges.currentValue);\n }\n }\n\n public ngOnInit() {\n if (this.withoutParameters) {\n this.call();\n }\n }\n\n public call(parameters?: Parameters): void {\n this.zone.onStable.pipe(\n take(1),\n tap(() => {\n this.zone.run(() => {\n this.remoteMethodLoader\n .call$(this._remoteMethodOrIdOrToken, parameters, undefined, this.injector)\n .then(response => {\n this._empty = response.length === 0;\n this._data = response;\n this.cdr.detectChanges();\n })\n .catch(error => {\n this._error = error;\n this.cdr.detectChanges();\n });\n });\n })\n ).subscribe();\n }\n\n protected applyChanges(changes: IterableChanges<ReturnType>) {\n\n const insertTuples: RecordViewTuple<ReturnType>[] = [];\n changes.forEachOperation(\n (item: IterableChangeRecord<any>, adjustedPreviousIndex: number | null, currentIndex: number | null) => {\n\n if (item.previousIndex == null) {\n\n // NgForOf is never \"null\" or \"undefined\" here because the differ detected\n // that a new item needs to be inserted from the iterable. This implies that\n // there is an iterable value for \"_ngForOf\".\n const view = this.viewContainerRef.createEmbeddedView(\n this.template,\n new RemoteMethodTemplateCollectionDirectiveContext<ReturnType>(null!, -1, -1),\n currentIndex === null ? undefined : currentIndex\n );\n const tuple = new RecordViewTuple<ReturnType>(item, view);\n insertTuples.push(tuple);\n\n } else if (currentIndex == null) {\n\n this.viewContainerRef.remove(adjustedPreviousIndex === null ? undefined : adjustedPreviousIndex);\n\n } else if (adjustedPreviousIndex !== null) {\n\n const view = this.viewContainerRef.get(adjustedPreviousIndex)!;\n this.viewContainerRef.move(view, currentIndex);\n const tuple = new RecordViewTuple(item, <EmbeddedViewRef<RemoteMethodTemplateCollectionDirectiveContext<ReturnType>>>view);\n insertTuples.push(tuple);\n\n }\n\n });\n\n for (let i = 0; i < insertTuples.length; i++) {\n this.perViewChange(insertTuples[i].view, insertTuples[i].record);\n }\n\n for (let i = 0, ilen = this.viewContainerRef.length; i < ilen; i++) {\n const viewRef = <EmbeddedViewRef<RemoteMethodTemplateCollectionDirectiveContext<ReturnType>>>this.viewContainerRef.get(i);\n viewRef.context.index = i;\n viewRef.context.count = ilen;\n }\n\n changes.forEachIdentityChange((record: any) => {\n const viewRef =\n <EmbeddedViewRef<RemoteMethodTemplateCollectionDirectiveContext<ReturnType>>>this.viewContainerRef.get(record.currentIndex);\n viewRef.context.$implicit = record.item;\n });\n\n }\n\n private perViewChange(\n view: EmbeddedViewRef<RemoteMethodTemplateCollectionDirectiveContext<ReturnType>>, record: IterableChangeRecord<any>) {\n view.context.$implicit = record.item;\n }\n\n /**\n * Applies the changes when needed.\n */\n public ngDoCheck(): void {\n if (this._error !== null) {\n\n this.viewContainerRef.clear();\n this._differ = null;\n\n if (this.errorTemplate) {\n this._errorTemplateViewRef = this.viewContainerRef.createEmbeddedView(this.errorTemplate, { $implicit: this._error, message: this._error.message, name: this._error.name });\n }\n\n } else if (this._empty === true) {\n\n this.viewContainerRef.clear();\n this._differ = null;\n\n // attaches the empty template if the data source is empty\n if (this.emptyTemplate) {\n this._emptyTemplateViewRef = this.viewContainerRef.createEmbeddedView(this.emptyTemplate);\n }\n\n } else if (this._empty === false) {\n\n // detach and destroy the empty template if the data source is not\n // empty any more\n if (this._emptyTemplateViewRef) {\n this._emptyTemplateViewRef.detach();\n this._emptyTemplateViewRef.destroy();\n this._errorTemplateViewRef = null;\n }\n\n if (this._errorTemplateViewRef) {\n this._errorTemplateViewRef.detach();\n this._errorTemplateViewRef.destroy();\n this._errorTemplateViewRef = null;\n }\n\n if (this._data) {\n this._dirty = false;\n // React on ngForOf changes only once all inputs have been initialized\n const value = this._data;\n if (!this._differ && value) {\n try {\n this._differ = this.differs.find(value).create(this.trackBy);\n } catch {\n throw new Error(`Cannot find a differ supporting object '${value}' of type '${\n getTypeName(value)}'. NgFor only supports binding to Iterables such as Arrays.`);\n }\n }\n }\n if (this._differ) {\n const changes = this._differ.diff(this._data);\n if (changes) {\n this.applyChanges(changes);\n }\n }\n }\n }\n\n}\n\n@NgModule({\n declarations: [RemoteMethodTemplateCollectionDirective],\n exports: [RemoteMethodTemplateCollectionDirective]\n})\nexport class RemoteMethodTemplateCollectionDirectiveModule {}\n"]}
@@ -1,204 +0,0 @@
1
- import { __awaiter, __decorate, __metadata } from "tslib";
2
- import { Directive, TemplateRef, Inject, Input, Injector, INJECTOR, ViewContainerRef, ChangeDetectorRef, NgModule, EventEmitter, Output, isDevMode, Optional, Self } from '@angular/core';
3
- import { RemoteMethodLoader } from '@rxap/remote-method';
4
- import { Required, Deprecated } from '@rxap/utilities';
5
- import { RXAP_REMOTE_METHOD_DIRECTIVE_TOKEN } from './tokens';
6
- import { ToggleSubject } from '@rxap/utilities/rxjs';
7
- import * as i0 from "@angular/core";
8
- import * as i1 from "@rxap/remote-method";
9
- export class RemoteMethodTemplateDirective {
10
- constructor(template, remoteMethodLoader, injector, viewContainerRef, cdr, remoteMethodToken) {
11
- this.template = template;
12
- this.remoteMethodLoader = remoteMethodLoader;
13
- this.injector = injector;
14
- this.viewContainerRef = viewContainerRef;
15
- this.cdr = cdr;
16
- this.remoteMethodToken = remoteMethodToken;
17
- this.executed$ = new EventEmitter();
18
- this.failure$ = new EventEmitter();
19
- this.successful$ = new EventEmitter();
20
- /**
21
- * true - a remote method call is in progress
22
- */
23
- this.executing$ = new ToggleSubject();
24
- this.withoutParameters = false;
25
- this.embedded = new EventEmitter();
26
- if (this.remoteMethodToken) {
27
- this._remoteMethodOrIdOrToken = this.remoteMethodToken;
28
- }
29
- }
30
- // TODO : remove template context Guard
31
- // the template context Guard must be defined with a concrete context type
32
- // else the context guard is resolved to any
33
- // For each child directive that should have a template context guard
34
- // the template context guard must be defined
35
- // !! add generation of concrete template context guard to openapi schematics !!
36
- static ngTemplateContextGuard(dir, ctx) {
37
- return true;
38
- }
39
- set remoteMethodOrIdOrToken(value) {
40
- if (value) {
41
- this._remoteMethodOrIdOrToken = value;
42
- }
43
- }
44
- ngOnChanges(changes) {
45
- const parametersChanges = changes.parameters;
46
- if (parametersChanges) {
47
- this.execute(parametersChanges.currentValue);
48
- }
49
- }
50
- ngOnInit() {
51
- this.renderLoadingTemplate();
52
- if (this.withoutParameters) {
53
- this.execute();
54
- }
55
- }
56
- execute(parameters = this.parameters) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- this.executing$.enable();
59
- this.renderLoadingTemplate();
60
- try {
61
- const result = yield this.remoteMethodLoader.call$(this._remoteMethodOrIdOrToken, parameters, this.metadata, this.injector);
62
- this.executed(result);
63
- this.renderTemplate(result);
64
- this.successful(result);
65
- }
66
- catch (error) {
67
- if (isDevMode()) {
68
- console.error(`Remote method directive execution failed:`, error.message);
69
- }
70
- this.failure(error);
71
- }
72
- finally {
73
- this.executing$.disable();
74
- }
75
- });
76
- }
77
- /**
78
- * @deprecated removed
79
- * @protected
80
- */
81
- call(parameters) {
82
- this.execute(parameters)
83
- .catch(error => console.error('Remote method template rendering failed: ' + error.message));
84
- }
85
- setParameter(parameterKey, value) {
86
- this.updateParameters({ [parameterKey]: value });
87
- }
88
- updateParameters(parameters) {
89
- var _a;
90
- this.parameters = Object.assign(Object.assign({}, ((_a = this.parameters) !== null && _a !== void 0 ? _a : {})), parameters);
91
- }
92
- renderLoadingTemplate() {
93
- if (this.loadingTemplate) {
94
- this.viewContainerRef.clear();
95
- this.viewContainerRef.createEmbeddedView(this.loadingTemplate);
96
- }
97
- }
98
- executed(result) {
99
- this.executed$.emit(result);
100
- }
101
- failure(error) {
102
- this.failure$.emit(error);
103
- }
104
- successful(result) {
105
- this.successful$.emit(result);
106
- }
107
- renderTemplate(result) {
108
- this.viewContainerRef.clear();
109
- try {
110
- this.viewContainerRef.createEmbeddedView(this.template, { $implicit: result });
111
- }
112
- catch (error) {
113
- if (this.errorTemplate) {
114
- this.viewContainerRef.createEmbeddedView(this.errorTemplate, { $implicit: error, message: error.message });
115
- }
116
- console.error(error.message);
117
- }
118
- this.embedded.emit();
119
- this.cdr.detectChanges();
120
- }
121
- }
122
- RemoteMethodTemplateDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.1", ngImport: i0, type: RemoteMethodTemplateDirective, deps: [{ token: TemplateRef }, { token: RemoteMethodLoader }, { token: INJECTOR }, { token: ViewContainerRef }, { token: ChangeDetectorRef }, { token: RXAP_REMOTE_METHOD_DIRECTIVE_TOKEN, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive });
123
- RemoteMethodTemplateDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.0.1", type: RemoteMethodTemplateDirective, selector: "[rxapRemoteMethod]", inputs: { remoteMethodOrIdOrToken: ["rxapRemoteMethodCall", "remoteMethodOrIdOrToken"], metadata: ["rxapRemoteMethodMetadata", "metadata"], parameters: ["rxapRemoteMethodParameters", "parameters"], errorTemplate: ["rxapRemoteMethodError", "errorTemplate"], loadingTemplate: ["rxapRemoteMethodLoading", "loadingTemplate"], withoutParameters: ["rxapRemoteMethodWithoutParameters", "withoutParameters"] }, outputs: { executed$: "executed", failure$: "failure", successful$: "successful", embedded: "embedded" }, exportAs: ["rxapRemoteMethod"], usesOnChanges: true, ngImport: i0 });
124
- __decorate([
125
- Required,
126
- __metadata("design:type", Object)
127
- ], RemoteMethodTemplateDirective.prototype, "_remoteMethodOrIdOrToken", void 0);
128
- __decorate([
129
- Deprecated('removed'),
130
- __metadata("design:type", Function),
131
- __metadata("design:paramtypes", [Object]),
132
- __metadata("design:returntype", void 0)
133
- ], RemoteMethodTemplateDirective.prototype, "call", null);
134
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.1", ngImport: i0, type: RemoteMethodTemplateDirective, decorators: [{
135
- type: Directive,
136
- args: [{
137
- selector: '[rxapRemoteMethod]',
138
- exportAs: 'rxapRemoteMethod'
139
- }]
140
- }], ctorParameters: function () { return [{ type: i0.TemplateRef, decorators: [{
141
- type: Inject,
142
- args: [TemplateRef]
143
- }] }, { type: i1.RemoteMethodLoader, decorators: [{
144
- type: Inject,
145
- args: [RemoteMethodLoader]
146
- }] }, { type: i0.Injector, decorators: [{
147
- type: Inject,
148
- args: [INJECTOR]
149
- }] }, { type: i0.ViewContainerRef, decorators: [{
150
- type: Inject,
151
- args: [ViewContainerRef]
152
- }] }, { type: i0.ChangeDetectorRef, decorators: [{
153
- type: Inject,
154
- args: [ChangeDetectorRef]
155
- }] }, { type: undefined, decorators: [{
156
- type: Optional
157
- }, {
158
- type: Self
159
- }, {
160
- type: Inject,
161
- args: [RXAP_REMOTE_METHOD_DIRECTIVE_TOKEN]
162
- }] }]; }, propDecorators: { remoteMethodOrIdOrToken: [{
163
- type: Input,
164
- args: ['rxapRemoteMethodCall']
165
- }], executed$: [{
166
- type: Output,
167
- args: ['executed']
168
- }], failure$: [{
169
- type: Output,
170
- args: ['failure']
171
- }], successful$: [{
172
- type: Output,
173
- args: ['successful']
174
- }], metadata: [{
175
- type: Input,
176
- args: ['rxapRemoteMethodMetadata']
177
- }], parameters: [{
178
- type: Input,
179
- args: ['rxapRemoteMethodParameters']
180
- }], errorTemplate: [{
181
- type: Input,
182
- args: ['rxapRemoteMethodError']
183
- }], loadingTemplate: [{
184
- type: Input,
185
- args: ['rxapRemoteMethodLoading']
186
- }], withoutParameters: [{
187
- type: Input,
188
- args: ['rxapRemoteMethodWithoutParameters']
189
- }], _remoteMethodOrIdOrToken: [], embedded: [{
190
- type: Output
191
- }], call: [] } });
192
- export class RemoteMethodTemplateDirectiveModule {
193
- }
194
- RemoteMethodTemplateDirectiveModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.1", ngImport: i0, type: RemoteMethodTemplateDirectiveModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
195
- RemoteMethodTemplateDirectiveModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.1", ngImport: i0, type: RemoteMethodTemplateDirectiveModule, declarations: [RemoteMethodTemplateDirective], exports: [RemoteMethodTemplateDirective] });
196
- RemoteMethodTemplateDirectiveModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.1", ngImport: i0, type: RemoteMethodTemplateDirectiveModule });
197
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.1", ngImport: i0, type: RemoteMethodTemplateDirectiveModule, decorators: [{
198
- type: NgModule,
199
- args: [{
200
- declarations: [RemoteMethodTemplateDirective],
201
- exports: [RemoteMethodTemplateDirective]
202
- }]
203
- }] });
204
- //# sourceMappingURL=remote-method-template.directive.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remote-method-template.directive.js","sourceRoot":"","sources":["../../../../../../libs/remote-method/directive/src/lib/remote-method-template.directive.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,SAAS,EACT,WAAW,EACX,MAAM,EACN,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EAIR,YAAY,EACZ,MAAM,EACN,SAAS,EACT,QAAQ,EACR,IAAI,EACL,MAAM,eAAe,CAAC;AACvB,OAAO,EAGL,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,QAAQ,EACR,UAAU,EACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;;;AAerD,MAAM,OAAO,6BAA6B;IAwDxC,YAEmB,QAAuE,EAErE,kBAAsC,EAExC,QAAkB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mitter,\n Output,\n isDevMode,\n Optional,\n Self\n} from '@angular/core';\nimport {\n BaseRemoteMethod,\n BaseRemoteMethodMetadata,\n RemoteMethodLoader\n} from '@rxap/remote-method';\nimport {\n Required,\n Deprecated\n} from '@rxap/utilities';\nimport { IdOrInstanceOrToken } from '@rxap/definition';\nimport { RXAP_REMOTE_METHOD_DIRECTIVE_TOKEN } from './tokens';\nimport { ToggleSubject } from '@rxap/utilities/rxjs';\n\nexport interface RemoteMethodTemplateDirectiveContext<ReturnType = any> {\n $implicit: ReturnType;\n}\n\nexport interface RemoteMethodTemplateDirectiveErrorContext {\n $implicit: Error;\n message: string;\n}\n\n@Directive({\n selector: '[rxapRemoteMethod]',\n exportAs: 'rxapRemoteMethod'\n})\nexport class RemoteMethodTemplateDirective<ReturnType = any, Parameters = any, Metadata extends BaseRemoteMethodMetadata = BaseRemoteMethodMetadata>\n implements OnChanges, OnInit {\n\n // TODO : remove template context Guard\n // the template context Guard must be defined with a concrete context type\n // else the context guard is resolved to any\n // For each child directive that should have a template context guard\n // the template context guard must be defined\n // !! add generation of concrete template context guard to openapi schematics !!\n static ngTemplateContextGuard<T>(dir: RemoteMethodTemplateDirective<T>, ctx: any):\n ctx is RemoteMethodTemplateDirectiveContext<T> {\n return true;\n }\n\n @Input('rxapRemoteMethodCall')\n public set remoteMethodOrIdOrToken(value: IdOrInstanceOrToken<BaseRemoteMethod<ReturnType, Parameters, Metadata>>) {\n if (value) {\n this._remoteMethodOrIdOrToken = value;\n }\n }\n\n @Output('executed')\n public executed$ = new EventEmitter();\n\n @Output('failure')\n public failure$ = new EventEmitter<Error>();\n\n @Output('successful')\n public successful$ = new EventEmitter<ReturnType>();\n\n @Input('rxapRemoteMethodMetadata')\n public metadata?: Metadata;\n\n /**\n * true - a remote method call is in progress\n */\n public executing$ = new ToggleSubject();\n\n @Input('rxapRemoteMethodParameters')\n public parameters?: Parameters;\n\n @Input('rxapRemoteMethodError')\n public errorTemplate?: TemplateRef<RemoteMethodTemplateDirectiveErrorContext>;\n\n @Input('rxapRemoteMethodLoading')\n public loadingTemplate?: TemplateRef<void>;\n\n @Input('rxapRemoteMethodWithoutParameters')\n public withoutParameters: boolean = false;\n\n @Required\n protected _remoteMethodOrIdOrToken!: IdOrInstanceOrToken<BaseRemoteMethod<ReturnType, Parameters, Metadata>>;\n\n @Output()\n public embedded = new EventEmitter();\n\n constructor(\n @Inject(TemplateRef)\n private readonly template: TemplateRef<RemoteMethodTemplateDirectiveContext<ReturnType>>,\n @Inject(RemoteMethodLoader)\n protected readonly remoteMethodLoader: RemoteMethodLoader,\n @Inject(INJECTOR)\n private readonly injector: Injector,\n @Inject(ViewContainerRef)\n private readonly viewContainerRef: ViewContainerRef,\n @Inject(ChangeDetectorRef)\n protected readonly cdr: ChangeDetectorRef,\n @Optional()\n @Self()\n @Inject(RXAP_REMOTE_METHOD_DIRECTIVE_TOKEN)\n private readonly remoteMethodToken?: any\n ) {\n if (this.remoteMethodToken) {\n this._remoteMethodOrIdOrToken = this.remoteMethodToken;\n }\n }\n\n public ngOnChanges(changes: SimpleChanges) {\n const parametersChanges = changes.parameters;\n if (parametersChanges) {\n this.execute(parametersChanges.currentValue);\n }\n }\n\n public ngOnInit() {\n this.renderLoadingTemplate();\n if (this.withoutParameters) {\n this.execute();\n }\n }\n\n public async execute(parameters: Parameters | undefined = this.parameters): Promise<void> {\n this.executing$.enable();\n this.renderLoadingTemplate();\n try {\n const result = await this.remoteMethodLoader.call$(this._remoteMethodOrIdOrToken, parameters, this.metadata, this.injector);\n this.executed(result);\n this.renderTemplate(result);\n this.successful(result);\n } catch (error) {\n if (isDevMode()) {\n console.error(`Remote method directive execution failed:`, error.message);\n }\n this.failure(error);\n } finally {\n this.executing$.disable();\n }\n }\n\n /**\n * @deprecated removed\n * @protected\n */\n @Deprecated('removed')\n public call(parameters?: Parameters): void {\n this.execute(parameters)\n .catch(error => console.error('Remote method template rendering failed: ' + error.message));\n }\n\n public setParameter<Key extends keyof Parameters>(parameterKey: Key, value: Parameters[Key]): void {\n this.updateParameters({ [ parameterKey ]: value } as any);\n }\n\n public updateParameters(parameters: Partial<Parameters>): void {\n this.parameters = { ...(this.parameters ?? {}), ...parameters } as any;\n }\n\n private renderLoadingTemplate() {\n if (this.loadingTemplate) {\n this.viewContainerRef.clear();\n this.viewContainerRef.createEmbeddedView(this.loadingTemplate);\n }\n }\n\n protected executed(result: any) {\n this.executed$.emit(result);\n }\n\n protected failure(error: Error) {\n this.failure$.emit(error);\n }\n\n protected successful(result: ReturnType) {\n this.successful$.emit(result);\n }\n\n protected renderTemplate(result: ReturnType) {\n\n this.viewContainerRef.clear();\n\n try {\n this.viewContainerRef.createEmbeddedView(this.template, { $implicit: result });\n } catch (error) {\n if (this.errorTemplate) {\n this.viewContainerRef.createEmbeddedView(this.errorTemplate, { $implicit: error, message: error.message });\n }\n console.error(error.message);\n }\n\n this.embedded.emit();\n\n this.cdr.detectChanges();\n\n }\n\n}\n\n@NgModule({\n declarations: [RemoteMethodTemplateDirective],\n exports: [RemoteMethodTemplateDirective]\n})\nexport class RemoteMethodTemplateDirectiveModule {}\n"]}