@aquera/ngx-smart-table 0.0.17-patch-0.4 → 0.0.17-patch-0.5

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.
@@ -2289,6 +2289,122 @@ class WorkbookState {
2289
2289
  }
2290
2290
  }
2291
2291
 
2292
+ /**
2293
+ * Convert an LDAP Distinguished Name (DN) string to a human-readable path.
2294
+ *
2295
+ * @example
2296
+ * "OU=Engineering,OU=India,DC=company,DC=com"
2297
+ * → "Engineering / India (company.com)"
2298
+ *
2299
+ * "CN=John Smith,OU=Admins,OU=Engineering,DC=company,DC=com"
2300
+ * → "John Smith / Admins / Engineering (company.com)"
2301
+ *
2302
+ * "OU=R\\,D,OU=Teams,DC=example,DC=org"
2303
+ * → "R,D / Teams (example.org)"
2304
+ */
2305
+ function dnToHumanReadable(dn) {
2306
+ if (!/^\s*\S/.test(dn)) {
2307
+ return '';
2308
+ }
2309
+ const pathParts = [];
2310
+ const domainParts = [];
2311
+ for (const match of dn.matchAll(/(?:^|(?<!\\),)\s*(CN|OU|DC)=((?:\\.|[^,])+)/g)) {
2312
+ const key = match[1];
2313
+ const value = match[2]
2314
+ .trim()
2315
+ .replace(/\\([,\\#+<>;"=])/g, '$1');
2316
+ if (/^(?:CN|OU)$/.test(key)) {
2317
+ pathParts.push(value);
2318
+ }
2319
+ else if (/^DC$/.test(key)) {
2320
+ domainParts.push(value);
2321
+ }
2322
+ }
2323
+ const path = pathParts.join(' / ');
2324
+ const domain = domainParts.join('.');
2325
+ return path && domain
2326
+ ? `${path} (${domain})`
2327
+ : path || domain || dn;
2328
+ }
2329
+ /**
2330
+ * Cell formatter that converts LDAP Distinguished Name (DN) strings
2331
+ * into human-readable OU paths with optional domain suffix.
2332
+ *
2333
+ * @example
2334
+ * // In column config:
2335
+ * formatter: new OUFormatter()
2336
+ *
2337
+ * // With options:
2338
+ * formatter: new OUFormatter({ separator: ' > ', showDomain: false })
2339
+ *
2340
+ * // Handles arrays from multiselect:
2341
+ * // ['OU=Eng,DC=co,DC=com', 'OU=HR,DC=co,DC=com'] → "Eng (co.com), HR (co.com)"
2342
+ */
2343
+ class OUFormatter {
2344
+ constructor(options) {
2345
+ this.options = options;
2346
+ }
2347
+ format(value) {
2348
+ if (Array.isArray(value)) {
2349
+ return value
2350
+ .map(v => this.formatSingle(v))
2351
+ .filter(v => !!v)
2352
+ .join(this.options?.arraySeparator ?? ', ');
2353
+ }
2354
+ return this.formatSingle(value);
2355
+ }
2356
+ formatSingle(value) {
2357
+ if (value === null || value === undefined || typeof value !== 'string' || !/^\s*\S/.test(value)) {
2358
+ return this.options?.emptyText ?? '';
2359
+ }
2360
+ const separator = this.options?.separator ?? ' / ';
2361
+ const showDomain = this.options?.showDomain !== false;
2362
+ const pathParts = [];
2363
+ const domainParts = [];
2364
+ for (const match of value.matchAll(/(?:^|(?<!\\),)\s*(CN|OU|DC)=((?:\\.|[^,])+)/g)) {
2365
+ const key = match[1];
2366
+ const val = match[2]
2367
+ .trim()
2368
+ .replace(/\\([,\\#+<>;"=])/g, '$1');
2369
+ if (/^(?:CN|OU)$/.test(key)) {
2370
+ pathParts.push(val);
2371
+ }
2372
+ else if (/^DC$/.test(key)) {
2373
+ domainParts.push(val);
2374
+ }
2375
+ }
2376
+ const path = pathParts.join(separator);
2377
+ const domain = domainParts.join('.');
2378
+ if (path && domain && showDomain)
2379
+ return `${path} (${domain})`;
2380
+ if (path)
2381
+ return path;
2382
+ if (domain && showDomain)
2383
+ return domain;
2384
+ return value;
2385
+ }
2386
+ }
2387
+
2388
+ const BUILTIN_FORMATTERS = {
2389
+ ouFormatter: () => new OUFormatter(),
2390
+ };
2391
+ const customFormatters = {};
2392
+ /**
2393
+ * Resolve a formatter by name. Looks up custom formatters first, then built-in.
2394
+ * Returns undefined if the name is not registered.
2395
+ */
2396
+ function resolveFormatter(name) {
2397
+ const factory = customFormatters[name] ?? BUILTIN_FORMATTERS[name];
2398
+ return factory ? factory() : undefined;
2399
+ }
2400
+ /**
2401
+ * Register a custom formatter so it can be referenced by string name
2402
+ * in column configs (e.g. `formatter: 'myFormatter'`).
2403
+ */
2404
+ function registerFormatter(name, factory) {
2405
+ customFormatters[name] = factory;
2406
+ }
2407
+
2292
2408
  /**
2293
2409
  * Cell class - represents individual cell instances
2294
2410
  * Combines ColumnConfig (Flyweight) with CellState (unique per instance)
@@ -2353,17 +2469,22 @@ class Cell {
2353
2469
  * Render cell value as formatted string (delegates to formatter strategy)
2354
2470
  */
2355
2471
  render() {
2356
- if (!this.columnConfig.formatter) {
2472
+ let formatter = this.columnConfig.formatter;
2473
+ if (!formatter) {
2357
2474
  return String(this.state.value ?? '');
2358
2475
  }
2359
- if (this.columnConfig.formatter.formatWithContext) {
2360
- return this.columnConfig.formatter.formatWithContext(this.state.value, this.rowData, this.columnConfig.key);
2476
+ if (typeof formatter === 'string') {
2477
+ formatter = resolveFormatter(formatter);
2478
+ if (!formatter) {
2479
+ return String(this.state.value ?? '');
2480
+ }
2481
+ }
2482
+ if (formatter.formatWithContext) {
2483
+ return formatter.formatWithContext(this.state.value, this.rowData, this.columnConfig.key);
2361
2484
  }
2362
- // Ensure format method exists before calling it
2363
- if (this.columnConfig.formatter.format) {
2364
- return this.columnConfig.formatter.format(this.state.value);
2485
+ if (formatter.format) {
2486
+ return formatter.format(this.state.value);
2365
2487
  }
2366
- // Fallback if formatter exists but has no methods
2367
2488
  return String(this.state.value ?? '');
2368
2489
  }
2369
2490
  /**
@@ -2816,7 +2937,9 @@ class BaseColumnConfig {
2816
2937
  this.key = merged.key;
2817
2938
  this.header = merged.header;
2818
2939
  this.dataType = merged.dataType;
2819
- this.formatter = merged.formatter;
2940
+ this.formatter = typeof merged.formatter === 'string'
2941
+ ? resolveFormatter(merged.formatter)
2942
+ : merged.formatter;
2820
2943
  this.validator = merged.validator;
2821
2944
  this.editor = merged.editor;
2822
2945
  this.parser = merged.parser;
@@ -2977,11 +3100,15 @@ class BaseColumnConfig {
2977
3100
  * Format value for display (can be overridden)
2978
3101
  */
2979
3102
  formatValue(value, rowData) {
2980
- if (this.formatter) {
2981
- if (this.formatter.formatWithContext && rowData) {
2982
- return this.formatter.formatWithContext(value, rowData, this.key);
3103
+ let formatter = this.formatter;
3104
+ if (typeof formatter === 'string') {
3105
+ formatter = resolveFormatter(formatter);
3106
+ }
3107
+ if (formatter) {
3108
+ if (formatter.formatWithContext && rowData) {
3109
+ return formatter.formatWithContext(value, rowData, this.key);
2983
3110
  }
2984
- return this.formatter.format(value);
3111
+ return formatter.format(value);
2985
3112
  }
2986
3113
  return String(value ?? '');
2987
3114
  }
@@ -8826,7 +8953,7 @@ class StTableComponent {
8826
8953
  const columns = this.getActiveColumns();
8827
8954
  const oldGrid = this.internalCellGrid;
8828
8955
  this.internalCellGrid = this.data.map((rowData, rowIndex) => columns.map((column, colIndex) => {
8829
- const newCell = new Cell(column, rowData[column.key], rowData, rowIndex);
8956
+ const newCell = column.createCell(rowData, rowIndex);
8830
8957
  const oldCell = oldGrid?.[rowIndex]?.[colIndex];
8831
8958
  if (oldCell && oldCell.getColumnConfig().key === column.key) {
8832
8959
  oldCell.setReplacement(newCell);
@@ -13223,5 +13350,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImpor
13223
13350
  * Generated bundle index. Do not edit.
13224
13351
  */
13225
13352
 
13226
- export { ArrayFormatter, AutosaveService, BaseColumnConfig, BooleanEditor, BooleanFormatter, BuilderPreviewComponent, BuilderToolbarComponent, Cell, CellAlignment, CellDataType, CellLifecycleState, CellVerticalAlignment, ChainValidator, ClickOutsideDirective, ColumnConfigFactory, ColumnEditorComponent, ColumnListComponent, Columns, CurrencyFormatter, DEFAULT_AUTOSAVE_CONFIG, DEFAULT_COLUMN_CONFIG, DEFAULT_TABLE_CONFIG, DateEditor, DateFormatter, DateRangeValidator, DefaultFormatter, DefinitionBuilderComponent, DefinitionBuilderModule, DefinitionBuilderService, DefinitionExportService, DefinitionImportService, EditMode, EmailValidator, FilterOperator, FunctionFormatter, FunctionValidator, JsonSchemaValidatorService, LengthValidator, NavigationDirection, NavigationKey, NileAutoCompleteEditor, NileCalendarEditor, NileCodeEditor, NileDatePickerEditor, NileInputEditor, NileSelectEditor, NumberEditor, NumberFormatter, PatternValidators, PercentageFormatter, RangeValidator, RegexValidator, RequiredValidator, RowValidationService, SampleDataGeneratorService, SelectEditor, SharedTableComponentsModule, SheetState, SimpleColumnConfig, SmartTableModule, SortDirection, StAddColumnButtonComponent, StCellComponent, StColumnEditorModalComponent, StColumnFilterComponent, StColumnMenuDropdownComponent, StColumnResizeDirective, StColumnVisibilityComponent, StHeaderComponent, StKeyboardNavigationDirective, StPaginationComponent, StRowActionsDropdownComponent, StSheetActionsComponent, StSheetComponent, StTableActionsComponent, StTableComponent, StWorkbookComponent, StringFormatter, TableConfigEditorComponent, TableState, TableZIndex, TemplateFormatter, TextAreaEditor, TextEditor, UrlValidator, ValidationLoggerService, VirtualScrollService, WorkbookState, canEdit, createCellState, createMemento, isCellValid, isDisplayMode, isNullOrUndefined, isValidDate, isValidationSuccess, mergeTableConfig, restoreFromMemento };
13353
+ export { ArrayFormatter, AutosaveService, BaseColumnConfig, BooleanEditor, BooleanFormatter, BuilderPreviewComponent, BuilderToolbarComponent, Cell, CellAlignment, CellDataType, CellLifecycleState, CellVerticalAlignment, ChainValidator, ClickOutsideDirective, ColumnConfigFactory, ColumnEditorComponent, ColumnListComponent, Columns, CurrencyFormatter, DEFAULT_AUTOSAVE_CONFIG, DEFAULT_COLUMN_CONFIG, DEFAULT_TABLE_CONFIG, DateEditor, DateFormatter, DateRangeValidator, DefaultFormatter, DefinitionBuilderComponent, DefinitionBuilderModule, DefinitionBuilderService, DefinitionExportService, DefinitionImportService, EditMode, EmailValidator, FilterOperator, FunctionFormatter, FunctionValidator, JsonSchemaValidatorService, LengthValidator, NavigationDirection, NavigationKey, NileAutoCompleteEditor, NileCalendarEditor, NileCodeEditor, NileDatePickerEditor, NileInputEditor, NileSelectEditor, NumberEditor, NumberFormatter, OUFormatter, PatternValidators, PercentageFormatter, RangeValidator, RegexValidator, RequiredValidator, RowValidationService, SampleDataGeneratorService, SelectEditor, SharedTableComponentsModule, SheetState, SimpleColumnConfig, SmartTableModule, SortDirection, StAddColumnButtonComponent, StCellComponent, StColumnEditorModalComponent, StColumnFilterComponent, StColumnMenuDropdownComponent, StColumnResizeDirective, StColumnVisibilityComponent, StHeaderComponent, StKeyboardNavigationDirective, StPaginationComponent, StRowActionsDropdownComponent, StSheetActionsComponent, StSheetComponent, StTableActionsComponent, StTableComponent, StWorkbookComponent, StringFormatter, TableConfigEditorComponent, TableState, TableZIndex, TemplateFormatter, TextAreaEditor, TextEditor, UrlValidator, ValidationLoggerService, VirtualScrollService, WorkbookState, canEdit, createCellState, createMemento, dnToHumanReadable, isCellValid, isDisplayMode, isNullOrUndefined, isValidDate, isValidationSuccess, mergeTableConfig, registerFormatter, resolveFormatter, restoreFromMemento };
13227
13354
  //# sourceMappingURL=aquera-ngx-smart-table.mjs.map