@dmlibs/dm-cmps 0.1.10 → 0.1.12

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,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { signal, input, booleanAttribute, model, computed, output, effect, Component, Injectable, numberAttribute, Input, Directive, HostListener } from '@angular/core';
2
+ import { signal, input, booleanAttribute, model, computed, output, effect, Component, Injectable, numberAttribute, Input, Directive, HostListener, Pipe } from '@angular/core';
3
3
  import { toObservable } from '@angular/core/rxjs-interop';
4
4
  import { Subject, Subscription, switchMap, debounceTime, distinctUntilChanged } from 'rxjs';
5
5
  import * as i2 from '@angular/material/form-field';
@@ -67,6 +67,7 @@ class DmCmpsDataSource {
67
67
  value.toString().toLowerCase().includes(term.toLowerCase()));
68
68
  };
69
69
  if (this.speratedSearch) {
70
+ console.log('sperated search active !!!');
70
71
  const terms = filter
71
72
  .split(' ')
72
73
  .map((t) => t.trim())
@@ -1587,6 +1588,7 @@ class DmTable {
1587
1588
  this.datasource().setFilterPredicate(this._filterPredicate);
1588
1589
  }
1589
1590
  if (this.enableSperatedSearch()) {
1591
+ console.log('enableSperatedSearch');
1590
1592
  this.datasource().applySperatedSearch(true);
1591
1593
  }
1592
1594
  if (this.enablePagination() || dataSource.length >= this.autoPaginationAboveRowsCount()) {
@@ -1680,13 +1682,20 @@ class DmTable {
1680
1682
  return;
1681
1683
  this.datasource().setFilterPredicate((row, filter) => {
1682
1684
  const filterLower = filter.toLowerCase();
1683
- for (const col of this.runtimeColumns()) {
1685
+ const match = (term) => this.runtimeColumns().some((col) => {
1686
+ if (col.type && ['actions', '$index', 'component', 'customHtml'].includes(col.type))
1687
+ return false;
1684
1688
  const cellValue = this.resolveCellValue(row, col);
1685
- if (cellValue != null && cellValue.toString().toLowerCase().includes(filterLower)) {
1686
- return true;
1687
- }
1689
+ return cellValue != null && cellValue.toString().includes(term);
1690
+ });
1691
+ if (this.enableSperatedSearch()) {
1692
+ const terms = filterLower
1693
+ .split(' ')
1694
+ .map((term) => term.trim())
1695
+ .filter((term) => !!term);
1696
+ return terms.every((term) => match(term));
1688
1697
  }
1689
- return false;
1698
+ return match(filterLower);
1690
1699
  });
1691
1700
  }
1692
1701
  createCellContext = (row, column) => ({
@@ -2203,9 +2212,281 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImpor
2203
2212
  args: ['window:keyup.shift', ['$event']]
2204
2213
  }], tableId: [{ type: i0.Input, args: [{ isSignal: true, alias: "tableId", required: false }] }], dataSource: [{ type: i0.Input, args: [{ isSignal: true, alias: "dataSource", required: true }] }], columns: [{ type: i0.Input, args: [{ isSignal: true, alias: "columns", required: true }] }], noDataMessage: [{ type: i0.Input, args: [{ isSignal: true, alias: "noDataMessage", required: false }] }], enableSearch: [{ type: i0.Input, args: [{ isSignal: true, alias: "enableSearch", required: false }] }], searchPlaceholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "searchPlaceholder", required: false }] }], clearSearchTooltip: [{ type: i0.Input, args: [{ isSignal: true, alias: "clearSearchTooltip", required: false }] }], searchInputAppearance: [{ type: i0.Input, args: [{ isSignal: true, alias: "searchInputAppearance", required: false }] }], filterPredicate: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterPredicate", required: false }] }], enableSperatedSearch: [{ type: i0.Input, args: [{ isSignal: true, alias: "enableSperatedSearch", required: false }] }], actionButtons: [{ type: i0.Input, args: [{ isSignal: true, alias: "actionButtons", required: false }] }], enablePrint: [{ type: i0.Input, args: [{ isSignal: true, alias: "enablePrint", required: false }] }], printButton: [{ type: i0.Input, args: [{ isSignal: true, alias: "printButton", required: false }] }], enablePagination: [{ type: i0.Input, args: [{ isSignal: true, alias: "enablePagination", required: false }] }], autoPaginationAboveRowsCount: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoPaginationAboveRowsCount", required: false }] }], paginatorSettings: [{ type: i0.Input, args: [{ isSignal: true, alias: "paginatorSettings", required: false }] }], enableLoadingProgressbar: [{ type: i0.Input, args: [{ isSignal: true, alias: "enableLoadingProgressbar", required: false }] }], enableColumnsDragAndDrop: [{ type: i0.Input, args: [{ isSignal: true, alias: "enableColumnsDragAndDrop", required: false }] }], enableColumnsDragHandle: [{ type: i0.Input, args: [{ isSignal: true, alias: "enableColumnsDragHandle", required: false }] }], enableTotalRow: [{ type: i0.Input, args: [{ isSignal: true, alias: "enableTotalRow", required: false }] }], tableStyle: [{ type: i0.Input, args: [{ isSignal: true, alias: "tableStyle", required: false }] }], tableClasses: [{ type: i0.Input, args: [{ isSignal: true, alias: "tableClasses", required: false }] }], rowStyleFn: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowStyleFn", required: false }] }], editColumnsVisibility: [{ type: i0.Input, args: [{ isSignal: true, alias: "editColumnsVisibility", required: false }] }], editColumnsVisibilityButton: [{ type: i0.Input, args: [{ isSignal: true, alias: "editColumnsVisibilityButton", required: false }] }], editColumnsVisibilitySelectAllLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "editColumnsVisibilitySelectAllLabel", required: false }] }], rowIdentifierField: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowIdentifierField", required: false }] }] } });
2205
2214
 
2215
+ class DmDatePipe {
2216
+ /**
2217
+ * Transforms a date to a string
2218
+ * @param value - the date to transform
2219
+ * @param format - the format of the date
2220
+ * @param lang - the language of the date
2221
+ * @returns the date as a string
2222
+ * @example
2223
+ * {{ date | dmDate: 'dd/MM/yyyy' }}
2224
+ * {{ date | dmDate: 'dd/MM/yyyy HH:mm' }}
2225
+ * {{ date | dmDate: 'yyyy/MM/dd' }}
2226
+ * {{ date | dmDate: 'dd/MM/yyyy': 'en' }}
2227
+ * {{ date | dmDate: 'dd/MM/yyyy': 'he' }}
2228
+ * {{ date | dmDate: 'dd/MM/yyyy': 'ar' }}
2229
+ * {{ date | dmDate: 'dd/MM/yyyy HH:mm': 'en' }}
2230
+ * {{ date | dmDate: 'dd/MM/yyyy HH:mm': 'he' }}
2231
+ * {{ date | dmDate: 'dd/MM/yyyy HH:mm': 'ar' }}
2232
+ * {{ date | dmDate: 'yyyy/MM/dd': 'en' }}
2233
+ * {{ date | dmDate: 'yyyy/MM/dd': 'he' }}
2234
+ *
2235
+ * The format can be any string that contains the following:
2236
+ * - 'dd' - the day of the month
2237
+ * - 'MM' - the month
2238
+ * - 'yyyy' - the year
2239
+ * - 'yy' - the year (2 digits)
2240
+ * - 'HH' - the hour
2241
+ * - 'mm' - the minute
2242
+ * - 'ss' - the second
2243
+ * - 'SSS' - the millisecond
2244
+ * - 'DM_a' - the AM/PM
2245
+ * - 'DM_E' - the day of the week
2246
+ * - 'DM_Z' - the time zone
2247
+ * - 'DM_z' - the time zone offset
2248
+ * - 'DM_yw' - the week of the year
2249
+ * - 'DM_mw' - the week of the month
2250
+ * - 'DM_yd' - the day of the year
2251
+ */
2252
+ transform(value, format = 'dd/MM/yyyy', lang = 'he') {
2253
+ if (!value)
2254
+ return '';
2255
+ return DmDateService.getDateString(value, format, lang);
2256
+ }
2257
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: DmDatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2258
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.0.3", ngImport: i0, type: DmDatePipe, isStandalone: true, name: "dmDate" });
2259
+ }
2260
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: DmDatePipe, decorators: [{
2261
+ type: Pipe,
2262
+ args: [{
2263
+ name: 'dmDate',
2264
+ }]
2265
+ }] });
2266
+
2267
+ class DmRunOncePipeSevice {
2268
+ cache = new Map();
2269
+ argsMap = new Map();
2270
+ generateFunctionKey(func, ...args) {
2271
+ let functionName = func.name;
2272
+ if (functionName.includes('bound')) {
2273
+ functionName = functionName.replace('bound ', '');
2274
+ }
2275
+ const argsString = args
2276
+ .map((arg) => {
2277
+ if (typeof arg === 'object') {
2278
+ return JSON.stringify(arg);
2279
+ }
2280
+ else if (typeof arg === 'function') {
2281
+ return arg.name;
2282
+ }
2283
+ else {
2284
+ return arg;
2285
+ }
2286
+ })
2287
+ .join(':');
2288
+ if (argsString) {
2289
+ functionName = `${functionName}:${argsString}`;
2290
+ }
2291
+ return `${functionName}`;
2292
+ }
2293
+ getOrCache(key, fn, args) {
2294
+ if (this.cache.has(key) && this.argsMap.has(key)) {
2295
+ const cachedArgs = this.argsMap.get(key);
2296
+ if (JSON.stringify(cachedArgs) == JSON.stringify(args)) {
2297
+ return this.cache.get(key);
2298
+ }
2299
+ }
2300
+ const result = fn();
2301
+ this.cache.set(key, result);
2302
+ this.argsMap.set(key, args);
2303
+ return result;
2304
+ }
2305
+ clearCache(key) {
2306
+ if (key) {
2307
+ this.cache.delete(key);
2308
+ }
2309
+ else {
2310
+ this.cache.clear();
2311
+ }
2312
+ }
2313
+ /**
2314
+ *
2315
+ * @param func - the function that called with the pipe `runOnce`
2316
+ *
2317
+ * @result when you need to trigger the function again, just call `triggerFunction` with the function
2318
+ *
2319
+ * @usageExample
2320
+ *
2321
+ * #### html
2322
+ * ```html
2323
+ * <!-- example without properties -->
2324
+ * <div [innerText]="myFucntion.bind(this) | runOnce"></div>
2325
+ *
2326
+ * <!-- example with properties -->
2327
+ * <div [innerText]="myFucntion.bind(this) | runOnce : '1122'"></div>
2328
+ * ```
2329
+ *
2330
+ * you can define properties as you need
2331
+ *
2332
+ * #### typescript
2333
+ * ```typescript
2334
+ * export class YourComponent {
2335
+ * constructor(private runOncePipeService: DmCmpsRunOncePipeService) {}
2336
+ *
2337
+ * myFucntion(prop?: any) {
2338
+ * let result: any;
2339
+ * // any logic here
2340
+ * return result;
2341
+ * }
2342
+ *
2343
+ * //this will trigger the function every time its called
2344
+ * triggerFunction() {
2345
+ * this.runOncePipeService.triggerFunction(this.myFucntion)
2346
+ * }
2347
+ * }
2348
+ * ```
2349
+ */
2350
+ triggerFunction(func) {
2351
+ const key = this.generateFunctionKey(func);
2352
+ this.clearCache(key);
2353
+ }
2354
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: DmRunOncePipeSevice, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
2355
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: DmRunOncePipeSevice, providedIn: 'root' });
2356
+ }
2357
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: DmRunOncePipeSevice, decorators: [{
2358
+ type: Injectable,
2359
+ args: [{
2360
+ providedIn: 'root',
2361
+ }]
2362
+ }] });
2363
+
2364
+ class DmFilterByPipe {
2365
+ /**
2366
+ *
2367
+ * @param array - (any[]) source array
2368
+ * @param filterPredicate - can get a function or object:
2369
+ *
2370
+ * @usageNotes
2371
+ * #### Example as function
2372
+ *
2373
+ * ```typescript
2374
+ * filterPredicateFunction(item: any) {
2375
+ * return item.age > 18 && item.weight > 80;
2376
+ * }
2377
+ * ```
2378
+ *
2379
+ * #### Example as object
2380
+ *
2381
+ * ```typescript
2382
+ * filterPredicateObject: { [key: string]: any } = {
2383
+ * age: 18,
2384
+ * weight: 80
2385
+ * }
2386
+ * ```
2387
+ *
2388
+ * @usageExample
2389
+ * #### Use function predicate
2390
+ * ```html
2391
+ * <div *ngFor="let item of source | filterBy: filterPredicateFunction.bind(this)">
2392
+ * <!-- any html content here -->
2393
+ * </div>
2394
+ * ```
2395
+ *
2396
+ * #### Use object - with check all
2397
+ * ```html
2398
+ * <div *ngFor="let item of source | filterBy: filterPredicateObject">
2399
+ * <!-- any html content here -->
2400
+ * </div>
2401
+ * ```
2402
+ *
2403
+ * #### Use object - returns the items that have some properties from the object
2404
+ * ```html
2405
+ * <div *ngFor="let item of source | filterBy: filterPredicateObject : false">
2406
+ * <!-- any html content here -->
2407
+ * </div>
2408
+ * ```
2409
+ *
2410
+ * @param checkAll - when `filterPredicate` is an object,
2411
+ * if `checkAll=true` it will return just the elements that have the `filterPredicate` keys and values,
2412
+ * if `checkAll=false` it will return all the elements thet have some properties from the `filterPredicate` with same values,
2413
+ * | default is `checkAll=true`
2414
+ *
2415
+ *
2416
+ * @returns (any[]) filterd array
2417
+ */
2418
+ transform(array, filterPredicate, checkAll = true, ...args) {
2419
+ if (!Array.isArray(array)) {
2420
+ return array;
2421
+ }
2422
+ if (typeof filterPredicate === 'function') {
2423
+ return array.filter(filterPredicate);
2424
+ }
2425
+ if (typeof filterPredicate === 'object') {
2426
+ return array.filter((item) => {
2427
+ if (checkAll) {
2428
+ return Object.keys(filterPredicate).every((key) => {
2429
+ return item[key] === filterPredicate[key];
2430
+ });
2431
+ }
2432
+ else {
2433
+ return Object.keys(filterPredicate).some((key) => {
2434
+ return item[key] === filterPredicate[key];
2435
+ });
2436
+ }
2437
+ });
2438
+ }
2439
+ return array;
2440
+ }
2441
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: DmFilterByPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2442
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.0.3", ngImport: i0, type: DmFilterByPipe, isStandalone: true, name: "filterBy", pure: false });
2443
+ }
2444
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: DmFilterByPipe, decorators: [{
2445
+ type: Pipe,
2446
+ args: [{
2447
+ name: 'filterBy',
2448
+ pure: false,
2449
+ }]
2450
+ }] });
2451
+
2452
+ class DmRunOncePipe {
2453
+ runOncePipeService;
2454
+ constructor(runOncePipeService) {
2455
+ this.runOncePipeService = runOncePipeService;
2456
+ }
2457
+ /**
2458
+ * @explain - Runs the specified function only once, simplifying function calls in HTML.
2459
+ * - This prevents redundant computations by caching results.
2460
+ * @param func - The function to be executed only once.
2461
+ * @param args - The arguments to be passed to the `func` function.
2462
+ * @result The result of executing the `func` function, or the cached result if already executed.
2463
+ * ### Example of Usage
2464
+ * ```html
2465
+ * <!-- function without arguments -->
2466
+ * <div [innerText]="myFunction.bind(this) | runOnce"></div>
2467
+ *
2468
+ * <!-- function with arguments -->
2469
+ * <div [innerText]="myFunction.bind(this) | runOnce : '' : myVariable : false"></div>
2470
+ * ```
2471
+ */
2472
+ transform(func, ...args) {
2473
+ const key = this.runOncePipeService.generateFunctionKey(func, ...args);
2474
+ return this.runOncePipeService.getOrCache(key, () => func(...args), [...args]);
2475
+ }
2476
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: DmRunOncePipe, deps: [{ token: DmRunOncePipeSevice }], target: i0.ɵɵFactoryTarget.Pipe });
2477
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.0.3", ngImport: i0, type: DmRunOncePipe, isStandalone: true, name: "runOnce", pure: false });
2478
+ }
2479
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: DmRunOncePipe, decorators: [{
2480
+ type: Pipe,
2481
+ args: [{
2482
+ name: 'runOnce',
2483
+ pure: false,
2484
+ }]
2485
+ }], ctorParameters: () => [{ type: DmRunOncePipeSevice }] });
2486
+
2206
2487
  /**
2207
2488
  * Generated bundle index. Do not edit.
2208
2489
  */
2209
2490
 
2210
- export { DmCmpsDataSource, DmColorPicker, DmDateService, DmIcon, DmMatSelect, DmSpinner, DmSpinnerService, DmTable };
2491
+ export { DmCmpsDataSource, DmColorPicker, DmDatePipe, DmDateService, DmFilterByPipe, DmIcon, DmMatSelect, DmRunOncePipe, DmRunOncePipeSevice, DmSpinner, DmSpinnerService, DmTable };
2211
2492
  //# sourceMappingURL=dmlibs-dm-cmps.mjs.map