@rxap/form-system 18.2.0-dev.0 → 18.2.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/compodoc/changelog.html +25 -0
- package/compodoc/dependencies.html +18 -14
- package/compodoc/directives/AutocompleteOptionsFromMethodDirective.html +1367 -0
- package/compodoc/directives/FormArrayItemButton.html +58 -19
- package/compodoc/directives/FormArrayItemRemoveButtonDirective.html +113 -10
- package/compodoc/directives/FormArrayItemRestoreButtonDirective.html +43 -5
- package/compodoc/directives/FormArrayRemovableDirective.html +25 -20
- package/compodoc/directives/OptionsFromMethodDirective.html +71 -66
- package/compodoc/interfaces/AutocompleteOptionsFromMethodDirectiveParameters.html +512 -0
- package/compodoc/interfaces/AutocompleteOptionsFromMethodDirectiveSettings.html +518 -0
- package/compodoc/interfaces/AutocompleteOptionsFromRemoteMethodTemplateContext.html +506 -0
- package/compodoc/interfaces/OptionsFromMethodDirectiveSettings.html +26 -14
- package/compodoc/interfaces/OptionsFromMethodTemplateContext.html +26 -14
- package/compodoc/js/menu-wc.js +12 -0
- package/compodoc/js/menu-wc_es5.js +1 -1
- package/compodoc/js/search/search_index.js +2 -2
- package/compodoc/miscellaneous/functions.html +356 -0
- package/compodoc/overview.html +2 -2
- package/compodoc/properties.html +1 -1
- package/esm2022/lib/directives/autocomplete-options-from-method.directive.mjs +25 -9
- package/esm2022/lib/directives/options-from-method.directive.mjs +2 -2
- package/esm2022/lib/mixins/apply-use-function.adapters.mjs +32 -0
- package/esm2022/lib/mixins/extract-function.mixin.mjs +24 -0
- package/esm2022/lib/mixins/extract-functions.mixin.mjs +21 -0
- package/esm2022/lib/mixins/extract-is-value-function.mixin.mjs +22 -0
- package/fesm2022/rxap-form-system.mjs +109 -10
- package/fesm2022/rxap-form-system.mjs.map +1 -1
- package/lib/directives/autocomplete-options-from-method.directive.d.ts +14 -3
- package/lib/mixins/apply-use-function.adapters.d.ts +3 -0
- package/lib/mixins/extract-function.mixin.d.ts +9 -0
- package/lib/mixins/extract-functions.mixin.d.ts +19 -0
- package/lib/mixins/extract-is-value-function.mixin.d.ts +13 -0
- package/package.json +2 -2
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html class="no-js" lang="">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
6
|
+
<title>angular-form-system</title>
|
|
7
|
+
<meta name="description" content="">
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
+
|
|
10
|
+
<link rel="icon" type="image/x-icon" href="../images/favicon.ico">
|
|
11
|
+
<link rel="stylesheet" href="../styles/style.css">
|
|
12
|
+
<link rel="stylesheet" href="../styles/dark.css">
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<script>
|
|
16
|
+
// Blocking script to avoid flickering dark mode
|
|
17
|
+
// Dark mode toggle button
|
|
18
|
+
var useDark = window.matchMedia('(prefers-color-scheme: dark)');
|
|
19
|
+
var darkModeState = useDark.matches;
|
|
20
|
+
var $darkModeToggleSwitchers = document.querySelectorAll('.dark-mode-switch input');
|
|
21
|
+
var $darkModeToggles = document.querySelectorAll('.dark-mode-switch');
|
|
22
|
+
var darkModeStateLocal = localStorage.getItem('compodoc_darkmode-state');
|
|
23
|
+
|
|
24
|
+
function checkToggle(check) {
|
|
25
|
+
for (var i = 0; i < $darkModeToggleSwitchers.length; i++) {
|
|
26
|
+
$darkModeToggleSwitchers[i].checked = check;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function toggleDarkMode(state) {
|
|
31
|
+
if (window.localStorage) {
|
|
32
|
+
localStorage.setItem('compodoc_darkmode-state', state);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
checkToggle(state);
|
|
36
|
+
|
|
37
|
+
const hasClass = document.body.classList.contains('dark');
|
|
38
|
+
|
|
39
|
+
if (state) {
|
|
40
|
+
for (var i = 0; i < $darkModeToggles.length; i++) {
|
|
41
|
+
$darkModeToggles[i].classList.add('dark');
|
|
42
|
+
}
|
|
43
|
+
if (!hasClass) {
|
|
44
|
+
document.body.classList.add('dark');
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
for (var i = 0; i < $darkModeToggles.length; i++) {
|
|
48
|
+
$darkModeToggles[i].classList.remove('dark');
|
|
49
|
+
}
|
|
50
|
+
if (hasClass) {
|
|
51
|
+
document.body.classList.remove('dark');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
useDark.addEventListener('change', function (evt) {
|
|
57
|
+
toggleDarkMode(evt.matches);
|
|
58
|
+
});
|
|
59
|
+
if (darkModeStateLocal) {
|
|
60
|
+
darkModeState = darkModeStateLocal === 'true';
|
|
61
|
+
}
|
|
62
|
+
toggleDarkMode(darkModeState);
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<div class="navbar navbar-default navbar-fixed-top d-md-none p-0">
|
|
66
|
+
<div class="d-flex">
|
|
67
|
+
<a href="../" class="navbar-brand">angular-form-system</a>
|
|
68
|
+
<button type="button" class="btn btn-default btn-menu ion-ios-menu" id="btn-menu"></button>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<div class="xs-menu menu" id="mobile-menu">
|
|
73
|
+
<div id="book-search-input" role="search"><input type="text" placeholder="Type to search"></div> <compodoc-menu></compodoc-menu>
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
<div class="container-fluid main">
|
|
77
|
+
<div class="row main">
|
|
78
|
+
<div class="d-none d-md-block menu">
|
|
79
|
+
<compodoc-menu mode="normal"></compodoc-menu>
|
|
80
|
+
</div>
|
|
81
|
+
<!-- START CONTENT -->
|
|
82
|
+
<div class="content interface">
|
|
83
|
+
<div class="content-data">
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
<ol class="breadcrumb">
|
|
98
|
+
<li class="breadcrumb-item">Interfaces</li>
|
|
99
|
+
<li class="breadcrumb-item"
|
|
100
|
+
>
|
|
101
|
+
AutocompleteOptionsFromRemoteMethodTemplateContext</li>
|
|
102
|
+
</ol>
|
|
103
|
+
|
|
104
|
+
<ul class="nav nav-tabs" role="tablist">
|
|
105
|
+
<li class="nav-item">
|
|
106
|
+
<a href="#info"
|
|
107
|
+
class="nav-link"
|
|
108
|
+
class="nav-link active"
|
|
109
|
+
role="tab" id="info-tab" data-bs-toggle="tab" data-link="info">Info</a>
|
|
110
|
+
</li>
|
|
111
|
+
<li class="nav-item">
|
|
112
|
+
<a href="#readme"
|
|
113
|
+
class="nav-link"
|
|
114
|
+
|
|
115
|
+
role="tab" id="readme-tab" data-bs-toggle="tab" data-link="readme">README</a>
|
|
116
|
+
</li>
|
|
117
|
+
<li class="nav-item">
|
|
118
|
+
<a href="#source"
|
|
119
|
+
class="nav-link"
|
|
120
|
+
|
|
121
|
+
role="tab" id="source-tab" data-bs-toggle="tab" data-link="source">Source</a>
|
|
122
|
+
</li>
|
|
123
|
+
</ul>
|
|
124
|
+
|
|
125
|
+
<div class="tab-content">
|
|
126
|
+
<div class="tab-pane fade active in" id="info">
|
|
127
|
+
<p class="comment">
|
|
128
|
+
<h3>File</h3>
|
|
129
|
+
</p>
|
|
130
|
+
<p class="comment">
|
|
131
|
+
<code>src/lib/directives/autocomplete-options-from-method.directive.ts</code>
|
|
132
|
+
</p>
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
<section data-compodoc="block-index">
|
|
138
|
+
<h3 id="index">Index</h3>
|
|
139
|
+
<table class="table table-sm table-bordered index-table">
|
|
140
|
+
<tbody>
|
|
141
|
+
<tr>
|
|
142
|
+
<td class="col-md-4">
|
|
143
|
+
<h6><b>Properties</b></h6>
|
|
144
|
+
</td>
|
|
145
|
+
</tr>
|
|
146
|
+
<tr>
|
|
147
|
+
<td class="col-md-4">
|
|
148
|
+
<ul class="index-list">
|
|
149
|
+
<li>
|
|
150
|
+
<a href="#$implicit"
|
|
151
|
+
>
|
|
152
|
+
$implicit
|
|
153
|
+
</a>
|
|
154
|
+
</li>
|
|
155
|
+
</ul>
|
|
156
|
+
</td>
|
|
157
|
+
</tr>
|
|
158
|
+
</tbody>
|
|
159
|
+
</table>
|
|
160
|
+
</section>
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
<section data-compodoc="block-properties">
|
|
165
|
+
<h3 id="inputs">Properties</h3>
|
|
166
|
+
<table class="table table-sm table-bordered">
|
|
167
|
+
<tbody>
|
|
168
|
+
<tr>
|
|
169
|
+
<td class="col-md-4">
|
|
170
|
+
<a name="$implicit"></a>
|
|
171
|
+
<span class="name "><b>$implicit</b>
|
|
172
|
+
<a href="#$implicit">
|
|
173
|
+
<span class="icon ion-ios-link"></span>
|
|
174
|
+
</a>
|
|
175
|
+
</span>
|
|
176
|
+
</td>
|
|
177
|
+
</tr>
|
|
178
|
+
<tr>
|
|
179
|
+
<td class="col-md-4">
|
|
180
|
+
<code>$implicit: <code>ControlOption</code>
|
|
181
|
+
</code>
|
|
182
|
+
</td>
|
|
183
|
+
</tr>
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
<tr>
|
|
187
|
+
<td class="col-md-4">
|
|
188
|
+
<i>Type : </i> <code>ControlOption</code>
|
|
189
|
+
|
|
190
|
+
</td>
|
|
191
|
+
</tr>
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
</tbody>
|
|
198
|
+
</table>
|
|
199
|
+
</section>
|
|
200
|
+
</div>
|
|
201
|
+
|
|
202
|
+
<div class="tab-pane fade " id="readme">
|
|
203
|
+
<p><h1>Test</h1>
|
|
204
|
+
</p>
|
|
205
|
+
</div>
|
|
206
|
+
|
|
207
|
+
<div class="tab-pane fade tab-source-code" id="source">
|
|
208
|
+
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import {
|
|
209
|
+
AfterViewInit,
|
|
210
|
+
Directive,
|
|
211
|
+
inject,
|
|
212
|
+
Injector,
|
|
213
|
+
INJECTOR,
|
|
214
|
+
Input,
|
|
215
|
+
isDevMode,
|
|
216
|
+
OnDestroy,
|
|
217
|
+
ProviderToken,
|
|
218
|
+
} from '@angular/core';
|
|
219
|
+
import { MatAutocomplete } from '@angular/material/autocomplete';
|
|
220
|
+
import { ControlOption, ControlOptions } from '@rxap/utilities';
|
|
221
|
+
import { distinctUntilChanged, Subscription, tap } from 'rxjs';
|
|
222
|
+
import { isUUID } from '@rxap/validator';
|
|
223
|
+
import { Method, MethodWithParameters } from '@rxap/pattern';
|
|
224
|
+
import { Mixin } from '@rxap/mixin';
|
|
225
|
+
import { NgControl } from '@angular/forms';
|
|
226
|
+
import { MatFormField } from '@angular/material/form-field';
|
|
227
|
+
import { isDefined } from '@rxap/rxjs';
|
|
228
|
+
import { UseMethodConfig } from '../mixins/extract-methods.mixin';
|
|
229
|
+
import { UseOptionsMethod } from '../mixins/extract-options-method.mixin';
|
|
230
|
+
import {
|
|
231
|
+
ExtractResolveMethodMixin,
|
|
232
|
+
UseResolveMethod,
|
|
233
|
+
} from '../mixins/extract-resolve-method.mixin';
|
|
234
|
+
import { OptionsFromMethodDirective, OptionsFromMethodDirectiveSettings } from './options-from-method.directive';
|
|
235
|
+
import { OpenApiRemoteMethodParameter } from '@rxap/open-api/remote-method';
|
|
236
|
+
import { controlValueChanges$ } from '@rxap/forms';
|
|
237
|
+
|
|
238
|
+
export function UseAutocompleteOptionsMethod(
|
|
239
|
+
method: ProviderToken<MethodWithParameters<ControlOptions, AutocompleteOptionsFromMethodDirectiveParameters>>,
|
|
240
|
+
): any;
|
|
241
|
+
export function UseAutocompleteOptionsMethod(
|
|
242
|
+
method: ProviderToken<MethodWithParameters<ControlOptions, OpenApiRemoteMethodParameter<AutocompleteOptionsFromMethodDirectiveParameters>>>,
|
|
243
|
+
): any;
|
|
244
|
+
export function UseAutocompleteOptionsMethod(
|
|
245
|
+
method: ProviderToken<MethodWithParameters>,
|
|
246
|
+
config: UseMethodConfig<ControlOptions, AutocompleteOptionsFromMethodDirectiveParameters>,
|
|
247
|
+
): any;
|
|
248
|
+
export function UseAutocompleteOptionsMethod(
|
|
249
|
+
method: ProviderToken<MethodWithParameters<ControlOptions, AutocompleteOptionsFromMethodDirectiveParameters | OpenApiRemoteMethodParameter<AutocompleteOptionsFromMethodDirectiveParameters>>>,
|
|
250
|
+
config: UseMethodConfig = {},
|
|
251
|
+
) {
|
|
252
|
+
config.adapter ??= {};
|
|
253
|
+
config.adapter.parameter ??= (parameters) => ({parameters});
|
|
254
|
+
return UseOptionsMethod(method as any, config);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function UseAutocompleteResolveMethod<Value = unknown>(
|
|
258
|
+
method: ProviderToken<MethodWithParameters<ControlOption<Value>, OpenApiRemoteMethodParameter<{ value: string }>>>,
|
|
259
|
+
config: UseMethodConfig = {},
|
|
260
|
+
) {
|
|
261
|
+
config.adapter ??= {};
|
|
262
|
+
config.adapter.parameter ??= (parameters) => ({parameters});
|
|
263
|
+
return UseResolveMethod(method, config);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export interface AutocompleteOptionsFromRemoteMethodTemplateContext {
|
|
267
|
+
$implicit: ControlOption;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export interface AutocompleteOptionsFromMethodDirectiveSettings extends OptionsFromMethodDirectiveSettings {
|
|
271
|
+
filteredOptions?: boolean;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export interface AutocompleteOptionsFromMethodDirectiveParameters<Value = any> {
|
|
275
|
+
search?: Value | null;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
279
|
+
export interface AutocompleteOptionsFromMethodDirective<Value = any, Parameters extends AutocompleteOptionsFromMethodDirectiveParameters<Value> = AutocompleteOptionsFromMethodDirectiveParameters<Value>>
|
|
280
|
+
extends ExtractResolveMethodMixin, AfterViewInit, OnDestroy {
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
@Mixin(ExtractResolveMethodMixin)
|
|
284
|
+
@Directive({
|
|
285
|
+
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
286
|
+
selector: '[rxapAutocompleteOptionsFromMethod]',
|
|
287
|
+
standalone: true,
|
|
288
|
+
})
|
|
289
|
+
export class AutocompleteOptionsFromMethodDirective<Value = any, Parameters extends AutocompleteOptionsFromMethodDirectiveParameters<Value> = AutocompleteOptionsFromMethodDirectiveParameters<Value>>
|
|
290
|
+
extends OptionsFromMethodDirective<Value, Parameters>
|
|
291
|
+
implements AfterViewInit, OnDestroy {
|
|
292
|
+
|
|
293
|
+
static override ngTemplateContextGuard(
|
|
294
|
+
dir: OptionsFromMethodDirective,
|
|
295
|
+
ctx: any,
|
|
296
|
+
): ctx is AutocompleteOptionsFromRemoteMethodTemplateContext {
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
@Input('rxapAutocompleteOptionsFromMethodParameters')
|
|
301
|
+
public declare parameters?: Parameters;
|
|
302
|
+
@Input('rxapAutocompleteOptionsFromMethodResetOnChange')
|
|
303
|
+
public declare resetOnChange?: Value;
|
|
304
|
+
@Input('rxapAutocompleteOptionsFromMethodMatAutocomplete')
|
|
305
|
+
public matAutocomplete?: MatAutocomplete;
|
|
306
|
+
// eslint-disable-next-line @angular-eslint/no-input-rename
|
|
307
|
+
@Input('rxapAutocompleteOptionsFromMethodCall')
|
|
308
|
+
public declare method: Method<ControlOptions, Parameters>;
|
|
309
|
+
// eslint-disable-next-line @angular-eslint/no-input-rename
|
|
310
|
+
@Input('rxapAutocompleteOptionsFromMethodResolve')
|
|
311
|
+
public resolveMethod?: MethodWithParameters<ControlOption, { value: Value } & Parameters>;
|
|
312
|
+
protected override ngControl: NgControl | null = null;
|
|
313
|
+
protected override matFormField: MatFormField | null = null;
|
|
314
|
+
protected override injector: Injector = inject(INJECTOR);
|
|
315
|
+
protected override settings: AutocompleteOptionsFromMethodDirectiveSettings = {};
|
|
316
|
+
/**
|
|
317
|
+
* This flag is used to prevent the setValue is called for each refresh
|
|
318
|
+
* of the options list. This is needed because the setValue method will
|
|
319
|
+
* trigger a new refresh of the options list. This results in an endless
|
|
320
|
+
* call stack. This flag is set to true if the setValue method is called
|
|
321
|
+
* once.
|
|
322
|
+
*/
|
|
323
|
+
private isAutocompleteToDisplayTriggered = false;
|
|
324
|
+
|
|
325
|
+
private _subscription?: Subscription;
|
|
326
|
+
|
|
327
|
+
public ngOnDestroy() {
|
|
328
|
+
this._subscription?.unsubscribe();
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
public override async ngAfterViewInit() {
|
|
332
|
+
if (this.matAutocomplete) {
|
|
333
|
+
this.matAutocomplete.displayWith = this.toDisplay.bind(this);
|
|
334
|
+
this.settings ??= {};
|
|
335
|
+
this.settings.filteredOptions ??= true;
|
|
336
|
+
}
|
|
337
|
+
await super.ngAfterViewInit();
|
|
338
|
+
this.resolveMethod ??= this.extractResolveMethod();
|
|
339
|
+
if (!this.control) {
|
|
340
|
+
throw new Error('The control is not yet defined');
|
|
341
|
+
}
|
|
342
|
+
const value$ = controlValueChanges$(this.control);
|
|
343
|
+
this._subscription = value$.pipe(
|
|
344
|
+
isDefined(),
|
|
345
|
+
// only trigger the load options or resolve value if the value is changed
|
|
346
|
+
// this is required because in the resolveValue method the control value is set
|
|
347
|
+
// to trigger the toDisplay function in the mat-autocomplete
|
|
348
|
+
distinctUntilChanged(),
|
|
349
|
+
tap(async value => {
|
|
350
|
+
this.setOptions(await this.loadOptions(this.parameters));
|
|
351
|
+
if (this.isValue(value)) {
|
|
352
|
+
this.triggerAutocompleteToDisplay();
|
|
353
|
+
}
|
|
354
|
+
}),
|
|
355
|
+
).subscribe();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
public toDisplay(value: any): string {
|
|
359
|
+
if (!value) {
|
|
360
|
+
return '';
|
|
361
|
+
}
|
|
362
|
+
const option = this.findOptionByValue(value);
|
|
363
|
+
return option?.display ?? (isDevMode() ? 'to display error' : '...');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
public isValue(value: any): boolean {
|
|
367
|
+
return typeof value === 'string' && isUUID(value);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
protected override loadOptions(parameters: Parameters = {} as Parameters): Promise<ControlOptions | null> {
|
|
371
|
+
if (!this.control) {
|
|
372
|
+
throw new Error('The control is not yet defined');
|
|
373
|
+
}
|
|
374
|
+
const value = this.control?.value;
|
|
375
|
+
const c_parameters = {...parameters};
|
|
376
|
+
if (this.isValue(value)) {
|
|
377
|
+
return this.resolveValue(value, c_parameters);
|
|
378
|
+
} else {
|
|
379
|
+
c_parameters.search ??= value;
|
|
380
|
+
if (!c_parameters.search) {
|
|
381
|
+
return Promise.resolve([]);
|
|
382
|
+
}
|
|
383
|
+
return super.loadOptions(c_parameters);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
protected override renderTemplate() {
|
|
388
|
+
super.renderTemplate();
|
|
389
|
+
if (this.matAutocomplete && !this.isAutocompleteToDisplayTriggered) {
|
|
390
|
+
this.isAutocompleteToDisplayTriggered = true;
|
|
391
|
+
this.triggerAutocompleteToDisplay();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
protected async resolveValue(value: Value, parameters: Parameters = {} as Parameters) {
|
|
396
|
+
if (!this.resolveMethod) {
|
|
397
|
+
if (isDevMode()) {
|
|
398
|
+
console.warn('The resolve method is not yet defined');
|
|
399
|
+
}
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
// only resolve the value if the option is not already loaded
|
|
403
|
+
if (!this.findOptionByValue(value)) {
|
|
404
|
+
const option = await this.resolveMethod!.call({...parameters, value});
|
|
405
|
+
if (option.value !== value) {
|
|
406
|
+
throw new Error('The resolved value is not the same as the input value');
|
|
407
|
+
}
|
|
408
|
+
return [ option ];
|
|
409
|
+
}
|
|
410
|
+
return this.options;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
private triggerAutocompleteToDisplay() {
|
|
414
|
+
// trigger a change detection after the options are rendered
|
|
415
|
+
// this is needed to trigger the mat-autocomplete options to display function
|
|
416
|
+
this.ngControl?.control?.setValue(this.ngControl?.control?.value);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private findOptionByValue(value: Value): ControlOption | null {
|
|
420
|
+
return this.options?.find((option: ControlOption) => option.value === value) ?? null;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
}
|
|
424
|
+
</code></pre>
|
|
425
|
+
</div>
|
|
426
|
+
</div>
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
</div><div class="search-results">
|
|
436
|
+
<div class="has-results">
|
|
437
|
+
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
|
|
438
|
+
<ul class="search-results-list"></ul>
|
|
439
|
+
</div>
|
|
440
|
+
<div class="no-results">
|
|
441
|
+
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
|
|
442
|
+
</div>
|
|
443
|
+
</div>
|
|
444
|
+
</div>
|
|
445
|
+
<!-- END CONTENT -->
|
|
446
|
+
</div>
|
|
447
|
+
</div>
|
|
448
|
+
|
|
449
|
+
<label class="dark-mode-switch">
|
|
450
|
+
<input type="checkbox">
|
|
451
|
+
<span class="slider">
|
|
452
|
+
<svg class="slider-icon" viewBox="0 0 24 24" fill="none" height="20" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" width="20" xmlns="http://www.w3.org/2000/svg">
|
|
453
|
+
<path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"></path>
|
|
454
|
+
</svg>
|
|
455
|
+
</span>
|
|
456
|
+
</label>
|
|
457
|
+
|
|
458
|
+
<script>
|
|
459
|
+
var COMPODOC_CURRENT_PAGE_DEPTH = 1;
|
|
460
|
+
var COMPODOC_CURRENT_PAGE_CONTEXT = 'interface';
|
|
461
|
+
var COMPODOC_CURRENT_PAGE_URL = 'AutocompleteOptionsFromRemoteMethodTemplateContext.html';
|
|
462
|
+
var MAX_SEARCH_RESULTS = 15;
|
|
463
|
+
</script>
|
|
464
|
+
|
|
465
|
+
<script>
|
|
466
|
+
$darkModeToggleSwitchers = document.querySelectorAll('.dark-mode-switch input');
|
|
467
|
+
checkToggle(darkModeState);
|
|
468
|
+
if ($darkModeToggleSwitchers.length > 0) {
|
|
469
|
+
for (var i = 0; i < $darkModeToggleSwitchers.length; i++) {
|
|
470
|
+
$darkModeToggleSwitchers[i].addEventListener('change', function (event) {
|
|
471
|
+
darkModeState = !darkModeState;
|
|
472
|
+
toggleDarkMode(darkModeState);
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
</script>
|
|
477
|
+
|
|
478
|
+
<script src="../js/libs/custom-elements.min.js"></script>
|
|
479
|
+
<script src="../js/libs/lit-html.js"></script>
|
|
480
|
+
|
|
481
|
+
<script src="../js/menu-wc.js" defer></script>
|
|
482
|
+
<script nomodule src="../js/menu-wc_es5.js" defer></script>
|
|
483
|
+
|
|
484
|
+
<script src="../js/libs/bootstrap-native.js"></script>
|
|
485
|
+
|
|
486
|
+
<script src="../js/libs/es6-shim.min.js"></script>
|
|
487
|
+
<script src="../js/libs/EventDispatcher.js"></script>
|
|
488
|
+
<script src="../js/libs/promise.min.js"></script>
|
|
489
|
+
<script src="../js/libs/zepto.min.js"></script>
|
|
490
|
+
|
|
491
|
+
<script src="../js/compodoc.js"></script>
|
|
492
|
+
|
|
493
|
+
<script src="../js/tabs.js"></script>
|
|
494
|
+
<script src="../js/menu.js"></script>
|
|
495
|
+
<script src="../js/libs/clipboard.min.js"></script>
|
|
496
|
+
<script src="../js/libs/prism.js"></script>
|
|
497
|
+
<script src="../js/sourceCode.js"></script>
|
|
498
|
+
<script src="../js/search/search.js"></script>
|
|
499
|
+
<script src="../js/search/lunr.min.js"></script>
|
|
500
|
+
<script src="../js/search/search-lunr.js"></script>
|
|
501
|
+
<script src="../js/search/search_index.js"></script>
|
|
502
|
+
<script src="../js/lazy-load-graphs.js"></script>
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
</body>
|
|
506
|
+
</html>
|
|
@@ -148,8 +148,12 @@
|
|
|
148
148
|
TemplateRef,
|
|
149
149
|
ViewContainerRef,
|
|
150
150
|
} from '@angular/core';
|
|
151
|
-
import {
|
|
151
|
+
import {
|
|
152
|
+
AbstractControlDirective,
|
|
153
|
+
NgControl,
|
|
154
|
+
} from '@angular/forms';
|
|
152
155
|
import { MatFormField } from '@angular/material/form-field';
|
|
156
|
+
import { RxapFormControl } from '@rxap/forms';
|
|
153
157
|
import { Mixin } from '@rxap/mixin';
|
|
154
158
|
import { Method } from '@rxap/pattern';
|
|
155
159
|
import {
|
|
@@ -193,20 +197,23 @@ export class OptionsFromMethodDirective<Value = any, Parameters = a
|
|
|
193
197
|
@Input('rxapOptionsFromMethodResetOnChange')
|
|
194
198
|
public resetOnChange?: Value;
|
|
195
199
|
|
|
196
|
-
public options: ControlOptions | null
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
protected
|
|
201
|
-
protected
|
|
202
|
-
protected
|
|
200
|
+
public options: ControlOptions | null = null;
|
|
201
|
+
// eslint-disable-next-line @angular-eslint/no-input-rename
|
|
202
|
+
@Input('rxapOptionsFromMethodCall')
|
|
203
|
+
public method!: Method<ControlOptions, Parameters>;
|
|
204
|
+
protected ngControl: NgControl | AbstractControlDirective | null = null;
|
|
205
|
+
protected matFormField: MatFormField | null = null;
|
|
206
|
+
protected settings: OptionsFromMethodDirectiveSettings = {};
|
|
207
|
+
protected readonly viewContainerRef: ViewContainerRef = inject(ViewContainerRef);
|
|
208
|
+
protected readonly injector: Injector = inject(INJECTOR);
|
|
203
209
|
protected readonly cdr: ChangeDetectorRef = inject(ChangeDetectorRef);
|
|
204
210
|
private readonly template: TemplateRef<OptionsFromMethodTemplateContext> = inject(TemplateRef);
|
|
205
211
|
|
|
206
212
|
public async ngAfterViewInit() {
|
|
207
|
-
this.ngControl = this.injector.get(NgControl, null);
|
|
208
213
|
this.matFormField = this.injector.get(MatFormField, null);
|
|
209
|
-
this.
|
|
214
|
+
this.ngControl = this.injector.get(NgControl, this.matFormField?._control.ngControl);
|
|
215
|
+
this.control = (this.ngControl?.control as RxapFormControl) ?? undefined;
|
|
216
|
+
this.method ??= this.extractOptionsMethod();
|
|
210
217
|
// ensure that the options are loaded. It is possible that the ngOnChange is triggered before the ngAfterViewInit
|
|
211
218
|
// then the options are not loaded.
|
|
212
219
|
if (!this.options) {
|
|
@@ -227,7 +234,7 @@ export class OptionsFromMethodDirective<Value = any, Parameters = a
|
|
|
227
234
|
}
|
|
228
235
|
}
|
|
229
236
|
|
|
230
|
-
protected async loadOptions(parameters?: Parameters): Promise<ControlOptions> {
|
|
237
|
+
protected async loadOptions(parameters?: Parameters): Promise<ControlOptions | null> {
|
|
231
238
|
return this.method.call(parameters);
|
|
232
239
|
}
|
|
233
240
|
|
|
@@ -251,9 +258,14 @@ export class OptionsFromMethodDirective<Value = any, Parameters = a
|
|
|
251
258
|
|
|
252
259
|
}
|
|
253
260
|
|
|
254
|
-
protected setOptions(options: ControlOptions) {
|
|
255
|
-
|
|
256
|
-
|
|
261
|
+
protected setOptions(options: ControlOptions | null) {
|
|
262
|
+
if (!options) {
|
|
263
|
+
this.options = null;
|
|
264
|
+
this.viewContainerRef.clear();
|
|
265
|
+
} else {
|
|
266
|
+
this.options = options.slice();
|
|
267
|
+
this.renderTemplate();
|
|
268
|
+
}
|
|
257
269
|
}
|
|
258
270
|
|
|
259
271
|
}
|
|
@@ -208,8 +208,12 @@
|
|
|
208
208
|
TemplateRef,
|
|
209
209
|
ViewContainerRef,
|
|
210
210
|
} from '@angular/core';
|
|
211
|
-
import {
|
|
211
|
+
import {
|
|
212
|
+
AbstractControlDirective,
|
|
213
|
+
NgControl,
|
|
214
|
+
} from '@angular/forms';
|
|
212
215
|
import { MatFormField } from '@angular/material/form-field';
|
|
216
|
+
import { RxapFormControl } from '@rxap/forms';
|
|
213
217
|
import { Mixin } from '@rxap/mixin';
|
|
214
218
|
import { Method } from '@rxap/pattern';
|
|
215
219
|
import {
|
|
@@ -253,20 +257,23 @@ export class OptionsFromMethodDirective<Value = any, Parameters = a
|
|
|
253
257
|
@Input('rxapOptionsFromMethodResetOnChange')
|
|
254
258
|
public resetOnChange?: Value;
|
|
255
259
|
|
|
256
|
-
public options: ControlOptions | null
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
protected
|
|
261
|
-
protected
|
|
262
|
-
protected
|
|
260
|
+
public options: ControlOptions | null = null;
|
|
261
|
+
// eslint-disable-next-line @angular-eslint/no-input-rename
|
|
262
|
+
@Input('rxapOptionsFromMethodCall')
|
|
263
|
+
public method!: Method<ControlOptions, Parameters>;
|
|
264
|
+
protected ngControl: NgControl | AbstractControlDirective | null = null;
|
|
265
|
+
protected matFormField: MatFormField | null = null;
|
|
266
|
+
protected settings: OptionsFromMethodDirectiveSettings = {};
|
|
267
|
+
protected readonly viewContainerRef: ViewContainerRef = inject(ViewContainerRef);
|
|
268
|
+
protected readonly injector: Injector = inject(INJECTOR);
|
|
263
269
|
protected readonly cdr: ChangeDetectorRef = inject(ChangeDetectorRef);
|
|
264
270
|
private readonly template: TemplateRef<OptionsFromMethodTemplateContext> = inject(TemplateRef);
|
|
265
271
|
|
|
266
272
|
public async ngAfterViewInit() {
|
|
267
|
-
this.ngControl = this.injector.get(NgControl, null);
|
|
268
273
|
this.matFormField = this.injector.get(MatFormField, null);
|
|
269
|
-
this.
|
|
274
|
+
this.ngControl = this.injector.get(NgControl, this.matFormField?._control.ngControl);
|
|
275
|
+
this.control = (this.ngControl?.control as RxapFormControl) ?? undefined;
|
|
276
|
+
this.method ??= this.extractOptionsMethod();
|
|
270
277
|
// ensure that the options are loaded. It is possible that the ngOnChange is triggered before the ngAfterViewInit
|
|
271
278
|
// then the options are not loaded.
|
|
272
279
|
if (!this.options) {
|
|
@@ -287,7 +294,7 @@ export class OptionsFromMethodDirective<Value = any, Parameters = a
|
|
|
287
294
|
}
|
|
288
295
|
}
|
|
289
296
|
|
|
290
|
-
protected async loadOptions(parameters?: Parameters): Promise<ControlOptions> {
|
|
297
|
+
protected async loadOptions(parameters?: Parameters): Promise<ControlOptions | null> {
|
|
291
298
|
return this.method.call(parameters);
|
|
292
299
|
}
|
|
293
300
|
|
|
@@ -311,9 +318,14 @@ export class OptionsFromMethodDirective<Value = any, Parameters = a
|
|
|
311
318
|
|
|
312
319
|
}
|
|
313
320
|
|
|
314
|
-
protected setOptions(options: ControlOptions) {
|
|
315
|
-
|
|
316
|
-
|
|
321
|
+
protected setOptions(options: ControlOptions | null) {
|
|
322
|
+
if (!options) {
|
|
323
|
+
this.options = null;
|
|
324
|
+
this.viewContainerRef.clear();
|
|
325
|
+
} else {
|
|
326
|
+
this.options = options.slice();
|
|
327
|
+
this.renderTemplate();
|
|
328
|
+
}
|
|
317
329
|
}
|
|
318
330
|
|
|
319
331
|
}
|