@toolbox-web/grid-angular 2.0.0-beta → 2.0.0-beta.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.
@@ -2,7 +2,8 @@ import * as i0 from '@angular/core';
2
2
  import { inject, ElementRef, contentChild, TemplateRef, effect, Directive, InjectionToken, Injectable, makeEnvironmentProviders, createComponent, DestroyRef, signal, afterNextRender, computed, EnvironmentInjector, ApplicationRef, ViewContainerRef, input, output } from '@angular/core';
3
3
  import { createPluginFromFeature } from '@toolbox-web/grid/features/registry';
4
4
  export { clearFeatureRegistry, createPluginFromFeature, getFeatureFactory, getRegisteredFeatures, isFeatureRegistered, registerFeature } from '@toolbox-web/grid/features/registry';
5
- import { DataGridElement } from '@toolbox-web/grid';
5
+ import { applyColumnDefaults, normalizeColumns, DataGridElement } from '@toolbox-web/grid';
6
+ export { applyColumnDefaults, hasColumnShorthands, normalizeColumns, parseColumnShorthand } from '@toolbox-web/grid';
6
7
 
7
8
  // #endregion
8
9
  // #region Utilities
@@ -190,10 +191,10 @@ class TbwRenderer {
190
191
  });
191
192
  }
192
193
  registerTemplate() {
193
- // Find the parent tbw-grid-column element
194
+ // Find the parent tbw-grid-column or tbw-grid-type element
194
195
  // The template's host element may not be in the DOM yet, so we traverse from the comment node
195
196
  let parent = this.elementRef.nativeElement?.parentElement;
196
- while (parent && parent.tagName !== 'TBW-GRID-COLUMN') {
197
+ while (parent && parent.tagName !== 'TBW-GRID-COLUMN' && parent.tagName !== 'TBW-GRID-TYPE') {
197
198
  parent = parent.parentElement;
198
199
  }
199
200
  if (parent) {
@@ -1977,87 +1978,35 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImpor
1977
1978
  }]
1978
1979
  }] });
1979
1980
 
1980
- /** Capitalize the first letter of a string for header generation. */
1981
- function capitalize(str) {
1982
- return str.charAt(0).toUpperCase() + str.slice(1);
1983
- }
1984
- /**
1985
- * Generate a human-readable header from a field name.
1986
- *
1987
- * Handles camelCase, snake_case, and kebab-case.
1988
- *
1989
- * @example
1990
- * generateHeader('firstName') → 'First Name'
1991
- * generateHeader('last_name') → 'Last Name'
1992
- * generateHeader('email-address') → 'Email Address'
1993
- * generateHeader('id') → 'ID' (special case)
1994
- */
1995
- function generateHeader(field) {
1996
- if (field.toLowerCase() === 'id')
1997
- return 'ID';
1998
- const words = field
1999
- .replace(/([a-z])([A-Z])/g, '$1 $2')
2000
- .replace(/[_-]/g, ' ')
2001
- .split(' ')
2002
- .filter(Boolean);
2003
- return words.map(capitalize).join(' ');
2004
- }
2005
- /** Valid column types from the shorthand notation. */
2006
- const VALID_TYPES = new Set(['string', 'number', 'boolean', 'date', 'datetime', 'currency']);
2007
1981
  /**
2008
- * Parse a column shorthand string into a ColumnConfig.
1982
+ * Directive that registers `<tbw-grid-type>` as a known Angular element.
2009
1983
  *
2010
- * Supports formats:
2011
- * - `'fieldName'` → `{ field: 'fieldName', header: 'Field Name' }`
2012
- * - `'fieldName:type'` → `{ field: 'fieldName', header: 'Field Name', type: 'type' }`
1984
+ * This keeps Angular template compilation happy without requiring
1985
+ * `CUSTOM_ELEMENTS_SCHEMA` and mirrors the existing `TbwGridColumn` directive.
2013
1986
  *
2014
- * @param shorthand - The shorthand string (e.g., 'name', 'salary:number')
2015
- * @returns A ColumnConfig object
2016
- * @since 1.4.0
1987
+ * @category Directive
1988
+ * @since 2.0.0
2017
1989
  */
2018
- function parseColumnShorthand(shorthand) {
2019
- const colonIndex = shorthand.lastIndexOf(':');
2020
- if (colonIndex > 0) {
2021
- const potentialType = shorthand.slice(colonIndex + 1).toLowerCase();
2022
- if (VALID_TYPES.has(potentialType)) {
2023
- const field = shorthand.slice(0, colonIndex);
2024
- return {
2025
- field: field,
2026
- header: generateHeader(field),
2027
- type: potentialType,
2028
- };
2029
- }
2030
- }
2031
- return {
2032
- field: shorthand,
2033
- header: generateHeader(shorthand),
2034
- };
1990
+ class TbwGridType {
1991
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: TbwGridType, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1992
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.5", type: TbwGridType, isStandalone: true, selector: "tbw-grid-type", ngImport: i0 });
2035
1993
  }
1994
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: TbwGridType, decorators: [{
1995
+ type: Directive,
1996
+ args: [{
1997
+ selector: 'tbw-grid-type',
1998
+ }]
1999
+ }] });
2000
+
2036
2001
  /**
2037
- * Normalize an array of column shorthands to ColumnConfig objects.
2002
+ * Column shorthand parsing for `@toolbox-web/grid-angular`.
2038
2003
  *
2039
- * @param columns - Array of column shorthands (strings or ColumnConfig objects)
2040
- * @returns Array of ColumnConfig objects
2041
- * @since 1.4.0
2004
+ * The parser, header generation and defaults helpers live in `@toolbox-web/grid`
2005
+ * core (issue #276). This module re-exports them so the adapter's public import
2006
+ * path is unchanged while the implementation stays in one place. Angular's
2007
+ * shorthand API types against core's `ColumnConfig` (these helpers take no
2008
+ * component-typed override), so a direct re-export is type-identical.
2042
2009
  */
2043
- function normalizeColumns(columns) {
2044
- return columns.map((col) => (typeof col === 'string' ? parseColumnShorthand(col) : col));
2045
- }
2046
- /**
2047
- * Apply column defaults to a list of columns. Individual column properties
2048
- * override defaults.
2049
- * @since 1.4.0
2050
- */
2051
- function applyColumnDefaults(columns, defaults) {
2052
- if (!defaults)
2053
- return columns;
2054
- return columns.map((col) => ({ ...defaults, ...col }));
2055
- }
2056
- /** Check if an array of columns contains any shorthand strings. * @since 1.4.0
2057
- */
2058
- function hasColumnShorthands(columns) {
2059
- return columns.some((col) => typeof col === 'string');
2060
- }
2061
2010
 
2062
2011
  /** Per-element map of claimed feature names → config getter. */
2063
2012
  const featureClaims = new WeakMap();
@@ -2919,5 +2868,5 @@ function provideGrid(options = {}) {
2919
2868
  * Generated bundle index. Do not edit.
2920
2869
  */
2921
2870
 
2922
- export { GRID_ICONS, GRID_TYPE_DEFAULTS, Grid, GridAdapter, GridColumnView, GridIconRegistry, GridTypeRegistry, TbwGridColumn, TbwGridHeader, TbwGridToolButtons, TbwRenderer, applyColumnDefaults, claimEvent, getFeatureClaim, getFeatureConfigPreprocessor, hasColumnShorthands, injectGrid, isComponentClass, isEventClaimed, makeFlushFocusedInput, normalizeColumns, parseColumnShorthand, provideGrid, provideGridIcons, provideGridTypeDefaults, registerDetailRendererBridge, registerEditorMountHook, registerEditorSpecBridge, registerFeatureClaim, registerFeatureConfigPreprocessor, registerFilterPanelTypeDefaultBridge, registerResponsiveCardRendererBridge, registerTemplateBridge, registerToolPanelRendererBridge, runTemplateBridges, unclaimEvent, unregisterFeatureClaim };
2871
+ export { GRID_ICONS, GRID_TYPE_DEFAULTS, Grid, GridAdapter, GridColumnView, GridIconRegistry, GridTypeRegistry, TbwGridColumn, TbwGridHeader, TbwGridToolButtons, TbwGridType, TbwRenderer, claimEvent, getFeatureClaim, getFeatureConfigPreprocessor, injectGrid, isComponentClass, isEventClaimed, makeFlushFocusedInput, provideGrid, provideGridIcons, provideGridTypeDefaults, registerDetailRendererBridge, registerEditorMountHook, registerEditorSpecBridge, registerFeatureClaim, registerFeatureConfigPreprocessor, registerFilterPanelTypeDefaultBridge, registerResponsiveCardRendererBridge, registerTemplateBridge, registerToolPanelRendererBridge, runTemplateBridges, unclaimEvent, unregisterFeatureClaim };
2923
2872
  //# sourceMappingURL=toolbox-web-grid-angular.mjs.map