@toolbox-web/grid 2.14.0 → 2.15.0

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.
Files changed (53) hide show
  1. package/all.js +2 -2
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/index.js.map +1 -1
  5. package/lib/core/constants.d.ts +6 -6
  6. package/lib/core/plugin/base-plugin.d.ts +1 -1
  7. package/lib/core/types.d.ts +125 -0
  8. package/lib/features/registry.js +1 -1
  9. package/lib/features/registry.js.map +1 -1
  10. package/lib/plugins/clipboard/index.js.map +1 -1
  11. package/lib/plugins/column-virtualization/index.js.map +1 -1
  12. package/lib/plugins/context-menu/index.js.map +1 -1
  13. package/lib/plugins/editing/index.js +1 -1
  14. package/lib/plugins/editing/index.js.map +1 -1
  15. package/lib/plugins/editing/internal/helpers.d.ts +13 -0
  16. package/lib/plugins/export/index.js.map +1 -1
  17. package/lib/plugins/filtering/FilteringPlugin.d.ts +22 -2
  18. package/lib/plugins/filtering/index.js +1 -1
  19. package/lib/plugins/filtering/index.js.map +1 -1
  20. package/lib/plugins/grouping-columns/index.js.map +1 -1
  21. package/lib/plugins/grouping-rows/index.js.map +1 -1
  22. package/lib/plugins/master-detail/index.js.map +1 -1
  23. package/lib/plugins/multi-sort/index.js.map +1 -1
  24. package/lib/plugins/pinned-columns/index.js.map +1 -1
  25. package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts +8 -0
  26. package/lib/plugins/pinned-rows/index.js +1 -1
  27. package/lib/plugins/pinned-rows/index.js.map +1 -1
  28. package/lib/plugins/pinned-rows/pinned-rows.d.ts +7 -1
  29. package/lib/plugins/pivot/index.js.map +1 -1
  30. package/lib/plugins/print/index.js.map +1 -1
  31. package/lib/plugins/reorder-columns/index.js.map +1 -1
  32. package/lib/plugins/reorder-rows/index.js.map +1 -1
  33. package/lib/plugins/responsive/index.js.map +1 -1
  34. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  35. package/lib/plugins/selection/index.js.map +1 -1
  36. package/lib/plugins/server-side/index.js.map +1 -1
  37. package/lib/plugins/sticky-rows/index.js.map +1 -1
  38. package/lib/plugins/tooltip/index.js.map +1 -1
  39. package/lib/plugins/tree/index.js.map +1 -1
  40. package/lib/plugins/undo-redo/index.js.map +1 -1
  41. package/lib/plugins/visibility/index.js.map +1 -1
  42. package/package.json +1 -1
  43. package/public.d.ts +1 -1
  44. package/umd/grid.all.umd.js +1 -1
  45. package/umd/grid.all.umd.js.map +1 -1
  46. package/umd/grid.umd.js +1 -1
  47. package/umd/grid.umd.js.map +1 -1
  48. package/umd/plugins/editing.umd.js +1 -1
  49. package/umd/plugins/editing.umd.js.map +1 -1
  50. package/umd/plugins/filtering.umd.js +1 -1
  51. package/umd/plugins/filtering.umd.js.map +1 -1
  52. package/umd/plugins/pinned-rows.umd.js +1 -1
  53. package/umd/plugins/pinned-rows.umd.js.map +1 -1
@@ -30,9 +30,9 @@ export declare const GridClasses: {
30
30
  readonly ROWS_VIEWPORT: "rows-viewport";
31
31
  readonly ROWS_SPACER: "rows-spacer";
32
32
  readonly ROWS_CONTAINER: "rows";
33
- readonly DATA_ROW: "data-row";
33
+ readonly DATA_ROW: "data-grid-row";
34
34
  readonly GROUP_ROW: "group-row";
35
- readonly DATA_CELL: "data-cell";
35
+ readonly DATA_CELL: "cell";
36
36
  readonly SELECTED: "selected";
37
37
  readonly FOCUSED: "focused";
38
38
  readonly EDITING: "editing";
@@ -81,12 +81,12 @@ export declare const GridSelectors: {
81
81
  readonly HEADER_CELL: ".header-cell";
82
82
  readonly ROWS_VIEWPORT: ".rows-viewport";
83
83
  readonly ROWS_CONTAINER: ".rows";
84
- readonly DATA_ROW: ".data-row";
85
- readonly DATA_CELL: ".data-cell";
84
+ readonly DATA_ROW: ".data-grid-row";
85
+ readonly DATA_CELL: ".cell";
86
86
  readonly GROUP_ROW: ".group-row";
87
87
  readonly CELL_BY_FIELD: (field: string) => string;
88
- readonly SELECTED_ROWS: ".data-row.selected";
89
- readonly EDITING_CELL: ".data-cell.editing";
88
+ readonly SELECTED_ROWS: ".data-grid-row.selected";
89
+ readonly EDITING_CELL: ".cell.editing";
90
90
  };
91
91
  /**
92
92
  * CSS custom property names for theming.
@@ -785,7 +785,7 @@ export declare abstract class BaseGridPlugin<TConfig = unknown> implements GridP
785
785
  * ```ts
786
786
  * afterRender(): void {
787
787
  * // Apply selection styling to rendered rows
788
- * const rows = this.gridElement?.querySelectorAll('.data-row');
788
+ * const rows = this.gridElement?.querySelectorAll('.data-grid-row');
789
789
  * rows?.forEach((row, i) => {
790
790
  * row.classList.toggle('selected', this.selectedRows.has(i));
791
791
  * });
@@ -1568,6 +1568,41 @@ export interface FrameworkAdapter {
1568
1568
  * to use its default built-in editors.
1569
1569
  */
1570
1570
  createEditor<TRow = unknown, TValue = unknown>(element: HTMLElement): ColumnEditorSpec<TRow, TValue> | undefined;
1571
+ /**
1572
+ * Creates a header cell renderer from a light DOM element (e.g. a slot or
1573
+ * template on a `<tbw-grid-column>`). Receives `HeaderCellContext` and
1574
+ * returns DOM / string for the entire header cell — the user is
1575
+ * responsible for sort icons and filter buttons (use
1576
+ * `ctx.renderSortIcon()` / `ctx.renderFilterButton()` helpers).
1577
+ *
1578
+ * Resize handles are appended automatically by the grid for resizable
1579
+ * columns regardless of which renderer path is active; do not render one
1580
+ * yourself.
1581
+ *
1582
+ * Returns undefined when the adapter has no header renderer registered
1583
+ * for this element, letting the grid fall back to its built-in header.
1584
+ *
1585
+ * Mirrors `headerRenderer` from `BaseColumnConfig`. Optional on the
1586
+ * adapter — adapters that don't expose a slot/template surface for
1587
+ * full-header customization can omit it; callers must null-check.
1588
+ *
1589
+ * @since 2.15.0
1590
+ */
1591
+ createHeaderRenderer?<TRow = unknown>(element: HTMLElement): HeaderRenderer<TRow> | undefined;
1592
+ /**
1593
+ * Creates a header *label* renderer from a light DOM element. The grid
1594
+ * keeps ownership of the sort icon, filter button, and resize handle;
1595
+ * the returned function only customizes the label content.
1596
+ *
1597
+ * Returns undefined when the adapter has no header label renderer
1598
+ * registered for this element.
1599
+ *
1600
+ * Mirrors `headerLabelRenderer` from `BaseColumnConfig`. Optional on
1601
+ * the adapter — see `createHeaderRenderer` for rationale.
1602
+ *
1603
+ * @since 2.15.0
1604
+ */
1605
+ createHeaderLabelRenderer?<TRow = unknown>(element: HTMLElement): HeaderLabelRenderer<TRow> | undefined;
1571
1606
  /**
1572
1607
  * Creates a tool panel renderer from a light DOM element.
1573
1608
  * The renderer receives a container element and optionally returns a cleanup function.
@@ -3766,6 +3801,62 @@ export interface GridColumnState {
3766
3801
  /** Array of column states. */
3767
3802
  columns: ColumnState[];
3768
3803
  }
3804
+ /**
3805
+ * Detail for the {@link DataGridEventMap.render | `render`} event.
3806
+ *
3807
+ * Fired once at the end of every render cycle (the single RAF flush in the
3808
+ * render scheduler), after all plugin `afterRender` hooks have run and after
3809
+ * `grid.ready()` has resolved.
3810
+ *
3811
+ * Use this when you need to act on the rendered DOM (e.g. focus the first
3812
+ * input of a freshly added row when `editing.mode === 'grid'`) without
3813
+ * resorting to `setTimeout` or double-`requestAnimationFrame` hacks.
3814
+ *
3815
+ * @example
3816
+ * ```typescript
3817
+ * // Focus the first cell's input after adding a row in full-grid edit mode
3818
+ * function addEmployee() {
3819
+ * grid.addRow({ id: crypto.randomUUID(), name: '', email: '' });
3820
+ * grid.addEventListener(
3821
+ * 'render',
3822
+ * () => {
3823
+ * const input = grid.querySelector<HTMLInputElement>(
3824
+ * '[data-row="0"][data-col="0"] input',
3825
+ * );
3826
+ * input?.focus();
3827
+ * },
3828
+ * { once: true },
3829
+ * );
3830
+ * }
3831
+ * ```
3832
+ *
3833
+ * @category Events
3834
+ * @since 2.15.0
3835
+ */
3836
+ export interface RenderDetail {
3837
+ /**
3838
+ * The highest render phase that executed this cycle (see {@link RenderPhase}).
3839
+ * Use this to skip cheap scroll-only renders (`phase < RenderPhase.ROWS`)
3840
+ * if you only care about row/column model changes.
3841
+ */
3842
+ phase: RenderPhase;
3843
+ /** `true` only for the very first render after the grid was connected. */
3844
+ initial: boolean;
3845
+ /** Number of rows in the effective row model after plugin `processRows` hooks ran. */
3846
+ rowCount: number;
3847
+ /**
3848
+ * The visible virtual window — `start` inclusive, `end` exclusive — or `null`
3849
+ * when virtualization is disabled (small datasets below the bypass threshold).
3850
+ *
3851
+ * When virtualization is enabled but no rows are visible (e.g. empty dataset)
3852
+ * this is `{ start: 0, end: 0 }`, NOT `null` — that lets consumers distinguish
3853
+ * "virtualization disabled" from "enabled but currently empty".
3854
+ */
3855
+ visibleRange: {
3856
+ start: number;
3857
+ end: number;
3858
+ } | null;
3859
+ }
3769
3860
  /**
3770
3861
  * Detail for a cell click event.
3771
3862
  * Provides full context about the clicked cell including row data.
@@ -4313,6 +4404,40 @@ export interface DataGridEventMap<TRow = unknown> {
4313
4404
  * @group Core Events
4314
4405
  */
4315
4406
  'column-state-change': GridColumnState;
4407
+ /**
4408
+ * Fired once at the end of every render cycle, after all plugin
4409
+ * `afterRender` hooks have run and `ready()` has resolved.
4410
+ *
4411
+ * This is the canonical post-render hook for consumers. Use it instead of
4412
+ * `setTimeout` / double-`requestAnimationFrame` to act on the rendered DOM
4413
+ * after a programmatic mutation.
4414
+ *
4415
+ * Note: `ready()` only resolves once (after the first render). The `render`
4416
+ * event fires on every flush — including scroll-driven virtual-window
4417
+ * updates — so prefer `{ once: true }` (or check `detail.phase`) when you
4418
+ * want to act on a specific mutation.
4419
+ *
4420
+ * @example
4421
+ * ```typescript
4422
+ * // Focus the first cell's input after addRow in full-grid edit mode
4423
+ * grid.addRow({ id: crypto.randomUUID(), name: '', email: '' });
4424
+ * grid.addEventListener(
4425
+ * 'render',
4426
+ * () => {
4427
+ * const input = grid.querySelector<HTMLInputElement>(
4428
+ * '[data-row="0"][data-col="0"] input',
4429
+ * );
4430
+ * input?.focus();
4431
+ * },
4432
+ * { once: true },
4433
+ * );
4434
+ * ```
4435
+ *
4436
+ * @see {@link RenderDetail}
4437
+ * @group Core Events
4438
+ * @since 2.15.0
4439
+ */
4440
+ render: RenderDetail;
4316
4441
  }
4317
4442
  /**
4318
4443
  * Extracts the event detail type for a given event name.
@@ -1,2 +1,2 @@
1
- import{setFeatureResolver as o}from"@toolbox-web/grid";function t(o,t,e,n){console.warn(function(o,t){return`[tbw-grid] ${o}: ${t}\n\n → More info: ${function(o){return`https://toolboxjs.com/grid/errors#${o.toLowerCase()}`}(o)}`}(o,t))}const e=/* @__PURE__ */new Map,n=/* @__PURE__ */new Set,r=()=>"undefined"!=typeof window&&("localhost"===window.location?.hostname||"127.0.0.1"===window.location?.hostname);function i(o,n,i){r()&&e.has(o)&&!i?.override&&t("TBW030",`Feature "${o}" was re-registered. Previous registration overwritten.`),e.set(o,{factory:n,name:o})}function s(o){return e.has(o)}function c(o){return e.get(o)?.factory}function f(){return Array.from(e.keys())}const u={undoRedo:["editing"],clipboard:["selection"]};function a(o,i){const s=e.get(o);if(s)return s.factory(i);if(r()&&!n.has(o)){n.add(o);const e=o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();t("TBW031",`Feature "${o}" is configured but not registered.\nAdd this import to enable it:\n\n import '@toolbox-web/grid/features/${e}';\n`)}}function d(o){const e=[],n=[];for(const[t,r]of Object.entries(o))void 0!==r&&!1!==r&&n.push(t);!function(o){const e=new Set(o);for(const n of o){const o=u[n];if(o)for(const i of o)e.has(i)||r()&&t("TBW032",`Feature "${n}" requires "${i}" to be enabled. Add "${i}" to your features configuration.`)}}(n);const i=["selection","editing",...n.filter(o=>"selection"!==o&&"editing"!==o)],s=[...new Set(i)].filter(o=>n.includes(o));for(const t of s){const n=o[t];if(void 0===n||!1===n)continue;const r=a(t,n);r&&e.push(r)}return e}function l(){e.clear(),n.clear()}o(d);export{l as clearFeatureRegistry,a as createPluginFromFeature,d as createPluginsFromFeatures,c as getFeatureFactory,f as getRegisteredFeatures,s as isFeatureRegistered,i as registerFeature};
1
+ import{setFeatureResolver as o}from"@toolbox-web/grid";function e(o,e,t,n){console.warn(function(o,e){return`[tbw-grid] ${o}: ${e}\n\n → More info: ${function(o){return`https://toolboxjs.com/grid/errors#${o.toLowerCase()}`}(o)}`}(o,e))}const t="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev",n=/* @__PURE__ */Symbol.for(`@toolbox-web/grid:feature-registry@${t}/v1`),r=/* @__PURE__ */Symbol.for(`@toolbox-web/grid:feature-registry-warned@${t}/v1`);function i(o,e){let t=Reflect.get(globalThis,o);return void 0===t&&(t=e(),Reflect.set(globalThis,o,t)),t}const s=i(n,()=>/* @__PURE__ */new Map),c=i(r,()=>/* @__PURE__ */new Set),f=()=>"undefined"!=typeof window&&("localhost"===window.location?.hostname||"127.0.0.1"===window.location?.hostname);function u(o,t,n){f()&&s.has(o)&&!n?.override&&e("TBW030",`Feature "${o}" was re-registered. Previous registration overwritten.`),s.set(o,{factory:t,name:o})}function a(o){return s.has(o)}function d(o){return s.get(o)?.factory}function l(){return Array.from(s.keys())}const g={undoRedo:["editing"],clipboard:["selection"]};function w(o,t){const n=s.get(o);if(n)return n.factory(t);if(f()&&!c.has(o)){c.add(o);const t=o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();e("TBW031",`Feature "${o}" is configured but not registered.\nAdd this import to enable it:\n\n import '@toolbox-web/grid/features/${t}';\n`)}}function b(o){const t=[],n=[];for(const[e,s]of Object.entries(o))void 0!==s&&!1!==s&&n.push(e);!function(o){const t=new Set(o);for(const n of o){const o=g[n];if(o)for(const r of o)t.has(r)||f()&&e("TBW032",`Feature "${n}" requires "${r}" to be enabled. Add "${r}" to your features configuration.`)}}(n);const r=["selection","editing",...n.filter(o=>"selection"!==o&&"editing"!==o)],i=[...new Set(r)].filter(o=>n.includes(o));for(const e of i){const n=o[e];if(void 0===n||!1===n)continue;const r=w(e,n);r&&t.push(r)}return t}function $(){s.clear(),c.clear()}o(b);export{$ as clearFeatureRegistry,w as createPluginFromFeature,b as createPluginsFromFeatures,d as getFeatureFactory,l as getRegisteredFeatures,a as isFeatureRegistered,u as registerFeature};
2
2
  //# sourceMappingURL=registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sources":["../../../../../libs/grid/src/lib/core/internal/diagnostics.ts","../../../../../libs/grid/src/lib/features/registry.ts"],"sourcesContent":["/**\n * Centralized diagnostic messages for @toolbox-web/grid.\n *\n * Every user-facing warning, error, or info message in the grid has a unique\n * diagnostic code (e.g. `TBW001`). Each code maps to a section on the online\n * troubleshooting page, giving developers a direct link to resolution steps.\n *\n * ## Usage\n *\n * ```ts\n * import { MISSING_BREAKPOINT, warnDiagnostic, throwDiagnostic } from './diagnostics';\n *\n * // Warn with a code\n * warnDiagnostic(MISSING_BREAKPOINT, 'Set a breakpoint...', gridId);\n *\n * // Throw with a code\n * throwDiagnostic(MISSING_ROW_ID, 'Configure getRowId...', gridId);\n * ```\n *\n * Plugins should prefer `this.warn(MISSING_BREAKPOINT, message)` via BaseGridPlugin\n * instead of importing this module directly.\n *\n * @internal\n */\n\n// #region Grid Prefix\n\n/**\n * Build the `[tbw-grid]` or `[tbw-grid#my-id]` log prefix.\n * Pass `pluginName` for a scoped prefix like `[tbw-grid:SelectionPlugin]`.\n */\nexport function gridPrefix(gridId?: string, pluginName?: string): string {\n const id = gridId ? `#${gridId}` : '';\n const plugin = pluginName ? `:${pluginName}` : '';\n return `[tbw-grid${id}${plugin}]`;\n}\n\n// #endregion\n\n// #region Diagnostic Codes\n\n/**\n * Diagnostic codes used across the grid library.\n *\n * Each code is an individual export so that unused codes are tree-shaken\n * from bundles that don't reference them (esbuild can't tree-shake\n * properties from a single object).\n *\n * Naming: TBW + 3-digit number.\n * Ranges:\n * 001–019 Configuration validation (missing plugins, bad config)\n * 020–029 Plugin lifecycle (dependencies, incompatibilities, deprecation)\n * 030–039 Feature registry\n * 040–049 Row operations (row ID, row mutations)\n * 050–059 Column operations (width, template)\n * 060–069 Rendering (callbacks, formatters, external views)\n * 070–079 Shell (tool panels, header/toolbar content)\n * 080–089 Editing & editors\n * 090–099 Print\n * 100–109 Clipboard\n * 110–119 Plugin-specific (responsive, undo-redo, grouping-columns)\n * 120–129 Style injection\n * 130–139 Attribute parsing\n */\n\n// --- Config validation (001–019) ---\n/** Column uses a plugin-owned property but the plugin is not loaded. */\nexport const MISSING_PLUGIN = 'TBW001' as const;\n/** Grid config uses a plugin-owned property but the plugin is not loaded. */\nexport const MISSING_PLUGIN_CONFIG = 'TBW002' as const;\n/** Plugin config rule violation (error severity). */\nexport const CONFIG_RULE_ERROR = 'TBW003' as const;\n/** Plugin config rule violation (warning severity). */\nexport const CONFIG_RULE_WARN = 'TBW004' as const;\n\n// --- Plugin lifecycle (020–029) ---\n/** Required plugin dependency is missing. */\nexport const MISSING_DEPENDENCY = 'TBW020' as const;\n/** Optional plugin dependency is missing. */\nexport const OPTIONAL_DEPENDENCY = 'TBW021' as const;\n/** Two loaded plugins are incompatible. */\nexport const INCOMPATIBLE_PLUGINS = 'TBW022' as const;\n/** Two plugin instances resolve to the same canonical name (alias collapse). */\nexport const PLUGIN_ALIAS_COLLAPSE = 'TBW023' as const;\n/** Error thrown inside a plugin event handler. */\nexport const PLUGIN_EVENT_ERROR = 'TBW024' as const;\n/** Conflicting config values found while merging alias-collapsed plugin instances. */\nexport const PLUGIN_ALIAS_CONFIG_CONFLICT = 'TBW025' as const;\n\n// --- Feature registry (030–039) ---\n/** Feature was re-registered (overwritten). */\nexport const FEATURE_REREGISTERED = 'TBW030' as const;\n/** Feature configured but not imported. */\nexport const FEATURE_NOT_IMPORTED = 'TBW031' as const;\n/** Feature depends on another feature that is not enabled. */\nexport const FEATURE_MISSING_DEP = 'TBW032' as const;\n\n// --- Row operations (040–049) ---\n/** Cannot determine row ID (no getRowId and no id property). */\nexport const MISSING_ROW_ID = 'TBW040' as const;\n/** Row with given ID not found. */\nexport const ROW_NOT_FOUND = 'TBW041' as const;\n\n// --- Column operations (050–059) ---\n/** Column has an invalid CSS width value. */\nexport const INVALID_COLUMN_WIDTH = 'TBW050' as const;\n\n// --- Rendering callbacks (060–069) ---\n/** rowClass callback threw an error. */\nexport const ROW_CLASS_ERROR = 'TBW060' as const;\n/** cellClass callback threw an error. */\nexport const CELL_CLASS_ERROR = 'TBW061' as const;\n/** Column format function threw an error. */\nexport const FORMAT_ERROR = 'TBW062' as const;\n/** External view mount() threw an error. */\nexport const VIEW_MOUNT_ERROR = 'TBW063' as const;\n/** External view event dispatch error. */\nexport const VIEW_DISPATCH_ERROR = 'TBW064' as const;\n\n// --- Shell (070–079) ---\n/** Tool panel missing required id or title. */\nexport const TOOL_PANEL_MISSING_ATTR = 'TBW070' as const;\n/** No tool panels registered. */\nexport const NO_TOOL_PANELS = 'TBW071' as const;\n/** Tool panel section not found. */\nexport const TOOL_PANEL_NOT_FOUND = 'TBW072' as const;\n/** Tool panel already registered. */\nexport const TOOL_PANEL_DUPLICATE = 'TBW073' as const;\n/** Header content already registered. */\nexport const HEADER_CONTENT_DUPLICATE = 'TBW074' as const;\n/** Toolbar content already registered. */\nexport const TOOLBAR_CONTENT_DUPLICATE = 'TBW075' as const;\n\n// --- Editing & editors (080–089) ---\n/** External editor mount() threw an error. */\nexport const EDITOR_MOUNT_ERROR = 'TBW080' as const;\n\n// --- Print (090–099) ---\n/** Print already in progress. */\nexport const PRINT_IN_PROGRESS = 'TBW090' as const;\n/** Grid not available for printing. */\nexport const PRINT_NO_GRID = 'TBW091' as const;\n/** Print operation failed. */\nexport const PRINT_FAILED = 'TBW092' as const;\n/** Multiple elements share the same grid ID (print isolation issue). */\nexport const PRINT_DUPLICATE_ID = 'TBW093' as const;\n\n// --- Clipboard (100–109) ---\n/** Clipboard API write failed. */\nexport const CLIPBOARD_FAILED = 'TBW100' as const;\n\n// --- Plugin-specific (110–119) ---\n/** ResponsivePlugin: no breakpoint configured. */\nexport const MISSING_BREAKPOINT = 'TBW110' as const;\n/** UndoRedoPlugin: transaction already in progress. */\nexport const TRANSACTION_IN_PROGRESS = 'TBW111' as const;\n/** UndoRedoPlugin: no transaction in progress. */\nexport const NO_TRANSACTION = 'TBW112' as const;\n/** GroupingColumnsPlugin: missing id or header on column group definition. */\nexport const COLUMN_GROUP_NO_ID = 'TBW113' as const;\n/** GroupingColumnsPlugin: conflicting columnGroups sources. */\nexport const COLUMN_GROUPS_CONFLICT = 'TBW114' as const;\n\n// --- Style injection (120–129) ---\n/** Failed to extract grid.css from document stylesheets. */\nexport const STYLE_EXTRACT_FAILED = 'TBW120' as const;\n/** Could not find grid.css in document.styleSheets. */\nexport const STYLE_NOT_FOUND = 'TBW121' as const;\n\n// --- Attribute parsing (130–139) ---\n/** Invalid JSON in an HTML attribute. */\nexport const INVALID_ATTRIBUTE_JSON = 'TBW130' as const;\n\n// --- DataSource / ServerSide (140–149) ---\n/** ServerSidePlugin: getRows() rejected. */\nexport const DATASOURCE_FETCH_ERROR = 'TBW140' as const;\n/** ServerSidePlugin: getChildRows() rejected. */\nexport const DATASOURCE_CHILD_FETCH_ERROR = 'TBW141' as const;\n/** ServerSidePlugin: getChildRows() not implemented but a plugin queried for children. */\nexport const DATASOURCE_NO_CHILD_HANDLER = 'TBW142' as const;\n/** ServerSidePlugin: concurrent request limit reached, request deferred. */\nexport const DATASOURCE_THROTTLED = 'TBW143' as const;\n\nexport type DiagnosticCode =\n | typeof MISSING_PLUGIN\n | typeof MISSING_PLUGIN_CONFIG\n | typeof CONFIG_RULE_ERROR\n | typeof CONFIG_RULE_WARN\n | typeof MISSING_DEPENDENCY\n | typeof OPTIONAL_DEPENDENCY\n | typeof INCOMPATIBLE_PLUGINS\n | typeof PLUGIN_ALIAS_COLLAPSE\n | typeof PLUGIN_EVENT_ERROR\n | typeof PLUGIN_ALIAS_CONFIG_CONFLICT\n | typeof FEATURE_REREGISTERED\n | typeof FEATURE_NOT_IMPORTED\n | typeof FEATURE_MISSING_DEP\n | typeof MISSING_ROW_ID\n | typeof ROW_NOT_FOUND\n | typeof INVALID_COLUMN_WIDTH\n | typeof ROW_CLASS_ERROR\n | typeof CELL_CLASS_ERROR\n | typeof FORMAT_ERROR\n | typeof VIEW_MOUNT_ERROR\n | typeof VIEW_DISPATCH_ERROR\n | typeof TOOL_PANEL_MISSING_ATTR\n | typeof NO_TOOL_PANELS\n | typeof TOOL_PANEL_NOT_FOUND\n | typeof TOOL_PANEL_DUPLICATE\n | typeof HEADER_CONTENT_DUPLICATE\n | typeof TOOLBAR_CONTENT_DUPLICATE\n | typeof EDITOR_MOUNT_ERROR\n | typeof PRINT_IN_PROGRESS\n | typeof PRINT_NO_GRID\n | typeof PRINT_FAILED\n | typeof PRINT_DUPLICATE_ID\n | typeof CLIPBOARD_FAILED\n | typeof MISSING_BREAKPOINT\n | typeof TRANSACTION_IN_PROGRESS\n | typeof NO_TRANSACTION\n | typeof COLUMN_GROUP_NO_ID\n | typeof COLUMN_GROUPS_CONFLICT\n | typeof STYLE_EXTRACT_FAILED\n | typeof STYLE_NOT_FOUND\n | typeof INVALID_ATTRIBUTE_JSON\n | typeof DATASOURCE_FETCH_ERROR\n | typeof DATASOURCE_CHILD_FETCH_ERROR\n | typeof DATASOURCE_NO_CHILD_HANDLER\n | typeof DATASOURCE_THROTTLED;\n\n// #endregion\n\n// #region Docs URL\n\nconst DOCS_BASE = 'https://toolboxjs.com/grid/errors';\n\n/** Build a direct link to the troubleshooting section for a code. */\nfunction docsUrl(code: DiagnosticCode): string {\n return `${DOCS_BASE}#${code.toLowerCase()}`;\n}\n\n// #endregion\n\n// #region Formatting\n\n/**\n * Format a diagnostic message with prefix, code, and docs link.\n *\n * Output format:\n * ```\n * [tbw-grid#my-id] TBW001: Your message here.\n *\n * → More info: https://toolboxjs.com/grid/errors#tbw001\n * ```\n */\nexport function formatDiagnostic(code: DiagnosticCode, message: string, gridId?: string, pluginName?: string): string {\n const prefix = gridPrefix(gridId, pluginName);\n return `${prefix} ${code}: ${message}\\n\\n → More info: ${docsUrl(code)}`;\n}\n\n// #endregion\n\n// #region Public API\n\n/**\n * Throw an error with a diagnostic code and docs link.\n * Use for configuration errors and API misuse that should halt execution.\n */\nexport function throwDiagnostic(code: DiagnosticCode, message: string, gridId?: string, pluginName?: string): never {\n throw new Error(formatDiagnostic(code, message, gridId, pluginName));\n}\n\n/**\n * Log a warning with a diagnostic code and docs link.\n * Use for recoverable issues the developer should fix.\n */\nexport function warnDiagnostic(code: DiagnosticCode, message: string, gridId?: string, pluginName?: string): void {\n console.warn(formatDiagnostic(code, message, gridId, pluginName));\n}\n\n/**\n * Log a debug message with a diagnostic code and docs link.\n * Use for optional/soft dependency notifications — visible only when\n * the browser DevTools \"Verbose\" log level is enabled.\n */\nexport function debugDiagnostic(code: DiagnosticCode, message: string, gridId?: string, pluginName?: string): void {\n console.debug(formatDiagnostic(code, message, gridId, pluginName));\n}\n\n/**\n * Log an error with a diagnostic code and docs link.\n * Use for non-throwing errors (e.g., failed async operations).\n */\nexport function errorDiagnostic(code: DiagnosticCode, message: string, gridId?: string, pluginName?: string): void {\n console.error(formatDiagnostic(code, message, gridId, pluginName));\n}\n\n// #endregion\n","/**\n * Core Feature Registry for @toolbox-web/grid\n *\n * This module provides a framework-agnostic registry for plugin factories.\n * Features are registered via side-effect imports, enabling tree-shaking\n * while maintaining a clean declarative API.\n *\n * @example\n * ```typescript\n * // Import features you need (side-effect imports)\n * import '@toolbox-web/grid/features/selection';\n * import '@toolbox-web/grid/features/filtering';\n *\n * // Configure grid declaratively\n * grid.gridConfig = {\n * features: {\n * selection: 'range',\n * filtering: { debounceMs: 200 },\n * },\n * };\n * ```\n *\n * @packageDocumentation\n * @module Features\n */\n\nimport {\n FEATURE_MISSING_DEP,\n FEATURE_NOT_IMPORTED,\n FEATURE_REREGISTERED,\n warnDiagnostic,\n} from '../core/internal/diagnostics';\nimport { setFeatureResolver } from '../core/internal/feature-hook';\nimport type { FeatureConfig, GridPlugin } from '../core/types';\n\n// #region Types\n\n/** Feature name — keys of the augmented FeatureConfig interface. */\nexport type FeatureName = keyof FeatureConfig;\n\n/** Factory function that creates a plugin from a feature config value. */\nexport type PluginFactory<TConfig = unknown> = (config: TConfig) => GridPlugin;\n\ninterface RegistryEntry {\n factory: PluginFactory;\n name: string;\n}\n\n// #endregion\n\n// #region Registry State\n\nconst featureRegistry = new Map<string, RegistryEntry>();\nconst warnedFeatures = new Set<string>();\n\n// #endregion\n\n// #region Registration API\n\n/** Runtime dev-mode check (localhost or 127.0.0.1). */\nconst isDev = (): boolean =>\n typeof window !== 'undefined' &&\n (window.location?.hostname === 'localhost' || window.location?.hostname === '127.0.0.1');\n\n/** Optional flags passed to {@link registerFeature}. */\nexport interface RegisterFeatureOptions {\n /**\n * Set to `true` when the registration is intentionally overwriting an\n * existing entry (e.g. a framework adapter wrapping the vanilla factory\n * with reactive bridging). Suppresses the TBW030 dev-mode warning.\n */\n override?: boolean;\n}\n\n/**\n * Register a feature's plugin factory.\n * Called by side-effect feature imports (e.g., `import '@toolbox-web/grid/features/selection'`).\n *\n * @param name - The feature name (matches a key on FeatureConfig)\n * @param factory - Function that creates a plugin instance from config\n * @param options - Pass `{ override: true }` for intentional re-registration\n * (framework adapters bridging the vanilla factory) to suppress TBW030.\n */\nexport function registerFeature<K extends FeatureName>(\n name: K,\n factory: PluginFactory<FeatureConfig[K]>,\n options?: RegisterFeatureOptions,\n): void;\nexport function registerFeature(name: string, factory: PluginFactory, options?: RegisterFeatureOptions): void;\nexport function registerFeature(name: string, factory: PluginFactory, options?: RegisterFeatureOptions): void {\n if (isDev() && featureRegistry.has(name) && !options?.override) {\n warnDiagnostic(FEATURE_REREGISTERED, `Feature \"${name}\" was re-registered. Previous registration overwritten.`);\n }\n featureRegistry.set(name, { factory, name });\n}\n\n/**\n * Check if a feature has been registered.\n */\nexport function isFeatureRegistered(name: string): boolean {\n return featureRegistry.has(name);\n}\n\n/**\n * Get a registered feature's factory. Returns undefined if not registered.\n */\nexport function getFeatureFactory(name: string): PluginFactory | undefined {\n return featureRegistry.get(name)?.factory;\n}\n\n/**\n * Get all registered feature names.\n */\nexport function getRegisteredFeatures(): string[] {\n return Array.from(featureRegistry.keys());\n}\n\n// #endregion\n\n// #region Plugin Creation\n\n/**\n * Plugin dependency declarations.\n * Some plugins require others to be loaded first.\n */\nconst PLUGIN_DEPENDENCIES: Record<string, string[]> = {\n undoRedo: ['editing'],\n clipboard: ['selection'],\n};\n\n/**\n * Create a plugin instance for a single feature.\n * Shows a warning if the feature is not registered.\n */\nexport function createPluginFromFeature(name: string, config: unknown): GridPlugin | undefined {\n const entry = featureRegistry.get(name);\n\n if (!entry) {\n if (isDev() && !warnedFeatures.has(name)) {\n warnedFeatures.add(name);\n const kebab = name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();\n warnDiagnostic(\n FEATURE_NOT_IMPORTED,\n `Feature \"${name}\" is configured but not registered.\\n` +\n `Add this import to enable it:\\n\\n` +\n ` import '@toolbox-web/grid/features/${kebab}';\\n`,\n );\n }\n return undefined;\n }\n\n return entry.factory(config);\n}\n\n/**\n * Validate feature dependencies and log warnings for missing ones.\n */\nfunction validateDependencies(featureNames: string[]): void {\n const featureSet = new Set(featureNames);\n\n for (const feature of featureNames) {\n const deps = PLUGIN_DEPENDENCIES[feature];\n if (!deps) continue;\n\n for (const dep of deps) {\n if (!featureSet.has(dep)) {\n if (isDev()) {\n warnDiagnostic(\n FEATURE_MISSING_DEP,\n `Feature \"${feature}\" requires \"${dep}\" to be enabled. ` + `Add \"${dep}\" to your features configuration.`,\n );\n }\n }\n }\n }\n}\n\n/**\n * Create plugin instances from a features configuration object.\n *\n * Handles:\n * - Dependency validation (clipboard needs selection)\n * - Dependency ordering (selection before clipboard)\n * - Skipping false/undefined values\n *\n * @param features - Partial FeatureConfig object\n * @returns Array of plugin instances ready for gridConfig.plugins\n */\nexport function createPluginsFromFeatures(features: Record<string, unknown>): GridPlugin[] {\n const plugins: GridPlugin[] = [];\n const enabledFeatures: string[] = [];\n\n // Collect enabled feature names\n for (const [key, value] of Object.entries(features)) {\n if (value === undefined || value === false) continue;\n enabledFeatures.push(key);\n }\n\n // Validate dependencies\n validateDependencies(enabledFeatures);\n\n // Create plugins in dependency order: dep-targets first, then the rest\n const dependencyOrder: string[] = [\n 'selection',\n 'editing',\n ...enabledFeatures.filter((f) => f !== 'selection' && f !== 'editing'),\n ];\n const orderedFeatures = [...new Set(dependencyOrder)].filter((f) => enabledFeatures.includes(f));\n\n for (const featureName of orderedFeatures) {\n const config = features[featureName];\n if (config === undefined || config === false) continue;\n\n const plugin = createPluginFromFeature(featureName, config);\n if (plugin) {\n plugins.push(plugin);\n }\n }\n\n return plugins;\n}\n\n// #endregion\n\n// #region Auto-Registration\n\n// Wire feature resolver into grid core so `gridConfig.features` is handled automatically.\n// This runs when any feature module is imported (they all import this registry).\nsetFeatureResolver(createPluginsFromFeatures as (features: Record<string, unknown>) => GridPlugin[]);\n\n// #endregion\n\n// #region Testing Utilities\n\n/**\n * Clear the registry. For testing only.\n * @internal\n */\nexport function clearFeatureRegistry(): void {\n featureRegistry.clear();\n warnedFeatures.clear();\n}\n\n// #endregion\n"],"names":["warnDiagnostic","code","message","gridId","pluginName","console","warn","toLowerCase","docsUrl","formatDiagnostic","featureRegistry","Map","warnedFeatures","Set","isDev","window","location","hostname","registerFeature","name","factory","options","has","override","set","isFeatureRegistered","getFeatureFactory","get","getRegisteredFeatures","Array","from","keys","PLUGIN_DEPENDENCIES","undoRedo","clipboard","createPluginFromFeature","config","entry","add","kebab","replace","createPluginsFromFeatures","features","plugins","enabledFeatures","key","value","Object","entries","push","featureNames","featureSet","feature","deps","dep","validateDependencies","dependencyOrder","filter","f","orderedFeatures","includes","featureName","plugin","clearFeatureRegistry","clear","setFeatureResolver"],"mappings":"uDAoRO,SAASA,EAAeC,EAAsBC,EAAiBC,EAAiBC,GACrFC,QAAQC,KAtBH,SAA0BL,EAAsBC,GAErD,MAAO,cAAaD,MAASC,uBApB/B,SAAiBD,GACf,MAAO,qCAAgBA,EAAKM,eAC9B,CAkB4DC,CAAQP,IACpE,CAmBeQ,CAAiBR,EAAMC,GACtC,CClOA,MAAMQ,qBAAsBC,IACtBC,qBAAqBC,IAOrBC,EAAQ,IACM,oBAAXC,SACwB,cAA9BA,OAAOC,UAAUC,UAA0D,cAA9BF,OAAOC,UAAUC,UA2B1D,SAASC,EAAgBC,EAAcC,EAAwBC,GAChEP,KAAWJ,EAAgBY,IAAIH,KAAUE,GAASE,UACpDvB,EDAgC,SCAK,YAAYmB,4DAEnDT,EAAgBc,IAAIL,EAAM,CAAEC,UAASD,QACvC,CAKO,SAASM,EAAoBN,GAClC,OAAOT,EAAgBY,IAAIH,EAC7B,CAKO,SAASO,EAAkBP,GAChC,OAAOT,EAAgBiB,IAAIR,IAAOC,OACpC,CAKO,SAASQ,IACd,OAAOC,MAAMC,KAAKpB,EAAgBqB,OACpC,CAUA,MAAMC,EAAgD,CACpDC,SAAU,CAAC,WACXC,UAAW,CAAC,cAOP,SAASC,EAAwBhB,EAAciB,GACpD,MAAMC,EAAQ3B,EAAgBiB,IAAIR,GAElC,GAAKkB,EAcL,OAAOA,EAAMjB,QAAQgB,GAbnB,GAAItB,MAAYF,EAAeU,IAAIH,GAAO,CACxCP,EAAe0B,IAAInB,GACnB,MAAMoB,EAAQpB,EAAKqB,QAAQ,kBAAmB,SAASjC,cACvDP,EDhD8B,SCkD5B,YAAYmB,+GAE8BoB,QAE9C,CAKJ,CAoCO,SAASE,EAA0BC,GACxC,MAAMC,EAAwB,GACxBC,EAA4B,GAGlC,IAAA,MAAYC,EAAKC,KAAUC,OAAOC,QAAQN,QAC1B,IAAVI,IAAiC,IAAVA,GAC3BF,EAAgBK,KAAKJ,IAtCzB,SAA8BK,GAC5B,MAAMC,EAAa,IAAItC,IAAIqC,GAE3B,IAAA,MAAWE,KAAWF,EAAc,CAClC,MAAMG,EAAOrB,EAAoBoB,GACjC,GAAKC,EAEL,IAAA,MAAWC,KAAOD,EACXF,EAAW7B,IAAIgC,IACdxC,KACFd,EDxEyB,SC0EvB,YAAYoD,gBAAsBE,0BAAiCA,qCAK7E,CACF,CAwBEC,CAAqBX,GAGrB,MAAMY,EAA4B,CAChC,YACA,aACGZ,EAAgBa,OAAQC,GAAY,cAANA,GAA2B,YAANA,IAElDC,EAAkB,IAAI,IAAI9C,IAAI2C,IAAkBC,OAAQC,GAAMd,EAAgBgB,SAASF,IAE7F,IAAA,MAAWG,KAAeF,EAAiB,CACzC,MAAMvB,EAASM,EAASmB,GACxB,QAAe,IAAXzB,IAAmC,IAAXA,EAAkB,SAE9C,MAAM0B,EAAS3B,EAAwB0B,EAAazB,GAChD0B,GACFnB,EAAQM,KAAKa,EAEjB,CAEA,OAAOnB,CACT,CAkBO,SAASoB,IACdrD,EAAgBsD,QAChBpD,EAAeoD,OACjB,CAbAC,EAAmBxB"}
1
+ {"version":3,"file":"registry.js","sources":["../../../../../libs/grid/src/lib/core/internal/diagnostics.ts","../../../../../libs/grid/src/lib/features/registry.ts"],"sourcesContent":["/**\n * Centralized diagnostic messages for @toolbox-web/grid.\n *\n * Every user-facing warning, error, or info message in the grid has a unique\n * diagnostic code (e.g. `TBW001`). Each code maps to a section on the online\n * troubleshooting page, giving developers a direct link to resolution steps.\n *\n * ## Usage\n *\n * ```ts\n * import { MISSING_BREAKPOINT, warnDiagnostic, throwDiagnostic } from './diagnostics';\n *\n * // Warn with a code\n * warnDiagnostic(MISSING_BREAKPOINT, 'Set a breakpoint...', gridId);\n *\n * // Throw with a code\n * throwDiagnostic(MISSING_ROW_ID, 'Configure getRowId...', gridId);\n * ```\n *\n * Plugins should prefer `this.warn(MISSING_BREAKPOINT, message)` via BaseGridPlugin\n * instead of importing this module directly.\n *\n * @internal\n */\n\n// #region Grid Prefix\n\n/**\n * Build the `[tbw-grid]` or `[tbw-grid#my-id]` log prefix.\n * Pass `pluginName` for a scoped prefix like `[tbw-grid:SelectionPlugin]`.\n */\nexport function gridPrefix(gridId?: string, pluginName?: string): string {\n const id = gridId ? `#${gridId}` : '';\n const plugin = pluginName ? `:${pluginName}` : '';\n return `[tbw-grid${id}${plugin}]`;\n}\n\n// #endregion\n\n// #region Diagnostic Codes\n\n/**\n * Diagnostic codes used across the grid library.\n *\n * Each code is an individual export so that unused codes are tree-shaken\n * from bundles that don't reference them (esbuild can't tree-shake\n * properties from a single object).\n *\n * Naming: TBW + 3-digit number.\n * Ranges:\n * 001–019 Configuration validation (missing plugins, bad config)\n * 020–029 Plugin lifecycle (dependencies, incompatibilities, deprecation)\n * 030–039 Feature registry\n * 040–049 Row operations (row ID, row mutations)\n * 050–059 Column operations (width, template)\n * 060–069 Rendering (callbacks, formatters, external views)\n * 070–079 Shell (tool panels, header/toolbar content)\n * 080–089 Editing & editors\n * 090–099 Print\n * 100–109 Clipboard\n * 110–119 Plugin-specific (responsive, undo-redo, grouping-columns)\n * 120–129 Style injection\n * 130–139 Attribute parsing\n */\n\n// --- Config validation (001–019) ---\n/** Column uses a plugin-owned property but the plugin is not loaded. */\nexport const MISSING_PLUGIN = 'TBW001' as const;\n/** Grid config uses a plugin-owned property but the plugin is not loaded. */\nexport const MISSING_PLUGIN_CONFIG = 'TBW002' as const;\n/** Plugin config rule violation (error severity). */\nexport const CONFIG_RULE_ERROR = 'TBW003' as const;\n/** Plugin config rule violation (warning severity). */\nexport const CONFIG_RULE_WARN = 'TBW004' as const;\n\n// --- Plugin lifecycle (020–029) ---\n/** Required plugin dependency is missing. */\nexport const MISSING_DEPENDENCY = 'TBW020' as const;\n/** Optional plugin dependency is missing. */\nexport const OPTIONAL_DEPENDENCY = 'TBW021' as const;\n/** Two loaded plugins are incompatible. */\nexport const INCOMPATIBLE_PLUGINS = 'TBW022' as const;\n/** Two plugin instances resolve to the same canonical name (alias collapse). */\nexport const PLUGIN_ALIAS_COLLAPSE = 'TBW023' as const;\n/** Error thrown inside a plugin event handler. */\nexport const PLUGIN_EVENT_ERROR = 'TBW024' as const;\n/** Conflicting config values found while merging alias-collapsed plugin instances. */\nexport const PLUGIN_ALIAS_CONFIG_CONFLICT = 'TBW025' as const;\n\n// --- Feature registry (030–039) ---\n/** Feature was re-registered (overwritten). */\nexport const FEATURE_REREGISTERED = 'TBW030' as const;\n/** Feature configured but not imported. */\nexport const FEATURE_NOT_IMPORTED = 'TBW031' as const;\n/** Feature depends on another feature that is not enabled. */\nexport const FEATURE_MISSING_DEP = 'TBW032' as const;\n\n// --- Row operations (040–049) ---\n/** Cannot determine row ID (no getRowId and no id property). */\nexport const MISSING_ROW_ID = 'TBW040' as const;\n/** Row with given ID not found. */\nexport const ROW_NOT_FOUND = 'TBW041' as const;\n\n// --- Column operations (050–059) ---\n/** Column has an invalid CSS width value. */\nexport const INVALID_COLUMN_WIDTH = 'TBW050' as const;\n\n// --- Rendering callbacks (060–069) ---\n/** rowClass callback threw an error. */\nexport const ROW_CLASS_ERROR = 'TBW060' as const;\n/** cellClass callback threw an error. */\nexport const CELL_CLASS_ERROR = 'TBW061' as const;\n/** Column format function threw an error. */\nexport const FORMAT_ERROR = 'TBW062' as const;\n/** External view mount() threw an error. */\nexport const VIEW_MOUNT_ERROR = 'TBW063' as const;\n/** External view event dispatch error. */\nexport const VIEW_DISPATCH_ERROR = 'TBW064' as const;\n\n// --- Shell (070–079) ---\n/** Tool panel missing required id or title. */\nexport const TOOL_PANEL_MISSING_ATTR = 'TBW070' as const;\n/** No tool panels registered. */\nexport const NO_TOOL_PANELS = 'TBW071' as const;\n/** Tool panel section not found. */\nexport const TOOL_PANEL_NOT_FOUND = 'TBW072' as const;\n/** Tool panel already registered. */\nexport const TOOL_PANEL_DUPLICATE = 'TBW073' as const;\n/** Header content already registered. */\nexport const HEADER_CONTENT_DUPLICATE = 'TBW074' as const;\n/** Toolbar content already registered. */\nexport const TOOLBAR_CONTENT_DUPLICATE = 'TBW075' as const;\n\n// --- Editing & editors (080–089) ---\n/** External editor mount() threw an error. */\nexport const EDITOR_MOUNT_ERROR = 'TBW080' as const;\n\n// --- Print (090–099) ---\n/** Print already in progress. */\nexport const PRINT_IN_PROGRESS = 'TBW090' as const;\n/** Grid not available for printing. */\nexport const PRINT_NO_GRID = 'TBW091' as const;\n/** Print operation failed. */\nexport const PRINT_FAILED = 'TBW092' as const;\n/** Multiple elements share the same grid ID (print isolation issue). */\nexport const PRINT_DUPLICATE_ID = 'TBW093' as const;\n\n// --- Clipboard (100–109) ---\n/** Clipboard API write failed. */\nexport const CLIPBOARD_FAILED = 'TBW100' as const;\n\n// --- Plugin-specific (110–119) ---\n/** ResponsivePlugin: no breakpoint configured. */\nexport const MISSING_BREAKPOINT = 'TBW110' as const;\n/** UndoRedoPlugin: transaction already in progress. */\nexport const TRANSACTION_IN_PROGRESS = 'TBW111' as const;\n/** UndoRedoPlugin: no transaction in progress. */\nexport const NO_TRANSACTION = 'TBW112' as const;\n/** GroupingColumnsPlugin: missing id or header on column group definition. */\nexport const COLUMN_GROUP_NO_ID = 'TBW113' as const;\n/** GroupingColumnsPlugin: conflicting columnGroups sources. */\nexport const COLUMN_GROUPS_CONFLICT = 'TBW114' as const;\n\n// --- Style injection (120–129) ---\n/** Failed to extract grid.css from document stylesheets. */\nexport const STYLE_EXTRACT_FAILED = 'TBW120' as const;\n/** Could not find grid.css in document.styleSheets. */\nexport const STYLE_NOT_FOUND = 'TBW121' as const;\n\n// --- Attribute parsing (130–139) ---\n/** Invalid JSON in an HTML attribute. */\nexport const INVALID_ATTRIBUTE_JSON = 'TBW130' as const;\n\n// --- DataSource / ServerSide (140–149) ---\n/** ServerSidePlugin: getRows() rejected. */\nexport const DATASOURCE_FETCH_ERROR = 'TBW140' as const;\n/** ServerSidePlugin: getChildRows() rejected. */\nexport const DATASOURCE_CHILD_FETCH_ERROR = 'TBW141' as const;\n/** ServerSidePlugin: getChildRows() not implemented but a plugin queried for children. */\nexport const DATASOURCE_NO_CHILD_HANDLER = 'TBW142' as const;\n/** ServerSidePlugin: concurrent request limit reached, request deferred. */\nexport const DATASOURCE_THROTTLED = 'TBW143' as const;\n\nexport type DiagnosticCode =\n | typeof MISSING_PLUGIN\n | typeof MISSING_PLUGIN_CONFIG\n | typeof CONFIG_RULE_ERROR\n | typeof CONFIG_RULE_WARN\n | typeof MISSING_DEPENDENCY\n | typeof OPTIONAL_DEPENDENCY\n | typeof INCOMPATIBLE_PLUGINS\n | typeof PLUGIN_ALIAS_COLLAPSE\n | typeof PLUGIN_EVENT_ERROR\n | typeof PLUGIN_ALIAS_CONFIG_CONFLICT\n | typeof FEATURE_REREGISTERED\n | typeof FEATURE_NOT_IMPORTED\n | typeof FEATURE_MISSING_DEP\n | typeof MISSING_ROW_ID\n | typeof ROW_NOT_FOUND\n | typeof INVALID_COLUMN_WIDTH\n | typeof ROW_CLASS_ERROR\n | typeof CELL_CLASS_ERROR\n | typeof FORMAT_ERROR\n | typeof VIEW_MOUNT_ERROR\n | typeof VIEW_DISPATCH_ERROR\n | typeof TOOL_PANEL_MISSING_ATTR\n | typeof NO_TOOL_PANELS\n | typeof TOOL_PANEL_NOT_FOUND\n | typeof TOOL_PANEL_DUPLICATE\n | typeof HEADER_CONTENT_DUPLICATE\n | typeof TOOLBAR_CONTENT_DUPLICATE\n | typeof EDITOR_MOUNT_ERROR\n | typeof PRINT_IN_PROGRESS\n | typeof PRINT_NO_GRID\n | typeof PRINT_FAILED\n | typeof PRINT_DUPLICATE_ID\n | typeof CLIPBOARD_FAILED\n | typeof MISSING_BREAKPOINT\n | typeof TRANSACTION_IN_PROGRESS\n | typeof NO_TRANSACTION\n | typeof COLUMN_GROUP_NO_ID\n | typeof COLUMN_GROUPS_CONFLICT\n | typeof STYLE_EXTRACT_FAILED\n | typeof STYLE_NOT_FOUND\n | typeof INVALID_ATTRIBUTE_JSON\n | typeof DATASOURCE_FETCH_ERROR\n | typeof DATASOURCE_CHILD_FETCH_ERROR\n | typeof DATASOURCE_NO_CHILD_HANDLER\n | typeof DATASOURCE_THROTTLED;\n\n// #endregion\n\n// #region Docs URL\n\nconst DOCS_BASE = 'https://toolboxjs.com/grid/errors';\n\n/** Build a direct link to the troubleshooting section for a code. */\nfunction docsUrl(code: DiagnosticCode): string {\n return `${DOCS_BASE}#${code.toLowerCase()}`;\n}\n\n// #endregion\n\n// #region Formatting\n\n/**\n * Format a diagnostic message with prefix, code, and docs link.\n *\n * Output format:\n * ```\n * [tbw-grid#my-id] TBW001: Your message here.\n *\n * → More info: https://toolboxjs.com/grid/errors#tbw001\n * ```\n */\nexport function formatDiagnostic(code: DiagnosticCode, message: string, gridId?: string, pluginName?: string): string {\n const prefix = gridPrefix(gridId, pluginName);\n return `${prefix} ${code}: ${message}\\n\\n → More info: ${docsUrl(code)}`;\n}\n\n// #endregion\n\n// #region Public API\n\n/**\n * Throw an error with a diagnostic code and docs link.\n * Use for configuration errors and API misuse that should halt execution.\n */\nexport function throwDiagnostic(code: DiagnosticCode, message: string, gridId?: string, pluginName?: string): never {\n throw new Error(formatDiagnostic(code, message, gridId, pluginName));\n}\n\n/**\n * Log a warning with a diagnostic code and docs link.\n * Use for recoverable issues the developer should fix.\n */\nexport function warnDiagnostic(code: DiagnosticCode, message: string, gridId?: string, pluginName?: string): void {\n console.warn(formatDiagnostic(code, message, gridId, pluginName));\n}\n\n/**\n * Log a debug message with a diagnostic code and docs link.\n * Use for optional/soft dependency notifications — visible only when\n * the browser DevTools \"Verbose\" log level is enabled.\n */\nexport function debugDiagnostic(code: DiagnosticCode, message: string, gridId?: string, pluginName?: string): void {\n console.debug(formatDiagnostic(code, message, gridId, pluginName));\n}\n\n/**\n * Log an error with a diagnostic code and docs link.\n * Use for non-throwing errors (e.g., failed async operations).\n */\nexport function errorDiagnostic(code: DiagnosticCode, message: string, gridId?: string, pluginName?: string): void {\n console.error(formatDiagnostic(code, message, gridId, pluginName));\n}\n\n// #endregion\n","/**\n * Core Feature Registry for @toolbox-web/grid\n *\n * This module provides a framework-agnostic registry for plugin factories.\n * Features are registered via side-effect imports, enabling tree-shaking\n * while maintaining a clean declarative API.\n *\n * @example\n * ```typescript\n * // Import features you need (side-effect imports)\n * import '@toolbox-web/grid/features/selection';\n * import '@toolbox-web/grid/features/filtering';\n *\n * // Configure grid declaratively\n * grid.gridConfig = {\n * features: {\n * selection: 'range',\n * filtering: { debounceMs: 200 },\n * },\n * };\n * ```\n *\n * @packageDocumentation\n * @module Features\n */\n\nimport {\n FEATURE_MISSING_DEP,\n FEATURE_NOT_IMPORTED,\n FEATURE_REREGISTERED,\n warnDiagnostic,\n} from '../core/internal/diagnostics';\nimport { setFeatureResolver } from '../core/internal/feature-hook';\nimport type { FeatureConfig, GridPlugin } from '../core/types';\n\n// #region Types\n\n/** Feature name — keys of the augmented FeatureConfig interface. */\nexport type FeatureName = keyof FeatureConfig;\n\n/** Factory function that creates a plugin from a feature config value. */\nexport type PluginFactory<TConfig = unknown> = (config: TConfig) => GridPlugin;\n\ninterface RegistryEntry {\n factory: PluginFactory;\n name: string;\n}\n\n// #endregion\n\n// #region Registry State\n\n/*\n * Cross-bundle singleton (version-scoped).\n *\n * The custom-elements registry is realm-global, but `import` graphs are not:\n * when two micro-frontend widgets on the same page bundle their own copy of\n * `@toolbox-web/grid`, each copy gets its own `featureRegistry` Map. The\n * `<tbw-grid>` class is realm-global (see `registerDataGrid()` in\n * `core/grid.ts`), so the *running* class resolves features via the resolver\n * its own bundle wired up — which closes over the *local* Map. Side-effect\n * imports from any other bundle (`import '@toolbox-web/grid/features/tree'`)\n * land in a different Map that the running class never reads, producing\n * spurious TBW031 \"feature not registered\" warnings.\n *\n * Fix: persist the Map on `globalThis` under a `Symbol.for(...)` key so every\n * loaded copy of this module reads and writes the same instance.\n *\n * The key embeds `__GRID_VERSION__` so **only same-version** bundles share a\n * registry. `registerDataGrid()` already isolates differently-versioned grid\n * classes by registering them under suffixed tag names — the version is\n * sanitized to ASCII letters/digits/dashes, so `2.14.0` becomes the tag\n * `tbw-grid-v2-14-0` (issue #339). The feature registry must mirror that\n * isolation, otherwise the last-loaded bundle's plugin factories would\n * overwrite earlier versions' entries and the running grid would attach\n * plugin instances built against a different internal contract. The trailing\n * `/v1` is a schema version for the slot shape — bump if the stored value's\n * shape changes incompatibly.\n *\n * Issue: planning #9 (two Roma widgets each bundling their own grid copy).\n */\ndeclare const __GRID_VERSION__: string;\nconst GRID_VERSION = typeof __GRID_VERSION__ !== 'undefined' ? __GRID_VERSION__ : 'dev';\nconst REGISTRY_KEY = Symbol.for(`@toolbox-web/grid:feature-registry@${GRID_VERSION}/v1`);\nconst WARNED_KEY = Symbol.for(`@toolbox-web/grid:feature-registry-warned@${GRID_VERSION}/v1`);\n\nfunction getOrCreateGlobal<T>(key: symbol, make: () => T): T {\n let value = Reflect.get(globalThis, key) as T | undefined;\n if (value === undefined) {\n value = make();\n Reflect.set(globalThis, key, value);\n }\n return value;\n}\n\nconst featureRegistry = getOrCreateGlobal(REGISTRY_KEY, () => new Map<string, RegistryEntry>());\nconst warnedFeatures = getOrCreateGlobal(WARNED_KEY, () => new Set<string>());\n\n// #endregion\n\n// #region Registration API\n\n/** Runtime dev-mode check (localhost or 127.0.0.1). */\nconst isDev = (): boolean =>\n typeof window !== 'undefined' &&\n (window.location?.hostname === 'localhost' || window.location?.hostname === '127.0.0.1');\n\n/** Optional flags passed to {@link registerFeature}. */\nexport interface RegisterFeatureOptions {\n /**\n * Set to `true` when the registration is intentionally overwriting an\n * existing entry (e.g. a framework adapter wrapping the vanilla factory\n * with reactive bridging). Suppresses the TBW030 dev-mode warning.\n */\n override?: boolean;\n}\n\n/**\n * Register a feature's plugin factory.\n * Called by side-effect feature imports (e.g., `import '@toolbox-web/grid/features/selection'`).\n *\n * @param name - The feature name (matches a key on FeatureConfig)\n * @param factory - Function that creates a plugin instance from config\n * @param options - Pass `{ override: true }` for intentional re-registration\n * (framework adapters bridging the vanilla factory) to suppress TBW030.\n */\nexport function registerFeature<K extends FeatureName>(\n name: K,\n factory: PluginFactory<FeatureConfig[K]>,\n options?: RegisterFeatureOptions,\n): void;\nexport function registerFeature(name: string, factory: PluginFactory, options?: RegisterFeatureOptions): void;\nexport function registerFeature(name: string, factory: PluginFactory, options?: RegisterFeatureOptions): void {\n if (isDev() && featureRegistry.has(name) && !options?.override) {\n warnDiagnostic(FEATURE_REREGISTERED, `Feature \"${name}\" was re-registered. Previous registration overwritten.`);\n }\n featureRegistry.set(name, { factory, name });\n}\n\n/**\n * Check if a feature has been registered.\n */\nexport function isFeatureRegistered(name: string): boolean {\n return featureRegistry.has(name);\n}\n\n/**\n * Get a registered feature's factory. Returns undefined if not registered.\n */\nexport function getFeatureFactory(name: string): PluginFactory | undefined {\n return featureRegistry.get(name)?.factory;\n}\n\n/**\n * Get all registered feature names.\n */\nexport function getRegisteredFeatures(): string[] {\n return Array.from(featureRegistry.keys());\n}\n\n// #endregion\n\n// #region Plugin Creation\n\n/**\n * Plugin dependency declarations.\n * Some plugins require others to be loaded first.\n */\nconst PLUGIN_DEPENDENCIES: Record<string, string[]> = {\n undoRedo: ['editing'],\n clipboard: ['selection'],\n};\n\n/**\n * Create a plugin instance for a single feature.\n * Shows a warning if the feature is not registered.\n */\nexport function createPluginFromFeature(name: string, config: unknown): GridPlugin | undefined {\n const entry = featureRegistry.get(name);\n\n if (!entry) {\n if (isDev() && !warnedFeatures.has(name)) {\n warnedFeatures.add(name);\n const kebab = name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();\n warnDiagnostic(\n FEATURE_NOT_IMPORTED,\n `Feature \"${name}\" is configured but not registered.\\n` +\n `Add this import to enable it:\\n\\n` +\n ` import '@toolbox-web/grid/features/${kebab}';\\n`,\n );\n }\n return undefined;\n }\n\n return entry.factory(config);\n}\n\n/**\n * Validate feature dependencies and log warnings for missing ones.\n */\nfunction validateDependencies(featureNames: string[]): void {\n const featureSet = new Set(featureNames);\n\n for (const feature of featureNames) {\n const deps = PLUGIN_DEPENDENCIES[feature];\n if (!deps) continue;\n\n for (const dep of deps) {\n if (!featureSet.has(dep)) {\n if (isDev()) {\n warnDiagnostic(\n FEATURE_MISSING_DEP,\n `Feature \"${feature}\" requires \"${dep}\" to be enabled. ` + `Add \"${dep}\" to your features configuration.`,\n );\n }\n }\n }\n }\n}\n\n/**\n * Create plugin instances from a features configuration object.\n *\n * Handles:\n * - Dependency validation (clipboard needs selection)\n * - Dependency ordering (selection before clipboard)\n * - Skipping false/undefined values\n *\n * @param features - Partial FeatureConfig object\n * @returns Array of plugin instances ready for gridConfig.plugins\n */\nexport function createPluginsFromFeatures(features: Record<string, unknown>): GridPlugin[] {\n const plugins: GridPlugin[] = [];\n const enabledFeatures: string[] = [];\n\n // Collect enabled feature names\n for (const [key, value] of Object.entries(features)) {\n if (value === undefined || value === false) continue;\n enabledFeatures.push(key);\n }\n\n // Validate dependencies\n validateDependencies(enabledFeatures);\n\n // Create plugins in dependency order: dep-targets first, then the rest\n const dependencyOrder: string[] = [\n 'selection',\n 'editing',\n ...enabledFeatures.filter((f) => f !== 'selection' && f !== 'editing'),\n ];\n const orderedFeatures = [...new Set(dependencyOrder)].filter((f) => enabledFeatures.includes(f));\n\n for (const featureName of orderedFeatures) {\n const config = features[featureName];\n if (config === undefined || config === false) continue;\n\n const plugin = createPluginFromFeature(featureName, config);\n if (plugin) {\n plugins.push(plugin);\n }\n }\n\n return plugins;\n}\n\n// #endregion\n\n// #region Auto-Registration\n\n// Wire feature resolver into grid core so `gridConfig.features` is handled automatically.\n// This runs when any feature module is imported (they all import this registry).\nsetFeatureResolver(createPluginsFromFeatures as (features: Record<string, unknown>) => GridPlugin[]);\n\n// #endregion\n\n// #region Testing Utilities\n\n/**\n * Clear the registry. For testing only.\n * @internal\n */\nexport function clearFeatureRegistry(): void {\n featureRegistry.clear();\n warnedFeatures.clear();\n}\n\n// #endregion\n"],"names":["warnDiagnostic","code","message","gridId","pluginName","console","warn","toLowerCase","docsUrl","formatDiagnostic","GRID_VERSION","__GRID_VERSION__","REGISTRY_KEY","Symbol","for","WARNED_KEY","getOrCreateGlobal","key","make","value","Reflect","get","globalThis","set","featureRegistry","Map","warnedFeatures","Set","isDev","window","location","hostname","registerFeature","name","factory","options","has","override","isFeatureRegistered","getFeatureFactory","getRegisteredFeatures","Array","from","keys","PLUGIN_DEPENDENCIES","undoRedo","clipboard","createPluginFromFeature","config","entry","add","kebab","replace","createPluginsFromFeatures","features","plugins","enabledFeatures","Object","entries","push","featureNames","featureSet","feature","deps","dep","validateDependencies","dependencyOrder","filter","f","orderedFeatures","includes","featureName","plugin","clearFeatureRegistry","clear","setFeatureResolver"],"mappings":"uDAoRO,SAASA,EAAeC,EAAsBC,EAAiBC,EAAiBC,GACrFC,QAAQC,KAtBH,SAA0BL,EAAsBC,GAErD,MAAO,cAAaD,MAASC,uBApB/B,SAAiBD,GACf,MAAO,qCAAgBA,EAAKM,eAC9B,CAkB4DC,CAAQP,IACpE,CAmBeQ,CAAiBR,EAAMC,GACtC,CCpMA,MAAMQ,EAA2C,oBAArBC,iBAAmCA,iBAAmB,MAC5EC,iBAAeC,OAAOC,IAAI,sCAAsCJ,QAChEK,iBAAaF,OAAOC,IAAI,6CAA6CJ,QAE3E,SAASM,EAAqBC,EAAaC,GACzC,IAAIC,EAAQC,QAAQC,IAAIC,WAAYL,GAKpC,YAJc,IAAVE,IACFA,EAAQD,IACRE,QAAQG,IAAID,WAAYL,EAAKE,IAExBA,CACT,CAEA,MAAMK,EAAkBR,EAAkBJ,EAAc,mBAAM,IAAIa,KAC5DC,EAAiBV,EAAkBD,EAAY,mBAAM,IAAIY,KAOzDC,EAAQ,IACM,oBAAXC,SACwB,cAA9BA,OAAOC,UAAUC,UAA0D,cAA9BF,OAAOC,UAAUC,UA2B1D,SAASC,EAAgBC,EAAcC,EAAwBC,GAChEP,KAAWJ,EAAgBY,IAAIH,KAAUE,GAASE,UACpDrC,ED3CgC,SC2CK,YAAYiC,4DAEnDT,EAAgBD,IAAIU,EAAM,CAAEC,UAASD,QACvC,CAKO,SAASK,EAAoBL,GAClC,OAAOT,EAAgBY,IAAIH,EAC7B,CAKO,SAASM,EAAkBN,GAChC,OAAOT,EAAgBH,IAAIY,IAAOC,OACpC,CAKO,SAASM,IACd,OAAOC,MAAMC,KAAKlB,EAAgBmB,OACpC,CAUA,MAAMC,EAAgD,CACpDC,SAAU,CAAC,WACXC,UAAW,CAAC,cAOP,SAASC,EAAwBd,EAAce,GACpD,MAAMC,EAAQzB,EAAgBH,IAAIY,GAElC,GAAKgB,EAcL,OAAOA,EAAMf,QAAQc,GAbnB,GAAIpB,MAAYF,EAAeU,IAAIH,GAAO,CACxCP,EAAewB,IAAIjB,GACnB,MAAMkB,EAAQlB,EAAKmB,QAAQ,kBAAmB,SAAS7C,cACvDP,ED3F8B,SC6F5B,YAAYiC,+GAE8BkB,QAE9C,CAKJ,CAoCO,SAASE,EAA0BC,GACxC,MAAMC,EAAwB,GACxBC,EAA4B,GAGlC,IAAA,MAAYvC,EAAKE,KAAUsC,OAAOC,QAAQJ,QAC1B,IAAVnC,IAAiC,IAAVA,GAC3BqC,EAAgBG,KAAK1C,IAtCzB,SAA8B2C,GAC5B,MAAMC,EAAa,IAAIlC,IAAIiC,GAE3B,IAAA,MAAWE,KAAWF,EAAc,CAClC,MAAMG,EAAOnB,EAAoBkB,GACjC,GAAKC,EAEL,IAAA,MAAWC,KAAOD,EACXF,EAAWzB,IAAI4B,IACdpC,KACF5B,EDnHyB,SCqHvB,YAAY8D,gBAAsBE,0BAAiCA,qCAK7E,CACF,CAwBEC,CAAqBT,GAGrB,MAAMU,EAA4B,CAChC,YACA,aACGV,EAAgBW,OAAQC,GAAY,cAANA,GAA2B,YAANA,IAElDC,EAAkB,IAAI,IAAI1C,IAAIuC,IAAkBC,OAAQC,GAAMZ,EAAgBc,SAASF,IAE7F,IAAA,MAAWG,KAAeF,EAAiB,CACzC,MAAMrB,EAASM,EAASiB,GACxB,QAAe,IAAXvB,IAAmC,IAAXA,EAAkB,SAE9C,MAAMwB,EAASzB,EAAwBwB,EAAavB,GAChDwB,GACFjB,EAAQI,KAAKa,EAEjB,CAEA,OAAOjB,CACT,CAkBO,SAASkB,IACdjD,EAAgBkD,QAChBhD,EAAegD,OACjB,CAbAC,EAAmBtB"}