@grafana/scenes 4.32.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { useLocation } from 'react-router-dom';
3
+ import { getUrlSyncManager } from './UrlSyncManager.js';
4
+ import { locationService } from '@grafana/runtime';
5
+
6
+ function useUrlSync(sceneRoot) {
7
+ const urlSyncManager = getUrlSyncManager();
8
+ const location = useLocation();
9
+ const [isInitialized, setIsInitialized] = useState(false);
10
+ useEffect(() => {
11
+ urlSyncManager.initSync(sceneRoot);
12
+ setIsInitialized(true);
13
+ return () => urlSyncManager.cleanUp(sceneRoot);
14
+ }, [sceneRoot, urlSyncManager]);
15
+ useEffect(() => {
16
+ const latestLocation = locationService.getLocation();
17
+ const locationToHandle = latestLocation !== location ? latestLocation : location;
18
+ if (latestLocation !== location) {
19
+ console.log("latestLocation different from location");
20
+ }
21
+ urlSyncManager.handleNewLocation(locationToHandle);
22
+ }, [sceneRoot, urlSyncManager, location]);
23
+ return isInitialized;
24
+ }
25
+
26
+ export { useUrlSync };
27
+ //# sourceMappingURL=useUrlSync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUrlSync.js","sources":["../../../src/services/useUrlSync.ts"],"sourcesContent":["import { SceneObject } from '../core/types';\nimport { useEffect, useState } from 'react';\nimport { useLocation } from 'react-router-dom';\nimport { getUrlSyncManager } from './UrlSyncManager';\nimport { locationService } from '@grafana/runtime';\n\nexport function useUrlSync(sceneRoot: SceneObject): boolean {\n const urlSyncManager = getUrlSyncManager();\n const location = useLocation();\n const [isInitialized, setIsInitialized] = useState(false);\n\n useEffect(() => {\n urlSyncManager.initSync(sceneRoot);\n setIsInitialized(true);\n return () => urlSyncManager.cleanUp(sceneRoot);\n }, [sceneRoot, urlSyncManager]);\n\n useEffect(() => {\n // Use latest location, as by the time this effect runs, the location might have changed again\n const latestLocation = locationService.getLocation();\n const locationToHandle = latestLocation !== location ? latestLocation : location;\n\n if (latestLocation !== location) {\n console.log('latestLocation different from location');\n }\n\n urlSyncManager.handleNewLocation(locationToHandle);\n }, [sceneRoot, urlSyncManager, location]);\n\n return isInitialized;\n}\n\nexport interface UrlSyncContextProviderProps {\n scene: SceneObject;\n children: React.ReactNode;\n}\n"],"names":[],"mappings":";;;;;AAMO,SAAS,WAAW,SAAiC,EAAA;AAC1D,EAAA,MAAM,iBAAiB,iBAAkB,EAAA,CAAA;AACzC,EAAA,MAAM,WAAW,WAAY,EAAA,CAAA;AAC7B,EAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AAExD,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,cAAA,CAAe,SAAS,SAAS,CAAA,CAAA;AACjC,IAAA,gBAAA,CAAiB,IAAI,CAAA,CAAA;AACrB,IAAO,OAAA,MAAM,cAAe,CAAA,OAAA,CAAQ,SAAS,CAAA,CAAA;AAAA,GAC5C,EAAA,CAAC,SAAW,EAAA,cAAc,CAAC,CAAA,CAAA;AAE9B,EAAA,SAAA,CAAU,MAAM;AAEd,IAAM,MAAA,cAAA,GAAiB,gBAAgB,WAAY,EAAA,CAAA;AACnD,IAAM,MAAA,gBAAA,GAAmB,cAAmB,KAAA,QAAA,GAAW,cAAiB,GAAA,QAAA,CAAA;AAExE,IAAA,IAAI,mBAAmB,QAAU,EAAA;AAC/B,MAAA,OAAA,CAAQ,IAAI,wCAAwC,CAAA,CAAA;AAAA,KACtD;AAEA,IAAA,cAAA,CAAe,kBAAkB,gBAAgB,CAAA,CAAA;AAAA,GAChD,EAAA,CAAC,SAAW,EAAA,cAAA,EAAgB,QAAQ,CAAC,CAAA,CAAA;AAExC,EAAO,OAAA,aAAA,CAAA;AACT;;;;"}
@@ -3,7 +3,6 @@ import { UniqueUrlKeyMapper } from './UniqueUrlKeyMapper.js';
3
3
 
4
4
  function getUrlState(root) {
5
5
  const urlKeyMapper = new UniqueUrlKeyMapper();
6
- urlKeyMapper.rebuildIndex(root);
7
6
  const result = {};
8
7
  const visitNode = (obj) => {
9
8
  if (obj.urlSync) {
@@ -22,10 +21,18 @@ function getUrlState(root) {
22
21
  }
23
22
  function syncStateFromSearchParams(root, urlParams) {
24
23
  const urlKeyMapper = new UniqueUrlKeyMapper();
25
- urlKeyMapper.rebuildIndex(root);
26
24
  syncStateFromUrl(root, urlParams, urlKeyMapper);
27
25
  }
28
- function syncStateFromUrl(sceneObject, urlParams, urlKeyMapper) {
26
+ function syncStateFromUrl(root, urlParams, urlKeyMapper) {
27
+ if (!root.parent) {
28
+ syncUrlStateToObject(root, urlParams, urlKeyMapper);
29
+ }
30
+ root.forEachChild((child) => {
31
+ syncUrlStateToObject(child, urlParams, urlKeyMapper);
32
+ });
33
+ root.forEachChild((child) => syncStateFromUrl(child, urlParams, urlKeyMapper));
34
+ }
35
+ function syncUrlStateToObject(sceneObject, urlParams, urlKeyMapper) {
29
36
  if (sceneObject.urlSync) {
30
37
  const urlState = {};
31
38
  const currentState = sceneObject.urlSync.getUrlState();
@@ -50,7 +57,6 @@ function syncStateFromUrl(sceneObject, urlParams, urlKeyMapper) {
50
57
  sceneObject.urlSync.updateFromUrl(urlState);
51
58
  }
52
59
  }
53
- sceneObject.forEachChild((child) => syncStateFromUrl(child, urlParams, urlKeyMapper));
54
60
  }
55
61
  function isUrlValueEqual(currentUrlValue, newUrlValue) {
56
62
  if (currentUrlValue.length === 0 && newUrlValue == null) {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../src/services/utils.ts"],"sourcesContent":["import { isEqual } from 'lodash';\n\nimport { SceneObject, SceneObjectUrlValue, SceneObjectUrlValues } from '../core/types';\nimport { UniqueUrlKeyMapper } from './UniqueUrlKeyMapper';\n\n/**\n * @param root\n * @returns the full scene url state as a object with keys and values\n */\nexport function getUrlState(root: SceneObject): SceneObjectUrlValues {\n const urlKeyMapper = new UniqueUrlKeyMapper();\n urlKeyMapper.rebuildIndex(root);\n\n const result: SceneObjectUrlValues = {};\n\n const visitNode = (obj: SceneObject) => {\n if (obj.urlSync) {\n const newUrlState = obj.urlSync.getUrlState();\n\n for (const [key, value] of Object.entries(newUrlState)) {\n if (value != null) {\n const uniqueKey = urlKeyMapper.getUniqueKey(key, obj);\n result[uniqueKey] = value;\n }\n }\n }\n\n obj.forEachChild(visitNode);\n };\n\n visitNode(root);\n return result;\n}\n\n/**\n * Exported util function to sync state from an initial url state.\n * Useful for initializing an embedded scenes with a url state string.\n */\nexport function syncStateFromSearchParams(root: SceneObject, urlParams: URLSearchParams) {\n const urlKeyMapper = new UniqueUrlKeyMapper();\n urlKeyMapper.rebuildIndex(root);\n syncStateFromUrl(root, urlParams, urlKeyMapper);\n}\n\nexport function syncStateFromUrl(\n sceneObject: SceneObject,\n urlParams: URLSearchParams,\n urlKeyMapper: UniqueUrlKeyMapper\n) {\n if (sceneObject.urlSync) {\n const urlState: SceneObjectUrlValues = {};\n const currentState = sceneObject.urlSync.getUrlState();\n\n for (const key of sceneObject.urlSync.getKeys()) {\n const uniqueKey = urlKeyMapper.getUniqueKey(key, sceneObject);\n const newValue = urlParams.getAll(uniqueKey);\n const currentValue = currentState[key];\n\n if (isUrlValueEqual(newValue, currentValue)) {\n continue;\n }\n\n if (newValue.length > 0) {\n if (Array.isArray(currentValue)) {\n urlState[key] = newValue;\n } else {\n urlState[key] = newValue[0];\n }\n } else {\n // mark this key as having no url state\n urlState[key] = null;\n }\n }\n\n if (Object.keys(urlState).length > 0) {\n sceneObject.urlSync.updateFromUrl(urlState);\n }\n }\n\n sceneObject.forEachChild((child) => syncStateFromUrl(child, urlParams, urlKeyMapper));\n}\n\nexport function isUrlValueEqual(currentUrlValue: string[], newUrlValue: SceneObjectUrlValue): boolean {\n if (currentUrlValue.length === 0 && newUrlValue == null) {\n return true;\n }\n\n if (!Array.isArray(newUrlValue) && currentUrlValue?.length === 1) {\n return newUrlValue === currentUrlValue[0];\n }\n\n if (newUrlValue?.length === 0 && currentUrlValue === null) {\n return true;\n }\n\n // We have two arrays, lets compare them\n return is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,IAAI,CAAC,KAAM,CAAA,OAAA,CAAQ,WAAW,CAAK,IAAA,CAAA,eAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,eAAA,CAAiB,YAAW,CAAG,EAAA;AAChE,IAAA,OAAO,gBAAgB,eAAgB,CAAA,CAAA,CAAA,CAAA;AAAA,GACzC;AAEA,EAAA,IAAA,CAAI,WAAa,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,WAAA,CAAA,MAAA,MAAW,CAAK,IAAA,eAAA,KAAoB,IAAM,EAAA;AACzD,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAGA,EAAO,OAAA,OAAA,CAAQ,iBAAiB,WAAW,CAAA,CAAA;AAC7C;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../src/services/utils.ts"],"sourcesContent":["import { isEqual } from 'lodash';\n\nimport { SceneObject, SceneObjectUrlValue, SceneObjectUrlValues } from '../core/types';\nimport { UniqueUrlKeyMapper } from './UniqueUrlKeyMapper';\n\n/**\n * @param root\n * @returns the full scene url state as a object with keys and values\n */\nexport function getUrlState(root: SceneObject): SceneObjectUrlValues {\n const urlKeyMapper = new UniqueUrlKeyMapper();\n const result: SceneObjectUrlValues = {};\n\n const visitNode = (obj: SceneObject) => {\n if (obj.urlSync) {\n const newUrlState = obj.urlSync.getUrlState();\n\n for (const [key, value] of Object.entries(newUrlState)) {\n if (value != null) {\n const uniqueKey = urlKeyMapper.getUniqueKey(key, obj);\n result[uniqueKey] = value;\n }\n }\n }\n\n obj.forEachChild(visitNode);\n };\n\n visitNode(root);\n return result;\n}\n\n/**\n * Exported util function to sync state from an initial url state.\n * Useful for initializing an embedded scenes with a url state string.\n */\nexport function syncStateFromSearchParams(root: SceneObject, urlParams: URLSearchParams) {\n const urlKeyMapper = new UniqueUrlKeyMapper();\n syncStateFromUrl(root, urlParams, urlKeyMapper);\n}\n\nexport function syncStateFromUrl(root: SceneObject, urlParams: URLSearchParams, urlKeyMapper: UniqueUrlKeyMapper) {\n if (!root.parent) {\n // If top level object we need to sync here\n syncUrlStateToObject(root, urlParams, urlKeyMapper);\n }\n\n // These two forEachChild loops might look strange but it's to make sure we walk through the scene graph one level at a time as url key conflicts depend depth in the scene tree\n root.forEachChild((child) => {\n syncUrlStateToObject(child, urlParams, urlKeyMapper);\n });\n\n root.forEachChild((child) => syncStateFromUrl(child, urlParams, urlKeyMapper));\n}\n\nfunction syncUrlStateToObject(sceneObject: SceneObject, urlParams: URLSearchParams, urlKeyMapper: UniqueUrlKeyMapper) {\n if (sceneObject.urlSync) {\n const urlState: SceneObjectUrlValues = {};\n const currentState = sceneObject.urlSync.getUrlState();\n\n for (const key of sceneObject.urlSync.getKeys()) {\n const uniqueKey = urlKeyMapper.getUniqueKey(key, sceneObject);\n const newValue = urlParams.getAll(uniqueKey);\n const currentValue = currentState[key];\n\n if (isUrlValueEqual(newValue, currentValue)) {\n continue;\n }\n\n if (newValue.length > 0) {\n if (Array.isArray(currentValue)) {\n urlState[key] = newValue;\n } else {\n urlState[key] = newValue[0];\n }\n } else {\n // mark this key as having no url state\n urlState[key] = null;\n }\n }\n\n if (Object.keys(urlState).length > 0) {\n sceneObject.urlSync.updateFromUrl(urlState);\n }\n }\n}\n\nexport function isUrlValueEqual(currentUrlValue: string[], newUrlValue: SceneObjectUrlValue): boolean {\n if (currentUrlValue.length === 0 && newUrlValue == null) {\n return true;\n }\n\n if (!Array.isArray(newUrlValue) && currentUrlValue?.length === 1) {\n return newUrlValue === currentUrlValue[0];\n }\n\n if (newUrlValue?.length === 0 && currentUrlValue === null) {\n return true;\n }\n\n // We have two arrays, lets compare them\n return isEqual(currentUrlValue, newUrlValue);\n}\n"],"names":[],"mappings":";;;AASO,SAAS,YAAY,IAAyC,EAAA;AACnE,EAAM,MAAA,YAAA,GAAe,IAAI,kBAAmB,EAAA,CAAA;AAC5C,EAAA,MAAM,SAA+B,EAAC,CAAA;AAEtC,EAAM,MAAA,SAAA,GAAY,CAAC,GAAqB,KAAA;AACtC,IAAA,I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ACT;AAEA,EAAA,IAAI,CAAC,KAAM,CAAA,OAAA,CAAQ,WAAW,CAAK,IAAA,CAAA,eAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,eAAA,CAAiB,YAAW,CAAG,EAAA;AAChE,IAAA,OAAO,gBAAgB,eAAgB,CAAA,CAAA,CAAA,CAAA;AAAA,GACzC;AAEA,EAAA,IAAA,CAAI,WAAa,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,WAAA,CAAA,MAAA,MAAW,CAAK,IAAA,eAAA,KAAoB,IAAM,EAAA;AACzD,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAGA,EAAO,OAAA,OAAA,CAAQ,iBAAiB,WAAW,CAAA,CAAA;AAC7C;;;;"}
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ import { Observable, Unsubscribable, MonoTypeOperatorFunction, Subscription, Rep
7
7
  import * as _grafana_schema from '@grafana/schema';
8
8
  import { VariableType, VariableHide, TimeZone, DataTopic, DataQuery, DataSourceRef, VariableRefresh, LoadingState, DashboardCursorSync, MatcherConfig, TableFieldOptions } from '@grafana/schema';
9
9
  import { VariableInterpolation } from '@grafana/runtime';
10
+ import { Location } from 'history';
10
11
  import { PanelContext, IconName } from '@grafana/ui';
11
12
  import ReactGridLayout from 'react-grid-layout';
12
13
  import { RouteComponentProps } from 'react-router-dom';
@@ -1567,26 +1568,33 @@ interface UrlSyncManagerLike {
1567
1568
  initSync(root: SceneObject): void;
1568
1569
  cleanUp(root: SceneObject): void;
1569
1570
  getUrlState(root: SceneObject): SceneObjectUrlValues;
1571
+ handleNewLocation(location: Location): void;
1572
+ handleNewObject(sceneObj: SceneObject): void;
1570
1573
  }
1571
1574
  declare class UrlSyncManager implements UrlSyncManagerLike {
1572
- private _urlKeyMapper;
1573
- private _sceneRoot;
1574
- private _stateSub;
1575
- private _locationSub?;
1576
- private _lastPath?;
1577
- private _ignoreNextLocationUpdate;
1575
+ #private;
1578
1576
  /**
1579
1577
  * Updates the current scene state to match URL state.
1580
1578
  */
1581
1579
  initSync(root: SceneObject): void;
1582
1580
  cleanUp(root: SceneObject): void;
1583
- syncFrom(sceneObj: SceneObject): void;
1584
- private _onLocationUpdate;
1585
- private _onStateChanged;
1581
+ handleNewLocation(location: Location): void;
1582
+ handleNewObject(sceneObj: SceneObject): void;
1586
1583
  getUrlState(root: SceneObject): SceneObjectUrlValues;
1587
1584
  }
1588
1585
  declare function getUrlSyncManager(): UrlSyncManagerLike;
1589
1586
 
1587
+ declare function useUrlSync(sceneRoot: SceneObject): boolean;
1588
+
1589
+ interface UrlSyncContextProviderProps {
1590
+ scene: SceneObject;
1591
+ children: React.ReactNode;
1592
+ }
1593
+ /**
1594
+ * Right now this is actually not defining a context, but think it might in the future (with UrlSyncManager as the context value)
1595
+ */
1596
+ declare function UrlSyncContextProvider({ children, scene }: UrlSyncContextProviderProps): React$1.ReactNode;
1597
+
1590
1598
  interface EmbeddedSceneState extends SceneObjectState {
1591
1599
  /**
1592
1600
  * The main content of the scene (usually a SceneFlexLayout)
@@ -1600,13 +1608,6 @@ interface EmbeddedSceneState extends SceneObjectState {
1600
1608
  declare class EmbeddedScene extends SceneObjectBase<EmbeddedSceneState> {
1601
1609
  static Component: typeof EmbeddedSceneRenderer;
1602
1610
  constructor(state: EmbeddedSceneState);
1603
- /**
1604
- * initUrlSync should be called before the scene is rendered to ensure that objects are in sync
1605
- * before they get activated. This saves some unnecessary re-renders and makes sure variables
1606
- * queries are issued as needed. If your using SceneAppPage you will not need to call this as
1607
- * url sync is handled on the SceneAppPage level not this level.
1608
- */
1609
- initUrlSync(): void;
1610
1611
  }
1611
1612
  declare function EmbeddedSceneRenderer({ model }: SceneComponentProps<EmbeddedScene>): React__default.JSX.Element;
1612
1613
 
@@ -2643,4 +2644,4 @@ declare const sceneUtils: {
2643
2644
  isGroupByVariable: typeof isGroupByVariable;
2644
2645
  };
2645
2646
 
2646
- export { AdHocFiltersVariable, CancelActivationHandler, ConstantVariable, ControlsLayout, CustomFormatterVariable, CustomTransformOperator, CustomTransformerDefinition, CustomVariable, CustomVariableValue, DataLayerFilter, DataRequestEnricher, DataSourceVariable, DeepPartial, EmbeddedScene, EmbeddedSceneState, ExtraQueryDataProcessor, ExtraQueryDescriptor, ExtraQueryProvider, FieldConfigBuilder, FieldConfigBuilders, FieldConfigOverridesBuilder, FiltersRequestEnricher, FormatVariable, GroupByVariable, InterpolationFormatParameter, IntervalVariable, LocalValueVariable, MacroVariableConstructor, MultiValueVariable, MultiValueVariableState, NestedScene, PanelBuilders, PanelOptionsBuilders, QueryRunnerState, QueryVariable, RuntimeDataSource, SceneActivationHandler, SceneApp, SceneAppDrilldownView, SceneAppPage, SceneAppPageLike, SceneAppPageState, SceneAppRoute, SceneByFrameRepeater, SceneByVariableRepeater, SceneCSSGridItem, SceneCSSGridLayout, SceneCanvasText, SceneComponent, SceneComponentProps, SceneControlsSpacer, SceneDataLayerBase, SceneDataLayerControls, SceneDataLayerProvider, SceneDataLayerProviderState, SceneDataLayerSet, SceneDataLayerSetBase, SceneDataNode, SceneDataProvider, SceneDataProviderResult, SceneDataQuery, SceneDataState, SceneDataTransformer, SceneDeactivationHandler, SceneDebugger, SceneFlexItem, SceneFlexItemLike, SceneFlexItemState, SceneFlexLayout, SceneGridItem, SceneGridItemLike, SceneGridItemStateLike, SceneGridLayout, SceneGridRow, SceneLayout, SceneLayoutChildOptions, SceneLayoutState, SceneObject, SceneObjectBase, SceneObjectRef, SceneObjectState, SceneObjectStateChangedEvent, SceneObjectStateChangedPayload, SceneObjectUrlSyncConfig, SceneObjectUrlSyncHandler, SceneObjectUrlValue, SceneObjectUrlValues, SceneObjectWithUrlSync, SceneQueryControllerEntry, SceneQueryControllerEntryType, SceneQueryControllerLike, SceneQueryRunner, SceneReactObject, SceneRefreshPicker, SceneRefreshPickerState, SceneRouteMatch, SceneStateChangedHandler, SceneStatelessBehavior, SceneTimePicker, SceneTimeRange, SceneTimeRangeCompare, SceneTimeRangeLike, SceneTimeRangeState, SceneTimeRangeTransformerBase, SceneTimeZoneOverride, SceneToolbarButton, SceneToolbarInput, SceneVariable, SceneVariableDependencyConfigLike, SceneVariableSet, SceneVariableSetState, SceneVariableState, SceneVariableValueChangedEvent, SceneVariables, SplitLayout, TestVariable, TextBoxVariable, UrlSyncManager, UrlSyncManagerLike, UseStateHookOptions, UserActionEvent, ValidateAndUpdateResult, VariableCustomFormatterFn, VariableDependencyConfig, VariableGetOptionsArgs, VariableValue, VariableValueControl, VariableValueOption, VariableValueSelectWrapper, VariableValueSelectors, VariableValueSingle, VizConfig, VizConfigBuilder, VizConfigBuilders, VizPanel, VizPanelBuilder, VizPanelMenu, VizPanelState, index$1 as behaviors, index as dataLayers, formatRegistry, getUrlSyncManager, isCustomVariableValue, isDataLayer, isDataRequestEnricher, isFiltersRequestEnricher, isSceneObject, registerQueryWithController, registerRuntimeDataSource, renderSelectForVariable, sceneGraph, sceneUtils, useSceneApp, useSceneObjectState };
2647
+ export { AdHocFiltersVariable, CancelActivationHandler, ConstantVariable, ControlsLayout, CustomFormatterVariable, CustomTransformOperator, CustomTransformerDefinition, CustomVariable, CustomVariableValue, DataLayerFilter, DataRequestEnricher, DataSourceVariable, DeepPartial, EmbeddedScene, EmbeddedSceneState, ExtraQueryDataProcessor, ExtraQueryDescriptor, ExtraQueryProvider, FieldConfigBuilder, FieldConfigBuilders, FieldConfigOverridesBuilder, FiltersRequestEnricher, FormatVariable, GroupByVariable, InterpolationFormatParameter, IntervalVariable, LocalValueVariable, MacroVariableConstructor, MultiValueVariable, MultiValueVariableState, NestedScene, PanelBuilders, PanelOptionsBuilders, QueryRunnerState, QueryVariable, RuntimeDataSource, SceneActivationHandler, SceneApp, SceneAppDrilldownView, SceneAppPage, SceneAppPageLike, SceneAppPageState, SceneAppRoute, SceneByFrameRepeater, SceneByVariableRepeater, SceneCSSGridItem, SceneCSSGridLayout, SceneCanvasText, SceneComponent, SceneComponentProps, SceneControlsSpacer, SceneDataLayerBase, SceneDataLayerControls, SceneDataLayerProvider, SceneDataLayerProviderState, SceneDataLayerSet, SceneDataLayerSetBase, SceneDataNode, SceneDataProvider, SceneDataProviderResult, SceneDataQuery, SceneDataState, SceneDataTransformer, SceneDeactivationHandler, SceneDebugger, SceneFlexItem, SceneFlexItemLike, SceneFlexItemState, SceneFlexLayout, SceneGridItem, SceneGridItemLike, SceneGridItemStateLike, SceneGridLayout, SceneGridRow, SceneLayout, SceneLayoutChildOptions, SceneLayoutState, SceneObject, SceneObjectBase, SceneObjectRef, SceneObjectState, SceneObjectStateChangedEvent, SceneObjectStateChangedPayload, SceneObjectUrlSyncConfig, SceneObjectUrlSyncHandler, SceneObjectUrlValue, SceneObjectUrlValues, SceneObjectWithUrlSync, SceneQueryControllerEntry, SceneQueryControllerEntryType, SceneQueryControllerLike, SceneQueryRunner, SceneReactObject, SceneRefreshPicker, SceneRefreshPickerState, SceneRouteMatch, SceneStateChangedHandler, SceneStatelessBehavior, SceneTimePicker, SceneTimeRange, SceneTimeRangeCompare, SceneTimeRangeLike, SceneTimeRangeState, SceneTimeRangeTransformerBase, SceneTimeZoneOverride, SceneToolbarButton, SceneToolbarInput, SceneVariable, SceneVariableDependencyConfigLike, SceneVariableSet, SceneVariableSetState, SceneVariableState, SceneVariableValueChangedEvent, SceneVariables, SplitLayout, TestVariable, TextBoxVariable, UrlSyncContextProvider, UrlSyncManager, UrlSyncManagerLike, UseStateHookOptions, UserActionEvent, ValidateAndUpdateResult, VariableCustomFormatterFn, VariableDependencyConfig, VariableGetOptionsArgs, VariableValue, VariableValueControl, VariableValueOption, VariableValueSelectWrapper, VariableValueSelectors, VariableValueSingle, VizConfig, VizConfigBuilder, VizConfigBuilders, VizPanel, VizPanelBuilder, VizPanelMenu, VizPanelState, index$1 as behaviors, index as dataLayers, formatRegistry, getUrlSyncManager, isCustomVariableValue, isDataLayer, isDataRequestEnricher, isFiltersRequestEnricher, isSceneObject, registerQueryWithController, registerRuntimeDataSource, renderSelectForVariable, sceneGraph, sceneUtils, useSceneApp, useSceneObjectState, useUrlSync };