1 | {"version":3,"file":"useCustomizationSettings.js","sourceRoot":"../src/","sources":["customizations/useCustomizationSettings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAa,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,UAAoB,EAAE,SAAkB;IAC/E,IAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAC7B,IAAA,mEAAc,CAAyC;IACvD,IAAA,wDAAmB,CAAoB;IAC/C,KAAK,CAAC,SAAS,CAAC;QACd,IAAI,CAAC,mBAAmB,EAAE;YACxB,cAAc,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;SACrC;QACD,OAAO;YACL,IAAI,CAAC,mBAAmB,EAAE;gBACxB,cAAc,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;aACvC;QACH,CAAC,CAAC;QACF,8EAA8E;IAChF,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAE1B,OAAO,cAAc,CAAC,WAAW,CAAC,UAAU,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,cAAc;IACf,IAAA,sBAAgC,EAA7B,gBAA6B,CAAC;IACvC,OAAO,cAAM,OAAA,QAAQ,CAAC,UAAA,KAAK,IAAI,OAAA,EAAE,KAAK,EAAP,CAAO,CAAC,EAA1B,CAA0B,CAAC;AAC1C,CAAC","sourcesContent":["import * as React from 'react';\nimport { ISettings, Customizations } from './Customizations';\nimport { CustomizerContext } from './CustomizerContext';\n\n/**\n * Hook to get Customizations settings from Customizations singleton or CustomizerContext.\n * It will trigger component state update on settings change observed.\n */\nexport function useCustomizationSettings(properties: string[], scopeName?: string): ISettings {\n const forceUpdate = useForceUpdate();\n const { customizations } = React.useContext(CustomizerContext);\n const { inCustomizerContext } = customizations;\n React.useEffect(() => {\n if (!inCustomizerContext) {\n Customizations.observe(forceUpdate);\n }\n return () => {\n if (!inCustomizerContext) {\n Customizations.unobserve(forceUpdate);\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- exclude forceUpdate\n }, [inCustomizerContext]);\n\n return Customizations.getSettings(properties, scopeName, customizations);\n}\n\nfunction useForceUpdate() {\n const [, setValue] = React.useState(0);\n return () => setValue(value => ++value);\n}\n"]} |