You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
3.5 KiB

{"ast":null,"code":"import * as React from 'react';\nexport default function useDocumentTitle(ref) {\n var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref$enabled = _ref.enabled,\n enabled = _ref$enabled === void 0 ? true : _ref$enabled,\n _ref$formatter = _ref.formatter,\n formatter = _ref$formatter === void 0 ? function (options, route) {\n var _ref2;\n return (_ref2 = options === null || options === void 0 ? void 0 : options.title) != null ? _ref2 : route === null || route === void 0 ? void 0 : route.name;\n } : _ref$formatter;\n React.useEffect(function () {\n if (!enabled) {\n return;\n }\n var navigation = ref.current;\n if (navigation) {\n var title = formatter(navigation.getCurrentOptions(), navigation.getCurrentRoute());\n document.title = title;\n }\n return navigation === null || navigation === void 0 ? void 0 : navigation.addListener('options', function (e) {\n var title = formatter(e.data.options, navigation === null || navigation === void 0 ? void 0 : navigation.getCurrentRoute());\n document.title = title;\n });\n });\n}","map":{"version":3,"sources":["useDocumentTitle.tsx"],"names":["React","useDocumentTitle","ref","enabled","formatter","options","route","title","name","useEffect","navigation","current","getCurrentOptions","getCurrentRoute","document","addListener","e","data"],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAO9B,eAAe,SAASC,gBAAgB,CACtCC,GAA2D,EAK3D;EAJA,WAGuB,SAAA,CAAA,MAAA,GAAA,CAAA,IAAA,SAAA,CAAA,CAAA,CAAA,KAAA,SAAA,GAAA,SAAA,CAAA,CAAA,CAAA,GAAG,CAAC,CAAC;IAAA,oBAF1BC,OAAO;IAAPA,OAAO,6BAAG,IAAI;IAAA,sBACdC,SAAS;IAATA,SAAS,+BAAG,UAACC,OAAO,EAAEC,KAAK;MAAA;MAAA,gBAAK,OAAO,KAAA,IAAA,IAAP,OAAO,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAP,OAAO,CAAEC,KAAK,oBAAID,KAAK,KAAA,IAAA,IAALA,KAAK,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAALA,KAAK,CAAEE,IAAI;IAAA,CAAA;EAG/DR,KAAK,CAACS,SAAS,CAAC,YAAM;IACpB,IAAI,CAACN,OAAO,EAAE;MACZ;IACF;IAEA,IAAMO,UAAU,GAAGR,GAAG,CAACS,OAAO;IAE9B,IAAID,UAAU,EAAE;MACd,IAAMH,KAAK,GAAGH,SAAS,CACrBM,UAAU,CAACE,iBAAiB,EAAE,EAC9BF,UAAU,CAACG,eAAe,EAAE,CAC7B;MAEDC,QAAQ,CAACP,KAAK,GAAGA,KAAK;IACxB;IAEA,OAAOG,UAAU,KAAA,IAAA,IAAVA,UAAU,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAVA,UAAU,CAAEK,WAAW,CAAC,SAAS,EAAGC,UAAAA,CAAC,EAAK;MAC/C,IAAMT,KAAK,GAAGH,SAAS,CAACY,CAAC,CAACC,IAAI,CAACZ,OAAO,EAAEK,UAAU,KAAA,IAAA,IAAVA,UAAU,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAVA,UAAU,CAAEG,eAAe,EAAE,CAAC;MAEtEC,QAAQ,CAACP,KAAK,GAAGA,KAAK;IACxB,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ","sourceRoot":"../../src","sourcesContent":["import * as React from 'react';\n/**\n * Set the document title for the active screen\n */\nexport default function useDocumentTitle(ref) {\n let {\n enabled = true,\n formatter = (options, route) => (options === null || options === void 0 ? void 0 : options.title) ?? (route === null || route === void 0 ? void 0 : route.name)\n } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n const navigation = ref.current;\n if (navigation) {\n const title = formatter(navigation.getCurrentOptions(), navigation.getCurrentRoute());\n document.title = title;\n }\n return navigation === null || navigation === void 0 ? void 0 : navigation.addListener('options', e => {\n const title = formatter(e.data.options, navigation === null || navigation === void 0 ? void 0 : navigation.getCurrentRoute());\n document.title = title;\n });\n });\n}\n//# sourceMappingURL=useDocumentTitle.js.map"]},"metadata":{},"sourceType":"module"}