@grafana/scenes 6.28.3 → 6.28.4--canary.1196.16600049151.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.
@@ -21,13 +21,17 @@ const macrosIndex = /* @__PURE__ */ new Map([
21
21
  ["__interval", IntervalMacro],
22
22
  ["__interval_ms", IntervalMacro]
23
23
  ]);
24
- function registerVariableMacro(name, macro) {
25
- if (macrosIndex.get(name)) {
24
+ function registerVariableMacro(name, macro, replace = false) {
25
+ if (!replace && macrosIndex.get(name)) {
26
26
  throw new Error(`Macro already registered ${name}`);
27
27
  }
28
28
  macrosIndex.set(name, macro);
29
29
  return () => {
30
- macrosIndex.delete(name);
30
+ if (replace) {
31
+ throw new Error(`Replaced macros can not be unregistered. They need to be restored manually.`);
32
+ } else {
33
+ macrosIndex.delete(name);
34
+ }
31
35
  };
32
36
  }
33
37
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/variables/macros/index.ts"],"sourcesContent":["import { DataLinkBuiltInVars } from '@grafana/data';\nimport { MacroVariableConstructor } from './types';\nimport { IntervalMacro, TimeFromAndToMacro, TimezoneMacro, UrlTimeRangeMacro } from './timeMacros';\nimport { AllVariablesMacro } from './AllVariablesMacro';\nimport { DataMacro, FieldMacro, SeriesMacro, ValueMacro } from './dataMacros';\nimport { UrlMacro } from './urlMacros';\nimport { OrgMacro, UserMacro } from './contextMacros';\n\nexport const macrosIndex = new Map<string, MacroVariableConstructor>([\n [DataLinkBuiltInVars.includeVars, AllVariablesMacro],\n [DataLinkBuiltInVars.keepTime, UrlTimeRangeMacro],\n ['__value', ValueMacro],\n ['__data', DataMacro],\n ['__series', SeriesMacro],\n ['__field', FieldMacro],\n ['__url', UrlMacro],\n ['__from', TimeFromAndToMacro],\n ['__to', TimeFromAndToMacro],\n ['__timezone', TimezoneMacro],\n ['__user', UserMacro],\n ['__org', OrgMacro],\n ['__interval', IntervalMacro],\n ['__interval_ms', IntervalMacro],\n]);\n\n/**\n * Allows you to register a variable expression macro that can then be used in strings with syntax ${<macro_name>.<fieldPath>}\n * Call this on app activation and unregister the macro on deactivation.\n * @returns a function that unregisters the macro\n */\nexport function registerVariableMacro(name: string, macro: MacroVariableConstructor): () => void {\n if (macrosIndex.get(name)) {\n throw new Error(`Macro already registered ${name}`);\n }\n\n macrosIndex.set(name, macro);\n\n return () => {\n macrosIndex.delete(name);\n };\n}\n"],"names":[],"mappings":";;;;;;;AAQa,MAAA,WAAA,uBAAkB,GAAsC,CAAA;AAAA,EACnE,CAAC,mBAAoB,CAAA,WAAA,EAAa,iBAAiB,CAAA;AAAA,EACnD,CAAC,mBAAoB,CAAA,QAAA,EAAU,iBAAiB,CAAA;AAAA,EAChD,CAAC,WAAW,UAAU,CAAA;AAAA,EACtB,CAAC,UAAU,SAAS,CAAA;AAAA,EACpB,CAAC,YAAY,WAAW,CAAA;AAAA,EACxB,CAAC,WAAW,UAAU,CAAA;AAAA,EACtB,CAAC,SAAS,QAAQ,CAAA;AAAA,EAClB,CAAC,UAAU,kBAAkB,CAAA;AAAA,EAC7B,CAAC,QAAQ,kBAAkB,CAAA;AAAA,EAC3B,CAAC,cAAc,aAAa,CAAA;AAAA,EAC5B,CAAC,UAAU,SAAS,CAAA;AAAA,EACpB,CAAC,SAAS,QAAQ,CAAA;AAAA,EAClB,CAAC,cAAc,aAAa,CAAA;AAAA,EAC5B,CAAC,iBAAiB,aAAa;AACjC,CAAC;AAOe,SAAA,qBAAA,CAAsB,MAAc,KAA6C,EAAA;AAC/F,EAAI,IAAA,WAAA,CAAY,GAAI,CAAA,IAAI,CAAG,EAAA;AACzB,IAAA,MAAM,IAAI,KAAA,CAAM,CAA4B,yBAAA,EAAA,IAAI,CAAE,CAAA,CAAA;AAAA;AAGpD,EAAY,WAAA,CAAA,GAAA,CAAI,MAAM,KAAK,CAAA;AAE3B,EAAA,OAAO,MAAM;AACX,IAAA,WAAA,CAAY,OAAO,IAAI,CAAA;AAAA,GACzB;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/variables/macros/index.ts"],"sourcesContent":["import { DataLinkBuiltInVars } from '@grafana/data';\nimport { MacroVariableConstructor } from './types';\nimport { IntervalMacro, TimeFromAndToMacro, TimezoneMacro, UrlTimeRangeMacro } from './timeMacros';\nimport { AllVariablesMacro } from './AllVariablesMacro';\nimport { DataMacro, FieldMacro, SeriesMacro, ValueMacro } from './dataMacros';\nimport { UrlMacro } from './urlMacros';\nimport { OrgMacro, UserMacro } from './contextMacros';\n\nexport const macrosIndex = new Map<string, MacroVariableConstructor>([\n [DataLinkBuiltInVars.includeVars, AllVariablesMacro],\n [DataLinkBuiltInVars.keepTime, UrlTimeRangeMacro],\n ['__value', ValueMacro],\n ['__data', DataMacro],\n ['__series', SeriesMacro],\n ['__field', FieldMacro],\n ['__url', UrlMacro],\n ['__from', TimeFromAndToMacro],\n ['__to', TimeFromAndToMacro],\n ['__timezone', TimezoneMacro],\n ['__user', UserMacro],\n ['__org', OrgMacro],\n ['__interval', IntervalMacro],\n ['__interval_ms', IntervalMacro],\n]);\n\n/**\n * Allows you to register a variable expression macro that can then be used in strings with syntax ${<macro_name>.<fieldPath>}\n * Call this on app activation and unregister the macro on deactivation.\n * @param replace WARNING! If true, this will replace the existing macro with the same name. This is global and will affect all apps. Unregistering the macro will restore the original macro.\n * @returns a function that unregisters the macro\n */\nexport function registerVariableMacro(name: string, macro: MacroVariableConstructor, replace = false): () => void {\n if (!replace && macrosIndex.get(name)) {\n throw new Error(`Macro already registered ${name}`);\n }\n\n macrosIndex.set(name, macro);\n\n return () => {\n if (replace) {\n throw new Error(`Replaced macros can not be unregistered. They need to be restored manually.`);\n } else {\n macrosIndex.delete(name);\n }\n };\n}\n"],"names":[],"mappings":";;;;;;;AAQa,MAAA,WAAA,uBAAkB,GAAsC,CAAA;AAAA,EACnE,CAAC,mBAAoB,CAAA,WAAA,EAAa,iBAAiB,CAAA;AAAA,EACnD,CAAC,mBAAoB,CAAA,QAAA,EAAU,iBAAiB,CAAA;AAAA,EAChD,CAAC,WAAW,UAAU,CAAA;AAAA,EACtB,CAAC,UAAU,SAAS,CAAA;AAAA,EACpB,CAAC,YAAY,WAAW,CAAA;AAAA,EACxB,CAAC,WAAW,UAAU,CAAA;AAAA,EACtB,CAAC,SAAS,QAAQ,CAAA;AAAA,EAClB,CAAC,UAAU,kBAAkB,CAAA;AAAA,EAC7B,CAAC,QAAQ,kBAAkB,CAAA;AAAA,EAC3B,CAAC,cAAc,aAAa,CAAA;AAAA,EAC5B,CAAC,UAAU,SAAS,CAAA;AAAA,EACpB,CAAC,SAAS,QAAQ,CAAA;AAAA,EAClB,CAAC,cAAc,aAAa,CAAA;AAAA,EAC5B,CAAC,iBAAiB,aAAa;AACjC,CAAC;AAQM,SAAS,qBAAsB,CAAA,IAAA,EAAc,KAAiC,EAAA,OAAA,GAAU,KAAmB,EAAA;AAChH,EAAA,IAAI,CAAC,OAAA,IAAW,WAAY,CAAA,GAAA,CAAI,IAAI,CAAG,EAAA;AACrC,IAAA,MAAM,IAAI,KAAA,CAAM,CAA4B,yBAAA,EAAA,IAAI,CAAE,CAAA,CAAA;AAAA;AAGpD,EAAY,WAAA,CAAA,GAAA,CAAI,MAAM,KAAK,CAAA;AAE3B,EAAA,OAAO,MAAM;AACX,IAAA,IAAI,OAAS,EAAA;AACX,MAAM,MAAA,IAAI,MAAM,CAA6E,2EAAA,CAAA,CAAA;AAAA,KACxF,MAAA;AACL,MAAA,WAAA,CAAY,OAAO,IAAI,CAAA;AAAA;AACzB,GACF;AACF;;;;"}
package/dist/index.d.ts CHANGED
@@ -829,9 +829,10 @@ interface MacroVariableConstructor {
829
829
  /**
830
830
  * Allows you to register a variable expression macro that can then be used in strings with syntax ${<macro_name>.<fieldPath>}
831
831
  * Call this on app activation and unregister the macro on deactivation.
832
+ * @param replace WARNING! If true, this will replace the existing macro with the same name. This is global and will affect all apps. Unregistering the macro will restore the original macro.
832
833
  * @returns a function that unregisters the macro
833
834
  */
834
- declare function registerVariableMacro(name: string, macro: MacroVariableConstructor): () => void;
835
+ declare function registerVariableMacro(name: string, macro: MacroVariableConstructor, replace?: boolean): () => void;
835
836
 
836
837
  declare function renderPrometheusLabelFilters(filters: AdHocVariableFilter[]): string;
837
838
  declare function escapeLabelValueInExactSelector(labelValue: string): string;
package/dist/index.js CHANGED
@@ -2420,13 +2420,17 @@ const macrosIndex = /* @__PURE__ */ new Map([
2420
2420
  ["__interval", IntervalMacro],
2421
2421
  ["__interval_ms", IntervalMacro]
2422
2422
  ]);
2423
- function registerVariableMacro(name, macro) {
2424
- if (macrosIndex.get(name)) {
2423
+ function registerVariableMacro(name, macro, replace = false) {
2424
+ if (!replace && macrosIndex.get(name)) {
2425
2425
  throw new Error(`Macro already registered ${name}`);
2426
2426
  }
2427
2427
  macrosIndex.set(name, macro);
2428
2428
  return () => {
2429
- macrosIndex.delete(name);
2429
+ if (replace) {
2430
+ throw new Error(`Replaced macros can not be unregistered. They need to be restored manually.`);
2431
+ } else {
2432
+ macrosIndex.delete(name);
2433
+ }
2430
2434
  };
2431
2435
  }
2432
2436