@trops/dash-core 0.1.320 → 0.1.322

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/index.esm.js CHANGED
@@ -18385,6 +18385,7 @@ var WidgetCardHeader = function WidgetCardHeader(_ref) {
18385
18385
  _ref$onSplitVertical = _ref.onSplitVertical,
18386
18386
  onSplitVertical = _ref$onSplitVertical === void 0 ? null : _ref$onSplitVertical,
18387
18387
  onMoreOptions = _ref.onMoreOptions,
18388
+ onEditWithAI = _ref.onEditWithAI,
18388
18389
  _ref$isSelected = _ref.isSelected,
18389
18390
  isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
18390
18391
  _ref$isSelectable = _ref.isSelectable,
@@ -18502,6 +18503,16 @@ var WidgetCardHeader = function WidgetCardHeader(_ref) {
18502
18503
  }
18503
18504
  });
18504
18505
  }
18506
+ if (onEditWithAI && widgetItem) {
18507
+ overflowActions.push({
18508
+ icon: "wand-magic-sparkles",
18509
+ label: "Edit with AI",
18510
+ onClick: function onClick() {
18511
+ onEditWithAI(widgetItem);
18512
+ setShowOverflowMenu(false);
18513
+ }
18514
+ });
18515
+ }
18505
18516
  if (onSplitHorizontal) {
18506
18517
  overflowActions.push({
18507
18518
  icon: "arrows-left-right",
@@ -18651,6 +18662,13 @@ var WidgetCardHeader = function WidgetCardHeader(_ref) {
18651
18662
  },
18652
18663
  title: "Configure widget",
18653
18664
  theme: false
18665
+ }), onEditWithAI && widgetItem && /*#__PURE__*/jsx(ButtonIcon2, {
18666
+ icon: "wand-magic-sparkles",
18667
+ onClick: function onClick() {
18668
+ return onEditWithAI(widgetItem);
18669
+ },
18670
+ title: "Edit with AI",
18671
+ theme: false
18654
18672
  }), onSplitHorizontal && /*#__PURE__*/jsx(ButtonIcon2, {
18655
18673
  icon: "arrows-left-right",
18656
18674
  onClick: function onClick(e) {
@@ -20418,6 +20436,92 @@ var LayoutBuilder = function LayoutBuilder(_ref) {
20418
20436
  // eslint-disable-next-line react-hooks/exhaustive-deps
20419
20437
  }, [currentWorkspace]);
20420
20438
 
20439
+ // Ref for current workspace state (avoids stale closure in event listener)
20440
+ var wsRef = useRef(currentWorkspace);
20441
+ useEffect(function () {
20442
+ wsRef.current = currentWorkspace;
20443
+ }, [currentWorkspace]);
20444
+
20445
+ // Listen for AI widget builder placement — modifies layout state directly
20446
+ useEffect(function () {
20447
+ var handler = function handler(e) {
20448
+ var _ref4 = e.detail || {},
20449
+ widgetComponentName = _ref4.widgetComponentName,
20450
+ cellNumber = _ref4.cellNumber,
20451
+ gridItemId = _ref4.gridItemId;
20452
+ if (!widgetComponentName || !cellNumber || !gridItemId) return;
20453
+ var ws = wsRef.current;
20454
+ if (!(ws !== null && ws !== void 0 && ws.layout)) return;
20455
+ var gridItem = ws.layout.find(function (item) {
20456
+ return item.id === gridItemId;
20457
+ });
20458
+ if (!(gridItem !== null && gridItem !== void 0 && gridItem.grid)) return;
20459
+ var config = ComponentManager.config(widgetComponentName);
20460
+ if (!config) {
20461
+ return;
20462
+ }
20463
+ try {
20464
+ var hasChildren = config.type === "workspace";
20465
+ var newLayout = addItemToItemLayout(ws.layout, gridItem.id, _objectSpread$z(_objectSpread$z({}, config), {}, {
20466
+ component: widgetComponentName
20467
+ }), hasChildren);
20468
+ var newWidgetId = newLayout[newLayout.length - 1].id;
20469
+ var updatedGrid = newLayout.find(function (item) {
20470
+ return item.id === gridItem.id;
20471
+ });
20472
+ if (updatedGrid !== null && updatedGrid !== void 0 && updatedGrid.grid) {
20473
+ updatedGrid.grid[cellNumber] = {
20474
+ component: newWidgetId,
20475
+ hide: false
20476
+ };
20477
+ }
20478
+ var newWorkspace = JSON.parse(JSON.stringify(ws));
20479
+ newWorkspace.layout = newLayout;
20480
+ setCurrentWorkspace(newWorkspace);
20481
+ } catch (err) {
20482
+ }
20483
+ };
20484
+ window.addEventListener("dash:place-widget-in-cell", handler);
20485
+ return function () {
20486
+ return window.removeEventListener("dash:place-widget-in-cell", handler);
20487
+ };
20488
+ // eslint-disable-next-line react-hooks/exhaustive-deps
20489
+ }, []);
20490
+
20491
+ // Listen for AI widget remix — swaps existing widget component in-place
20492
+ useEffect(function () {
20493
+ var handler = function handler(e) {
20494
+ var _ref5 = e.detail || {},
20495
+ widgetComponentName = _ref5.widgetComponentName,
20496
+ widgetId = _ref5.widgetId;
20497
+ if (!widgetComponentName || !widgetId) return;
20498
+ var ws = wsRef.current;
20499
+ if (!(ws !== null && ws !== void 0 && ws.layout)) return;
20500
+ var config = ComponentManager.config(widgetComponentName);
20501
+ if (!config) {
20502
+ return;
20503
+ }
20504
+ try {
20505
+ var newLayout = updateLayoutItem(ws.layout, {
20506
+ id: widgetId,
20507
+ component: widgetComponentName
20508
+ });
20509
+ if (!newLayout) {
20510
+ return;
20511
+ }
20512
+ var newWorkspace = JSON.parse(JSON.stringify(ws));
20513
+ newWorkspace.layout = newLayout;
20514
+ setCurrentWorkspace(newWorkspace);
20515
+ } catch (err) {
20516
+ }
20517
+ };
20518
+ window.addEventListener("dash:swap-widget-in-cell", handler);
20519
+ return function () {
20520
+ return window.removeEventListener("dash:swap-widget-in-cell", handler);
20521
+ };
20522
+ // eslint-disable-next-line react-hooks/exhaustive-deps
20523
+ }, []);
20524
+
20421
20525
  /**
20422
20526
  * onClickAdd
20423
20527
  * From the Widget or Container, clicked plus button to add a widget
@@ -20829,11 +20933,11 @@ var LayoutBuilder = function LayoutBuilder(_ref) {
20829
20933
 
20830
20934
  // Grid Operation Handlers
20831
20935
 
20832
- function handleSplitCell(_ref4) {
20833
- var cellNumber = _ref4.cellNumber,
20834
- direction = _ref4.direction,
20835
- count = _ref4.count,
20836
- gridContainer = _ref4.gridContainer;
20936
+ function handleSplitCell(_ref6) {
20937
+ var cellNumber = _ref6.cellNumber,
20938
+ direction = _ref6.direction,
20939
+ count = _ref6.count,
20940
+ gridContainer = _ref6.gridContainer;
20837
20941
  try {
20838
20942
  var dashboard = new DashboardModel(currentWorkspace);
20839
20943
  var result = dashboard.splitGridCell(gridContainer.id, cellNumber, direction, count);
@@ -20845,10 +20949,10 @@ var LayoutBuilder = function LayoutBuilder(_ref) {
20845
20949
  } catch (e) {
20846
20950
  }
20847
20951
  }
20848
- function handleMergeCells(_ref5) {
20849
- var cellNumbers = _ref5.cellNumbers,
20850
- gridContainer = _ref5.gridContainer,
20851
- keepComponent = _ref5.keepComponent;
20952
+ function handleMergeCells(_ref7) {
20953
+ var cellNumbers = _ref7.cellNumbers,
20954
+ gridContainer = _ref7.gridContainer,
20955
+ keepComponent = _ref7.keepComponent;
20852
20956
  try {
20853
20957
  var dashboard = new DashboardModel(currentWorkspace);
20854
20958
  var result = dashboard.mergeGridCells(gridContainer.id, cellNumbers);
@@ -25101,7 +25205,13 @@ var LayoutGridContainer = /*#__PURE__*/memo(function (_ref3) {
25101
25205
  })]
25102
25206
  }), /*#__PURE__*/jsxs("button", {
25103
25207
  onClick: function onClick() {
25104
- return window.dispatchEvent(new Event("dash:open-widget-builder"));
25208
+ return window.dispatchEvent(new CustomEvent("dash:open-widget-builder", {
25209
+ detail: {
25210
+ cellNumber: cellNumber,
25211
+ gridItemId: item.id,
25212
+ workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id
25213
+ }
25214
+ }));
25105
25215
  },
25106
25216
  className: "flex items-center gap-1.5 px-3 py-1 rounded-md text-xs text-indigo-400/70 hover:text-indigo-300 hover:bg-indigo-900/20 transition-colors",
25107
25217
  children: [/*#__PURE__*/jsx(FontAwesomeIcon, {
@@ -25163,6 +25273,19 @@ var LayoutGridContainer = /*#__PURE__*/memo(function (_ref3) {
25163
25273
  } : undefined,
25164
25274
  onDelete: cellComponent ? function () {
25165
25275
  if (onClickRemove) onClickRemove(cellComponent.id);
25276
+ } : undefined,
25277
+ onEditWithAI: cellComponent ? function () {
25278
+ var _ComponentManager$con;
25279
+ window.dispatchEvent(new CustomEvent("dash:edit-widget-with-ai", {
25280
+ detail: {
25281
+ cellNumber: cellNumber,
25282
+ gridItemId: item.id,
25283
+ workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id,
25284
+ widgetComponentName: cellComponent.component,
25285
+ widgetId: cellComponent.id,
25286
+ sourcePackage: ((_ComponentManager$con = ComponentManager.config(cellComponent.component, cellComponent)) === null || _ComponentManager$con === void 0 ? void 0 : _ComponentManager$con._sourcePackage) || null
25287
+ }
25288
+ }));
25166
25289
  } : undefined
25167
25290
  }), cellComponent && ComponentManager.config(cellComponent.component, cellComponent) ? /*#__PURE__*/jsx(DraggableDroppableCellBody, {
25168
25291
  cellNumber: cellNumber,