@grafana/scenes 0.25.0 → 0.26.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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v0.26.0 (Tue Aug 29 2023)
2
+
3
+ #### 🚀 Enhancement
4
+
5
+ - sceneUtils: cloneSceneObjectState [#297](https://github.com/grafana/scenes/pull/297) ([@torkelo](https://github.com/torkelo))
6
+
7
+ #### Authors: 1
8
+
9
+ - Torkel Ödegaard ([@torkelo](https://github.com/torkelo))
10
+
11
+ ---
12
+
1
13
  # v0.25.0 (Tue Aug 22 2023)
2
14
 
3
15
  #### 🚀 Enhancement
@@ -17,7 +17,11 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  function cloneSceneObject(sceneObject, withState) {
20
- const clonedState = __spreadValues({}, sceneObject.state);
20
+ const clonedState = cloneSceneObjectState(sceneObject.state, withState);
21
+ return new sceneObject.constructor(clonedState);
22
+ }
23
+ function cloneSceneObjectState(sceneState, withState) {
24
+ const clonedState = __spreadValues({}, sceneState);
21
25
  for (const key in clonedState) {
22
26
  const propValue = clonedState[key];
23
27
  if (propValue instanceof SceneObjectBase) {
@@ -36,7 +40,7 @@ function cloneSceneObject(sceneObject, withState) {
36
40
  }
37
41
  }
38
42
  Object.assign(clonedState, withState);
39
- return new sceneObject.constructor(clonedState);
43
+ return clonedState;
40
44
  }
41
45
  function getClosest(sceneObject, extract) {
42
46
  let curSceneObject = sceneObject;
@@ -48,5 +52,5 @@ function getClosest(sceneObject, extract) {
48
52
  return extracted;
49
53
  }
50
54
 
51
- export { cloneSceneObject, getClosest };
55
+ export { cloneSceneObject, cloneSceneObjectState, getClosest };
52
56
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../../src/core/sceneGraph/utils.ts"],"sourcesContent":["import { SceneObject, SceneObjectState } from '../types';\n\nimport { SceneObjectBase } from '../SceneObjectBase';\n\n/**\n * Will create new SceneItem with shalled cloned state, but all states items of type SceneObject are deep cloned\n */\nexport function cloneSceneObject<T extends SceneObjectBase<TState>, TState extends SceneObjectState>(\n sceneObject: SceneObjectBase<TState>,\n withState?: Partial<TState>\n): T {\n const clonedState = { ...sceneObject.state };\n\n // Clone any SceneItems in state\n for (const key in clonedState) {\n const propValue = clonedState[key];\n if (propValue instanceof SceneObjectBase) {\n clonedState[key] = propValue.clone();\n }\n\n // Clone scene objects in arrays\n if (Array.isArray(propValue)) {\n const newArray: any = [];\n for (const child of propValue) {\n if (child instanceof SceneObjectBase) {\n newArray.push(child.clone());\n } else {\n newArray.push(child);\n }\n }\n clonedState[key] = newArray;\n }\n }\n\n Object.assign(clonedState, withState);\n\n return new (sceneObject.constructor as any)(clonedState);\n}\n\n/** Walks up the scene graph, returning the first non-undefined result of `extract` */\nexport function getClosest<T>(sceneObject: SceneObject, extract: (s: SceneObject) => T | undefined): T | undefined {\n let curSceneObject: SceneObject | undefined = sceneObject;\n let extracted: T | undefined = undefined;\n\n while (curSceneObject && !extracted) {\n extracted = extract(curSceneObject);\n curSceneObject = curSceneObject.parent;\n }\n\n return extracted;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAOgB,SAAA,gBAAA,CACd,aACA,SACG,EAAA;AACH,EAAM,MAAA,WAAA,GAAc,mBAAK,WAAY,CAAA,KAAA,CAAA,CAAA;AAGrC,EAAA,KAAA,MAAW,OAAO,WAAa,EAAA;AAC7B,IAAA,MAAM,YAAY,WAAY,CAAA,GAAA,CAAA,CAAA;AAC9B,IAAA,IAAI,qBAAqB,eAAiB,EAAA;AACxC,MAAY,WAAA,CAAA,GAAA,CAAA,GAAO,UAAU,KAAM,EAAA,CAAA;AAAA,KACrC;AAGA,IAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,SAAS,CAAG,EAAA;AAC5B,MAAA,MAAM,WAAgB,EAAC,CAAA;AACvB,MAAA,KAAA,MAAW,SAAS,SAAW,EAAA;AAC7B,QAAA,IAAI,iBAAiB,eAAiB,EAAA;AACpC,UAAS,QAAA,CAAA,IAAA,CAAK,KAAM,CAAA,KAAA,EAAO,CAAA,CAAA;AAAA,SACtB,MAAA;AACL,UAAA,QAAA,CAAS,KAAK,KAAK,CAAA,CAAA;AAAA,SACrB;AAAA,OACF;AACA,MAAA,WAAA,CAAY,GAAO,CAAA,GAAA,QAAA,CAAA;AAAA,KACrB;AAAA,GACF;AAEA,EAAO,MAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA,CAAA;AAEpC,EAAO,OAAA,IAAK,WAAY,CAAA,WAAA,CAAoB,WAAW,CAAA,CAAA;AACzD,CAAA;AAGgB,SAAA,UAAA,CAAc,aAA0B,OAA2D,EAAA;AACjH,EAAA,IAAI,cAA0C,GAAA,WAAA,CAAA;AAC9C,EAAA,IAAI,SAA2B,GAAA,KAAA,CAAA,CAAA;AAE/B,EAAO,OAAA,cAAA,IAAkB,CAAC,SAAW,EAAA;AACnC,IAAA,SAAA,GAAY,QAAQ,cAAc,CAAA,CAAA;AAClC,IAAA,cAAA,GAAiB,cAAe,CAAA,MAAA,CAAA;AAAA,GAClC;AAEA,EAAO,OAAA,SAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/core/sceneGraph/utils.ts"],"sourcesContent":["import { SceneObject, SceneObjectState } from '../types';\n\nimport { SceneObjectBase } from '../SceneObjectBase';\n\n/**\n * Will create new SceneItem with shalled cloned state, but all states items of type SceneObject are deep cloned\n */\nexport function cloneSceneObject<T extends SceneObjectBase<TState>, TState extends SceneObjectState>(\n sceneObject: SceneObjectBase<TState>,\n withState?: Partial<TState>\n): T {\n const clonedState = cloneSceneObjectState(sceneObject.state, withState);\n return new (sceneObject.constructor as any)(clonedState);\n}\n\nexport function cloneSceneObjectState<TState extends SceneObjectState>(\n sceneState: TState,\n withState?: Partial<TState>\n): TState {\n const clonedState = { ...sceneState };\n\n // Clone any SceneItems in state\n for (const key in clonedState) {\n const propValue = clonedState[key];\n if (propValue instanceof SceneObjectBase) {\n clonedState[key] = propValue.clone();\n }\n\n // Clone scene objects in arrays\n if (Array.isArray(propValue)) {\n const newArray: any = [];\n for (const child of propValue) {\n if (child instanceof SceneObjectBase) {\n newArray.push(child.clone());\n } else {\n newArray.push(child);\n }\n }\n clonedState[key] = newArray;\n }\n }\n\n Object.assign(clonedState, withState);\n\n return clonedState;\n}\n\n/** Walks up the scene graph, returning the first non-undefined result of `extract` */\nexport function getClosest<T>(sceneObject: SceneObject, extract: (s: SceneObject) => T | undefined): T | undefined {\n let curSceneObject: SceneObject | undefined = sceneObject;\n let extracted: T | undefined = undefined;\n\n while (curSceneObject && !extracted) {\n extracted = extract(curSceneObject);\n curSceneObject = curSceneObject.parent;\n }\n\n return extracted;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAOgB,SAAA,gBAAA,CACd,aACA,SACG,EAAA;AACH,EAAA,MAAM,WAAc,GAAA,qBAAA,CAAsB,WAAY,CAAA,KAAA,EAAO,SAAS,CAAA,CAAA;AACtE,EAAO,OAAA,IAAK,WAAY,CAAA,WAAA,CAAoB,WAAW,CAAA,CAAA;AACzD,CAAA;AAEgB,SAAA,qBAAA,CACd,YACA,SACQ,EAAA;AACR,EAAA,MAAM,cAAc,cAAK,CAAA,EAAA,EAAA,UAAA,CAAA,CAAA;AAGzB,EAAA,KAAA,MAAW,OAAO,WAAa,EAAA;AAC7B,IAAA,MAAM,YAAY,WAAY,CAAA,GAAA,CAAA,CAAA;AAC9B,IAAA,IAAI,qBAAqB,eAAiB,EAAA;AACxC,MAAY,WAAA,CAAA,GAAA,CAAA,GAAO,UAAU,KAAM,EAAA,CAAA;AAAA,KACrC;AAGA,IAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,SAAS,CAAG,EAAA;AAC5B,MAAA,MAAM,WAAgB,EAAC,CAAA;AACvB,MAAA,KAAA,MAAW,SAAS,SAAW,EAAA;AAC7B,QAAA,IAAI,iBAAiB,eAAiB,EAAA;AACpC,UAAS,QAAA,CAAA,IAAA,CAAK,KAAM,CAAA,KAAA,EAAO,CAAA,CAAA;AAAA,SACtB,MAAA;AACL,UAAA,QAAA,CAAS,KAAK,KAAK,CAAA,CAAA;AAAA,SACrB;AAAA,OACF;AACA,MAAA,WAAA,CAAY,GAAO,CAAA,GAAA,QAAA,CAAA;AAAA,KACrB;AAAA,GACF;AAEA,EAAO,MAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA,CAAA;AAEpC,EAAO,OAAA,WAAA,CAAA;AACT,CAAA;AAGgB,SAAA,UAAA,CAAc,aAA0B,OAA2D,EAAA;AACjH,EAAA,IAAI,cAA0C,GAAA,WAAA,CAAA;AAC9C,EAAA,IAAI,SAA2B,GAAA,KAAA,CAAA,CAAA;AAE/B,EAAO,OAAA,cAAA,IAAkB,CAAC,SAAW,EAAA;AACnC,IAAA,SAAA,GAAY,QAAQ,cAAc,CAAA,CAAA;AAClC,IAAA,cAAA,GAAiB,cAAe,CAAA,MAAA,CAAA;AAAA,GAClC;AAEA,EAAO,OAAA,SAAA,CAAA;AACT;;;;"}
package/dist/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { getUrlWithAppState } from './components/SceneApp/utils.js';
2
2
  import { registerRuntimePanelPlugin } from './components/VizPanel/registerRuntimePanelPlugin.js';
3
+ import { cloneSceneObjectState } from './core/sceneGraph/utils.js';
3
4
  import { registerRuntimeDataSource } from './querying/RuntimeDataSource.js';
4
5
  export { RuntimeDataSource, registerRuntimeDataSource } from './querying/RuntimeDataSource.js';
5
6
  export { isSceneObject } from './core/types.js';
@@ -49,7 +50,8 @@ export { PanelBuilders } from './core/PanelBuilders/index.js';
49
50
  const sceneUtils = {
50
51
  getUrlWithAppState,
51
52
  registerRuntimePanelPlugin,
52
- registerRuntimeDataSource
53
+ registerRuntimeDataSource,
54
+ cloneSceneObjectState
53
55
  };
54
56
 
55
57
  export { sceneUtils };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { getUrlWithAppState } from './components/SceneApp/utils';\nimport { registerRuntimePanelPlugin } from './components/VizPanel/registerRuntimePanelPlugin';\nimport { registerRuntimeDataSource } from './querying/RuntimeDataSource';\n\nexport * from './core/types';\nexport * from './core/events';\nexport { sceneGraph } from './core/sceneGraph';\nexport * as behaviors from './behaviors';\n\nexport { SceneObjectBase } from './core/SceneObjectBase';\nexport { SceneDataNode } from './core/SceneDataNode';\nexport { SceneTimeRange } from './core/SceneTimeRange';\nexport { SceneTimeZoneOverride } from './core/SceneTimeZoneOverride';\n\nexport { SceneQueryRunner, type QueryRunnerState } from './querying/SceneQueryRunner';\nexport { SceneDataTransformer } from './querying/SceneDataTransformer';\nexport { registerRuntimeDataSource, RuntimeDataSource } from './querying/RuntimeDataSource';\n\nexport * from './variables/types';\nexport { VariableDependencyConfig } from './variables/VariableDependencyConfig';\nexport { formatRegistry, type FormatVariable } from './variables/interpolation/formatRegistry';\nexport { VariableValueSelectors } from './variables/components/VariableValueSelectors';\nexport { SceneVariableSet } from './variables/sets/SceneVariableSet';\nexport { ConstantVariable } from './variables/variants/ConstantVariable';\nexport { CustomVariable } from './variables/variants/CustomVariable';\nexport { DataSourceVariable } from './variables/variants/DataSourceVariable';\nexport { QueryVariable } from './variables/variants/query/QueryVariable';\nexport { TestVariable } from './variables/variants/TestVariable';\nexport { TextBoxVariable } from './variables/variants/TextBoxVariable';\n\nexport { type UrlSyncManagerLike as UrlSyncManager, getUrlSyncManager } from './services/UrlSyncManager';\nexport { SceneObjectUrlSyncConfig } from './services/SceneObjectUrlSyncConfig';\n\nexport { EmbeddedScene, type EmbeddedSceneState } from './components/EmbeddedScene';\nexport { VizPanel, type VizPanelState } from './components/VizPanel/VizPanel';\nexport { VizPanelMenu } from './components/VizPanel/VizPanelMenu';\nexport { NestedScene } from './components/NestedScene';\nexport { SceneCanvasText } from './components/SceneCanvasText';\nexport { SceneToolbarButton, SceneToolbarInput } from './components/SceneToolbarButton';\nexport { SceneTimePicker } from './components/SceneTimePicker';\nexport { SceneRefreshPicker } from './components/SceneRefreshPicker';\nexport { SceneByFrameRepeater } from './components/SceneByFrameRepeater';\nexport { SceneControlsSpacer } from './components/SceneControlsSpacer';\nexport { SceneFlexLayout, SceneFlexItem, type SceneFlexItemState } from './components/layout/SceneFlexLayout';\nexport { SceneGridLayout } from './components/layout/grid/SceneGridLayout';\nexport { SceneGridItem } from './components/layout/grid/SceneGridItem';\nexport { SceneGridRow } from './components/layout/grid/SceneGridRow';\nexport { SplitLayout } from './components/layout/split/SplitLayout';\nexport {\n type SceneAppPageLike,\n type SceneRouteMatch,\n type SceneAppPageState,\n type SceneAppDrilldownView,\n type SceneAppRoute,\n} from './components/SceneApp/types';\nexport { SceneApp } from './components/SceneApp/SceneApp';\nexport { SceneAppPage } from './components/SceneApp/SceneAppPage';\nexport { SceneReactObject } from './components/SceneReactObject';\nexport { PanelBuilders } from './core/PanelBuilders';\n\nexport const sceneUtils = {\n getUrlWithAppState,\n registerRuntimePanelPlugin,\n registerRuntimeDataSource,\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DO,MAAM,UAAa,GAAA;AAAA,EACxB,kBAAA;AAAA,EACA,0BAAA;AAAA,EACA,yBAAA;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { getUrlWithAppState } from './components/SceneApp/utils';\nimport { registerRuntimePanelPlugin } from './components/VizPanel/registerRuntimePanelPlugin';\nimport { cloneSceneObjectState } from './core/sceneGraph/utils';\nimport { registerRuntimeDataSource } from './querying/RuntimeDataSource';\n\nexport * from './core/types';\nexport * from './core/events';\nexport { sceneGraph } from './core/sceneGraph';\nexport * as behaviors from './behaviors';\n\nexport { SceneObjectBase } from './core/SceneObjectBase';\nexport { SceneDataNode } from './core/SceneDataNode';\nexport { SceneTimeRange } from './core/SceneTimeRange';\nexport { SceneTimeZoneOverride } from './core/SceneTimeZoneOverride';\n\nexport { SceneQueryRunner, type QueryRunnerState } from './querying/SceneQueryRunner';\nexport { SceneDataTransformer } from './querying/SceneDataTransformer';\nexport { registerRuntimeDataSource, RuntimeDataSource } from './querying/RuntimeDataSource';\n\nexport * from './variables/types';\nexport { VariableDependencyConfig } from './variables/VariableDependencyConfig';\nexport { formatRegistry, type FormatVariable } from './variables/interpolation/formatRegistry';\nexport { VariableValueSelectors } from './variables/components/VariableValueSelectors';\nexport { SceneVariableSet } from './variables/sets/SceneVariableSet';\nexport { ConstantVariable } from './variables/variants/ConstantVariable';\nexport { CustomVariable } from './variables/variants/CustomVariable';\nexport { DataSourceVariable } from './variables/variants/DataSourceVariable';\nexport { QueryVariable } from './variables/variants/query/QueryVariable';\nexport { TestVariable } from './variables/variants/TestVariable';\nexport { TextBoxVariable } from './variables/variants/TextBoxVariable';\n\nexport { type UrlSyncManagerLike as UrlSyncManager, getUrlSyncManager } from './services/UrlSyncManager';\nexport { SceneObjectUrlSyncConfig } from './services/SceneObjectUrlSyncConfig';\n\nexport { EmbeddedScene, type EmbeddedSceneState } from './components/EmbeddedScene';\nexport { VizPanel, type VizPanelState } from './components/VizPanel/VizPanel';\nexport { VizPanelMenu } from './components/VizPanel/VizPanelMenu';\nexport { NestedScene } from './components/NestedScene';\nexport { SceneCanvasText } from './components/SceneCanvasText';\nexport { SceneToolbarButton, SceneToolbarInput } from './components/SceneToolbarButton';\nexport { SceneTimePicker } from './components/SceneTimePicker';\nexport { SceneRefreshPicker } from './components/SceneRefreshPicker';\nexport { SceneByFrameRepeater } from './components/SceneByFrameRepeater';\nexport { SceneControlsSpacer } from './components/SceneControlsSpacer';\nexport { SceneFlexLayout, SceneFlexItem, type SceneFlexItemState } from './components/layout/SceneFlexLayout';\nexport { SceneGridLayout } from './components/layout/grid/SceneGridLayout';\nexport { SceneGridItem } from './components/layout/grid/SceneGridItem';\nexport { SceneGridRow } from './components/layout/grid/SceneGridRow';\nexport { SplitLayout } from './components/layout/split/SplitLayout';\nexport {\n type SceneAppPageLike,\n type SceneRouteMatch,\n type SceneAppPageState,\n type SceneAppDrilldownView,\n type SceneAppRoute,\n} from './components/SceneApp/types';\nexport { SceneApp } from './components/SceneApp/SceneApp';\nexport { SceneAppPage } from './components/SceneApp/SceneAppPage';\nexport { SceneReactObject } from './components/SceneReactObject';\nexport { PanelBuilders } from './core/PanelBuilders';\n\nexport const sceneUtils = {\n getUrlWithAppState,\n registerRuntimePanelPlugin,\n registerRuntimeDataSource,\n cloneSceneObjectState,\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DO,MAAM,UAAa,GAAA;AAAA,EACxB,kBAAA;AAAA,EACA,0BAAA;AAAA,EACA,yBAAA;AAAA,EACA,qBAAA;AACF;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BusEventWithPayload, PanelData, BusEvent, BusEventType, BusEventHandler, TimeRange, DataTransformContext, DataFrame, PanelPlugin, DataQuery, DataSourceApi, ScopedVars, EventBus, EventFilterOptions, DataTransformerConfig, Registry, RegistryItem, DataSourceRef as DataSourceRef$1, VariableRefresh, VariableSort, PanelMenuItem, FieldConfigSource, AbsoluteTimeRange, InterpolateFunction, IconName as IconName$1, FieldConfig, FieldType, FieldValueMatcherConfig } from '@grafana/data';
1
+ import { BusEventWithPayload, PanelData, BusEvent, BusEventType, BusEventHandler, TimeRange, DataTransformContext, DataFrame, PanelPlugin, EventBus, DataQuery, DataSourceApi, ScopedVars, EventFilterOptions, DataTransformerConfig, Registry, RegistryItem, DataSourceRef as DataSourceRef$1, VariableRefresh, VariableSort, PanelMenuItem, FieldConfigSource, AbsoluteTimeRange, InterpolateFunction, IconName as IconName$1, FieldConfig, FieldType, FieldValueMatcherConfig } from '@grafana/data';
2
2
  import React$1, { CSSProperties, ComponentType } from 'react';
3
3
  import { Observable, Unsubscribable, MonoTypeOperatorFunction, Subscription } from 'rxjs';
4
4
  import { VariableType, VariableHide, TimeZone, DashboardCursorSync, DataSourceRef, DataQuery as DataQuery$1, MatcherConfig, TableFieldOptions } from '@grafana/schema';
@@ -261,75 +261,6 @@ interface RuntimePanelPluginOptions {
261
261
  */
262
262
  declare function registerRuntimePanelPlugin({ pluginId, plugin }: RuntimePanelPluginOptions): void;
263
263
 
264
- declare abstract class RuntimeDataSource<TQuery extends DataQuery = DataQuery> extends DataSourceApi<TQuery> {
265
- constructor(pluginId: string, uid: string);
266
- testDatasource(): Promise<any>;
267
- }
268
- interface RuntimeDataSourceOptions {
269
- dataSource: RuntimeDataSource;
270
- }
271
- /**
272
- * Provides a way to register runtime panel plugins.
273
- * Please use a pluginId that is unlikely to collide with other plugins.
274
- */
275
- declare function registerRuntimeDataSource({ dataSource }: RuntimeDataSourceOptions): void;
276
-
277
- interface SceneObjectStateChangedPayload<TState extends SceneObjectState = SceneObjectState> {
278
- prevState: TState;
279
- newState: TState;
280
- partialUpdate: Partial<TState>;
281
- changedObject: SceneObject<TState>;
282
- }
283
- declare class SceneObjectStateChangedEvent extends BusEventWithPayload<SceneObjectStateChangedPayload> {
284
- static readonly type = "scene-object-state-change";
285
- }
286
-
287
- /**
288
- * Will walk the scene object graph up to the root looking for the first variable with the specified name
289
- */
290
- declare function lookupVariable(name: string, sceneObject: SceneObject): SceneVariable | null;
291
-
292
- /**
293
- * Will walk up the scene object graph to the closest $timeRange scene object
294
- */
295
- declare function getTimeRange(sceneObject: SceneObject): SceneTimeRangeLike;
296
-
297
- /**
298
- * Get the closest node with variables
299
- */
300
- declare function getVariables(sceneObject: SceneObject): SceneVariables;
301
- /**
302
- * Will walk up the scene object graph to the closest $data scene object
303
- */
304
- declare function getData(sceneObject: SceneObject): SceneDataProvider;
305
- /**
306
- * Will walk up the scene object graph to the closest $layout scene object
307
- */
308
- declare function getLayout(scene: SceneObject): SceneLayout;
309
- /**
310
- * Interpolates the given string using the current scene object as context. *
311
- */
312
- declare function interpolate(sceneObject: SceneObject, value: string | undefined | null, scopedVars?: ScopedVars, format?: string | VariableCustomFormatterFn): string;
313
- /**
314
- * Checks if the variable is currently loading or waiting to update
315
- */
316
- declare function hasVariableDependencyInLoadingState(sceneObject: SceneObject): boolean;
317
- /**
318
- * This will search the full scene graph, starting with the scene node passed in, then walking up the parent chain. *
319
- */
320
- declare function findObject(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject | null;
321
-
322
- declare const sceneGraph: {
323
- getVariables: typeof getVariables;
324
- getData: typeof getData;
325
- getTimeRange: typeof getTimeRange;
326
- getLayout: typeof getLayout;
327
- interpolate: typeof interpolate;
328
- lookupVariable: typeof lookupVariable;
329
- hasVariableDependencyInLoadingState: typeof hasVariableDependencyInLoadingState;
330
- findObject: typeof findObject;
331
- };
332
-
333
264
  declare abstract class SceneObjectBase<TState extends SceneObjectState = SceneObjectState> implements SceneObject<TState> {
334
265
  private _isActive;
335
266
  private _state;
@@ -403,6 +334,77 @@ declare abstract class SceneObjectBase<TState extends SceneObjectState = SceneOb
403
334
  forEachChild(callback: (child: SceneObjectBase) => void): void;
404
335
  }
405
336
 
337
+ declare function cloneSceneObjectState<TState extends SceneObjectState>(sceneState: TState, withState?: Partial<TState>): TState;
338
+
339
+ declare abstract class RuntimeDataSource<TQuery extends DataQuery = DataQuery> extends DataSourceApi<TQuery> {
340
+ constructor(pluginId: string, uid: string);
341
+ testDatasource(): Promise<any>;
342
+ }
343
+ interface RuntimeDataSourceOptions {
344
+ dataSource: RuntimeDataSource;
345
+ }
346
+ /**
347
+ * Provides a way to register runtime panel plugins.
348
+ * Please use a pluginId that is unlikely to collide with other plugins.
349
+ */
350
+ declare function registerRuntimeDataSource({ dataSource }: RuntimeDataSourceOptions): void;
351
+
352
+ interface SceneObjectStateChangedPayload<TState extends SceneObjectState = SceneObjectState> {
353
+ prevState: TState;
354
+ newState: TState;
355
+ partialUpdate: Partial<TState>;
356
+ changedObject: SceneObject<TState>;
357
+ }
358
+ declare class SceneObjectStateChangedEvent extends BusEventWithPayload<SceneObjectStateChangedPayload> {
359
+ static readonly type = "scene-object-state-change";
360
+ }
361
+
362
+ /**
363
+ * Will walk the scene object graph up to the root looking for the first variable with the specified name
364
+ */
365
+ declare function lookupVariable(name: string, sceneObject: SceneObject): SceneVariable | null;
366
+
367
+ /**
368
+ * Will walk up the scene object graph to the closest $timeRange scene object
369
+ */
370
+ declare function getTimeRange(sceneObject: SceneObject): SceneTimeRangeLike;
371
+
372
+ /**
373
+ * Get the closest node with variables
374
+ */
375
+ declare function getVariables(sceneObject: SceneObject): SceneVariables;
376
+ /**
377
+ * Will walk up the scene object graph to the closest $data scene object
378
+ */
379
+ declare function getData(sceneObject: SceneObject): SceneDataProvider;
380
+ /**
381
+ * Will walk up the scene object graph to the closest $layout scene object
382
+ */
383
+ declare function getLayout(scene: SceneObject): SceneLayout;
384
+ /**
385
+ * Interpolates the given string using the current scene object as context. *
386
+ */
387
+ declare function interpolate(sceneObject: SceneObject, value: string | undefined | null, scopedVars?: ScopedVars, format?: string | VariableCustomFormatterFn): string;
388
+ /**
389
+ * Checks if the variable is currently loading or waiting to update
390
+ */
391
+ declare function hasVariableDependencyInLoadingState(sceneObject: SceneObject): boolean;
392
+ /**
393
+ * This will search the full scene graph, starting with the scene node passed in, then walking up the parent chain. *
394
+ */
395
+ declare function findObject(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject | null;
396
+
397
+ declare const sceneGraph: {
398
+ getVariables: typeof getVariables;
399
+ getData: typeof getData;
400
+ getTimeRange: typeof getTimeRange;
401
+ getLayout: typeof getLayout;
402
+ interpolate: typeof interpolate;
403
+ lookupVariable: typeof lookupVariable;
404
+ hasVariableDependencyInLoadingState: typeof hasVariableDependencyInLoadingState;
405
+ findObject: typeof findObject;
406
+ };
407
+
406
408
  interface VariableDependencyConfigOptions<TState extends SceneObjectState> {
407
409
  /**
408
410
  * State paths to scan / extract variable dependencies from. Leave empty to scan all paths.
@@ -1474,6 +1476,7 @@ declare const sceneUtils: {
1474
1476
  getUrlWithAppState: typeof getUrlWithAppState;
1475
1477
  registerRuntimePanelPlugin: typeof registerRuntimePanelPlugin;
1476
1478
  registerRuntimeDataSource: typeof registerRuntimeDataSource;
1479
+ cloneSceneObjectState: typeof cloneSceneObjectState;
1477
1480
  };
1478
1481
 
1479
1482
  export { CancelActivationHandler, ConstantVariable, CustomFormatterVariable, CustomTransformOperator, CustomVariable, CustomVariableValue, DataSourceVariable, DeepPartial, EmbeddedScene, EmbeddedSceneState, FormatVariable, InterpolationFormatParameter, NestedScene, PanelBuilders, QueryRunnerState, QueryVariable, RuntimeDataSource, SceneActivationHandler, SceneApp, SceneAppDrilldownView, SceneAppPage, SceneAppPageLike, SceneAppPageState, SceneAppRoute, SceneByFrameRepeater, SceneCanvasText, SceneComponent, SceneComponentProps, SceneControlsSpacer, SceneDataNode, SceneDataProvider, SceneDataState, SceneDataTransformer, SceneDeactivationHandler, SceneFlexItem, SceneFlexItemState, SceneFlexLayout, SceneGridItem, SceneGridLayout, SceneGridRow, SceneLayout, SceneLayoutChildOptions, SceneLayoutState, SceneObject, SceneObjectBase, SceneObjectRef, SceneObjectState, SceneObjectStateChangedEvent, SceneObjectStateChangedPayload, SceneObjectUrlSyncConfig, SceneObjectUrlSyncHandler, SceneObjectUrlValue, SceneObjectUrlValues, SceneObjectWithUrlSync, SceneQueryRunner, SceneReactObject, SceneRefreshPicker, SceneRouteMatch, SceneStateChangedHandler, SceneStatelessBehavior, SceneTimePicker, SceneTimeRange, SceneTimeRangeLike, SceneTimeRangeState, SceneTimeZoneOverride, SceneToolbarButton, SceneToolbarInput, SceneVariable, SceneVariableDependencyConfigLike, SceneVariableSet, SceneVariableSetState, SceneVariableState, SceneVariableValueChangedEvent, SceneVariables, SplitLayout, TestVariable, TextBoxVariable, UrlSyncManagerLike as UrlSyncManager, ValidateAndUpdateResult, VariableCustomFormatterFn, VariableDependencyConfig, VariableValue, VariableValueOption, VariableValueSelectors, VariableValueSingle, VizPanel, VizPanelMenu, VizPanelState, index as behaviors, formatRegistry, getUrlSyncManager, isCustomVariableValue, isSceneObject, registerRuntimeDataSource, sceneGraph, sceneUtils };
package/dist/index.js CHANGED
@@ -6,9 +6,9 @@ var React = require('react');
6
6
  var reactRouterDom = require('react-router-dom');
7
7
  var data = require('@grafana/data');
8
8
  var runtime = require('@grafana/runtime');
9
- var schema = require('@grafana/schema');
10
9
  var rxjs = require('rxjs');
11
10
  var uuid = require('uuid');
11
+ var schema = require('@grafana/schema');
12
12
  var lodash = require('lodash');
13
13
  var e2eSelectors = require('@grafana/e2e-selectors');
14
14
  var ui = require('@grafana/ui');
@@ -125,77 +125,6 @@ function loadPanelPluginSync(pluginId) {
125
125
  return (_a = getPanelPluginFromCache(pluginId)) != null ? _a : runtimePanelPlugins.get(pluginId);
126
126
  }
127
127
 
128
- class RuntimeDataSource extends data.DataSourceApi {
129
- constructor(pluginId, uid) {
130
- super({
131
- name: "RuntimeDataSource-" + pluginId,
132
- uid,
133
- type: pluginId,
134
- id: 1,
135
- readOnly: true,
136
- jsonData: {},
137
- access: "direct",
138
- meta: {
139
- id: pluginId,
140
- name: "RuntimeDataSource-" + pluginId,
141
- type: data.PluginType.datasource,
142
- info: {
143
- author: {
144
- name: ""
145
- },
146
- description: "",
147
- links: [],
148
- logos: {
149
- large: "",
150
- small: ""
151
- },
152
- screenshots: [],
153
- updated: "",
154
- version: ""
155
- },
156
- module: "",
157
- baseUrl: ""
158
- }
159
- });
160
- }
161
- testDatasource() {
162
- return Promise.resolve({});
163
- }
164
- }
165
- const runtimeDataSources = /* @__PURE__ */ new Map();
166
- function registerRuntimeDataSource({ dataSource }) {
167
- if (runtimeDataSources.has(dataSource.uid)) {
168
- throw new Error(`A runtime data source with uid ${dataSource.uid} has already been registered`);
169
- }
170
- runtimeDataSources.set(dataSource.uid, dataSource);
171
- }
172
-
173
- function isSceneObject(obj) {
174
- return obj.useState !== void 0;
175
- }
176
-
177
- class SceneObjectStateChangedEvent extends data.BusEventWithPayload {
178
- }
179
- SceneObjectStateChangedEvent.type = "scene-object-state-change";
180
-
181
- function lookupVariable(name, sceneObject) {
182
- const variables = sceneObject.state.$variables;
183
- if (!variables) {
184
- if (sceneObject.parent) {
185
- return lookupVariable(name, sceneObject.parent);
186
- } else {
187
- return null;
188
- }
189
- }
190
- const found = variables.getByName(name);
191
- if (found) {
192
- return found;
193
- } else if (sceneObject.parent) {
194
- return lookupVariable(name, sceneObject.parent);
195
- }
196
- return null;
197
- }
198
-
199
128
  var __defProp$q = Object.defineProperty;
200
129
  var __defProps$e = Object.defineProperties;
201
130
  var __getOwnPropDescs$e = Object.getOwnPropertyDescriptors;
@@ -248,6 +177,10 @@ function EmptyRenderer(_) {
248
177
  return null;
249
178
  }
250
179
 
180
+ class SceneObjectStateChangedEvent extends data.BusEventWithPayload {
181
+ }
182
+ SceneObjectStateChangedEvent.type = "scene-object-state-change";
183
+
251
184
  var __defProp$p = Object.defineProperty;
252
185
  var __getOwnPropSymbols$s = Object.getOwnPropertySymbols;
253
186
  var __hasOwnProp$s = Object.prototype.hasOwnProperty;
@@ -264,54 +197,6 @@ var __spreadValues$p = (a, b) => {
264
197
  }
265
198
  return a;
266
199
  };
267
- function cloneSceneObject(sceneObject, withState) {
268
- const clonedState = __spreadValues$p({}, sceneObject.state);
269
- for (const key in clonedState) {
270
- const propValue = clonedState[key];
271
- if (propValue instanceof SceneObjectBase) {
272
- clonedState[key] = propValue.clone();
273
- }
274
- if (Array.isArray(propValue)) {
275
- const newArray = [];
276
- for (const child of propValue) {
277
- if (child instanceof SceneObjectBase) {
278
- newArray.push(child.clone());
279
- } else {
280
- newArray.push(child);
281
- }
282
- }
283
- clonedState[key] = newArray;
284
- }
285
- }
286
- Object.assign(clonedState, withState);
287
- return new sceneObject.constructor(clonedState);
288
- }
289
- function getClosest(sceneObject, extract) {
290
- let curSceneObject = sceneObject;
291
- let extracted = void 0;
292
- while (curSceneObject && !extracted) {
293
- extracted = extract(curSceneObject);
294
- curSceneObject = curSceneObject.parent;
295
- }
296
- return extracted;
297
- }
298
-
299
- var __defProp$o = Object.defineProperty;
300
- var __getOwnPropSymbols$r = Object.getOwnPropertySymbols;
301
- var __hasOwnProp$r = Object.prototype.hasOwnProperty;
302
- var __propIsEnum$r = Object.prototype.propertyIsEnumerable;
303
- var __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
304
- var __spreadValues$o = (a, b) => {
305
- for (var prop in b || (b = {}))
306
- if (__hasOwnProp$r.call(b, prop))
307
- __defNormalProp$o(a, prop, b[prop]);
308
- if (__getOwnPropSymbols$r)
309
- for (var prop of __getOwnPropSymbols$r(b)) {
310
- if (__propIsEnum$r.call(b, prop))
311
- __defNormalProp$o(a, prop, b[prop]);
312
- }
313
- return a;
314
- };
315
200
  class SceneObjectBase {
316
201
  constructor(state) {
317
202
  this._isActive = false;
@@ -368,7 +253,7 @@ class SceneObjectBase {
368
253
  }
369
254
  setState(update) {
370
255
  const prevState = this._state;
371
- const newState = __spreadValues$o(__spreadValues$o({}, this._state), update);
256
+ const newState = __spreadValues$p(__spreadValues$p({}, this._state), update);
372
257
  this._state = Object.freeze(newState);
373
258
  this._setParent();
374
259
  this.publishEvent(
@@ -488,6 +373,125 @@ function useSceneObjectState(model) {
488
373
  return model.state;
489
374
  }
490
375
 
376
+ var __defProp$o = Object.defineProperty;
377
+ var __getOwnPropSymbols$r = Object.getOwnPropertySymbols;
378
+ var __hasOwnProp$r = Object.prototype.hasOwnProperty;
379
+ var __propIsEnum$r = Object.prototype.propertyIsEnumerable;
380
+ var __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
381
+ var __spreadValues$o = (a, b) => {
382
+ for (var prop in b || (b = {}))
383
+ if (__hasOwnProp$r.call(b, prop))
384
+ __defNormalProp$o(a, prop, b[prop]);
385
+ if (__getOwnPropSymbols$r)
386
+ for (var prop of __getOwnPropSymbols$r(b)) {
387
+ if (__propIsEnum$r.call(b, prop))
388
+ __defNormalProp$o(a, prop, b[prop]);
389
+ }
390
+ return a;
391
+ };
392
+ function cloneSceneObject(sceneObject, withState) {
393
+ const clonedState = cloneSceneObjectState(sceneObject.state, withState);
394
+ return new sceneObject.constructor(clonedState);
395
+ }
396
+ function cloneSceneObjectState(sceneState, withState) {
397
+ const clonedState = __spreadValues$o({}, sceneState);
398
+ for (const key in clonedState) {
399
+ const propValue = clonedState[key];
400
+ if (propValue instanceof SceneObjectBase) {
401
+ clonedState[key] = propValue.clone();
402
+ }
403
+ if (Array.isArray(propValue)) {
404
+ const newArray = [];
405
+ for (const child of propValue) {
406
+ if (child instanceof SceneObjectBase) {
407
+ newArray.push(child.clone());
408
+ } else {
409
+ newArray.push(child);
410
+ }
411
+ }
412
+ clonedState[key] = newArray;
413
+ }
414
+ }
415
+ Object.assign(clonedState, withState);
416
+ return clonedState;
417
+ }
418
+ function getClosest(sceneObject, extract) {
419
+ let curSceneObject = sceneObject;
420
+ let extracted = void 0;
421
+ while (curSceneObject && !extracted) {
422
+ extracted = extract(curSceneObject);
423
+ curSceneObject = curSceneObject.parent;
424
+ }
425
+ return extracted;
426
+ }
427
+
428
+ class RuntimeDataSource extends data.DataSourceApi {
429
+ constructor(pluginId, uid) {
430
+ super({
431
+ name: "RuntimeDataSource-" + pluginId,
432
+ uid,
433
+ type: pluginId,
434
+ id: 1,
435
+ readOnly: true,
436
+ jsonData: {},
437
+ access: "direct",
438
+ meta: {
439
+ id: pluginId,
440
+ name: "RuntimeDataSource-" + pluginId,
441
+ type: data.PluginType.datasource,
442
+ info: {
443
+ author: {
444
+ name: ""
445
+ },
446
+ description: "",
447
+ links: [],
448
+ logos: {
449
+ large: "",
450
+ small: ""
451
+ },
452
+ screenshots: [],
453
+ updated: "",
454
+ version: ""
455
+ },
456
+ module: "",
457
+ baseUrl: ""
458
+ }
459
+ });
460
+ }
461
+ testDatasource() {
462
+ return Promise.resolve({});
463
+ }
464
+ }
465
+ const runtimeDataSources = /* @__PURE__ */ new Map();
466
+ function registerRuntimeDataSource({ dataSource }) {
467
+ if (runtimeDataSources.has(dataSource.uid)) {
468
+ throw new Error(`A runtime data source with uid ${dataSource.uid} has already been registered`);
469
+ }
470
+ runtimeDataSources.set(dataSource.uid, dataSource);
471
+ }
472
+
473
+ function isSceneObject(obj) {
474
+ return obj.useState !== void 0;
475
+ }
476
+
477
+ function lookupVariable(name, sceneObject) {
478
+ const variables = sceneObject.state.$variables;
479
+ if (!variables) {
480
+ if (sceneObject.parent) {
481
+ return lookupVariable(name, sceneObject.parent);
482
+ } else {
483
+ return null;
484
+ }
485
+ }
486
+ const found = variables.getByName(name);
487
+ if (found) {
488
+ return found;
489
+ } else if (sceneObject.parent) {
490
+ return lookupVariable(name, sceneObject.parent);
491
+ }
492
+ return null;
493
+ }
494
+
491
495
  var __defProp$n = Object.defineProperty;
492
496
  var __getOwnPropSymbols$q = Object.getOwnPropertySymbols;
493
497
  var __hasOwnProp$q = Object.prototype.hasOwnProperty;
@@ -6578,7 +6582,8 @@ const PanelBuilders = {
6578
6582
  const sceneUtils = {
6579
6583
  getUrlWithAppState,
6580
6584
  registerRuntimePanelPlugin,
6581
- registerRuntimeDataSource
6585
+ registerRuntimeDataSource,
6586
+ cloneSceneObjectState
6582
6587
  };
6583
6588
 
6584
6589
  exports.ConstantVariable = ConstantVariable;