{"version":3,"file":"useStableProps.mjs","sources":["../../../../src/components/CodeMirror/useStableProps.ts"],"sourcesContent":["import { useRef } from 'react';\n\nimport { shallowCompare } from '@grafana/data';\n\nexport { useStableCallback } from '../../utils/useStableCallback';\n\nfunction isShallowEqual(a: unknown, b: unknown): boolean {\n  if (a === b) {\n    return true;\n  }\n\n  if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {\n    return false;\n  }\n\n  // An array must not compare equal to an object with matching indices.\n  if (Array.isArray(a) !== Array.isArray(b)) {\n    return false;\n  }\n\n  return shallowCompare(a, b);\n}\n\n/**\n * Returns the previous reference whenever `value` is shallow-equal to it.\n *\n * A new `extensions` or `basicSetup` identity makes `@uiw/react-codemirror`\n * reconfigure the whole editor, discarding extension state such as an open\n * completion popup. Call sites pass inline literals, so identity alone is too\n * eager a signal.\n */\nexport function useShallowStable<T>(value: T): T {\n  const stable = useRef(value);\n\n  // Safe during render: a repeated render derives the same reference.\n  if (!isShallowEqual(stable.current, value)) {\n    stable.current = value;\n  }\n\n  return stable.current;\n}\n"],"names":[],"mappings":";;;;;AAMA,SAAS,cAAA,CAAe,GAAY,CAAA,EAAqB;AACvD,EAAA,IAAI,MAAM,CAAA,EAAG;AACX,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,IAAI,OAAO,MAAM,QAAA,IAAY,OAAO,MAAM,QAAA,IAAY,CAAA,KAAM,IAAA,IAAQ,CAAA,KAAM,IAAA,EAAM;AAC9E,IAAA,OAAO,KAAA;AAAA,EACT;AAGA,EAAA,IAAI,MAAM,OAAA,CAAQ,CAAC,MAAM,KAAA,CAAM,OAAA,CAAQ,CAAC,CAAA,EAAG;AACzC,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,OAAO,cAAA,CAAe,GAAG,CAAC,CAAA;AAC5B;AAUO,SAAS,iBAAoB,KAAA,EAAa;AAC/C,EAAA,MAAM,MAAA,GAAS,OAAO,KAAK,CAAA;AAG3B,EAAA,IAAI,CAAC,cAAA,CAAe,MAAA,CAAO,OAAA,EAAS,KAAK,CAAA,EAAG;AAC1C,IAAA,MAAA,CAAO,OAAA,GAAU,KAAA;AAAA,EACnB;AAEA,EAAA,OAAO,MAAA,CAAO,OAAA;AAChB;;;;"}