@trops/dash-core 0.1.280 → 0.1.281

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
@@ -25,6 +25,7 @@ import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstruct
25
25
  import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
26
26
  import _inherits from '@babel/runtime/helpers/inherits';
27
27
  import colors from 'tailwindcss/colors';
28
+ import _readOnlyError from '@babel/runtime/helpers/readOnlyError';
28
29
  import * as ReactDOM from 'react-dom';
29
30
  import { createPortal } from 'react-dom';
30
31
  import algoliasearch from 'algoliasearch';
@@ -8464,10 +8465,10 @@ var syntax = SyntaxError;
8464
8465
  var type = TypeError;
8465
8466
 
8466
8467
  /** @type {import('./gOPD')} */
8467
- var gOPD$5 = Object.getOwnPropertyDescriptor;
8468
+ var gOPD$6 = Object.getOwnPropertyDescriptor;
8468
8469
 
8469
8470
  /** @type {import('.')} */
8470
- var $gOPD$2 = gOPD$5;
8471
+ var $gOPD$2 = gOPD$6;
8471
8472
 
8472
8473
  if ($gOPD$2) {
8473
8474
  try {
@@ -8602,7 +8603,7 @@ defineProperties$1.supportsDescriptors = !!supportsDescriptors$2;
8602
8603
 
8603
8604
  var defineProperties_1 = defineProperties$1;
8604
8605
 
8605
- var callBind$6 = {exports: {}};
8606
+ var callBind$7 = {exports: {}};
8606
8607
 
8607
8608
  /** @type {import('.')} */
8608
8609
  var esObjectAtoms = Object;
@@ -8902,78 +8903,60 @@ var callBindApplyHelpers = function callBindBasic(args) {
8902
8903
  return $actualApply(bind$3, $call$1, args);
8903
8904
  };
8904
8905
 
8905
- var get;
8906
- var hasRequiredGet;
8906
+ var callBind$6 = callBindApplyHelpers;
8907
+ var gOPD$5 = gopd$1;
8907
8908
 
8908
- function requireGet () {
8909
- if (hasRequiredGet) return get;
8910
- hasRequiredGet = 1;
8911
-
8912
- var callBind = callBindApplyHelpers;
8913
- var gOPD = gopd$1;
8914
-
8915
- var hasProtoAccessor;
8916
- try {
8917
- // eslint-disable-next-line no-extra-parens, no-proto
8918
- hasProtoAccessor = /** @type {{ __proto__?: typeof Array.prototype }} */ ([]).__proto__ === Array.prototype;
8919
- } catch (e) {
8920
- if (!e || typeof e !== 'object' || !('code' in e) || e.code !== 'ERR_PROTO_ACCESS') {
8921
- throw e;
8922
- }
8909
+ var hasProtoAccessor;
8910
+ try {
8911
+ // eslint-disable-next-line no-extra-parens, no-proto
8912
+ hasProtoAccessor = /** @type {{ __proto__?: typeof Array.prototype }} */ ([]).__proto__ === Array.prototype;
8913
+ } catch (e) {
8914
+ if (!e || typeof e !== 'object' || !('code' in e) || e.code !== 'ERR_PROTO_ACCESS') {
8915
+ throw e;
8923
8916
  }
8924
-
8925
- // eslint-disable-next-line no-extra-parens
8926
- var desc = !!hasProtoAccessor && gOPD && gOPD(Object.prototype, /** @type {keyof typeof Object.prototype} */ ('__proto__'));
8927
-
8928
- var $Object = Object;
8929
- var $getPrototypeOf = $Object.getPrototypeOf;
8930
-
8931
- /** @type {import('./get')} */
8932
- get = desc && typeof desc.get === 'function'
8933
- ? callBind([desc.get])
8934
- : typeof $getPrototypeOf === 'function'
8935
- ? /** @type {import('./get')} */ function getDunder(value) {
8936
- // eslint-disable-next-line eqeqeq
8937
- return $getPrototypeOf(value == null ? value : $Object(value));
8938
- }
8939
- : false;
8940
- return get;
8941
8917
  }
8942
8918
 
8943
- var getProto$3;
8944
- var hasRequiredGetProto;
8919
+ // eslint-disable-next-line no-extra-parens
8920
+ var desc = !!hasProtoAccessor && gOPD$5 && gOPD$5(Object.prototype, /** @type {keyof typeof Object.prototype} */ ('__proto__'));
8945
8921
 
8946
- function requireGetProto () {
8947
- if (hasRequiredGetProto) return getProto$3;
8948
- hasRequiredGetProto = 1;
8922
+ var $Object$3 = Object;
8923
+ var $getPrototypeOf = $Object$3.getPrototypeOf;
8949
8924
 
8950
- var reflectGetProto = requireReflect_getPrototypeOf();
8951
- var originalGetProto = requireObject_getPrototypeOf();
8925
+ /** @type {import('./get')} */
8926
+ var get = desc && typeof desc.get === 'function'
8927
+ ? callBind$6([desc.get])
8928
+ : typeof $getPrototypeOf === 'function'
8929
+ ? /** @type {import('./get')} */ function getDunder(value) {
8930
+ // eslint-disable-next-line eqeqeq
8931
+ return $getPrototypeOf(value == null ? value : $Object$3(value));
8932
+ }
8933
+ : false;
8952
8934
 
8953
- var getDunderProto = requireGet();
8935
+ var reflectGetProto = requireReflect_getPrototypeOf();
8936
+ var originalGetProto = requireObject_getPrototypeOf();
8954
8937
 
8955
- /** @type {import('.')} */
8956
- getProto$3 = reflectGetProto
8938
+ var getDunderProto = get;
8939
+
8940
+ /** @type {import('.')} */
8941
+ var getProto$3 = reflectGetProto
8942
+ ? function getProto(O) {
8943
+ // @ts-expect-error TS can't narrow inside a closure, for some reason
8944
+ return reflectGetProto(O);
8945
+ }
8946
+ : originalGetProto
8957
8947
  ? function getProto(O) {
8948
+ if (!O || (typeof O !== 'object' && typeof O !== 'function')) {
8949
+ throw new TypeError('getProto: not an object');
8950
+ }
8958
8951
  // @ts-expect-error TS can't narrow inside a closure, for some reason
8959
- return reflectGetProto(O);
8952
+ return originalGetProto(O);
8960
8953
  }
8961
- : originalGetProto
8954
+ : getDunderProto
8962
8955
  ? function getProto(O) {
8963
- if (!O || (typeof O !== 'object' && typeof O !== 'function')) {
8964
- throw new TypeError('getProto: not an object');
8965
- }
8966
8956
  // @ts-expect-error TS can't narrow inside a closure, for some reason
8967
- return originalGetProto(O);
8957
+ return getDunderProto(O);
8968
8958
  }
8969
- : getDunderProto
8970
- ? function getProto(O) {
8971
- // @ts-expect-error TS can't narrow inside a closure, for some reason
8972
- return getDunderProto(O);
8973
- }
8974
- : null;
8975
- return getProto$3;
8976
- }
8959
+ : null;
8977
8960
 
8978
8961
  var call = Function.prototype.call;
8979
8962
  var $hasOwn = Object.prototype.hasOwnProperty;
@@ -9036,7 +9019,7 @@ var ThrowTypeError = $gOPD$1
9036
9019
 
9037
9020
  var hasSymbols$3 = hasSymbols$4();
9038
9021
 
9039
- var getProto$2 = requireGetProto();
9022
+ var getProto$2 = getProto$3;
9040
9023
  var $ObjectGPO = requireObject_getPrototypeOf();
9041
9024
  var $ReflectGPO = requireReflect_getPrototypeOf();
9042
9025
 
@@ -9433,9 +9416,9 @@ var applyBind = function applyBind() {
9433
9416
  } else {
9434
9417
  module.exports.apply = applyBind$1;
9435
9418
  }
9436
- } (callBind$6));
9419
+ } (callBind$7));
9437
9420
 
9438
- var callBindExports = callBind$6.exports;
9421
+ var callBindExports = callBind$7.exports;
9439
9422
 
9440
9423
  var GetIntrinsic$7 = getIntrinsic;
9441
9424
 
@@ -9734,7 +9717,7 @@ var getPolyfill$3 = polyfill$2;
9734
9717
  var gOPD$2 = gopd$1;
9735
9718
  var defineProperty = Object.defineProperty;
9736
9719
  var $TypeError$5 = esErrors;
9737
- var getProto$1 = requireGetProto();
9720
+ var getProto$1 = getProto$3;
9738
9721
  var regex = /a/;
9739
9722
 
9740
9723
  var shim$3 = function shimFlags() {
@@ -11850,7 +11833,7 @@ var availableTypedArrays = availableTypedArrays$1;
11850
11833
  var callBind = callBindExports;
11851
11834
  var callBound$2 = callBound$i;
11852
11835
  var gOPD = gopd$1;
11853
- var getProto = requireGetProto();
11836
+ var getProto = getProto$3;
11854
11837
 
11855
11838
  var $toString = callBound$2('Object.prototype.toString');
11856
11839
  var hasToStringTag = shams();
@@ -21017,8 +21000,19 @@ var LayoutBuilder = function LayoutBuilder(_ref) {
21017
21000
  */
21018
21001
  function handleSelectWidgetForCell(widgetName, cellNumber, cellData, component, workspace) {
21019
21002
  try {
21003
+ var _gridContainer$grid2;
21020
21004
  // create the new dashboard.
21021
21005
  var dashboard = new DashboardModel(workspace);
21006
+
21007
+ // Remove old widget from layout if the target cell is already occupied
21008
+ var gridContainer = dashboard.layout.find(function (item) {
21009
+ return item.id === component.id;
21010
+ });
21011
+ 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) {
21012
+ var oldWidgetId = gridContainer.grid[cellNumber].component;
21013
+ dashboard.removeItemFromLayout(oldWidgetId);
21014
+ gridContainer.grid[cellNumber].component = null;
21015
+ }
21022
21016
  var componentToAdd = ComponentManager.getComponent(widgetName);
21023
21017
  var widget = LayoutModel(componentToAdd, dashboard.workspace(), dashboard.id);
21024
21018
  dashboard.addChildToLayoutItem(widget, component.id, cellNumber);
@@ -29377,13 +29371,31 @@ var DashboardModel = /*#__PURE__*/function () {
29377
29371
  }
29378
29372
  if (activeItemIds.size === 0) return;
29379
29373
 
29380
- // Keep root items (parent: 0) and items referenced by grid cells
29381
- var before = this.layout.length;
29374
+ // Identify orphaned item IDs before removing them
29375
+ var orphanedIds = this.layout.filter(function (item) {
29376
+ return item.parent !== 0 && !activeItemIds.has(item.id);
29377
+ }).map(function (item) {
29378
+ return item.id;
29379
+ });
29380
+ if (orphanedIds.length === 0) return;
29381
+
29382
+ // Remove orphaned items from layout
29382
29383
  this.layout = this.layout.filter(function (item) {
29383
29384
  return item.parent === 0 || activeItemIds.has(item.id);
29384
29385
  });
29385
- var removed = before - this.layout.length;
29386
- if (removed > 0) {
29386
+
29387
+ // Clean listener references on remaining items for each removed orphan
29388
+ var _iterator2 = _createForOfIteratorHelper$8(orphanedIds),
29389
+ _step2;
29390
+ try {
29391
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
29392
+ var id = _step2.value;
29393
+ this._cleanupListenerReferencesForId(id);
29394
+ }
29395
+ } catch (err) {
29396
+ _iterator2.e(err);
29397
+ } finally {
29398
+ _iterator2.f();
29387
29399
  }
29388
29400
  } catch (e) {
29389
29401
  }
@@ -50402,6 +50414,11 @@ var DashboardStageInner = function DashboardStageInner(_ref2) {
50402
50414
  });
50403
50415
  workspaceToSave["layout"] = layout;
50404
50416
 
50417
+ // Clean orphaned layout items and stale listener references before save
50418
+ var dashboardForCleanup = new DashboardModel(workspaceToSave);
50419
+ dashboardForCleanup.cleanOrphanedItems();
50420
+ dashboardForCleanup.workspace(), _readOnlyError("workspaceToSave");
50421
+
50405
50422
  // lets set a version so that we can compare...
50406
50423
  workspaceToSave["version"] = Date.now();
50407
50424
  if (dashApi && credentials) {