@trops/dash-core 0.1.280 → 0.1.282

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
@@ -22,6 +22,7 @@ var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstru
22
22
  var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
23
23
  var _inherits = require('@babel/runtime/helpers/inherits');
24
24
  var colors = require('tailwindcss/colors');
25
+ var _readOnlyError = require('@babel/runtime/helpers/readOnlyError');
25
26
  var ReactDOM = require('react-dom');
26
27
  var algoliasearch = require('algoliasearch');
27
28
  var reactInstantsearchHooksWeb = require('react-instantsearch-hooks-web');
@@ -6433,7 +6434,7 @@ var WizardDiscoverStep = function WizardDiscoverStep(_ref) {
6433
6434
  onClick: function onClick() {
6434
6435
  return handleToggleCategory(tag);
6435
6436
  },
6436
- className: filters.categories.includes(tag) ? "ring-1 ring-blue-400" : ""
6437
+ active: filters.categories.includes(tag)
6437
6438
  }, tag);
6438
6439
  })
6439
6440
  })]
@@ -6450,7 +6451,7 @@ var WizardDiscoverStep = function WizardDiscoverStep(_ref) {
6450
6451
  onClick: function onClick() {
6451
6452
  return handleToggleProvider(prov.key);
6452
6453
  },
6453
- className: filters.providers.includes(prov.key) ? "ring-1 ring-blue-400" : ""
6454
+ active: filters.providers.includes(prov.key)
6454
6455
  }, prov.key);
6455
6456
  })
6456
6457
  })]
@@ -21017,8 +21018,19 @@ var LayoutBuilder = function LayoutBuilder(_ref) {
21017
21018
  */
21018
21019
  function handleSelectWidgetForCell(widgetName, cellNumber, cellData, component, workspace) {
21019
21020
  try {
21021
+ var _gridContainer$grid2;
21020
21022
  // create the new dashboard.
21021
21023
  var dashboard = new DashboardModel(workspace);
21024
+
21025
+ // Remove old widget from layout if the target cell is already occupied
21026
+ var gridContainer = dashboard.layout.find(function (item) {
21027
+ return item.id === component.id;
21028
+ });
21029
+ if (gridContainer !== null && gridContainer !== void 0 && (_gridContainer$grid2 = gridContainer.grid) !== null && _gridContainer$grid2 !== void 0 && (_gridContainer$grid2 = _gridContainer$grid2[cellNumber]) !== null && _gridContainer$grid2 !== void 0 && _gridContainer$grid2.component) {
21030
+ var oldWidgetId = gridContainer.grid[cellNumber].component;
21031
+ dashboard.removeItemFromLayout(oldWidgetId);
21032
+ gridContainer.grid[cellNumber].component = null;
21033
+ }
21022
21034
  var componentToAdd = ComponentManager.getComponent(widgetName);
21023
21035
  var widget = LayoutModel(componentToAdd, dashboard.workspace(), dashboard.id);
21024
21036
  dashboard.addChildToLayoutItem(widget, component.id, cellNumber);
@@ -29377,13 +29389,31 @@ var DashboardModel = /*#__PURE__*/function () {
29377
29389
  }
29378
29390
  if (activeItemIds.size === 0) return;
29379
29391
 
29380
- // Keep root items (parent: 0) and items referenced by grid cells
29381
- var before = this.layout.length;
29392
+ // Identify orphaned item IDs before removing them
29393
+ var orphanedIds = this.layout.filter(function (item) {
29394
+ return item.parent !== 0 && !activeItemIds.has(item.id);
29395
+ }).map(function (item) {
29396
+ return item.id;
29397
+ });
29398
+ if (orphanedIds.length === 0) return;
29399
+
29400
+ // Remove orphaned items from layout
29382
29401
  this.layout = this.layout.filter(function (item) {
29383
29402
  return item.parent === 0 || activeItemIds.has(item.id);
29384
29403
  });
29385
- var removed = before - this.layout.length;
29386
- if (removed > 0) {
29404
+
29405
+ // Clean listener references on remaining items for each removed orphan
29406
+ var _iterator2 = _createForOfIteratorHelper$8(orphanedIds),
29407
+ _step2;
29408
+ try {
29409
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
29410
+ var id = _step2.value;
29411
+ this._cleanupListenerReferencesForId(id);
29412
+ }
29413
+ } catch (err) {
29414
+ _iterator2.e(err);
29415
+ } finally {
29416
+ _iterator2.f();
29387
29417
  }
29388
29418
  } catch (e) {
29389
29419
  }
@@ -50402,6 +50432,11 @@ var DashboardStageInner = function DashboardStageInner(_ref2) {
50402
50432
  });
50403
50433
  workspaceToSave["layout"] = layout;
50404
50434
 
50435
+ // Clean orphaned layout items and stale listener references before save
50436
+ var dashboardForCleanup = new DashboardModel(workspaceToSave);
50437
+ dashboardForCleanup.cleanOrphanedItems();
50438
+ dashboardForCleanup.workspace(), _readOnlyError("workspaceToSave");
50439
+
50405
50440
  // lets set a version so that we can compare...
50406
50441
  workspaceToSave["version"] = Date.now();
50407
50442
  if (dashApi && credentials) {