@grafana/scenes 6.23.0--canary.1165.15877190588.0 → 6.23.0--canary.1156.15877258579.0

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
@@ -417,7 +417,6 @@ class SceneObjectBase {
417
417
  /**
418
418
  * Loop through state and call callback for each direct child scene object.
419
419
  * Checks 1 level deep properties and arrays. So a scene object hidden in a nested plain object will not be detected.
420
- * Return false to exit loop early.
421
420
  */
422
421
  forEachChild(callback) {
423
422
  forEachChild(this.state, callback);
@@ -465,25 +464,14 @@ function useSceneObjectState(model, options) {
465
464
  function forEachChild(state, callback) {
466
465
  for (const propValue of Object.values(state)) {
467
466
  if (propValue instanceof SceneObjectBase) {
468
- const result = callback(propValue);
469
- if (result === false) {
470
- break;
471
- }
467
+ callback(propValue);
472
468
  }
473
469
  if (Array.isArray(propValue)) {
474
- let exitEarly = false;
475
470
  for (const child of propValue) {
476
471
  if (child instanceof SceneObjectBase) {
477
- const result = callback(child);
478
- if (result === false) {
479
- exitEarly = true;
480
- break;
481
- }
472
+ callback(child);
482
473
  }
483
474
  }
484
- if (exitEarly) {
485
- break;
486
- }
487
475
  }
488
476
  }
489
477
  }
@@ -7476,9 +7464,7 @@ function findObjectInternal(scene, check, alreadySearchedChild, shouldSearchUp)
7476
7464
  let maybe = findObjectInternal(child, check);
7477
7465
  if (maybe) {
7478
7466
  found = maybe;
7479
- return false;
7480
7467
  }
7481
- return;
7482
7468
  });
7483
7469
  if (found) {
7484
7470
  return found;
@@ -7592,11 +7578,27 @@ const sceneGraph = {
7592
7578
  getScopes
7593
7579
  };
7594
7580
 
7581
+ const DEFAULT_NAMESPACE = "";
7582
+ const DEFAULT_EXCLUDE_FROM_NAMESPACE = ["from", "to", "timezone"];
7595
7583
  class UniqueUrlKeyMapper {
7596
- constructor() {
7584
+ constructor(options) {
7597
7585
  this.index = /* @__PURE__ */ new Map();
7586
+ this.options = {
7587
+ namespace: (options == null ? void 0 : options.namespace) || DEFAULT_NAMESPACE,
7588
+ excludeFromNamespace: (options == null ? void 0 : options.excludeFromNamespace) || DEFAULT_EXCLUDE_FROM_NAMESPACE
7589
+ };
7598
7590
  }
7599
- getUniqueKey(key, obj) {
7591
+ getOptions() {
7592
+ return this.options;
7593
+ }
7594
+ getNamespacedKey(keyWithoutNamespace) {
7595
+ if (this.options.namespace && !this.options.excludeFromNamespace.includes(keyWithoutNamespace)) {
7596
+ return `${this.options.namespace}-${keyWithoutNamespace}`;
7597
+ }
7598
+ return keyWithoutNamespace;
7599
+ }
7600
+ getUniqueKey(keyWithoutNamespace, obj) {
7601
+ const key = this.getNamespacedKey(keyWithoutNamespace);
7600
7602
  const objectsWithKey = this.index.get(key);
7601
7603
  if (!objectsWithKey) {
7602
7604
  this.index.set(key, [obj]);
@@ -7633,8 +7635,8 @@ function isOrphanOrInActive(obj) {
7633
7635
  return false;
7634
7636
  }
7635
7637
 
7636
- function getUrlState(root) {
7637
- const urlKeyMapper = new UniqueUrlKeyMapper();
7638
+ function getUrlState(root, uniqueUrlKeyMapperOptions) {
7639
+ const urlKeyMapper = new UniqueUrlKeyMapper(uniqueUrlKeyMapperOptions);
7638
7640
  const result = {};
7639
7641
  const visitNode = (obj) => {
7640
7642
  if (obj.urlSync) {
@@ -7651,8 +7653,8 @@ function getUrlState(root) {
7651
7653
  visitNode(root);
7652
7654
  return result;
7653
7655
  }
7654
- function syncStateFromSearchParams(root, urlParams) {
7655
- const urlKeyMapper = new UniqueUrlKeyMapper();
7656
+ function syncStateFromSearchParams(root, urlParams, uniqueUrlKeyMapperOptions) {
7657
+ const urlKeyMapper = new UniqueUrlKeyMapper(uniqueUrlKeyMapperOptions);
7656
7658
  syncStateFromUrl(root, urlParams, urlKeyMapper);
7657
7659
  }
7658
7660
  function syncStateFromUrl(root, urlParams, urlKeyMapper, onlyChildren) {
@@ -10514,10 +10516,13 @@ class NewSceneObjectAddedEvent extends data.BusEventWithPayload {
10514
10516
  NewSceneObjectAddedEvent.type = "new-scene-object-added";
10515
10517
  class UrlSyncManager {
10516
10518
  constructor(_options = {}, locationService = runtime.locationService) {
10517
- this._urlKeyMapper = new UniqueUrlKeyMapper();
10518
10519
  this._options = _options;
10519
10520
  this._locationService = locationService;
10520
10521
  this._paramsCache = new UrlParamsCache(locationService);
10522
+ this._urlKeyMapper = new UniqueUrlKeyMapper({
10523
+ namespace: _options.namespace,
10524
+ excludeFromNamespace: _options.excludeFromNamespace
10525
+ });
10521
10526
  }
10522
10527
  /**
10523
10528
  * Updates the current scene state to match URL state.
@@ -10545,7 +10550,7 @@ class UrlSyncManager {
10545
10550
  this._lastLocation = this._locationService.getLocation();
10546
10551
  this.handleNewObject(this._sceneRoot);
10547
10552
  if (this._options.updateUrlOnInit) {
10548
- const urlState = getUrlState(root);
10553
+ const urlState = getUrlState(root, this._urlKeyMapper.getOptions());
10549
10554
  if (isUrlStateDifferent(urlState, this._paramsCache.getParams())) {
10550
10555
  this._locationService.partial(urlState, true);
10551
10556
  }
@@ -10607,7 +10612,7 @@ class UrlSyncManager {
10607
10612
  }
10608
10613
  }
10609
10614
  getUrlState(root) {
10610
- return getUrlState(root);
10615
+ return getUrlState(root, this._urlKeyMapper.getOptions());
10611
10616
  }
10612
10617
  }
10613
10618
  class UrlParamsCache {
@@ -10641,11 +10646,19 @@ function useUrlSyncManager(options, locationService) {
10641
10646
  () => new UrlSyncManager(
10642
10647
  {
10643
10648
  updateUrlOnInit: options.updateUrlOnInit,
10644
- createBrowserHistorySteps: options.createBrowserHistorySteps
10649
+ createBrowserHistorySteps: options.createBrowserHistorySteps,
10650
+ namespace: options.namespace,
10651
+ excludeFromNamespace: options.excludeFromNamespace
10645
10652
  },
10646
10653
  locationService
10647
10654
  ),
10648
- [options.updateUrlOnInit, options.createBrowserHistorySteps, locationService]
10655
+ [
10656
+ options.updateUrlOnInit,
10657
+ options.createBrowserHistorySteps,
10658
+ options.namespace,
10659
+ options.excludeFromNamespace,
10660
+ locationService
10661
+ ]
10649
10662
  );
10650
10663
  }
10651
10664
 
@@ -10674,9 +10687,16 @@ function UrlSyncContextProvider({
10674
10687
  children,
10675
10688
  scene,
10676
10689
  updateUrlOnInit,
10677
- createBrowserHistorySteps
10690
+ createBrowserHistorySteps,
10691
+ namespace,
10692
+ excludeFromNamespace
10678
10693
  }) {
10679
- const isInitialized = useUrlSync(scene, { updateUrlOnInit, createBrowserHistorySteps });
10694
+ const isInitialized = useUrlSync(scene, {
10695
+ updateUrlOnInit,
10696
+ createBrowserHistorySteps,
10697
+ namespace,
10698
+ excludeFromNamespace
10699
+ });
10680
10700
  if (!isInitialized) {
10681
10701
  return null;
10682
10702
  }