@rxap/material-table-window-system 21.0.1 → 22.0.0-dev.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.
@@ -1,217 +1,223 @@
1
- import { __decorate } from 'tslib';
2
- import * as i0 from '@angular/core';
3
- import { inject, INJECTOR, ViewContainerRef, input, isDevMode, Directive, Injector, ComponentRef, Injectable } from '@angular/core';
4
- import { MAT_FORM_FIELD } from '@angular/material/form-field';
5
- import { MatSelect } from '@angular/material/select';
6
- import { PipeDataSource, DataSourceLoader } from '@rxap/data-source';
7
- import { ExtractFormDefinitionMixin, ExtractDataSourcesMixin } from '@rxap/form-system';
8
- import { RxapFormControl } from '@rxap/forms';
9
- import { Mixin } from '@rxap/mixin';
10
- import { coerceArray } from '@rxap/utilities';
11
- import { map, take, tap } from 'rxjs/operators';
12
- import { WindowService, RXAP_WINDOW_SETTINGS } from '@rxap/window-system';
13
- import { RXAP_MATERIAL_TABLE_SYSTEM_SELECT_ROW_OPTIONS, TABLE_DATA_SOURCE, TABLE_REMOTE_METHOD, RXAP_TABLE_METHOD, TableSelectControlsComponent } from '@rxap/material-table-system';
14
- import { TableDataSource } from '@rxap/data-source/table';
15
- import { ComponentPortal } from '@angular/cdk/portal';
16
-
1
+ import { __decorate } from "tslib";
2
+ import * as i0 from "@angular/core";
3
+ import { ComponentRef, Directive, INJECTOR, Injectable, Injector, ViewContainerRef, inject, input, isDevMode } from "@angular/core";
4
+ import { MAT_FORM_FIELD } from "@angular/material/form-field";
5
+ import { MatSelect } from "@angular/material/select";
6
+ import { DataSourceLoader, PipeDataSource } from "@rxap/data-source";
7
+ import { ExtractDataSourcesMixin, ExtractFormDefinitionMixin } from "@rxap/form-system";
8
+ import { RxapFormControl } from "@rxap/forms";
9
+ import { Mixin } from "@rxap/mixin";
10
+ import { coerceArray } from "@rxap/utilities";
11
+ import { map, take, tap } from "rxjs/operators";
12
+ import { RXAP_WINDOW_SETTINGS, WindowService } from "@rxap/window-system";
13
+ import { RXAP_MATERIAL_TABLE_SYSTEM_SELECT_ROW_OPTIONS, RXAP_TABLE_METHOD, TABLE_DATA_SOURCE, TABLE_REMOTE_METHOD, TableSelectControlsComponent } from "@rxap/material-table-system";
14
+ import { TableDataSource } from "@rxap/data-source/table";
15
+ import { ComponentPortal } from "@angular/cdk/portal";
17
16
  let ExtractDatasourceMixin = class ExtractDatasourceMixin {
18
- // TODO : mv to rxap and replace in InputSelectOptionsDirective
19
- extractDatasource(dataSourceName, control = this.control) {
20
- const useDataSourceValue = this.extractDataSourceValue(dataSourceName, control);
21
- let dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource, this.metadata, this.injector);
22
- const settings = useDataSourceValue.settings;
23
- if (settings?.transformer) {
24
- dataSource = new PipeDataSource(dataSource, map(settings.transformer));
25
- }
26
- return this.dataSource = dataSource;
27
- }
28
- extractDataSourceValue(dataSourceName, control = this.control) {
29
- if (!control) {
30
- throw new Error('The control is not defined');
31
- }
32
- const formDefinition = this.extractFormDefinition(control);
33
- const useDataSourceValueMap = this.extractDataSources(formDefinition, control.controlId);
34
- if (!useDataSourceValueMap.has(dataSourceName)) {
35
- throw new Error(`The data source with the name 'options' is not defined`);
36
- }
37
- return useDataSourceValueMap.get(dataSourceName);
38
- }
39
- extractDataSourceTransformer(dataSourceName, control = this.control) {
40
- if (!control) {
41
- throw new Error('The control is not defined');
42
- }
43
- const useDataSourceValue = this.extractDataSourceValue(dataSourceName, control);
44
- const settings = useDataSourceValue.settings;
45
- return settings?.transformer ?? (v => v);
46
- }
17
+ extractDatasource(dataSourceName, control = this.control) {
18
+ const useDataSourceValue = this.extractDataSourceValue(dataSourceName, control);
19
+ let dataSource = this.dataSourceLoader.load(useDataSourceValue.dataSource, this.metadata, this.injector);
20
+ const settings = useDataSourceValue.settings;
21
+ if (settings?.transformer) dataSource = new PipeDataSource(dataSource, map(settings.transformer));
22
+ return this.dataSource = dataSource;
23
+ }
24
+ extractDataSourceValue(dataSourceName, control = this.control) {
25
+ if (!control) throw new Error("The control is not defined");
26
+ const formDefinition = this.extractFormDefinition(control);
27
+ const useDataSourceValueMap = this.extractDataSources(formDefinition, control.controlId);
28
+ if (!useDataSourceValueMap.has(dataSourceName)) throw new Error(`The data source with the name 'options' is not defined`);
29
+ return useDataSourceValueMap.get(dataSourceName);
30
+ }
31
+ extractDataSourceTransformer(dataSourceName, control = this.control) {
32
+ if (!control) throw new Error("The control is not defined");
33
+ return this.extractDataSourceValue(dataSourceName, control).settings?.transformer ?? ((v) => v);
34
+ }
47
35
  };
48
- ExtractDatasourceMixin = __decorate([
49
- Mixin(ExtractFormDefinitionMixin, ExtractDataSourcesMixin)
50
- ], ExtractDatasourceMixin);
36
+ ExtractDatasourceMixin = __decorate([Mixin(ExtractFormDefinitionMixin, ExtractDataSourcesMixin)], ExtractDatasourceMixin);
51
37
  let OpenTableSelectDirective = class OpenTableSelectDirective {
52
- constructor() {
53
- this.formField = inject(MAT_FORM_FIELD);
54
- this.dataSourceLoader = inject(DataSourceLoader);
55
- this.injector = inject(INJECTOR);
56
- this.viewContainerRef = inject(ViewContainerRef);
57
- this.openMethod = input.required({ ...(ngDevMode ? { debugName: "openMethod" } : /* istanbul ignore next */ {}), alias: "rxapOpenTableSelect" });
58
- this._windowRef = null;
59
- }
60
- ngOnInit() {
61
- const control = this.formField._control.ngControl?.control;
62
- if (!control) {
63
- throw new Error('Could not extract the control from the form field');
64
- }
65
- if (!(control instanceof RxapFormControl)) {
66
- throw new Error('The control is not an instance of RxapFormControl');
67
- }
68
- this.extractDatasource('options', this.control = control);
69
- this.tableSelectDataSource = new PipeDataSource(this.dataSource, map(source => {
70
- if (!Array.isArray(source)) {
71
- throw new Error('Only control options data source are supported as source data source for a select table');
72
- }
73
- return source.map(item => item.value);
74
- }));
75
- }
76
- async onClick() {
77
- const selected$ = this.openMethod().call({
78
- data: this.tableSelectDataSource,
79
- selected: coerceArray(this.control?.value),
80
- multiple: this.isMultiple(),
81
- injector: this.injector,
82
- viewContainerRef: this.viewContainerRef,
83
- });
84
- // set the component windowRef. If the component is destroyed
85
- // before the promise is resolved. The window is closed in
86
- // the ngOnDestroy hook
87
- this._windowRef = selected$.windowRef ?? null;
88
- const selected = await selected$;
89
- this._windowRef = null;
90
- if (isDevMode()) {
91
- console.log('table select returns', selected);
92
- }
93
- if (selected && Array.isArray(selected)) {
94
- if (this.isMultiple()) {
95
- this.control?.setValue(selected);
96
- }
97
- else {
98
- this.control?.setValue(selected[0] ?? null);
99
- }
100
- }
101
- }
102
- ngOnDestroy() {
103
- this._windowRef?.complete();
104
- }
105
- isMultiple() {
106
- const formFieldControl = this.formField._control;
107
- if (formFieldControl instanceof MatSelect) {
108
- return formFieldControl.multiple;
109
- }
110
- return false;
111
- }
112
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: OpenTableSelectDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
113
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: OpenTableSelectDirective, isStandalone: true, selector: "[rxapOpenTableSelect]", inputs: { openMethod: { classPropertyName: "openMethod", publicName: "rxapOpenTableSelect", isSignal: true, isRequired: true, transformFunction: null } }, host: { attributes: { "type": "button" }, listeners: { "click": "onClick()" } }, ngImport: i0 }); }
38
+ constructor() {
39
+ this.formField = inject(MAT_FORM_FIELD);
40
+ this.dataSourceLoader = inject(DataSourceLoader);
41
+ this.injector = inject(INJECTOR);
42
+ this.viewContainerRef = inject(ViewContainerRef);
43
+ this.openMethod = input.required({
44
+ ...ngDevMode ? { debugName: "openMethod" } : /* istanbul ignore next */ {},
45
+ alias: "rxapOpenTableSelect"
46
+ });
47
+ this._windowRef = null;
48
+ }
49
+ ngOnInit() {
50
+ const control = this.formField._control.ngControl?.control;
51
+ if (!control) throw new Error("Could not extract the control from the form field");
52
+ if (!(control instanceof RxapFormControl)) throw new Error("The control is not an instance of RxapFormControl");
53
+ this.extractDatasource("options", this.control = control);
54
+ this.tableSelectDataSource = new PipeDataSource(this.dataSource, map((source) => {
55
+ if (!Array.isArray(source)) throw new Error("Only control options data source are supported as source data source for a select table");
56
+ return source.map((item) => item.value);
57
+ }));
58
+ }
59
+ async onClick() {
60
+ const selected$ = this.openMethod().call({
61
+ data: this.tableSelectDataSource,
62
+ selected: coerceArray(this.control?.value),
63
+ multiple: this.isMultiple(),
64
+ injector: this.injector,
65
+ viewContainerRef: this.viewContainerRef
66
+ });
67
+ this._windowRef = selected$.windowRef ?? null;
68
+ const selected = await selected$;
69
+ this._windowRef = null;
70
+ if (isDevMode()) console.log("table select returns", selected);
71
+ if (selected && Array.isArray(selected)) {
72
+ if (this.isMultiple()) this.control?.setValue(selected);
73
+ else this.control?.setValue(selected[0] ?? null);
74
+ }
75
+ }
76
+ ngOnDestroy() {
77
+ this._windowRef?.complete();
78
+ }
79
+ isMultiple() {
80
+ const formFieldControl = this.formField._control;
81
+ if (formFieldControl instanceof MatSelect) return formFieldControl.multiple;
82
+ return false;
83
+ }
84
+ static {
85
+ this.ɵfac = i0.ɵɵngDeclareFactory({
86
+ minVersion: "12.0.0",
87
+ version: "22.3.0",
88
+ ngImport: i0,
89
+ type: OpenTableSelectDirective,
90
+ deps: [],
91
+ target: i0.ɵɵFactoryTarget.Directive
92
+ });
93
+ }
94
+ static {
95
+ this.ɵdir = i0.ɵɵngDeclareDirective({
96
+ minVersion: "17.1.0",
97
+ version: "22.3.0",
98
+ type: OpenTableSelectDirective,
99
+ isStandalone: true,
100
+ selector: "[rxapOpenTableSelect]",
101
+ inputs: { openMethod: {
102
+ classPropertyName: "openMethod",
103
+ publicName: "rxapOpenTableSelect",
104
+ isSignal: true,
105
+ isRequired: true,
106
+ transformFunction: null
107
+ } },
108
+ host: {
109
+ attributes: { "type": "button" },
110
+ listeners: { "click": "onClick()" }
111
+ },
112
+ ngImport: i0
113
+ });
114
+ }
114
115
  };
115
- OpenTableSelectDirective = __decorate([
116
- Mixin(ExtractDatasourceMixin)
117
- ], OpenTableSelectDirective);
118
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: OpenTableSelectDirective, decorators: [{
119
- type: Directive,
120
- args: [{
121
- selector: '[rxapOpenTableSelect]',
122
- standalone: true,
123
- host: {
124
- type: 'button',
125
- '(click)': 'onClick()',
126
- },
127
- }]
128
- }], propDecorators: { openMethod: [{ type: i0.Input, args: [{ isSignal: true, alias: "rxapOpenTableSelect", required: true }] }] } });
129
-
130
- class WindowTableSelectService {
131
- constructor() {
132
- this.windowService = inject(WindowService);
133
- this.injector = inject(INJECTOR);
134
- }
135
- open(component, options, windowConfig = {}) {
136
- const providers = [
137
- {
138
- provide: RXAP_MATERIAL_TABLE_SYSTEM_SELECT_ROW_OPTIONS,
139
- useValue: {
140
- multiple: options.multiple ?? false,
141
- selected: options.selected ?? [],
142
- },
143
- },
144
- {
145
- provide: RXAP_WINDOW_SETTINGS,
146
- useValue: {
147
- title: options.title ??
148
- $localize `:@@rxap.window-table-system.select-table.title:Select Options`,
149
- },
150
- },
151
- ];
152
- if (options.data) {
153
- providers.push({
154
- provide: TABLE_DATA_SOURCE,
155
- useValue: new TableDataSource(options.data),
156
- });
157
- }
158
- else {
159
- providers.push({
160
- provide: TABLE_DATA_SOURCE,
161
- useValue: null,
162
- });
163
- }
164
- providers.push({
165
- provide: TABLE_REMOTE_METHOD,
166
- useValue: null,
167
- });
168
- providers.push({
169
- provide: RXAP_TABLE_METHOD,
170
- useValue: null,
171
- });
172
- const windowRef = this.windowService.open({
173
- ...windowConfig,
174
- viewContainerRef: options.viewContainerRef,
175
- injector: Injector.create({
176
- parent: options.injector ?? windowConfig.injector ?? this.injector,
177
- providers,
178
- }),
179
- component,
180
- });
181
- windowRef.attachedRef$
182
- .pipe(take(1), tap((attachedRef) => {
183
- if (attachedRef instanceof ComponentRef) {
184
- windowRef.setFooterPortal(new ComponentPortal(TableSelectControlsComponent, options.viewContainerRef, attachedRef.injector));
185
- }
186
- else {
187
- throw new Error('FATAL: the attached ref was not an instance of Component ref');
188
- }
189
- }))
190
- .subscribe();
191
- const promise = windowRef.closed$
192
- .pipe(take(1), map((selected) => selected ?? []))
193
- .toPromise();
194
- // add the windowRef to the promise instance
195
- // The windowRef instance can be used to cancel the window
196
- // If the calling component / directive is destroyed the created window should
197
- // be also destroyed
198
- promise.windowRef = windowRef;
199
- return promise;
200
- }
201
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: WindowTableSelectService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
202
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: WindowTableSelectService, providedIn: 'root' }); }
203
- }
204
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: WindowTableSelectService, decorators: [{
205
- type: Injectable,
206
- args: [{ providedIn: 'root' }]
207
- }] });
208
-
209
- // region
210
- // endregion
211
-
212
- /**
213
- * Generated bundle index. Do not edit.
214
- */
215
-
116
+ OpenTableSelectDirective = __decorate([Mixin(ExtractDatasourceMixin)], OpenTableSelectDirective);
117
+ i0.ɵɵngDeclareClassMetadata({
118
+ minVersion: "12.0.0",
119
+ version: "22.3.0",
120
+ ngImport: i0,
121
+ type: OpenTableSelectDirective,
122
+ decorators: [{
123
+ type: Directive,
124
+ args: [{
125
+ selector: "[rxapOpenTableSelect]",
126
+ standalone: true,
127
+ host: {
128
+ type: "button",
129
+ "(click)": "onClick()"
130
+ }
131
+ }]
132
+ }],
133
+ propDecorators: { openMethod: [{
134
+ type: i0.Input,
135
+ args: [{
136
+ isSignal: true,
137
+ alias: "rxapOpenTableSelect",
138
+ required: true
139
+ }]
140
+ }] }
141
+ });
142
+ var WindowTableSelectService = class WindowTableSelectService {
143
+ constructor() {
144
+ this.windowService = inject(WindowService);
145
+ this.injector = inject(INJECTOR);
146
+ }
147
+ open(component, options, windowConfig = {}) {
148
+ const providers = [{
149
+ provide: RXAP_MATERIAL_TABLE_SYSTEM_SELECT_ROW_OPTIONS,
150
+ useValue: {
151
+ multiple: options.multiple ?? false,
152
+ selected: options.selected ?? []
153
+ }
154
+ }, {
155
+ provide: RXAP_WINDOW_SETTINGS,
156
+ useValue: { title: options.title ?? $localize`:@@rxap.window-table-system.select-table.title:Select Options` }
157
+ }];
158
+ if (options.data) providers.push({
159
+ provide: TABLE_DATA_SOURCE,
160
+ useValue: new TableDataSource(options.data)
161
+ });
162
+ else providers.push({
163
+ provide: TABLE_DATA_SOURCE,
164
+ useValue: null
165
+ });
166
+ providers.push({
167
+ provide: TABLE_REMOTE_METHOD,
168
+ useValue: null
169
+ });
170
+ providers.push({
171
+ provide: RXAP_TABLE_METHOD,
172
+ useValue: null
173
+ });
174
+ const windowRef = this.windowService.open({
175
+ ...windowConfig,
176
+ viewContainerRef: options.viewContainerRef,
177
+ injector: Injector.create({
178
+ parent: options.injector ?? windowConfig.injector ?? this.injector,
179
+ providers
180
+ }),
181
+ component
182
+ });
183
+ windowRef.attachedRef$.pipe(take(1), tap((attachedRef) => {
184
+ if (attachedRef instanceof ComponentRef) windowRef.setFooterPortal(new ComponentPortal(TableSelectControlsComponent, options.viewContainerRef, attachedRef.injector));
185
+ else throw new Error("FATAL: the attached ref was not an instance of Component ref");
186
+ })).subscribe();
187
+ const promise = windowRef.closed$.pipe(take(1), map((selected) => selected ?? [])).toPromise();
188
+ promise.windowRef = windowRef;
189
+ return promise;
190
+ }
191
+ static {
192
+ this.ɵfac = i0.ɵɵngDeclareFactory({
193
+ minVersion: "12.0.0",
194
+ version: "22.3.0",
195
+ ngImport: i0,
196
+ type: WindowTableSelectService,
197
+ deps: [],
198
+ target: i0.ɵɵFactoryTarget.Injectable
199
+ });
200
+ }
201
+ static {
202
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
203
+ minVersion: "12.0.0",
204
+ version: "22.3.0",
205
+ ngImport: i0,
206
+ type: WindowTableSelectService,
207
+ providedIn: "root"
208
+ });
209
+ }
210
+ };
211
+ i0.ɵɵngDeclareClassMetadata({
212
+ minVersion: "12.0.0",
213
+ version: "22.3.0",
214
+ ngImport: i0,
215
+ type: WindowTableSelectService,
216
+ decorators: [{
217
+ type: Injectable,
218
+ args: [{ providedIn: "root" }]
219
+ }]
220
+ });
216
221
  export { ExtractDatasourceMixin, OpenTableSelectDirective, WindowTableSelectService };
217
- //# sourceMappingURL=rxap-material-table-window-system.mjs.map
222
+
223
+ //# sourceMappingURL=rxap-material-table-window-system.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"rxap-material-table-window-system.mjs","sources":["../../../../../../packages/angular/material/table-window-system/src/lib/open-table-select.directive.ts","../../../../../../packages/angular/material/table-window-system/src/lib/window-table-select.service.ts","../../../../../../packages/angular/material/table-window-system/src/index.ts","../../../../../../packages/angular/material/table-window-system/src/rxap-material-table-window-system.ts"],"sourcesContent":["import { Directive, INJECTOR, Injector, isDevMode, OnDestroy, OnInit, ViewContainerRef, input, inject } from '@angular/core';\nimport {\n MAT_FORM_FIELD,\n MatFormField,\n} from '@angular/material/form-field';\nimport { MatSelect } from '@angular/material/select';\nimport {\n BaseDataSource,\n BaseDataSourceMetadata,\n DataSourceLoader,\n PipeDataSource,\n} from '@rxap/data-source';\nimport {\n ExtractDataSourcesMixin,\n ExtractFormDefinitionMixin,\n} from '@rxap/form-system';\nimport { RxapFormControl } from '@rxap/forms';\nimport { Mixin } from '@rxap/mixin';\nimport { Method } from '@rxap/pattern';\nimport {\n coerceArray,\n ControlOptions,\n} from '@rxap/utilities';\nimport { WindowRef } from '@rxap/window-system';\nimport { map } from 'rxjs/operators';\nimport { WindowTableSelectOptions } from './window-table-select.service';\n\nexport interface ExtractDatasourceMixin extends ExtractFormDefinitionMixin, ExtractDataSourcesMixin {\n}\n\n@Mixin(ExtractFormDefinitionMixin, ExtractDataSourcesMixin)\nexport class ExtractDatasourceMixin {\n\n public metadata?: BaseDataSourceMetadata;\n protected control?: RxapFormControl;\n protected injector!: Injector;\n protected dataSourceLoader!: DataSourceLoader;\n protected dataSource!: BaseDataSource<ControlOptions | Record<string, any>>;\n\n // TODO : mv to rxap and replace in InputSelectOptionsDirective\n protected extractDatasource(\n dataSourceName: string,\n control: RxapFormControl | undefined = this.control,\n ): BaseDataSource<ControlOptions | Record<string, any>> {\n\n const useDataSourceValue = this.extractDataSourceValue(dataSourceName, control);\n\n let dataSource = this.dataSourceLoader.load(\n useDataSourceValue.dataSource,\n this.metadata,\n this.injector,\n );\n\n const settings = useDataSourceValue.settings;\n\n if (settings?.transformer) {\n dataSource = new PipeDataSource(dataSource, map(settings.transformer));\n }\n\n return this.dataSource = dataSource;\n }\n\n protected extractDataSourceValue(\n dataSourceName: string,\n control: RxapFormControl | undefined = this.control,\n ) {\n\n if (!control) {\n throw new Error('The control is not defined');\n }\n\n const formDefinition = this.extractFormDefinition(control);\n\n const useDataSourceValueMap = this.extractDataSources(formDefinition, control.controlId);\n\n if (!useDataSourceValueMap.has(dataSourceName)) {\n throw new Error(`The data source with the name 'options' is not defined`);\n }\n\n return useDataSourceValueMap.get(dataSourceName)!;\n }\n\n protected extractDataSourceTransformer(\n dataSourceName: string,\n control: RxapFormControl | undefined = this.control,\n ) {\n\n if (!control) {\n throw new Error('The control is not defined');\n }\n\n const useDataSourceValue = this.extractDataSourceValue(dataSourceName, control);\n const settings = useDataSourceValue.settings;\n return settings?.transformer ?? (v => v);\n }\n\n}\n\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface OpenTableSelectDirective<Data extends Record<string, any>> extends ExtractDatasourceMixin {\n}\n\n@Mixin(ExtractDatasourceMixin)\n@Directive({\n selector: '[rxapOpenTableSelect]',\n standalone: true,\n host: {\n type: 'button',\n '(click)': 'onClick()',\n },\n})\nexport class OpenTableSelectDirective<Data extends Record<string, any>> implements OnInit, OnDestroy {\n private readonly formField = inject<MatFormField>(MAT_FORM_FIELD);\n protected readonly dataSourceLoader = inject<DataSourceLoader>(DataSourceLoader);\n protected readonly injector = inject<Injector>(INJECTOR);\n private readonly viewContainerRef = inject<ViewContainerRef>(ViewContainerRef);\n\n\n public readonly openMethod = input.required<Method<Data[], WindowTableSelectOptions<Data>>>({ alias: \"rxapOpenTableSelect\" });\n\n private tableSelectDataSource!: BaseDataSource<Data[]>;\n\n private _windowRef: WindowRef | null = null;\n\n public ngOnInit() {\n const control = this.formField._control.ngControl?.control;\n\n if (!control) {\n throw new Error('Could not extract the control from the form field');\n }\n\n if (!(control instanceof RxapFormControl)) {\n throw new Error('The control is not an instance of RxapFormControl');\n }\n\n this.extractDatasource('options', this.control = control);\n\n this.tableSelectDataSource = new PipeDataSource(this.dataSource, map(source => {\n\n if (!Array.isArray(source)) {\n throw new Error('Only control options data source are supported as source data source for a select table');\n }\n\n return source.map(item => item.value);\n }));\n\n }\n\n public async onClick() {\n const selected$ = this.openMethod().call({\n data: this.tableSelectDataSource,\n selected: coerceArray(this.control?.value),\n multiple: this.isMultiple(),\n injector: this.injector,\n viewContainerRef: this.viewContainerRef,\n });\n // set the component windowRef. If the component is destroyed\n // before the promise is resolved. The window is closed in\n // the ngOnDestroy hook\n this._windowRef = (selected$ as any).windowRef ?? null;\n const selected = await selected$;\n this._windowRef = null;\n if (isDevMode()) {\n console.log('table select returns', selected);\n }\n if (selected && Array.isArray(selected)) {\n if (this.isMultiple()) {\n this.control?.setValue(selected);\n } else {\n this.control?.setValue(selected[0] ?? null);\n }\n }\n }\n\n public ngOnDestroy() {\n this._windowRef?.complete();\n }\n\n private isMultiple(): boolean {\n\n const formFieldControl = this.formField._control;\n\n if (formFieldControl instanceof MatSelect) {\n return formFieldControl.multiple;\n }\n\n return false;\n }\n\n}\n\n\n","import { ComponentRef, Injectable, INJECTOR, Injector, StaticProvider, ViewContainerRef, inject } from '@angular/core';\nimport {\n RXAP_WINDOW_SETTINGS,\n WindowConfig,\n WindowRef,\n WindowService,\n} from '@rxap/window-system';\nimport { ComponentType } from '@angular/cdk/overlay';\nimport {\n RXAP_MATERIAL_TABLE_SYSTEM_SELECT_ROW_OPTIONS,\n RXAP_TABLE_METHOD,\n TABLE_DATA_SOURCE,\n TABLE_REMOTE_METHOD,\n TableSelectControlsComponent,\n} from '@rxap/material-table-system';\nimport {\n map,\n take,\n tap,\n} from 'rxjs/operators';\nimport { BaseDataSource } from '@rxap/data-source';\nimport { TableDataSource } from '@rxap/data-source/table';\nimport { ComponentPortal } from '@angular/cdk/portal';\n\nexport interface WindowTableSelectOptions<RowData> {\n title?: string;\n multiple?: boolean;\n selected?: RowData[];\n data?: BaseDataSource<RowData[]>;\n viewContainerRef?: ViewContainerRef;\n injector: Injector;\n}\n\ndeclare const $localize: any;\n\n@Injectable({ providedIn: 'root' })\nexport class WindowTableSelectService {\n private readonly windowService = inject<WindowService>(WindowService);\n private readonly injector = inject<Injector>(INJECTOR);\n\n\n public open<RowData extends Record<string, any>>(\n component: ComponentType<any>,\n options: WindowTableSelectOptions<RowData>,\n windowConfig: Omit<WindowConfig, 'component'> = {},\n ): Promise<RowData[]> & { windowRef: WindowRef } {\n const providers: StaticProvider[] = [\n {\n provide: RXAP_MATERIAL_TABLE_SYSTEM_SELECT_ROW_OPTIONS,\n useValue: {\n multiple: options.multiple ?? false,\n selected: options.selected ?? [],\n },\n },\n {\n provide: RXAP_WINDOW_SETTINGS,\n useValue: {\n title:\n options.title ??\n $localize`:@@rxap.window-table-system.select-table.title:Select Options`,\n },\n },\n ];\n\n if (options.data) {\n providers.push({\n provide: TABLE_DATA_SOURCE,\n useValue: new TableDataSource<RowData>(options.data),\n });\n } else {\n providers.push({\n provide: TABLE_DATA_SOURCE,\n useValue: null,\n });\n }\n\n providers.push({\n provide: TABLE_REMOTE_METHOD,\n useValue: null,\n });\n\n providers.push({\n provide: RXAP_TABLE_METHOD,\n useValue: null,\n });\n\n const windowRef = this.windowService.open({\n ...windowConfig,\n viewContainerRef: options.viewContainerRef,\n injector: Injector.create({\n parent: options.injector ?? windowConfig.injector ?? this.injector,\n providers,\n }),\n component,\n });\n\n windowRef.attachedRef$\n .pipe(\n take(1),\n tap((attachedRef) => {\n if (attachedRef instanceof ComponentRef) {\n windowRef.setFooterPortal(\n new ComponentPortal(\n TableSelectControlsComponent,\n options.viewContainerRef,\n attachedRef.injector,\n ),\n );\n } else {\n throw new Error(\n 'FATAL: the attached ref was not an instance of Component ref',\n );\n }\n }),\n )\n .subscribe();\n\n const promise: Promise<RowData[]> & { windowRef?: WindowRef } = windowRef.closed$\n .pipe(\n take(1),\n map((selected) => selected ?? []),\n )\n .toPromise();\n\n // add the windowRef to the promise instance\n // The windowRef instance can be used to cancel the window\n // If the calling component / directive is destroyed the created window should\n // be also destroyed\n promise.windowRef = windowRef;\n\n return promise as Promise<RowData[]> & { windowRef: WindowRef };\n }\n}\n","// region \nexport * from './lib/open-table-select.directive';\nexport * from './lib/window-table-select.service';\n// endregion\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA+BO,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB,CAAA;;AASvB,IAAA,iBAAiB,CACzB,cAAsB,EACtB,OAAA,GAAuC,IAAI,CAAC,OAAO,EAAA;QAGnD,MAAM,kBAAkB,GAAG,IAAI,CAAC,sBAAsB,CAAC,cAAc,EAAE,OAAO,CAAC;QAE/E,IAAI,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CACzC,kBAAkB,CAAC,UAAU,EAC7B,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,QAAQ,CACd;AAED,QAAA,MAAM,QAAQ,GAAG,kBAAkB,CAAC,QAAQ;AAE5C,QAAA,IAAI,QAAQ,EAAE,WAAW,EAAE;AACzB,YAAA,UAAU,GAAG,IAAI,cAAc,CAAC,UAAU,EAAE,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QACxE;AAEA,QAAA,OAAO,IAAI,CAAC,UAAU,GAAG,UAAU;IACrC;AAEU,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E;AAErB,QAAA,MAAM,OAAO,GAAmD,SAAS,CAAC;AACA,aAAA,IAAI,CACH,IAAI,CAAC,CAAC,CAAC,EACP,GAAG,CAAC,CAAC,QAAQ,KAAK,QAAQ,IAAI,EAAE,CAAC;AAElC,aAAA,SAAS,EAAE;;;;;AAMrF,QAAA,OAAO,CAAC,SAAS,GAAG,SAAS;AAE7B,QAAA,OAAO,OAAwD;IACjE;8GA/FW,wBAAwB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAxB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,wBAAwB,cADX,MAAM,EAAA,CAAA,CAAA;;2FACnB,wBAAwB,EAAA,UAAA,EAAA,CAAA;kBADpC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACnClC;AAGA;;ACHA;;AAEG;;;;"}
1
+ {"version":3,"file":"rxap-material-table-window-system.mjs","names":[],"sources":["../../../../../../packages/angular/material/table-window-system/src/lib/open-table-select.directive.ts","../../../../../../packages/angular/material/table-window-system/src/lib/window-table-select.service.ts"],"sourcesContent":["import { Directive, INJECTOR, Injector, isDevMode, OnDestroy, OnInit, ViewContainerRef, input, inject } from '@angular/core';\nimport {\n MAT_FORM_FIELD,\n MatFormField,\n} from '@angular/material/form-field';\nimport { MatSelect } from '@angular/material/select';\nimport {\n BaseDataSource,\n BaseDataSourceMetadata,\n DataSourceLoader,\n PipeDataSource,\n} from '@rxap/data-source';\nimport {\n ExtractDataSourcesMixin,\n ExtractFormDefinitionMixin,\n} from '@rxap/form-system';\nimport { RxapFormControl } from '@rxap/forms';\nimport { Mixin } from '@rxap/mixin';\nimport { Method } from '@rxap/pattern';\nimport {\n coerceArray,\n ControlOptions,\n} from '@rxap/utilities';\nimport { WindowRef } from '@rxap/window-system';\nimport { map } from 'rxjs/operators';\nimport { WindowTableSelectOptions } from './window-table-select.service';\n\nexport interface ExtractDatasourceMixin extends ExtractFormDefinitionMixin, ExtractDataSourcesMixin {\n}\n\n@Mixin(ExtractFormDefinitionMixin, ExtractDataSourcesMixin)\nexport class ExtractDatasourceMixin {\n\n public metadata?: BaseDataSourceMetadata;\n protected control?: RxapFormControl;\n protected injector!: Injector;\n protected dataSourceLoader!: DataSourceLoader;\n protected dataSource!: BaseDataSource<ControlOptions | Record<string, any>>;\n\n // TODO : mv to rxap and replace in InputSelectOptionsDirective\n protected extractDatasource(\n dataSourceName: string,\n control: RxapFormControl | undefined = this.control,\n ): BaseDataSource<ControlOptions | Record<string, any>> {\n\n const useDataSourceValue = this.extractDataSourceValue(dataSourceName, control);\n\n let dataSource = this.dataSourceLoader.load(\n useDataSourceValue.dataSource,\n this.metadata,\n this.injector,\n );\n\n const settings = useDataSourceValue.settings;\n\n if (settings?.transformer) {\n dataSource = new PipeDataSource(dataSource, map(settings.transformer));\n }\n\n return this.dataSource = dataSource;\n }\n\n protected extractDataSourceValue(\n dataSourceName: string,\n control: RxapFormControl | undefined = this.control,\n ) {\n\n if (!control) {\n throw new Error('The control is not defined');\n }\n\n const formDefinition = this.extractFormDefinition(control);\n\n const useDataSourceValueMap = this.extractDataSources(formDefinition, control.controlId);\n\n if (!useDataSourceValueMap.has(dataSourceName)) {\n throw new Error(`The data source with the name 'options' is not defined`);\n }\n\n return useDataSourceValueMap.get(dataSourceName)!;\n }\n\n protected extractDataSourceTransformer(\n dataSourceName: string,\n control: RxapFormControl | undefined = this.control,\n ) {\n\n if (!control) {\n throw new Error('The control is not defined');\n }\n\n const useDataSourceValue = this.extractDataSourceValue(dataSourceName, control);\n const settings = useDataSourceValue.settings;\n return settings?.transformer ?? (v => v);\n }\n\n}\n\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface OpenTableSelectDirective<Data extends Record<string, any>> extends ExtractDatasourceMixin {\n}\n\n@Mixin(ExtractDatasourceMixin)\n@Directive({\n selector: '[rxapOpenTableSelect]',\n standalone: true,\n host: {\n type: 'button',\n '(click)': 'onClick()',\n },\n})\nexport class OpenTableSelectDirective<Data extends Record<string, any>> implements OnInit, OnDestroy {\n private readonly formField = inject<MatFormField>(MAT_FORM_FIELD);\n protected readonly dataSourceLoader = inject<DataSourceLoader>(DataSourceLoader);\n protected readonly injector = inject<Injector>(INJECTOR);\n private readonly viewContainerRef = inject<ViewContainerRef>(ViewContainerRef);\n\n\n public readonly openMethod = input.required<Method<Data[], WindowTableSelectOptions<Data>>>({ alias: \"rxapOpenTableSelect\" });\n\n private tableSelectDataSource!: BaseDataSource<Data[]>;\n\n private _windowRef: WindowRef | null = null;\n\n public ngOnInit() {\n const control = this.formField._control.ngControl?.control;\n\n if (!control) {\n throw new Error('Could not extract the control from the form field');\n }\n\n if (!(control instanceof RxapFormControl)) {\n throw new Error('The control is not an instance of RxapFormControl');\n }\n\n this.extractDatasource('options', this.control = control);\n\n this.tableSelectDataSource = new PipeDataSource(this.dataSource, map(source => {\n\n if (!Array.isArray(source)) {\n throw new Error('Only control options data source are supported as source data source for a select table');\n }\n\n return source.map(item => item.value);\n }));\n\n }\n\n public async onClick() {\n const selected$ = this.openMethod().call({\n data: this.tableSelectDataSource,\n selected: coerceArray(this.control?.value),\n multiple: this.isMultiple(),\n injector: this.injector,\n viewContainerRef: this.viewContainerRef,\n });\n // set the component windowRef. If the component is destroyed\n // before the promise is resolved. The window is closed in\n // the ngOnDestroy hook\n this._windowRef = (selected$ as any).windowRef ?? null;\n const selected = await selected$;\n this._windowRef = null;\n if (isDevMode()) {\n console.log('table select returns', selected);\n }\n if (selected && Array.isArray(selected)) {\n if (this.isMultiple()) {\n this.control?.setValue(selected);\n } else {\n this.control?.setValue(selected[0] ?? null);\n }\n }\n }\n\n public ngOnDestroy() {\n this._windowRef?.complete();\n }\n\n private isMultiple(): boolean {\n\n const formFieldControl = this.formField._control;\n\n if (formFieldControl instanceof MatSelect) {\n return formFieldControl.multiple;\n }\n\n return false;\n }\n\n}\n\n\n","import { ComponentRef, Injectable, INJECTOR, Injector, StaticProvider, ViewContainerRef, inject } from '@angular/core';\nimport {\n RXAP_WINDOW_SETTINGS,\n WindowConfig,\n WindowRef,\n WindowService,\n} from '@rxap/window-system';\nimport { ComponentType } from '@angular/cdk/overlay';\nimport {\n RXAP_MATERIAL_TABLE_SYSTEM_SELECT_ROW_OPTIONS,\n RXAP_TABLE_METHOD,\n TABLE_DATA_SOURCE,\n TABLE_REMOTE_METHOD,\n TableSelectControlsComponent,\n} from '@rxap/material-table-system';\nimport {\n map,\n take,\n tap,\n} from 'rxjs/operators';\nimport { BaseDataSource } from '@rxap/data-source';\nimport { TableDataSource } from '@rxap/data-source/table';\nimport { ComponentPortal } from '@angular/cdk/portal';\n\nexport interface WindowTableSelectOptions<RowData> {\n title?: string;\n multiple?: boolean;\n selected?: RowData[];\n data?: BaseDataSource<RowData[]>;\n viewContainerRef?: ViewContainerRef;\n injector: Injector;\n}\n\ndeclare const $localize: any;\n\n@Injectable({ providedIn: 'root' })\nexport class WindowTableSelectService {\n private readonly windowService = inject<WindowService>(WindowService);\n private readonly injector = inject<Injector>(INJECTOR);\n\n\n public open<RowData extends Record<string, any>>(\n component: ComponentType<any>,\n options: WindowTableSelectOptions<RowData>,\n windowConfig: Omit<WindowConfig, 'component'> = {},\n ): Promise<RowData[]> & { windowRef: WindowRef } {\n const providers: StaticProvider[] = [\n {\n provide: RXAP_MATERIAL_TABLE_SYSTEM_SELECT_ROW_OPTIONS,\n useValue: {\n multiple: options.multiple ?? false,\n selected: options.selected ?? [],\n },\n },\n {\n provide: RXAP_WINDOW_SETTINGS,\n useValue: {\n title:\n options.title ??\n $localize`:@@rxap.window-table-system.select-table.title:Select Options`,\n },\n },\n ];\n\n if (options.data) {\n providers.push({\n provide: TABLE_DATA_SOURCE,\n useValue: new TableDataSource<RowData>(options.data),\n });\n } else {\n providers.push({\n provide: TABLE_DATA_SOURCE,\n useValue: null,\n });\n }\n\n providers.push({\n provide: TABLE_REMOTE_METHOD,\n useValue: null,\n });\n\n providers.push({\n provide: RXAP_TABLE_METHOD,\n useValue: null,\n });\n\n const windowRef = this.windowService.open({\n ...windowConfig,\n viewContainerRef: options.viewContainerRef,\n injector: Injector.create({\n parent: options.injector ?? windowConfig.injector ?? this.injector,\n providers,\n }),\n component,\n });\n\n windowRef.attachedRef$\n .pipe(\n take(1),\n tap((attachedRef) => {\n if (attachedRef instanceof ComponentRef) {\n windowRef.setFooterPortal(\n new ComponentPortal(\n TableSelectControlsComponent,\n options.viewContainerRef,\n attachedRef.injector,\n ),\n );\n } else {\n throw new Error(\n 'FATAL: the attached ref was not an instance of Component ref',\n );\n }\n }),\n )\n .subscribe();\n\n const promise: Promise<RowData[]> & { windowRef?: WindowRef } = windowRef.closed$\n .pipe(\n take(1),\n map((selected) => selected ?? []),\n )\n .toPromise();\n\n // add the windowRef to the promise instance\n // The windowRef instance can be used to cancel the window\n // If the calling component / directive is destroyed the created window should\n // be also destroyed\n promise.windowRef = windowRef;\n\n return promise as Promise<RowData[]> & { windowRef: WindowRef };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA+BO,IAAM,yBAAN,MAAM,uBAAsB;CASvB,kBACR,gBACA,UAAuC,KAAK,SAAO;EAGnD,MAAM,qBAAqB,KAAK,uBAAuB,gBAAgB,OAAO;EAE9E,IAAI,aAAa,KAAK,iBAAiB,KACrC,mBAAmB,YACnB,KAAK,UACL,KAAK,QAAQ;EAGf,MAAM,WAAW,mBAAmB;EAEpC,IAAI,UAAU,aACZ,aAAa,IAAI,eAAe,YAAY,IAAI,SAAS,WAAW,CAAC;EAGvE,OAAO,KAAK,aAAa;CAC3B;CAEU,uBACR,gBACA,UAAuC,KAAK,SAAO;EAGnD,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,4BAA4B;EAG9C,MAAM,iBAAiB,KAAK,sBAAsB,OAAO;EAE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