@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.js CHANGED
@@ -18403,6 +18403,7 @@ var WidgetCardHeader = function WidgetCardHeader(_ref) {
18403
18403
  _ref$onSplitVertical = _ref.onSplitVertical,
18404
18404
  onSplitVertical = _ref$onSplitVertical === void 0 ? null : _ref$onSplitVertical,
18405
18405
  onMoreOptions = _ref.onMoreOptions,
18406
+ onEditWithAI = _ref.onEditWithAI,
18406
18407
  _ref$isSelected = _ref.isSelected,
18407
18408
  isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
18408
18409
  _ref$isSelectable = _ref.isSelectable,
@@ -18520,6 +18521,16 @@ var WidgetCardHeader = function WidgetCardHeader(_ref) {
18520
18521
  }
18521
18522
  });
18522
18523
  }
18524
+ if (onEditWithAI && widgetItem) {
18525
+ overflowActions.push({
18526
+ icon: "wand-magic-sparkles",
18527
+ label: "Edit with AI",
18528
+ onClick: function onClick() {
18529
+ onEditWithAI(widgetItem);
18530
+ setShowOverflowMenu(false);
18531
+ }
18532
+ });
18533
+ }
18523
18534
  if (onSplitHorizontal) {
18524
18535
  overflowActions.push({
18525
18536
  icon: "arrows-left-right",
@@ -18669,6 +18680,13 @@ var WidgetCardHeader = function WidgetCardHeader(_ref) {
18669
18680
  },
18670
18681
  title: "Configure widget",
18671
18682
  theme: false
18683
+ }), onEditWithAI && widgetItem && /*#__PURE__*/jsxRuntime.jsx(DashReact.ButtonIcon2, {
18684
+ icon: "wand-magic-sparkles",
18685
+ onClick: function onClick() {
18686
+ return onEditWithAI(widgetItem);
18687
+ },
18688
+ title: "Edit with AI",
18689
+ theme: false
18672
18690
  }), onSplitHorizontal && /*#__PURE__*/jsxRuntime.jsx(DashReact.ButtonIcon2, {
18673
18691
  icon: "arrows-left-right",
18674
18692
  onClick: function onClick(e) {
@@ -20436,6 +20454,92 @@ var LayoutBuilder = function LayoutBuilder(_ref) {
20436
20454
  // eslint-disable-next-line react-hooks/exhaustive-deps
20437
20455
  }, [currentWorkspace]);
20438
20456
 
20457
+ // Ref for current workspace state (avoids stale closure in event listener)
20458
+ var wsRef = React.useRef(currentWorkspace);
20459
+ React.useEffect(function () {
20460
+ wsRef.current = currentWorkspace;
20461
+ }, [currentWorkspace]);
20462
+
20463
+ // Listen for AI widget builder placement — modifies layout state directly
20464
+ React.useEffect(function () {
20465
+ var handler = function handler(e) {
20466
+ var _ref4 = e.detail || {},
20467
+ widgetComponentName = _ref4.widgetComponentName,
20468
+ cellNumber = _ref4.cellNumber,
20469
+ gridItemId = _ref4.gridItemId;
20470
+ if (!widgetComponentName || !cellNumber || !gridItemId) return;
20471
+ var ws = wsRef.current;
20472
+ if (!(ws !== null && ws !== void 0 && ws.layout)) return;
20473
+ var gridItem = ws.layout.find(function (item) {
20474
+ return item.id === gridItemId;
20475
+ });
20476
+ if (!(gridItem !== null && gridItem !== void 0 && gridItem.grid)) return;
20477
+ var config = ComponentManager.config(widgetComponentName);
20478
+ if (!config) {
20479
+ return;
20480
+ }
20481
+ try {
20482
+ var hasChildren = config.type === "workspace";
20483
+ var newLayout = addItemToItemLayout(ws.layout, gridItem.id, _objectSpread$z(_objectSpread$z({}, config), {}, {
20484
+ component: widgetComponentName
20485
+ }), hasChildren);
20486
+ var newWidgetId = newLayout[newLayout.length - 1].id;
20487
+ var updatedGrid = newLayout.find(function (item) {
20488
+ return item.id === gridItem.id;
20489
+ });
20490
+ if (updatedGrid !== null && updatedGrid !== void 0 && updatedGrid.grid) {
20491
+ updatedGrid.grid[cellNumber] = {
20492
+ component: newWidgetId,
20493
+ hide: false
20494
+ };
20495
+ }
20496
+ var newWorkspace = JSON.parse(JSON.stringify(ws));
20497
+ newWorkspace.layout = newLayout;
20498
+ setCurrentWorkspace(newWorkspace);
20499
+ } catch (err) {
20500
+ }
20501
+ };
20502
+ window.addEventListener("dash:place-widget-in-cell", handler);
20503
+ return function () {
20504
+ return window.removeEventListener("dash:place-widget-in-cell", handler);
20505
+ };
20506
+ // eslint-disable-next-line react-hooks/exhaustive-deps
20507
+ }, []);
20508
+
20509
+ // Listen for AI widget remix — swaps existing widget component in-place
20510
+ React.useEffect(function () {
20511
+ var handler = function handler(e) {
20512
+ var _ref5 = e.detail || {},
20513
+ widgetComponentName = _ref5.widgetComponentName,
20514
+ widgetId = _ref5.widgetId;
20515
+ if (!widgetComponentName || !widgetId) return;
20516
+ var ws = wsRef.current;
20517
+ if (!(ws !== null && ws !== void 0 && ws.layout)) return;
20518
+ var config = ComponentManager.config(widgetComponentName);
20519
+ if (!config) {
20520
+ return;
20521
+ }
20522
+ try {
20523
+ var newLayout = updateLayoutItem(ws.layout, {
20524
+ id: widgetId,
20525
+ component: widgetComponentName
20526
+ });
20527
+ if (!newLayout) {
20528
+ return;
20529
+ }
20530
+ var newWorkspace = JSON.parse(JSON.stringify(ws));
20531
+ newWorkspace.layout = newLayout;
20532
+ setCurrentWorkspace(newWorkspace);
20533
+ } catch (err) {
20534
+ }
20535
+ };
20536
+ window.addEventListener("dash:swap-widget-in-cell", handler);
20537
+ return function () {
20538
+ return window.removeEventListener("dash:swap-widget-in-cell", handler);
20539
+ };
20540
+ // eslint-disable-next-line react-hooks/exhaustive-deps
20541
+ }, []);
20542
+
20439
20543
  /**
20440
20544
  * onClickAdd
20441
20545
  * From the Widget or Container, clicked plus button to add a widget
@@ -20847,11 +20951,11 @@ var LayoutBuilder = function LayoutBuilder(_ref) {
20847
20951
 
20848
20952
  // Grid Operation Handlers
20849
20953
 
20850
- function handleSplitCell(_ref4) {
20851
- var cellNumber = _ref4.cellNumber,
20852
- direction = _ref4.direction,
20853
- count = _ref4.count,
20854
- gridContainer = _ref4.gridContainer;
20954
+ function handleSplitCell(_ref6) {
20955
+ var cellNumber = _ref6.cellNumber,
20956
+ direction = _ref6.direction,
20957
+ count = _ref6.count,
20958
+ gridContainer = _ref6.gridContainer;
20855
20959
  try {
20856
20960
  var dashboard = new DashboardModel(currentWorkspace);
20857
20961
  var result = dashboard.splitGridCell(gridContainer.id, cellNumber, direction, count);
@@ -20863,10 +20967,10 @@ var LayoutBuilder = function LayoutBuilder(_ref) {
20863
20967
  } catch (e) {
20864
20968
  }
20865
20969
  }
20866
- function handleMergeCells(_ref5) {
20867
- var cellNumbers = _ref5.cellNumbers,
20868
- gridContainer = _ref5.gridContainer,
20869
- keepComponent = _ref5.keepComponent;
20970
+ function handleMergeCells(_ref7) {
20971
+ var cellNumbers = _ref7.cellNumbers,
20972
+ gridContainer = _ref7.gridContainer,
20973
+ keepComponent = _ref7.keepComponent;
20870
20974
  try {
20871
20975
  var dashboard = new DashboardModel(currentWorkspace);
20872
20976
  var result = dashboard.mergeGridCells(gridContainer.id, cellNumbers);
@@ -25119,7 +25223,13 @@ var LayoutGridContainer = /*#__PURE__*/React.memo(function (_ref3) {
25119
25223
  })]
25120
25224
  }), /*#__PURE__*/jsxRuntime.jsxs("button", {
25121
25225
  onClick: function onClick() {
25122
- return window.dispatchEvent(new Event("dash:open-widget-builder"));
25226
+ return window.dispatchEvent(new CustomEvent("dash:open-widget-builder", {
25227
+ detail: {
25228
+ cellNumber: cellNumber,
25229
+ gridItemId: item.id,
25230
+ workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id
25231
+ }
25232
+ }));
25123
25233
  },
25124
25234
  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",
25125
25235
  children: [/*#__PURE__*/jsxRuntime.jsx(DashReact.FontAwesomeIcon, {
@@ -25181,6 +25291,19 @@ var LayoutGridContainer = /*#__PURE__*/React.memo(function (_ref3) {
25181
25291
  } : undefined,
25182
25292
  onDelete: cellComponent ? function () {
25183
25293
  if (onClickRemove) onClickRemove(cellComponent.id);
25294
+ } : undefined,
25295
+ onEditWithAI: cellComponent ? function () {
25296
+ var _ComponentManager$con;
25297
+ window.dispatchEvent(new CustomEvent("dash:edit-widget-with-ai", {
25298
+ detail: {
25299
+ cellNumber: cellNumber,
25300
+ gridItemId: item.id,
25301
+ workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id,
25302
+ widgetComponentName: cellComponent.component,
25303
+ widgetId: cellComponent.id,
25304
+ sourcePackage: ((_ComponentManager$con = ComponentManager.config(cellComponent.component, cellComponent)) === null || _ComponentManager$con === void 0 ? void 0 : _ComponentManager$con._sourcePackage) || null
25305
+ }
25306
+ }));
25184
25307
  } : undefined
25185
25308
  }), cellComponent && ComponentManager.config(cellComponent.component, cellComponent) ? /*#__PURE__*/jsxRuntime.jsx(DraggableDroppableCellBody, {
25186
25309
  cellNumber: cellNumber,