@dmlibs/dm-cmps 0.0.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.
@@ -0,0 +1,553 @@
1
+ import * as _angular_core from '@angular/core';
2
+ import { InputSignal, InputSignalWithTransform, ModelSignal, OutputEmitterRef, OnDestroy } from '@angular/core';
3
+ import { MatSelectChange } from '@angular/material/select';
4
+ import { FormControl } from '@angular/forms';
5
+ import { MatOptionSelectionChange } from '@angular/material/core';
6
+ import { MatCheckboxChange } from '@angular/material/checkbox';
7
+
8
+ interface DmCmpsDataSourceSort {
9
+ direction: 'asc' | 'desc';
10
+ field: string;
11
+ sortFn?: (a: any, b: any) => number;
12
+ }
13
+ declare class DmCmpsDataSource<T> implements DmCmpsDataSourceConfig<T> {
14
+ private data;
15
+ private filteredData;
16
+ private _resultData;
17
+ result: _angular_core.WritableSignal<T[]>;
18
+ private paginationEnabled;
19
+ private currentPageIndex;
20
+ private pageSize;
21
+ private autoPaginationAboveItemsCount;
22
+ private searchTerm;
23
+ private speratedSearch;
24
+ private filterPredicate;
25
+ private filterByObject;
26
+ private fieldsToSearchIn;
27
+ private sortMap;
28
+ private sortFn;
29
+ private searchTerms$;
30
+ private searchDebounceTime;
31
+ private readonly subscription;
32
+ /**
33
+ * builds a new DmCmpsDataSource
34
+ * @param initialData The data to be used as datasource
35
+ */
36
+ constructor(initialData?: T[]);
37
+ private updateResultData;
38
+ disconnect(): void;
39
+ setAutoPaginationAboveItemsCount(count: number): void;
40
+ applyPagination(pageSize?: number): void;
41
+ setPageSize(pageSize: number): void;
42
+ disablePagination(): void;
43
+ nextPage(): number;
44
+ previousPage(): number;
45
+ firstPage(): number;
46
+ lastPage(): number;
47
+ getCurrentPageIndex(): number;
48
+ getTotalPagesCount(): number;
49
+ setSearchDebounceTime(milliseconds: number): void;
50
+ setDatasource(newData: T[]): void;
51
+ private updateResultSignal;
52
+ search(filterTerm: string): void;
53
+ private applySearch;
54
+ setFilterPredicate(predicate: (data: T, filter: string) => boolean): void;
55
+ setFieldsToSearchIn(fields: string[]): void;
56
+ setSortFunction(sortFn: ((a: T, b: T) => number) | null): void;
57
+ private applySorting;
58
+ sortByFields(sortMap: DmCmpsDataSourceSort[]): void;
59
+ resetSorting(): void;
60
+ setFilterByObjectFields(filterObj: Partial<T> | null): void;
61
+ private applyObjectFilter;
62
+ applySperatedSearch(enabled: boolean): void;
63
+ }
64
+ interface DmCmpsDataSourceConfig<T = any> {
65
+ /**
66
+ * Disconnects the data source and performs any necessary cleanup.
67
+ */
68
+ disconnect: () => void;
69
+ /**
70
+ * Sets auto pagination threshold.
71
+ * When the number of items exceeds the given count, pagination will be enabled automatically.
72
+ * Use -1 to disable auto pagination.
73
+ *
74
+ * @param count Number of items threshold
75
+ * @default 100
76
+ */
77
+ setAutoPaginationAboveItemsCount: (count: number) => void;
78
+ /**
79
+ * ApplyPagination - Enables pagination with the given page size.
80
+ *
81
+ * @param pageSize Number of items per page, optional, default is 10, must be at least 5
82
+ * @default 10
83
+ */
84
+ applyPagination: (pageSize?: number) => void;
85
+ /**
86
+ * Sets the page size for pagination.
87
+ * @param pageSize Number of items per page, must be at least 5
88
+ */
89
+ setPageSize: (pageSize: number) => void;
90
+ /**
91
+ * Disables pagination.
92
+ */
93
+ disablePagination: () => void;
94
+ /**
95
+ * Moves to the next page and returns the current page index.
96
+ * @returns New current page index
97
+ */
98
+ nextPage: () => number;
99
+ /**
100
+ * Moves to the previous page and returns the current page index.
101
+ * @returns New current page index
102
+ */
103
+ previousPage: () => number;
104
+ /**
105
+ * Moves to the first page and returns the current page index.
106
+ * @returns New current page index
107
+ */
108
+ firstPage: () => number;
109
+ /**
110
+ * Moves to the last page and returns the current page index.
111
+ * @returns New current page index
112
+ */
113
+ lastPage: () => number;
114
+ /**
115
+ * Gets the current page index.
116
+ * @returns Current page index
117
+ */
118
+ getCurrentPageIndex: () => number;
119
+ /**
120
+ * Gets the total number of pages.
121
+ * @returns Total pages count
122
+ */
123
+ getTotalPagesCount: () => number;
124
+ /**
125
+ * Sets the debounce time for search input.
126
+ * @param milliseconds Debounce time in milliseconds
127
+ * @default 300
128
+ */
129
+ setSearchDebounceTime: (milliseconds: number) => void;
130
+ /**
131
+ * Sets the data source.
132
+ * @param newData New data array
133
+ */
134
+ setDatasource: (newData: T[]) => void;
135
+ /**
136
+ * Performs a search with the given filter term.
137
+ * @param filterTerm The term to filter the data
138
+ */
139
+ search: (filterTerm: string) => void;
140
+ /**
141
+ * Sets the filter predicate function.
142
+ * @param predicate Function to filter data items
143
+ *
144
+ * @default - A default predicate that checks if the item includes the filter term in any of its non Object properties.
145
+ */
146
+ setFilterPredicate: (predicate: (data: T, filter: string) => boolean) => void;
147
+ /**
148
+ * Sets the fields to search in.
149
+ * @param fields Array of field names to search in
150
+ *
151
+ * @default - All non Object properties of the data items.
152
+ */
153
+ setFieldsToSearchIn: (fields: string[]) => void;
154
+ /**
155
+ * Sets a custom sort function.
156
+ * @param sortFn Custom sort function
157
+ *
158
+ * @default - No custom sort function.
159
+ */
160
+ setSortFunction: (sortFn: ((a: T, b: T) => number) | null) => void;
161
+ /**
162
+ * Sorts the data by the given fields and directions.
163
+ * @param sortMap
164
+ * @default - No sorting applied.
165
+ */
166
+ sortByFields: (sortMap: DmCmpsDataSourceSort[]) => void;
167
+ /**
168
+ * Resets any applied sorting.
169
+ */
170
+ resetSorting: () => void;
171
+ /**
172
+ * Sets filter by object fields.
173
+ * @param filterObj Object with fields and values to filter by
174
+ * @default null (no filtering)
175
+ */
176
+ setFilterByObjectFields: (filterObj: Partial<T> | null) => void;
177
+ /**
178
+ * Enables or disables separated search.
179
+ * When enabled, the search term is split by spaces and each term is searched separately.
180
+ * @param enabled true to enable separated search, false to disable
181
+ * @default false
182
+ */
183
+ applySperatedSearch: (enabled: boolean) => void;
184
+ }
185
+
186
+ /**
187
+ * Public API for <dm-mat-select>
188
+ *
189
+ * This interface describes all inputs, outputs, and configuration options.
190
+ * It is used only for documentation and IntelliSense — not for runtime behavior.
191
+ */
192
+ interface DmMatSelectConfig<T = any> {
193
+ /**
194
+ * CSS classes applied to the mat-form-field element.
195
+ * ```
196
+ * type string
197
+ * ```
198
+ *
199
+ */
200
+ formFieldClass?: InputSignal<string>;
201
+ /**
202
+ * CSS classes applied to the wrapper div element.
203
+ * ```
204
+ * type string
205
+ * ```
206
+ *
207
+ */
208
+ wrapperClass?: InputSignal<string>;
209
+ /**
210
+ * Appearance style of the select component.
211
+ * ```
212
+ * type 'fill' | 'outline'
213
+ * ```
214
+ *
215
+ * @default fill
216
+ */
217
+ appearance?: InputSignal<'fill' | 'outline'>;
218
+ /**
219
+ * Enables multiple selection mode.
220
+ * ```
221
+ * type boolean
222
+ * ```
223
+ *
224
+ * @default false
225
+ */
226
+ multiple?: InputSignalWithTransform<boolean, unknown>;
227
+ /**
228
+ * Enables a "Select All" option in the dropdown.
229
+ * ```
230
+ * type boolean
231
+ * ```
232
+ *
233
+ * @default false
234
+ */
235
+ selectAllEnabled?: InputSignalWithTransform<boolean, unknown>;
236
+ /**
237
+ * Text of the "Select All" checkbox.
238
+ * ```
239
+ * type string
240
+ * ```
241
+ *
242
+ * @default 'בחר הכל'
243
+ */
244
+ selectAllLabel?: InputSignal<string>;
245
+ /**
246
+ * Label shown in the form field.
247
+ * ```
248
+ * type string
249
+ * ```
250
+ *
251
+ * @default ''
252
+ */
253
+ label?: InputSignal<string>;
254
+ /**
255
+ * The list of items shown in the dropdown.
256
+ * ```
257
+ * type T[]
258
+ * ```
259
+ *
260
+ * @default []
261
+ */
262
+ options: InputSignal<T[]>;
263
+ /**
264
+ * The property to use as the unique identifier of each item.
265
+ * ```
266
+ * type keyof T
267
+ * ```
268
+ *
269
+ * @default '_id'
270
+ */
271
+ optionValueKey?: InputSignal<keyof T>;
272
+ /**
273
+ * The property to use as the display label.
274
+ * ```
275
+ * type keyof T
276
+ * ```
277
+ *
278
+ * @default 'name'
279
+ */
280
+ optionLabelKey?: InputSignal<keyof T>;
281
+ /**
282
+ * Enables searching inside the dropdown.
283
+ * ```
284
+ * type boolean
285
+ * ```
286
+ *
287
+ * @default false
288
+ */
289
+ searchable?: InputSignalWithTransform<boolean, unknown>;
290
+ /**
291
+ * Function to filter options based on search input.
292
+ * ```
293
+ * type ((option: T, filter: string) => boolean) | null
294
+ * ```
295
+ *
296
+ * @default null
297
+ */
298
+ filterPredicate?: InputSignal<((option: T, filter: string) => boolean) | null>;
299
+ /**
300
+ * Marks field as required.
301
+ * ```
302
+ * type boolean
303
+ * ```
304
+ *
305
+ * @default false
306
+ */
307
+ required?: InputSignalWithTransform<boolean, unknown>;
308
+ /**
309
+ * Disables the component.
310
+ * ```
311
+ * type boolean
312
+ * ```
313
+ *
314
+ * @default false
315
+ */
316
+ disabled?: InputSignalWithTransform<boolean, unknown>;
317
+ /**
318
+ * Custom error message.
319
+ * ```
320
+ * type string | null
321
+ * ```
322
+ *
323
+ * @default null
324
+ */
325
+ error?: InputSignal<string | null>;
326
+ /**
327
+ * Placeholder text for the search input.
328
+ * ```
329
+ * type string
330
+ * ```
331
+ *
332
+ * @default 'חפש...'
333
+ */
334
+ searchPlaceholder?: InputSignal<string>;
335
+ /**
336
+ * Enables an empty option in the select dropdown.
337
+ * ```
338
+ * type boolean
339
+ * ```
340
+ *
341
+ * @default false
342
+ */
343
+ emptyOption?: InputSignalWithTransform<boolean, unknown>;
344
+ /**
345
+ * Label for the empty option.
346
+ * ```
347
+ * type string
348
+ * ```
349
+ *
350
+ * @default 'ללא'
351
+ */
352
+ emptyOptionLabel?: InputSignal<string>;
353
+ /**
354
+ * Value for the empty option.
355
+ * ```
356
+ * type null | string | number
357
+ * ```
358
+ *
359
+ * @default null
360
+ */
361
+ emptyOptionValue?: InputSignal<T | null>;
362
+ /**
363
+ * Function to format option names for display.
364
+ * ```
365
+ * type (option: T) => string
366
+ * ```
367
+ *
368
+ */
369
+ optionNameFormat?: InputSignal<((option: T) => string) | null>;
370
+ /**
371
+ * Width of the select panel.
372
+ * To set the panel width to match the trigger width, use 'auto'.
373
+ * To set a custom width, provide a CSS width value (e.g., '300px', '50%', etc.).
374
+ * To have the panel width adjust to its content, set to null or empty string.
375
+ * ```
376
+ * type string | null
377
+ * ```
378
+ *
379
+ * @default 'auto'
380
+ */
381
+ panelWidth?: InputSignal<string | null>;
382
+ /**\
383
+ * Custom CSS classes applied to the select panel.
384
+ * Can be a string, array of strings, Set of strings, or an object with class names as keys and boolean values.
385
+ * Accepts the same values as ngClass.
386
+ * ```
387
+ * type string | string[] | Set<string> | { [key: string]: any }
388
+ * ```
389
+ *
390
+ * @default ''
391
+ */
392
+ panelClass?: InputSignal<string | string[] | Set<string> | {
393
+ [key: string]: any;
394
+ }>;
395
+ /**\
396
+ * Background color for the search section.
397
+ * Uses CSS variable '--dm-mat-select-search-section-bg-color'.
398
+ * ```
399
+ * type string | null
400
+ * ```
401
+ *
402
+ * @default '#faf9fd'
403
+ */
404
+ searchSectionBackgroundColor?: InputSignal<string | null>;
405
+ /**
406
+ * Sort selected items at top of the list.
407
+ * ```
408
+ * type boolean
409
+ * ```
410
+ *
411
+ * @default false
412
+ */
413
+ sortBySelectedOnTop?: InputSignalWithTransform<boolean, unknown>;
414
+ /**
415
+ * A signal that holds the selected value(s) of the select component.
416
+ * ```
417
+ * type ModelSignal<DmMatSelectOutput<T>>
418
+ * ```
419
+ *
420
+ * @default null
421
+ */
422
+ value?: ModelSignal<DmMatSelectOutput<T>>;
423
+ /**
424
+ * FormControl to bind to the select component.
425
+ * ```
426
+ * type FormControl<DmMatSelectOutput<T>> | null
427
+ * ```
428
+ *
429
+ * @default null
430
+ */
431
+ formControl?: InputSignal<FormControl<DmMatSelectOutput<T>> | null>;
432
+ /**
433
+ * Event emitted when the selection changes.
434
+ * ```
435
+ * type OutputEmitterRef<MatSelectChange<DmMatSelectOutput<T>>>
436
+ * ```
437
+ *
438
+ *
439
+ */
440
+ selectionChange?: OutputEmitterRef<MatSelectChange<DmMatSelectOutput<T>>>;
441
+ /**
442
+ * Icon name to display in the select trigger.
443
+ * Can be a Material icon name or a Bootstrap icon html (like <i class="bi bi-name"></i>).
444
+ * ```
445
+ * type string | null
446
+ * ```
447
+ *
448
+ * @default null
449
+ */
450
+ icon?: InputSignal<string | null>;
451
+ /**
452
+ * Label to show in disabled option when there is no data to display.
453
+ * ```
454
+ * type string
455
+ * ```
456
+ *
457
+ * @default 'אין נתונים להצגה'
458
+ */
459
+ noDataLabel?: InputSignal<string>;
460
+ /**
461
+ * Cleans the search input after selecting an option.
462
+ * ```
463
+ * type boolean
464
+ * ```
465
+ *
466
+ * @default false
467
+ */
468
+ clearSearchAfterSelect?: InputSignalWithTransform<boolean, unknown>;
469
+ /**
470
+ * Tooltip text for the clear search button.
471
+ * ```
472
+ * type string
473
+ * ```
474
+ * @default 'נקה חיפוש'
475
+ */
476
+ clearSearchButtonTooltip?: InputSignal<string>;
477
+ /**
478
+ * Automatically focuses the search input when the panel opens.
479
+ * ```
480
+ * type boolean
481
+ * ```
482
+ *
483
+ * @default true
484
+ */
485
+ focusSearchInputOnPanelOpen?: InputSignalWithTransform<boolean, unknown>;
486
+ }
487
+
488
+ type DmMatSelectOutput<T> = T | T[] | string | string[] | number | number[] | null;
489
+ type DmMatSelectOption<T> = T & {
490
+ __dmMatSelectFormattedName: string;
491
+ };
492
+ declare class DmMatSelect<T = any> implements DmMatSelectConfig<T>, OnDestroy {
493
+ formFieldClass: _angular_core.InputSignal<string>;
494
+ wrapperClass: _angular_core.InputSignal<string>;
495
+ appearance: _angular_core.InputSignal<"fill" | "outline">;
496
+ multiple: _angular_core.InputSignalWithTransform<boolean, unknown>;
497
+ selectAllEnabled: _angular_core.InputSignalWithTransform<boolean, unknown>;
498
+ selectAllLabel: _angular_core.InputSignal<string>;
499
+ label: _angular_core.InputSignal<string>;
500
+ options: _angular_core.InputSignal<T[]>;
501
+ optionValueKey: _angular_core.InputSignal<keyof T>;
502
+ optionLabelKey: _angular_core.InputSignal<keyof T>;
503
+ searchable: _angular_core.InputSignalWithTransform<boolean, unknown>;
504
+ required: _angular_core.InputSignalWithTransform<boolean, unknown>;
505
+ disabled: _angular_core.InputSignalWithTransform<boolean, unknown>;
506
+ error: _angular_core.InputSignal<string | null>;
507
+ searchPlaceholder: _angular_core.InputSignal<string>;
508
+ emptyOption: _angular_core.InputSignalWithTransform<boolean, unknown>;
509
+ emptyOptionLabel: _angular_core.InputSignal<string>;
510
+ emptyOptionValue: _angular_core.InputSignal<T | null>;
511
+ optionNameFormat: _angular_core.InputSignal<((option: T) => string) | null>;
512
+ private _optionNameFormat;
513
+ protected datasource: _angular_core.WritableSignal<DmCmpsDataSource<DmMatSelectOption<T>>>;
514
+ value: _angular_core.ModelSignal<DmMatSelectOutput<T>>;
515
+ formControl: _angular_core.InputSignal<FormControl<DmMatSelectOutput<T>> | null>;
516
+ panelWidth: _angular_core.InputSignal<string | null>;
517
+ panelClass: _angular_core.InputSignal<string | string[] | Set<string> | {
518
+ [key: string]: any;
519
+ }>;
520
+ searchSectionBackgroundColor: _angular_core.InputSignal<string | null>;
521
+ sortBySelectedOnTop: _angular_core.InputSignalWithTransform<boolean, unknown>;
522
+ private internalControl;
523
+ protected control: _angular_core.Signal<FormControl<DmMatSelectOutput<T>>>;
524
+ selectionChange: _angular_core.OutputEmitterRef<MatSelectChange<DmMatSelectOutput<T>>>;
525
+ icon: _angular_core.InputSignal<string | null>;
526
+ protected isBootstrapIcon: _angular_core.Signal<boolean>;
527
+ noDataLabel: _angular_core.InputSignal<string>;
528
+ clearSearchAfterSelect: _angular_core.InputSignalWithTransform<boolean, unknown>;
529
+ clearSearchButtonTooltip: _angular_core.InputSignal<string>;
530
+ focusSearchInputOnPanelOpen: _angular_core.InputSignalWithTransform<boolean, unknown>;
531
+ filterPredicate: _angular_core.InputSignal<((option: T, filterText: string) => boolean) | null>;
532
+ private _filterPredicate;
533
+ simpleArray: _angular_core.Signal<boolean>;
534
+ private selectedOptionsIdsSet;
535
+ protected filterText: _angular_core.ModelSignal<string>;
536
+ protected checkIfAllSelected: _angular_core.Signal<boolean>;
537
+ constructor();
538
+ ngOnDestroy(): void;
539
+ setOptionsFormattedNames(options: DmMatSelectOption<T>[]): void;
540
+ private runEffects;
541
+ protected applyFilter(event: KeyboardEvent): void;
542
+ protected selectionChangeHandler(event: MatSelectChange<T | T[] | null>): void;
543
+ private getOptionValue;
544
+ protected onSelectionChangeHandler(event: MatOptionSelectionChange, option: T | null): void;
545
+ protected selectAllChange(event: MatCheckboxChange): void;
546
+ protected resetSearch(): void;
547
+ protected onPanelOpened(): void;
548
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<DmMatSelect<any>, never>;
549
+ static ɵcmp: _angular_core.ɵɵComponentDeclaration<DmMatSelect<any>, "dm-mat-select", never, { "formFieldClass": { "alias": "formFieldClass"; "required": false; "isSignal": true; }; "wrapperClass": { "alias": "wrapperClass"; "required": false; "isSignal": true; }; "appearance": { "alias": "appearance"; "required": false; "isSignal": true; }; "multiple": { "alias": "multiple"; "required": false; "isSignal": true; }; "selectAllEnabled": { "alias": "selectAllEnabled"; "required": false; "isSignal": true; }; "selectAllLabel": { "alias": "selectAllLabel"; "required": false; "isSignal": true; }; "label": { "alias": "label"; "required": false; "isSignal": true; }; "options": { "alias": "options"; "required": false; "isSignal": true; }; "optionValueKey": { "alias": "optionValueKey"; "required": false; "isSignal": true; }; "optionLabelKey": { "alias": "optionLabelKey"; "required": false; "isSignal": true; }; "searchable": { "alias": "searchable"; "required": false; "isSignal": true; }; "required": { "alias": "required"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; "error": { "alias": "error"; "required": false; "isSignal": true; }; "searchPlaceholder": { "alias": "searchPlaceholder"; "required": false; "isSignal": true; }; "emptyOption": { "alias": "emptyOption"; "required": false; "isSignal": true; }; "emptyOptionLabel": { "alias": "emptyOptionLabel"; "required": false; "isSignal": true; }; "emptyOptionValue": { "alias": "emptyOptionValue"; "required": false; "isSignal": true; }; "optionNameFormat": { "alias": "optionNameFormat"; "required": false; "isSignal": true; }; "value": { "alias": "value"; "required": false; "isSignal": true; }; "formControl": { "alias": "formControl"; "required": false; "isSignal": true; }; "panelWidth": { "alias": "panelWidth"; "required": false; "isSignal": true; }; "panelClass": { "alias": "panelClass"; "required": false; "isSignal": true; }; "searchSectionBackgroundColor": { "alias": "searchSectionBackgroundColor"; "required": false; "isSignal": true; }; "sortBySelectedOnTop": { "alias": "sortBySelectedOnTop"; "required": false; "isSignal": true; }; "icon": { "alias": "icon"; "required": false; "isSignal": true; }; "noDataLabel": { "alias": "noDataLabel"; "required": false; "isSignal": true; }; "clearSearchAfterSelect": { "alias": "clearSearchAfterSelect"; "required": false; "isSignal": true; }; "clearSearchButtonTooltip": { "alias": "clearSearchButtonTooltip"; "required": false; "isSignal": true; }; "focusSearchInputOnPanelOpen": { "alias": "focusSearchInputOnPanelOpen"; "required": false; "isSignal": true; }; "filterPredicate": { "alias": "filterPredicate"; "required": false; "isSignal": true; }; "filterText": { "alias": "filterText"; "required": false; "isSignal": true; }; }, { "value": "valueChange"; "selectionChange": "selectionChange"; "filterText": "filterTextChange"; }, never, ["[dm-mat-select-suffix]"], true, never>;
550
+ }
551
+
552
+ export { DmCmpsDataSource, DmMatSelect };
553
+ export type { DmCmpsDataSourceSort };