@aintela/bi 0.2.4 → 0.2.6

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.
package/dist/composer.js CHANGED
@@ -1,5 +1,5 @@
1
- import { C as e, a as t, b as o, c as r, d as n, e as i, f as d, g as C, h as m, i as E, D as S, j as l, k as p, l as P, m as T, n as _, o as u, p as c, q as D, E as I, r as h, s as A, t as v, u as R, v as O, F as k, w as g, x as L, G as b, y as f, H as y, P as N, z as V, A as F, S as x, B as G, I as H, J as B, K as M, M as Y, T as z, N as U, O as w, Q as K, R as j, V as q, X as W, Y as X, Z as J, _ as Q, $ as Z, a0 as $, a1 as aa, a2 as sa, a3 as ea, a4 as ta, a5 as oa, a6 as ra, a7 as na, a8 as ia, a9 as da, aa as Ca, ab as ma, ac as Ea, ad as Sa, ae as la, af as pa, ag as Pa, ah as Ta, ai as _a, aj as ua, ak as ca, al as Da, am as Ia, an as ha, ao as Aa, ap as va, aq as Ra, ar as Oa, as as ka, at as ga, au as La, av as ba, aw as fa, ax as ya, ay as Na, az as Va, aA as Fa, aB as xa, aC as Ga, aD as Ha, aF as Ba } from "./index-DOfnLVhs.js";
2
- import { EnvironmentProvider as Ya, InertEnvironmentProvider as za, useEnvironment as Ua, useEnvironmentOptional as wa } from "@aintela/chat/components";
1
+ import { C as e, a as t, b as o, c as r, d as n, e as i, f as d, g as C, h as m, i as E, D as S, j as l, k as p, l as T, m as P, n as _, o as u, p as c, q as D, E as I, r as h, s as A, t as v, u as R, v as O, F as k, w as g, x as L, G as b, y as f, H as y, P as N, z as V, A as x, S as G, B as F, I as H, J as B, K as M, M as Y, T as z, N as U, O as w, Q as K, R as j, V as q, X as J, Y as W, Z as X, _ as Q, $ as Z, a0 as $, a1 as aa, a2 as sa, a3 as ea, a4 as ta, a5 as oa, a6 as ra, a7 as na, a8 as ia, a9 as da, aa as Ca, ab as ma, ac as Ea, ad as Sa, ae as la, af as pa, ag as Ta, ah as Pa, ai as _a, aj as ua, ak as ca, al as Da, am as Ia, an as ha, ao as Aa, ap as va, aq as Ra, ar as Oa, as as ka, at as ga, au as La, av as ba, aw as fa, ax as ya, ay as Na, az as Va, aA as xa, aB as Ga, aC as Fa, aD as Ha, aE as Ba, aG as Ma } from "./index-DrS3V1Ke.js";
2
+ import { EnvironmentProvider as za, InertEnvironmentProvider as Ua, useEnvironment as wa, useEnvironmentOptional as Ka } from "@aintela/chat/components";
3
3
  export {
4
4
  e as CARD_TYPE_CATALOG,
5
5
  t as CATEGORY_ICONS,
@@ -14,15 +14,15 @@ export {
14
14
  S as DEFAULT_PAD_HEIGHT_PX,
15
15
  l as DRAFT_SAVE_DEBOUNCE_MS,
16
16
  p as DashboardPad,
17
- P as DashboardPadEditor,
18
- T as DashboardPadSketch,
17
+ T as DashboardPadEditor,
18
+ P as DashboardPadSketch,
19
19
  _ as DashboardPin,
20
20
  u as DashboardSidePanel,
21
21
  c as DatasetParameterizationControls,
22
22
  D as DrawablePrompt,
23
23
  I as ENV_HIGHLIGHT_CLASS,
24
24
  h as EntryEmptyState,
25
- Ya as EnvironmentProvider,
25
+ za as EnvironmentProvider,
26
26
  A as ExampleCardSkath,
27
27
  v as ExampleCardSketch,
28
28
  R as ExampleCardSketh,
@@ -33,12 +33,12 @@ export {
33
33
  b as GRID_ROW_HEIGHT_PX,
34
34
  f as GUIDE_SHOW_DELAY_MS,
35
35
  y as HoverButton,
36
- za as InertEnvironmentProvider,
36
+ Ua as InertEnvironmentProvider,
37
37
  N as PAD_INTERNAL_CLASSES,
38
38
  V as PAD_INTERNAL_IDS,
39
- F as PrototypePad,
40
- x as SPECIFIC_TYPE_ICONS,
41
- G as SPECIFIC_TYPE_ICON_NAMES,
39
+ x as PrototypePad,
40
+ G as SPECIFIC_TYPE_ICONS,
41
+ F as SPECIFIC_TYPE_ICON_NAMES,
42
42
  H as STARTER_TEMPLATES,
43
43
  B as SessionVisualizationsPanel,
44
44
  M as SessionVisualizationsPanelButton,
@@ -49,9 +49,9 @@ export {
49
49
  K as TitleSketch,
50
50
  j as ToolBox,
51
51
  q as VIEWER_COMMIT_DEBOUNCE_MS,
52
- W as activityPanelVariants,
53
- X as activityPanelVariantsReduced,
54
- J as ambientVariants,
52
+ J as activityPanelVariants,
53
+ W as activityPanelVariantsReduced,
54
+ X as ambientVariants,
55
55
  Q as ambientVariantsReduced,
56
56
  Z as autoComplete,
57
57
  $ as c,
@@ -70,8 +70,8 @@ export {
70
70
  Sa as groupCardCatalog,
71
71
  la as guideStepsRequireSketch,
72
72
  pa as isElementVisible,
73
- Pa as isSimplePadDefinition,
74
- Ta as joinClientSideChanges,
73
+ Ta as isSimplePadDefinition,
74
+ Pa as joinClientSideChanges,
75
75
  _a as padConfigToDashboard,
76
76
  ua as pickBestElement,
77
77
  ca as randomId,
@@ -79,23 +79,24 @@ export {
79
79
  Ia as resolveEnvironmentElements,
80
80
  ha as resolveGuideElement,
81
81
  Aa as sanitizeToJsVariable,
82
- va as seedFromTemplate,
83
- Ra as sketchCardItemComparer,
84
- Oa as sketchFilterComparer,
85
- ka as targetSuggestsPadInternal,
86
- ga as templateKinds,
87
- La as toDraftPayload,
88
- ba as toSelectorList,
89
- fa as upsertDashboardDraft,
90
- ya as useCardTypeIcons,
91
- Na as useComposer,
92
- Va as useComposerChatBridge,
93
- Fa as useComposerEnvironment,
94
- xa as useComposerStore,
95
- Ga as useComposerStoreOptional,
96
- Ha as useDashboardPad,
97
- Ua as useEnvironment,
98
- wa as useEnvironmentOptional,
99
- Ba as validateSketch
82
+ va as sanitizeToJsxComponentName,
83
+ Ra as seedFromTemplate,
84
+ Oa as sketchCardItemComparer,
85
+ ka as sketchFilterComparer,
86
+ ga as targetSuggestsPadInternal,
87
+ La as templateKinds,
88
+ ba as toDraftPayload,
89
+ fa as toSelectorList,
90
+ ya as upsertDashboardDraft,
91
+ Na as useCardTypeIcons,
92
+ Va as useComposer,
93
+ xa as useComposerChatBridge,
94
+ Ga as useComposerEnvironment,
95
+ Fa as useComposerStore,
96
+ Ha as useComposerStoreOptional,
97
+ Ba as useDashboardPad,
98
+ wa as useEnvironment,
99
+ Ka as useEnvironmentOptional,
100
+ Ma as validateSketch
100
101
  };
101
102
  //# sourceMappingURL=composer.js.map
package/dist/grid.js CHANGED
@@ -1,7 +1,7 @@
1
- import { B as s, D as o, a as t, b as e, c as i, d, G as n, e as C } from "./GridLayout-1gWuIKeZ.js";
1
+ import { B as s, D as o, a as t, b as e, c as i, d, G as n, e as C } from "./GridLayout-BQcuPzng.js";
2
2
  import { G as E } from "./GridCardPlaceHolder-DVVT3pqn.js";
3
3
  import { C as T, u as f } from "./ChartContext-C_f_6khG.js";
4
- import { t as _, a as u, b as R, u as l } from "./index-BzUugG0A.js";
4
+ import { t as _, a as u, b as R, u as l } from "./index-D6-YxBjl.js";
5
5
  export {
6
6
  s as BiErrorBoundary,
7
7
  T as ChartContextProvider,
@@ -1,6 +1,6 @@
1
1
  var b = Object.defineProperty;
2
2
  var d = (a, e) => b(a, "name", { value: e, configurable: !0 });
3
- import { a as g, B as v, D as w, b as M, c as R, d as G, G as L, e as _ } from "./GridLayout-1gWuIKeZ.js";
3
+ import { a as g, B as v, D as w, b as M, c as R, d as G, G as L, e as _ } from "./GridLayout-BQcuPzng.js";
4
4
  import { G as H } from "./GridCardPlaceHolder-DVVT3pqn.js";
5
5
  import { C as W, u as T } from "./ChartContext-C_f_6khG.js";
6
6
  import { useMemo as D } from "react";
@@ -133,4 +133,4 @@ export {
133
133
  f as t,
134
134
  k as u
135
135
  };
136
- //# sourceMappingURL=index-BzUugG0A.js.map
136
+ //# sourceMappingURL=index-D6-YxBjl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-BzUugG0A.js","sources":["../src/grid/useGridConfigTranslator.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport type { Layout, LayoutItem } from \"react-grid-layout\";\nimport type {\n GridConfig,\n RowConfig,\n ResponsiveGridConfig,\n ResponsiveLayouts,\n BreakpointName,\n} from \"./types\";\nimport { DEFAULT_COLS } from \"./types\";\n\n/**\n * Translates a GridConfig (row/cell tree) into a flat Layout array\n * that react-grid-layout understands.\n *\n * @param config - The grid configuration\n * @param cols - Number of columns (default: 12)\n * @returns Flat layout array for react-grid-layout\n */\nexport function translateGridConfig(\n config: GridConfig,\n cols: number = 12\n): Layout {\n const items: LayoutItem[] = [];\n\n function processRows(\n rows: RowConfig[],\n offsetX: number,\n offsetY: number,\n parentCols: number\n ): number {\n let y = offsetY;\n\n for (const row of rows) {\n const rowHeight = row.height ?? 1;\n let x = offsetX;\n\n for (const cell of row.cells) {\n // Scale width relative to parent columns\n const scaledW = Math.round((cell.width / 12) * parentCols);\n let cellHeight = cell.height ?? rowHeight;\n\n cellHeight = cellHeight == 1 ? 1 : cellHeight;\n\n if (cell.rows && cell.rows.length > 0) {\n // Nested rows - recurse\n processRows(cell.rows, x, y, scaledW);\n } else if (cell.key) {\n // Leaf cell - add to layout\n const item: LayoutItem = {\n i: cell.key,\n x,\n y,\n w: scaledW,\n h: (cellHeight * (config.rowMultipler ?? 1)) + 1,\n };\n\n // Add optional constraints\n if (cell.minW !== undefined) item.minW = cell.minW;\n if (cell.maxW !== undefined) item.maxW = cell.maxW;\n if (cell.minH !== undefined) item.minH = cell.minH;\n if (cell.maxH !== undefined) item.maxH = cell.maxH;\n if (cell.static !== undefined) item.static = cell.static;\n if (cell.isDraggable !== undefined) item.isDraggable = cell.isDraggable;\n if (cell.isResizable !== undefined) item.isResizable = cell.isResizable;\n\n items.push(item);\n }\n\n x += scaledW;\n }\n\n y += rowHeight;\n }\n\n return y;\n }\n\n processRows(config.rows, 0, 0, cols);\n\n return items;\n}\n\n/**\n * Translates a ResponsiveGridConfig into ResponsiveLayouts\n * If a breakpoint is not defined, it falls back to larger breakpoints\n *\n * @param config - The responsive grid configuration\n * @param colsPerBreakpoint - Columns per breakpoint (default: DEFAULT_COLS)\n * @returns Responsive layouts object for react-grid-layout\n */\nexport function translateResponsiveGridConfig(\n config: ResponsiveGridConfig,\n colsPerBreakpoint: Record<BreakpointName, number> = DEFAULT_COLS\n): ResponsiveLayouts {\n const breakpointOrder: BreakpointName[] = [\"lg\", \"md\", \"sm\", \"xs\", \"xxs\"];\n const layouts: ResponsiveLayouts = {};\n\n // Find the first defined config to use as fallback\n let fallbackConfig: GridConfig | undefined;\n\n for (const bp of breakpointOrder) {\n const bpConfig = config[bp];\n\n if (bpConfig) {\n fallbackConfig = bpConfig;\n layouts[bp] = translateGridConfig(bpConfig, colsPerBreakpoint[bp]);\n } else if (fallbackConfig) {\n // Use fallback from larger breakpoint, but translate with this breakpoint's cols\n layouts[bp] = translateGridConfig(\n fallbackConfig,\n colsPerBreakpoint[bp]\n );\n }\n }\n\n return layouts;\n}\n\n/**\n * Auto-responsive translation strategy.\n * Determines how items should be arranged when columns decrease.\n */\nexport type AutoResponsiveStrategy = \"scale\" | \"stack\" | \"hybrid\";\n\n/**\n * Translates a single GridConfig into responsive layouts automatically.\n * \n * This function intelligently adapts the layout for different screen sizes:\n * - For breakpoints with same column count as base: preserves layout\n * - For breakpoints with fewer columns: applies the chosen strategy\n * \n * Strategies:\n * - \"scale\": Proportionally scale widths (items may become very narrow)\n * - \"stack\": Stack items vertically (each item becomes full width)\n * - \"hybrid\": Scale for moderate reductions, stack for small screens (default)\n *\n * @param config - The grid configuration (designed for lg/12 columns)\n * @param colsPerBreakpoint - Columns per breakpoint (default: DEFAULT_COLS)\n * @param strategy - How to handle smaller breakpoints (default: \"hybrid\")\n * @returns Responsive layouts object for react-grid-layout\n */\nexport function translateGridConfigAutoResponsive(\n config: GridConfig,\n colsPerBreakpoint: Record<BreakpointName, number> = DEFAULT_COLS,\n strategy: AutoResponsiveStrategy = \"stack\"\n): ResponsiveLayouts {\n const breakpointOrder: BreakpointName[] = [\"lg\", \"md\", \"sm\", \"xs\", \"xxs\"];\n const layouts: ResponsiveLayouts = {};\n\n // Base layout (lg - 12 columns typically)\n const baseCols = colsPerBreakpoint.lg;\n const baseLayout = translateGridConfig(config, baseCols);\n\n for (const bp of breakpointOrder) {\n const targetCols = colsPerBreakpoint[bp];\n\n if (targetCols === baseCols) {\n // Same column count - use base layout directly\n layouts[bp] = baseLayout;\n } else {\n // Different column count - apply strategy\n const shouldStack =\n strategy === \"stack\" ||\n (strategy === \"hybrid\" && targetCols <= 4);\n\n if (shouldStack) {\n // Stack: arrange items vertically, full width\n layouts[bp] = createStackedLayout(baseLayout, targetCols);\n } else {\n // Scale: proportionally adjust widths\n layouts[bp] = createScaledLayout(baseLayout, baseCols, targetCols, config.rowMultipler ?? 1);\n }\n }\n }\n\n return layouts;\n}\n\n/**\n * Creates a stacked layout where each item takes full width\n * and items are arranged vertically.\n */\nfunction createStackedLayout(baseLayout: Layout, cols: number): Layout {\n let currentY = 0;\n\n // Sort by original position (top to bottom, left to right)\n const sorted = [...baseLayout].sort((a, b) => {\n if (a.y !== b.y) return a.y - b.y;\n return a.x - b.x;\n });\n\n return sorted.map((item) => {\n const newItem: LayoutItem = {\n ...item,\n x: 0,\n y: currentY,\n w: cols, // Full width\n // Keep height, but ensure minimum of 2 for readability on small screens\n h: Math.max(item.h, 2)\n };\n currentY += newItem.h;\n return newItem;\n });\n}\n\n/**\n * Creates a scaled layout by proportionally adjusting widths.\n * Items maintain their relative positions but widths are scaled.\n */\nfunction createScaledLayout(baseLayout: Layout, baseCols: number, targetCols: number, rowMultipler: number): Layout {\n const scale = targetCols / baseCols;\n\n return baseLayout.map((item) => {\n // Scale x and width, ensure minimum width of 1\n const scaledW = Math.max(1, Math.round(item.w * scale));\n const scaledX = Math.round(item.x * scale);\n\n // Ensure item doesn't overflow\n const adjustedX = Math.min(scaledX, targetCols - scaledW);\n\n return {\n ...item,\n x: Math.max(0, adjustedX) * rowMultipler,\n w: scaledW,\n\n };\n });\n}\n\n/**\n * Options for the useGridConfigTranslator hook\n */\nexport interface UseGridConfigTranslatorOptions {\n /** Grid configuration (single or responsive) */\n config: GridConfig | ResponsiveGridConfig;\n /** Whether the config is responsive (has per-breakpoint configs) */\n responsive?: boolean;\n /** Columns per breakpoint (only used if responsive) */\n cols?: Record<BreakpointName, number>;\n}\n\n/**\n * Result of the useGridConfigTranslator hook\n */\nexport interface UseGridConfigTranslatorResult {\n /** Single layout (only if not responsive) */\n layout: Layout | undefined;\n /** Responsive layouts (only if responsive) */\n layouts: ResponsiveLayouts | undefined;\n}\n\n/**\n * Hook to translate GridConfig to react-grid-layout format\n * Memoizes the result to avoid unnecessary recalculations\n *\n * @param options - Translation options\n * @returns Translated layout(s)\n */\nexport function useGridConfigTranslator(\n options: UseGridConfigTranslatorOptions\n): UseGridConfigTranslatorResult {\n const { config, responsive = false, cols = DEFAULT_COLS } = options;\n\n const result = useMemo(() => {\n if (responsive) {\n // Responsive mode - config should be ResponsiveGridConfig\n const responsiveConfig = config as ResponsiveGridConfig;\n\n // If it looks like a simple GridConfig (has rows), wrap it\n if (\"rows\" in responsiveConfig) {\n const simpleConfig = responsiveConfig as unknown as GridConfig;\n return {\n layout: undefined,\n layouts: translateResponsiveGridConfig(\n { lg: simpleConfig },\n cols\n ),\n };\n }\n\n const translatedResponsive = translateResponsiveGridConfig(responsiveConfig, cols);\n\n return {\n layout: undefined,\n layouts: translatedResponsive\n };\n } else {\n // Single layout mode\n const simpleConfig = config as GridConfig;\n const translated = translateGridConfig(simpleConfig, cols.lg ?? 12);\n\n return {\n layout: translated,\n layouts: undefined,\n };\n }\n }, [config, responsive, cols]);\n\n return result;\n}\n\nexport default useGridConfigTranslator;\n"],"names":["translateGridConfig","config","cols","items","processRows","rows","offsetX","offsetY","parentCols","y","row","rowHeight","x","cell","scaledW","cellHeight","item","__name","translateResponsiveGridConfig","colsPerBreakpoint","DEFAULT_COLS","breakpointOrder","layouts","fallbackConfig","bp","bpConfig","translateGridConfigAutoResponsive","strategy","baseCols","baseLayout","targetCols","createStackedLayout","createScaledLayout","currentY","a","b","newItem","rowMultipler","scale","scaledX","adjustedX","useGridConfigTranslator","options","responsive","useMemo","responsiveConfig"],"mappings":";;;;;;AAmB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CgBe,EAAAwB,GAAA;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index-D6-YxBjl.js","sources":["../src/grid/useGridConfigTranslator.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport type { Layout, LayoutItem } from \"react-grid-layout\";\nimport type {\n GridConfig,\n RowConfig,\n ResponsiveGridConfig,\n ResponsiveLayouts,\n BreakpointName,\n} from \"./types\";\nimport { DEFAULT_COLS } from \"./types\";\n\n/**\n * Translates a GridConfig (row/cell tree) into a flat Layout array\n * that react-grid-layout understands.\n *\n * @param config - The grid configuration\n * @param cols - Number of columns (default: 12)\n * @returns Flat layout array for react-grid-layout\n */\nexport function translateGridConfig(\n config: GridConfig,\n cols: number = 12\n): Layout {\n const items: LayoutItem[] = [];\n\n function processRows(\n rows: RowConfig[],\n offsetX: number,\n offsetY: number,\n parentCols: number\n ): number {\n let y = offsetY;\n\n for (const row of rows) {\n const rowHeight = row.height ?? 1;\n let x = offsetX;\n\n for (const cell of row.cells) {\n // Scale width relative to parent columns\n const scaledW = Math.round((cell.width / 12) * parentCols);\n let cellHeight = cell.height ?? rowHeight;\n\n cellHeight = cellHeight == 1 ? 1 : cellHeight;\n\n if (cell.rows && cell.rows.length > 0) {\n // Nested rows - recurse\n processRows(cell.rows, x, y, scaledW);\n } else if (cell.key) {\n // Leaf cell - add to layout\n const item: LayoutItem = {\n i: cell.key,\n x,\n y,\n w: scaledW,\n h: (cellHeight * (config.rowMultipler ?? 1)) + 1,\n };\n\n // Add optional constraints\n if (cell.minW !== undefined) item.minW = cell.minW;\n if (cell.maxW !== undefined) item.maxW = cell.maxW;\n if (cell.minH !== undefined) item.minH = cell.minH;\n if (cell.maxH !== undefined) item.maxH = cell.maxH;\n if (cell.static !== undefined) item.static = cell.static;\n if (cell.isDraggable !== undefined) item.isDraggable = cell.isDraggable;\n if (cell.isResizable !== undefined) item.isResizable = cell.isResizable;\n\n items.push(item);\n }\n\n x += scaledW;\n }\n\n y += rowHeight;\n }\n\n return y;\n }\n\n processRows(config.rows, 0, 0, cols);\n\n return items;\n}\n\n/**\n * Translates a ResponsiveGridConfig into ResponsiveLayouts\n * If a breakpoint is not defined, it falls back to larger breakpoints\n *\n * @param config - The responsive grid configuration\n * @param colsPerBreakpoint - Columns per breakpoint (default: DEFAULT_COLS)\n * @returns Responsive layouts object for react-grid-layout\n */\nexport function translateResponsiveGridConfig(\n config: ResponsiveGridConfig,\n colsPerBreakpoint: Record<BreakpointName, number> = DEFAULT_COLS\n): ResponsiveLayouts {\n const breakpointOrder: BreakpointName[] = [\"lg\", \"md\", \"sm\", \"xs\", \"xxs\"];\n const layouts: ResponsiveLayouts = {};\n\n // Find the first defined config to use as fallback\n let fallbackConfig: GridConfig | undefined;\n\n for (const bp of breakpointOrder) {\n const bpConfig = config[bp];\n\n if (bpConfig) {\n fallbackConfig = bpConfig;\n layouts[bp] = translateGridConfig(bpConfig, colsPerBreakpoint[bp]);\n } else if (fallbackConfig) {\n // Use fallback from larger breakpoint, but translate with this breakpoint's cols\n layouts[bp] = translateGridConfig(\n fallbackConfig,\n colsPerBreakpoint[bp]\n );\n }\n }\n\n return layouts;\n}\n\n/**\n * Auto-responsive translation strategy.\n * Determines how items should be arranged when columns decrease.\n */\nexport type AutoResponsiveStrategy = \"scale\" | \"stack\" | \"hybrid\";\n\n/**\n * Translates a single GridConfig into responsive layouts automatically.\n * \n * This function intelligently adapts the layout for different screen sizes:\n * - For breakpoints with same column count as base: preserves layout\n * - For breakpoints with fewer columns: applies the chosen strategy\n * \n * Strategies:\n * - \"scale\": Proportionally scale widths (items may become very narrow)\n * - \"stack\": Stack items vertically (each item becomes full width)\n * - \"hybrid\": Scale for moderate reductions, stack for small screens (default)\n *\n * @param config - The grid configuration (designed for lg/12 columns)\n * @param colsPerBreakpoint - Columns per breakpoint (default: DEFAULT_COLS)\n * @param strategy - How to handle smaller breakpoints (default: \"hybrid\")\n * @returns Responsive layouts object for react-grid-layout\n */\nexport function translateGridConfigAutoResponsive(\n config: GridConfig,\n colsPerBreakpoint: Record<BreakpointName, number> = DEFAULT_COLS,\n strategy: AutoResponsiveStrategy = \"stack\"\n): ResponsiveLayouts {\n const breakpointOrder: BreakpointName[] = [\"lg\", \"md\", \"sm\", \"xs\", \"xxs\"];\n const layouts: ResponsiveLayouts = {};\n\n // Base layout (lg - 12 columns typically)\n const baseCols = colsPerBreakpoint.lg;\n const baseLayout = translateGridConfig(config, baseCols);\n\n for (const bp of breakpointOrder) {\n const targetCols = colsPerBreakpoint[bp];\n\n if (targetCols === baseCols) {\n // Same column count - use base layout directly\n layouts[bp] = baseLayout;\n } else {\n // Different column count - apply strategy\n const shouldStack =\n strategy === \"stack\" ||\n (strategy === \"hybrid\" && targetCols <= 4);\n\n if (shouldStack) {\n // Stack: arrange items vertically, full width\n layouts[bp] = createStackedLayout(baseLayout, targetCols);\n } else {\n // Scale: proportionally adjust widths\n layouts[bp] = createScaledLayout(baseLayout, baseCols, targetCols, config.rowMultipler ?? 1);\n }\n }\n }\n\n return layouts;\n}\n\n/**\n * Creates a stacked layout where each item takes full width\n * and items are arranged vertically.\n */\nfunction createStackedLayout(baseLayout: Layout, cols: number): Layout {\n let currentY = 0;\n\n // Sort by original position (top to bottom, left to right)\n const sorted = [...baseLayout].sort((a, b) => {\n if (a.y !== b.y) return a.y - b.y;\n return a.x - b.x;\n });\n\n return sorted.map((item) => {\n const newItem: LayoutItem = {\n ...item,\n x: 0,\n y: currentY,\n w: cols, // Full width\n // Keep height, but ensure minimum of 2 for readability on small screens\n h: Math.max(item.h, 2)\n };\n currentY += newItem.h;\n return newItem;\n });\n}\n\n/**\n * Creates a scaled layout by proportionally adjusting widths.\n * Items maintain their relative positions but widths are scaled.\n */\nfunction createScaledLayout(baseLayout: Layout, baseCols: number, targetCols: number, rowMultipler: number): Layout {\n const scale = targetCols / baseCols;\n\n return baseLayout.map((item) => {\n // Scale x and width, ensure minimum width of 1\n const scaledW = Math.max(1, Math.round(item.w * scale));\n const scaledX = Math.round(item.x * scale);\n\n // Ensure item doesn't overflow\n const adjustedX = Math.min(scaledX, targetCols - scaledW);\n\n return {\n ...item,\n x: Math.max(0, adjustedX) * rowMultipler,\n w: scaledW,\n\n };\n });\n}\n\n/**\n * Options for the useGridConfigTranslator hook\n */\nexport interface UseGridConfigTranslatorOptions {\n /** Grid configuration (single or responsive) */\n config: GridConfig | ResponsiveGridConfig;\n /** Whether the config is responsive (has per-breakpoint configs) */\n responsive?: boolean;\n /** Columns per breakpoint (only used if responsive) */\n cols?: Record<BreakpointName, number>;\n}\n\n/**\n * Result of the useGridConfigTranslator hook\n */\nexport interface UseGridConfigTranslatorResult {\n /** Single layout (only if not responsive) */\n layout: Layout | undefined;\n /** Responsive layouts (only if responsive) */\n layouts: ResponsiveLayouts | undefined;\n}\n\n/**\n * Hook to translate GridConfig to react-grid-layout format\n * Memoizes the result to avoid unnecessary recalculations\n *\n * @param options - Translation options\n * @returns Translated layout(s)\n */\nexport function useGridConfigTranslator(\n options: UseGridConfigTranslatorOptions\n): UseGridConfigTranslatorResult {\n const { config, responsive = false, cols = DEFAULT_COLS } = options;\n\n const result = useMemo(() => {\n if (responsive) {\n // Responsive mode - config should be ResponsiveGridConfig\n const responsiveConfig = config as ResponsiveGridConfig;\n\n // If it looks like a simple GridConfig (has rows), wrap it\n if (\"rows\" in responsiveConfig) {\n const simpleConfig = responsiveConfig as unknown as GridConfig;\n return {\n layout: undefined,\n layouts: translateResponsiveGridConfig(\n { lg: simpleConfig },\n cols\n ),\n };\n }\n\n const translatedResponsive = translateResponsiveGridConfig(responsiveConfig, cols);\n\n return {\n layout: undefined,\n layouts: translatedResponsive\n };\n } else {\n // Single layout mode\n const simpleConfig = config as GridConfig;\n const translated = translateGridConfig(simpleConfig, cols.lg ?? 12);\n\n return {\n layout: translated,\n layouts: undefined,\n };\n }\n }, [config, responsive, cols]);\n\n return result;\n}\n\nexport default useGridConfigTranslator;\n"],"names":["translateGridConfig","config","cols","items","processRows","rows","offsetX","offsetY","parentCols","y","row","rowHeight","x","cell","scaledW","cellHeight","item","__name","translateResponsiveGridConfig","colsPerBreakpoint","DEFAULT_COLS","breakpointOrder","layouts","fallbackConfig","bp","bpConfig","translateGridConfigAutoResponsive","strategy","baseCols","baseLayout","targetCols","createStackedLayout","createScaledLayout","currentY","a","b","newItem","rowMultipler","scale","scaledX","adjustedX","useGridConfigTranslator","options","responsive","useMemo","responsiveConfig"],"mappings":";;;;;;AAmBO,SAASA,EACZC,GACAC,IAAe,IACT;AACN,QAAMC,IAAsB,CAAA;AAE5B,WAASC,EACLC,GACAC,GACAC,GACAC,GACM;AACN,QAAIC,IAAIF;AAER,eAAWG,KAAOL,GAAM;AACpB,YAAMM,IAAYD,EAAI,UAAU;AAChC,UAAIE,IAAIN;AAER,iBAAWO,KAAQH,EAAI,OAAO;AAE1B,cAAMI,IAAU,KAAK,MAAOD,EAAK,QAAQ,KAAML,CAAU;AACzD,YAAIO,IAAaF,EAAK,UAAUF;AAIhC,YAFAI,IAAaA,KAAc,IAAI,IAAIA,GAE/BF,EAAK,QAAQA,EAAK,KAAK,SAAS;AAEhC,UAAAT,EAAYS,EAAK,MAAMD,GAAGH,GAAGK,CAAO;AAAA,iBAC7BD,EAAK,KAAK;AAEjB,gBAAMG,IAAmB;AAAA,YACrB,GAAGH,EAAK;AAAA,YACR,GAAAD;AAAA,YACA,GAAAH;AAAA,YACA,GAAGK;AAAA,YACH,GAAIC,KAAcd,EAAO,gBAAgB,KAAM;AAAA,UAAA;AAInD,UAAIY,EAAK,SAAS,WAAWG,EAAK,OAAOH,EAAK,OAC1CA,EAAK,SAAS,WAAWG,EAAK,OAAOH,EAAK,OAC1CA,EAAK,SAAS,WAAWG,EAAK,OAAOH,EAAK,OAC1CA,EAAK,SAAS,WAAWG,EAAK,OAAOH,EAAK,OAC1CA,EAAK,WAAW,WAAWG,EAAK,SAASH,EAAK,SAC9CA,EAAK,gBAAgB,WAAWG,EAAK,cAAcH,EAAK,cACxDA,EAAK,gBAAgB,WAAWG,EAAK,cAAc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