@aquera/ngx-smart-table 0.0.24 → 0.0.25

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.
@@ -2290,6 +2290,122 @@ class WorkbookState {
2290
2290
  }
2291
2291
  }
2292
2292
 
2293
+ /**
2294
+ * Convert an LDAP Distinguished Name (DN) string to a human-readable path.
2295
+ *
2296
+ * @example
2297
+ * "OU=Engineering,OU=India,DC=company,DC=com"
2298
+ * → "Engineering / India (company.com)"
2299
+ *
2300
+ * "CN=John Smith,OU=Admins,OU=Engineering,DC=company,DC=com"
2301
+ * → "John Smith / Admins / Engineering (company.com)"
2302
+ *
2303
+ * "OU=R\\,D,OU=Teams,DC=example,DC=org"
2304
+ * → "R,D / Teams (example.org)"
2305
+ */
2306
+ function dnToHumanReadable(dn) {
2307
+ if (!/^\s*\S/.test(dn)) {
2308
+ return '';
2309
+ }
2310
+ const pathParts = [];
2311
+ const domainParts = [];
2312
+ for (const match of dn.matchAll(/(?:^|(?<!\\),)\s*(CN|OU|DC)=((?:\\.|[^,])+)/g)) {
2313
+ const key = match[1];
2314
+ const value = match[2]
2315
+ .trim()
2316
+ .replace(/\\([,\\#+<>;"=])/g, '$1');
2317
+ if (/^(?:CN|OU)$/.test(key)) {
2318
+ pathParts.push(value);
2319
+ }
2320
+ else if (/^DC$/.test(key)) {
2321
+ domainParts.push(value);
2322
+ }
2323
+ }
2324
+ const path = pathParts.join(' / ');
2325
+ const domain = domainParts.join('.');
2326
+ return path && domain
2327
+ ? `${path} (${domain})`
2328
+ : path || domain || dn;
2329
+ }
2330
+ /**
2331
+ * Cell formatter that converts LDAP Distinguished Name (DN) strings
2332
+ * into human-readable OU paths with optional domain suffix.
2333
+ *
2334
+ * @example
2335
+ * // In column config:
2336
+ * formatter: new OUFormatter()
2337
+ *
2338
+ * // With options:
2339
+ * formatter: new OUFormatter({ separator: ' > ', showDomain: false })
2340
+ *
2341
+ * // Handles arrays from multiselect:
2342
+ * // ['OU=Eng,DC=co,DC=com', 'OU=HR,DC=co,DC=com'] → "Eng (co.com), HR (co.com)"
2343
+ */
2344
+ class OUFormatter {
2345
+ constructor(options) {
2346
+ this.options = options;
2347
+ }
2348
+ format(value) {
2349
+ if (Array.isArray(value)) {
2350
+ return value
2351
+ .map(v => this.formatSingle(v))
2352
+ .filter(v => !!v)
2353
+ .join(this.options?.arraySeparator ?? ', ');
2354
+ }
2355
+ return this.formatSingle(value);
2356
+ }
2357
+ formatSingle(value) {
2358
+ if (value === null || value === undefined || typeof value !== 'string' || !/^\s*\S/.test(value)) {
2359
+ return this.options?.emptyText ?? '';
2360
+ }
2361
+ const separator = this.options?.separator ?? ' / ';
2362
+ const showDomain = this.options?.showDomain !== false;
2363
+ const pathParts = [];
2364
+ const domainParts = [];
2365
+ for (const match of value.matchAll(/(?:^|(?<!\\),)\s*(CN|OU|DC)=((?:\\.|[^,])+)/g)) {
2366
+ const key = match[1];
2367
+ const val = match[2]
2368
+ .trim()
2369
+ .replace(/\\([,\\#+<>;"=])/g, '$1');
2370
+ if (/^(?:CN|OU)$/.test(key)) {
2371
+ pathParts.push(val);
2372
+ }
2373
+ else if (/^DC$/.test(key)) {
2374
+ domainParts.push(val);
2375
+ }
2376
+ }
2377
+ const path = pathParts.join(separator);
2378
+ const domain = domainParts.join('.');
2379
+ if (path && domain && showDomain)
2380
+ return `${path} (${domain})`;
2381
+ if (path)
2382
+ return path;
2383
+ if (domain && showDomain)
2384
+ return domain;
2385
+ return value;
2386
+ }
2387
+ }
2388
+
2389
+ const BUILTIN_FORMATTERS = {
2390
+ ouFormatter: () => new OUFormatter(),
2391
+ };
2392
+ const customFormatters = {};
2393
+ /**
2394
+ * Resolve a formatter by name. Looks up custom formatters first, then built-in.
2395
+ * Returns undefined if the name is not registered.
2396
+ */
2397
+ function resolveFormatter(name) {
2398
+ const factory = customFormatters[name] ?? BUILTIN_FORMATTERS[name];
2399
+ return factory ? factory() : undefined;
2400
+ }
2401
+ /**
2402
+ * Register a custom formatter so it can be referenced by string name
2403
+ * in column configs (e.g. `formatter: 'myFormatter'`).
2404
+ */
2405
+ function registerFormatter(name, factory) {
2406
+ customFormatters[name] = factory;
2407
+ }
2408
+
2293
2409
  /**
2294
2410
  * Cell class - represents individual cell instances
2295
2411
  * Combines ColumnConfig (Flyweight) with CellState (unique per instance)
@@ -2354,17 +2470,22 @@ class Cell {
2354
2470
  * Render cell value as formatted string (delegates to formatter strategy)
2355
2471
  */
2356
2472
  render() {
2357
- if (!this.columnConfig.formatter) {
2473
+ let formatter = this.columnConfig.formatter;
2474
+ if (!formatter) {
2358
2475
  return String(this.state.value ?? '');
2359
2476
  }
2360
- if (this.columnConfig.formatter.formatWithContext) {
2361
- return this.columnConfig.formatter.formatWithContext(this.state.value, this.rowData, this.columnConfig.key);
2477
+ if (typeof formatter === 'string') {
2478
+ formatter = resolveFormatter(formatter);
2479
+ if (!formatter) {
2480
+ return String(this.state.value ?? '');
2481
+ }
2482
+ }
2483
+ if (formatter.formatWithContext) {
2484
+ return formatter.formatWithContext(this.state.value, this.rowData, this.columnConfig.key);
2362
2485
  }
2363
- // Ensure format method exists before calling it
2364
- if (this.columnConfig.formatter.format) {
2365
- return this.columnConfig.formatter.format(this.state.value);
2486
+ if (formatter.format) {
2487
+ return formatter.format(this.state.value);
2366
2488
  }
2367
- // Fallback if formatter exists but has no methods
2368
2489
  return String(this.state.value ?? '');
2369
2490
  }
2370
2491
  /**
@@ -2817,7 +2938,9 @@ class BaseColumnConfig {
2817
2938
  this.key = merged.key;
2818
2939
  this.header = merged.header;
2819
2940
  this.dataType = merged.dataType;
2820
- this.formatter = merged.formatter;
2941
+ this.formatter = typeof merged.formatter === 'string'
2942
+ ? resolveFormatter(merged.formatter)
2943
+ : merged.formatter;
2821
2944
  this.validator = merged.validator;
2822
2945
  this.editor = merged.editor;
2823
2946
  this.parser = merged.parser;
@@ -2978,11 +3101,15 @@ class BaseColumnConfig {
2978
3101
  * Format value for display (can be overridden)
2979
3102
  */
2980
3103
  formatValue(value, rowData) {
2981
- if (this.formatter) {
2982
- if (this.formatter.formatWithContext && rowData) {
2983
- return this.formatter.formatWithContext(value, rowData, this.key);
3104
+ let formatter = this.formatter;
3105
+ if (typeof formatter === 'string') {
3106
+ formatter = resolveFormatter(formatter);
3107
+ }
3108
+ if (formatter) {
3109
+ if (formatter.formatWithContext && rowData) {
3110
+ return formatter.formatWithContext(value, rowData, this.key);
2984
3111
  }
2985
- return this.formatter.format(value);
3112
+ return formatter.format(value);
2986
3113
  }
2987
3114
  return String(value ?? '');
2988
3115
  }
@@ -8813,7 +8940,7 @@ class StTableComponent {
8813
8940
  const columns = this.getActiveColumns();
8814
8941
  const oldGrid = this.internalCellGrid;
8815
8942
  this.internalCellGrid = dataValue.map((rowData, rowIndex) => columns.map((column, colIndex) => {
8816
- const newCell = new Cell(column, rowData[column.key], rowData, rowIndex);
8943
+ const newCell = column.createCell(rowData, rowIndex);
8817
8944
  const oldCell = oldGrid?.[rowIndex]?.[colIndex];
8818
8945
  if (oldCell && oldCell.getColumnConfig().key === column.key) {
8819
8946
  oldCell.setReplacement(newCell);
@@ -12705,5 +12832,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
12705
12832
  * Generated bundle index. Do not edit.
12706
12833
  */
12707
12834
 
12708
- 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 };
12835
+ 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 };
12709
12836
  //# sourceMappingURL=aquera-ngx-smart-table.mjs.map