@grafana/plugin-ui 0.10.9 → 0.10.10

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.
@@ -2880,6 +2880,18 @@ const standardSQLLanguageDefinition = {
2880
2880
  completionProvider: getStandardSQLCompletionProvider
2881
2881
  };
2882
2882
 
2883
+ function useLatestCallback(callback) {
2884
+ const ref = React.useRef(callback);
2885
+ React.useEffect(() => {
2886
+ ref.current = callback;
2887
+ });
2888
+ const hasCallback = Boolean(callback);
2889
+ return React.useMemo(
2890
+ () => hasCallback ? (...args) => ref.current(...args) : undefined,
2891
+ [hasCallback]
2892
+ );
2893
+ }
2894
+
2883
2895
  const STANDARD_SQL_LANGUAGE = "sql";
2884
2896
  const LANGUAGES_CACHE = /* @__PURE__ */ new Map();
2885
2897
  const INSTANCE_CACHE = /* @__PURE__ */ new Map();
@@ -2894,6 +2906,7 @@ const SQLEditor = ({
2894
2906
  }) => {
2895
2907
  const monacoRef = React.useRef(null);
2896
2908
  const langUid = React.useRef();
2909
+ const stableOnChange = useLatestCallback(onChange);
2897
2910
  const id = React.useMemo(() => {
2898
2911
  const uid = uuid.v4();
2899
2912
  const id2 = `${language.id}-${uid}`;
@@ -2914,7 +2927,7 @@ const SQLEditor = ({
2914
2927
  }
2915
2928
  }, []);
2916
2929
  const onSqlBlur = (text) => {
2917
- onChange && onChange(text, false);
2930
+ stableOnChange && stableOnChange(text, false);
2918
2931
  onBlur && onBlur(text);
2919
2932
  };
2920
2933
  return /* @__PURE__ */ React__namespace.default.createElement("div", { style: { width } }, /* @__PURE__ */ React__namespace.default.createElement(
@@ -2931,14 +2944,14 @@ const SQLEditor = ({
2931
2944
  monacoRef.current = editor;
2932
2945
  editor.onDidChangeModelContent((e) => {
2933
2946
  const text = editor.getValue();
2934
- if (onChange) {
2935
- onChange(text, false);
2947
+ if (stableOnChange) {
2948
+ stableOnChange(text, false);
2936
2949
  }
2937
2950
  });
2938
2951
  editor.addCommand(m.KeyMod.CtrlCmd | m.KeyCode.Enter, () => {
2939
2952
  const text = editor.getValue();
2940
- if (onChange) {
2941
- onChange(text, true);
2953
+ if (stableOnChange) {
2954
+ stableOnChange(text, true);
2942
2955
  }
2943
2956
  });
2944
2957
  editor.onKeyUp((e) => {