@ndla/safelink 7.0.132-alpha.0 → 7.0.133-alpha.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.
@@ -1 +1 @@
1
- {"version":3,"file":"MissingRouterContext.mjs","names":[],"sources":["../src/MissingRouterContext.ts"],"sourcesContent":["/**\n * Copyright (c) 2019-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { createContext } from \"react\";\n\nexport const MissingRouterContext = createContext(false);\n"],"mappings":";;;;;;;;;AAUA,MAAa,uBAAuB,cAAc,MAAM"}
1
+ {"version":3,"file":"MissingRouterContext.mjs","names":[],"sources":["../src/MissingRouterContext.ts"],"sourcesContent":["/**\n * Copyright (c) 2019-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { createContext } from \"react\";\n\nexport const MissingRouterContext = createContext(false);\n"],"mappings":";;;;;;;;;AAUA,MAAa,uBAAuB,cAAc,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"SafeLink.mjs","names":[],"sources":["../src/SafeLink.tsx"],"sourcesContent":["/**\n * Copyright (c) 2019-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport type { StyledProps } from \"@ndla/styled-system/types\";\nimport { forwardRef, useContext, type RefObject } from \"react\";\nimport { Link, type LinkProps } from \"react-router\";\nimport { MissingRouterContext } from \"./MissingRouterContext\";\n\nconst oldNdlaRegex = /(.*)\\/?node\\/(\\d+).*/;\n\nconst isExternalLink = (to?: LinkProps[\"to\"]) =>\n typeof to === \"string\" &&\n (to.startsWith(\"https://\") || to.startsWith(\"http://\") || to.startsWith(\"mailto:\") || to.endsWith(\".xml\"));\n\nexport const isOldNdlaLink = (to?: LinkProps[\"to\"]) => typeof to === \"string\" && to.match(oldNdlaRegex) !== null;\n\nexport interface SafeLinkProps extends LinkProps, StyledProps {\n ref?: RefObject<HTMLAnchorElement | null>;\n asAnchor?: boolean;\n disabled?: boolean;\n unstyled?: boolean;\n}\n\nconst StyledLink = styled(Link, {}, { baseComponent: true });\n\n// Fallback to normal link if app is missing RouterContext, link is external or is old ndla link\n\nexport const SafeLink = forwardRef<HTMLAnchorElement, SafeLinkProps>(\n ({ to, replace, state, disabled, unstyled, children, tabIndex, asAnchor, reloadDocument, ...rest }, ref) => {\n const isMissingRouterContext = useContext(MissingRouterContext);\n const unstyledProps = unstyled ? { \"data-unstyled\": \"\" } : {};\n\n if (isMissingRouterContext || isExternalLink(to) || isOldNdlaLink(to) || asAnchor || disabled) {\n const href = typeof to === \"string\" ? to : \"#\";\n return (\n <styled.a\n href={disabled ? undefined : href}\n role={disabled ? \"link\" : undefined}\n aria-disabled={disabled}\n ref={ref}\n tabIndex={tabIndex}\n {...unstyledProps}\n {...rest}\n >\n {children}\n </styled.a>\n );\n }\n\n return (\n // RR6 link immediately fails if to is somehow undefined, so we provide an empty fallback to recover.\n <StyledLink\n ref={ref}\n tabIndex={tabIndex ?? 0}\n to={to ?? \"\"}\n state={state}\n reloadDocument={reloadDocument}\n replace={replace}\n {...unstyledProps}\n {...rest}\n >\n {children}\n </StyledLink>\n );\n },\n);\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAM,eAAe;AAErB,MAAM,kBAAkB,OACtB,OAAO,OAAO,aACb,GAAG,WAAW,WAAW,IAAI,GAAG,WAAW,UAAU,IAAI,GAAG,WAAW,UAAU,IAAI,GAAG,SAAS,OAAO;AAE3G,MAAa,iBAAiB,OAAyB,OAAO,OAAO,YAAY,GAAG,MAAM,aAAa,KAAK;AAS5G,MAAM,aAAa,OAAO,MAAM,EAAE,EAAE,EAAE,eAAe,MAAM,CAAC;AAI5D,MAAa,WAAW,YACrB,EAAE,IAAI,SAAS,OAAO,UAAU,UAAU,UAAU,UAAU,UAAU,gBAAgB,GAAG,QAAQ,QAAQ;CAC1G,MAAM,yBAAyB,WAAW,qBAAqB;CAC/D,MAAM,gBAAgB,WAAW,EAAE,iBAAiB,IAAI,GAAG,EAAE;AAE7D,KAAI,0BAA0B,eAAe,GAAG,IAAI,cAAc,GAAG,IAAI,YAAY,UAAU;EAC7F,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK;AAC3C,SACE,oBAAC,OAAO,GAAR;GACE,MAAM,WAAW,KAAA,IAAY;GAC7B,MAAM,WAAW,SAAS,KAAA;GAC1B,iBAAe;GACV;GACK;GACV,GAAI;GACJ,GAAI;GAEH;GACQ,CAAA;;AAIf,QAEE,oBAAC,YAAD;EACO;EACL,UAAU,YAAY;EACtB,IAAI,MAAM;EACH;EACS;EACP;EACT,GAAI;EACJ,GAAI;EAEH;EACU,CAAA;EAGlB"}
1
+ {"version":3,"file":"SafeLink.mjs","names":[],"sources":["../src/SafeLink.tsx"],"sourcesContent":["/**\n * Copyright (c) 2019-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport type { StyledProps } from \"@ndla/styled-system/types\";\nimport { forwardRef, useContext, type RefObject } from \"react\";\nimport { Link, type LinkProps } from \"react-router\";\nimport { MissingRouterContext } from \"./MissingRouterContext\";\n\nconst oldNdlaRegex = /(.*)\\/?node\\/(\\d+).*/;\n\nconst isExternalLink = (to?: LinkProps[\"to\"]) =>\n typeof to === \"string\" &&\n (to.startsWith(\"https://\") || to.startsWith(\"http://\") || to.startsWith(\"mailto:\") || to.endsWith(\".xml\"));\n\nexport const isOldNdlaLink = (to?: LinkProps[\"to\"]) => typeof to === \"string\" && to.match(oldNdlaRegex) !== null;\n\nexport interface SafeLinkProps extends LinkProps, StyledProps {\n ref?: RefObject<HTMLAnchorElement | null>;\n asAnchor?: boolean;\n disabled?: boolean;\n unstyled?: boolean;\n}\n\nconst StyledLink = styled(Link, {}, { baseComponent: true });\n\n// Fallback to normal link if app is missing RouterContext, link is external or is old ndla link\n\nexport const SafeLink = forwardRef<HTMLAnchorElement, SafeLinkProps>(\n ({ to, replace, state, disabled, unstyled, children, tabIndex, asAnchor, reloadDocument, ...rest }, ref) => {\n const isMissingRouterContext = useContext(MissingRouterContext);\n const unstyledProps = unstyled ? { \"data-unstyled\": \"\" } : {};\n\n if (isMissingRouterContext || isExternalLink(to) || isOldNdlaLink(to) || asAnchor || disabled) {\n const href = typeof to === \"string\" ? to : \"#\";\n return (\n <styled.a\n href={disabled ? undefined : href}\n role={disabled ? \"link\" : undefined}\n aria-disabled={disabled}\n ref={ref}\n tabIndex={tabIndex}\n {...unstyledProps}\n {...rest}\n >\n {children}\n </styled.a>\n );\n }\n\n return (\n // RR6 link immediately fails if to is somehow undefined, so we provide an empty fallback to recover.\n <StyledLink\n ref={ref}\n tabIndex={tabIndex ?? 0}\n to={to ?? \"\"}\n state={state}\n reloadDocument={reloadDocument}\n replace={replace}\n {...unstyledProps}\n {...rest}\n >\n {children}\n </StyledLink>\n );\n },\n);\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAM,eAAe;AAErB,MAAM,kBAAkB,OACtB,OAAO,OAAO,aACb,GAAG,WAAW,UAAU,KAAK,GAAG,WAAW,SAAS,KAAK,GAAG,WAAW,SAAS,KAAK,GAAG,SAAS,MAAM;AAE1G,MAAa,iBAAiB,OAAyB,OAAO,OAAO,YAAY,GAAG,MAAM,YAAY,MAAM;AAS5G,MAAM,aAAa,OAAO,MAAM,CAAC,GAAG,EAAE,eAAe,KAAK,CAAC;AAI3D,MAAa,WAAW,YACrB,EAAE,IAAI,SAAS,OAAO,UAAU,UAAU,UAAU,UAAU,UAAU,gBAAgB,GAAG,QAAQ,QAAQ;CAC1G,MAAM,yBAAyB,WAAW,oBAAoB;CAC9D,MAAM,gBAAgB,WAAW,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAE5D,IAAI,0BAA0B,eAAe,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,UAAU;EAC7F,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK;EAC3C,OACE,oBAAC,OAAO,GAAR;GACE,MAAM,WAAW,KAAA,IAAY;GAC7B,MAAM,WAAW,SAAS,KAAA;GAC1B,iBAAe;GACV;GACK;GACV,GAAI;GACJ,GAAI;GAEH;EACO,CAAA;CAEd;CAEA,OAEE,oBAAC,YAAD;EACO;EACL,UAAU,YAAY;EACtB,IAAI,MAAM;EACH;EACS;EACP;EACT,GAAI;EACJ,GAAI;EAEH;CACS,CAAA;AAEhB,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"SafeLinkButton.mjs","names":[],"sources":["../src/SafeLinkButton.tsx"],"sourcesContent":["/**\n * Copyright (c) 2019-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { buttonBaseRecipe, buttonRecipe, type ButtonVariantProps } from \"@ndla/primitives\";\nimport { css } from \"@ndla/styled-system/css\";\nimport { forwardRef, type ReactNode } from \"react\";\nimport { SafeLink, type SafeLinkProps } from \"./SafeLink\";\n\nexport interface SafeLinkButtonProps extends SafeLinkProps, ButtonVariantProps {\n children: ReactNode;\n}\n\nexport const SafeLinkButton = forwardRef<HTMLAnchorElement, SafeLinkButtonProps>(\n ({ variant, size, css: cssProp, ...props }, ref) => (\n <SafeLink\n {...props}\n css={css.raw(\n buttonBaseRecipe.raw({ variant }),\n variant !== \"link\" ? buttonRecipe.raw({ size }) : undefined,\n cssProp,\n )}\n ref={ref}\n />\n ),\n);\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAa,iBAAiB,YAC3B,EAAE,SAAS,MAAM,KAAK,SAAS,GAAG,SAAS,QAC1C,oBAAC,UAAD;CACE,GAAI;CACJ,KAAK,IAAI,IACP,iBAAiB,IAAI,EAAE,SAAS,CAAC,EACjC,YAAY,SAAS,aAAa,IAAI,EAAE,MAAM,CAAC,GAAG,KAAA,GAClD,QACD;CACI;CACL,CAAA,CAEL"}
1
+ {"version":3,"file":"SafeLinkButton.mjs","names":[],"sources":["../src/SafeLinkButton.tsx"],"sourcesContent":["/**\n * Copyright (c) 2019-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { buttonBaseRecipe, buttonRecipe, type ButtonVariantProps } from \"@ndla/primitives\";\nimport { css } from \"@ndla/styled-system/css\";\nimport { forwardRef, type ReactNode } from \"react\";\nimport { SafeLink, type SafeLinkProps } from \"./SafeLink\";\n\nexport interface SafeLinkButtonProps extends SafeLinkProps, ButtonVariantProps {\n children: ReactNode;\n}\n\nexport const SafeLinkButton = forwardRef<HTMLAnchorElement, SafeLinkButtonProps>(\n ({ variant, size, css: cssProp, ...props }, ref) => (\n <SafeLink\n {...props}\n css={css.raw(\n buttonBaseRecipe.raw({ variant }),\n variant !== \"link\" ? buttonRecipe.raw({ size }) : undefined,\n cssProp,\n )}\n ref={ref}\n />\n ),\n);\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAa,iBAAiB,YAC3B,EAAE,SAAS,MAAM,KAAK,SAAS,GAAG,SAAS,QAC1C,oBAAC,UAAD;CACE,GAAI;CACJ,KAAK,IAAI,IACP,iBAAiB,IAAI,EAAE,QAAQ,CAAC,GAChC,YAAY,SAAS,aAAa,IAAI,EAAE,KAAK,CAAC,IAAI,KAAA,GAClD,OACF;CACK;AACN,CAAA,CAEL"}
@@ -1 +1 @@
1
- {"version":3,"file":"SafeLinkIconButton.mjs","names":[],"sources":["../src/SafeLinkIconButton.tsx"],"sourcesContent":["/**\n * Copyright (c) 2022-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { buttonBaseRecipe, iconButtonRecipe, type IconButtonVariantProps } from \"@ndla/primitives\";\nimport { css } from \"@ndla/styled-system/css\";\nimport { forwardRef, type ReactNode } from \"react\";\nimport { SafeLink, type SafeLinkProps } from \"./SafeLink\";\n\nexport interface SafeLinkIconButtonProps extends SafeLinkProps, IconButtonVariantProps {\n children: ReactNode;\n}\n\nexport const SafeLinkIconButton = forwardRef<HTMLAnchorElement, SafeLinkIconButtonProps>(\n ({ variant, size, css: cssProp, ...props }, ref) => (\n <SafeLink\n {...props}\n css={css.raw(buttonBaseRecipe.raw({ variant }), iconButtonRecipe.raw({ size }), cssProp)}\n ref={ref}\n />\n ),\n);\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAa,qBAAqB,YAC/B,EAAE,SAAS,MAAM,KAAK,SAAS,GAAG,SAAS,QAC1C,oBAAC,UAAD;CACE,GAAI;CACJ,KAAK,IAAI,IAAI,iBAAiB,IAAI,EAAE,SAAS,CAAC,EAAE,iBAAiB,IAAI,EAAE,MAAM,CAAC,EAAE,QAAQ;CACnF;CACL,CAAA,CAEL"}
1
+ {"version":3,"file":"SafeLinkIconButton.mjs","names":[],"sources":["../src/SafeLinkIconButton.tsx"],"sourcesContent":["/**\n * Copyright (c) 2022-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { buttonBaseRecipe, iconButtonRecipe, type IconButtonVariantProps } from \"@ndla/primitives\";\nimport { css } from \"@ndla/styled-system/css\";\nimport { forwardRef, type ReactNode } from \"react\";\nimport { SafeLink, type SafeLinkProps } from \"./SafeLink\";\n\nexport interface SafeLinkIconButtonProps extends SafeLinkProps, IconButtonVariantProps {\n children: ReactNode;\n}\n\nexport const SafeLinkIconButton = forwardRef<HTMLAnchorElement, SafeLinkIconButtonProps>(\n ({ variant, size, css: cssProp, ...props }, ref) => (\n <SafeLink\n {...props}\n css={css.raw(buttonBaseRecipe.raw({ variant }), iconButtonRecipe.raw({ size }), cssProp)}\n ref={ref}\n />\n ),\n);\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAa,qBAAqB,YAC/B,EAAE,SAAS,MAAM,KAAK,SAAS,GAAG,SAAS,QAC1C,oBAAC,UAAD;CACE,GAAI;CACJ,KAAK,IAAI,IAAI,iBAAiB,IAAI,EAAE,QAAQ,CAAC,GAAG,iBAAiB,IAAI,EAAE,KAAK,CAAC,GAAG,OAAO;CAClF;AACN,CAAA,CAEL"}
@@ -1 +1 @@
1
- {"version":3,"file":"MissingRouterContext.js","names":[],"sources":["../src/MissingRouterContext.ts"],"sourcesContent":["/**\n * Copyright (c) 2019-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { createContext } from \"react\";\n\nexport const MissingRouterContext = createContext(false);\n"],"mappings":";;;;;;;;AAUA,MAAa,wBAAA,mBAAA,CAAA,eAAqC,MAAM"}
1
+ {"version":3,"file":"MissingRouterContext.js","names":[],"sources":["../src/MissingRouterContext.ts"],"sourcesContent":["/**\n * Copyright (c) 2019-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { createContext } from \"react\";\n\nexport const MissingRouterContext = createContext(false);\n"],"mappings":";;;;;;;;AAUA,MAAa,wBAAA,kBAAA,EAAA,eAAqC,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"SafeLink.js","names":["Link","MissingRouterContext","styled"],"sources":["../src/SafeLink.tsx"],"sourcesContent":["/**\n * Copyright (c) 2019-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport type { StyledProps } from \"@ndla/styled-system/types\";\nimport { forwardRef, useContext, type RefObject } from \"react\";\nimport { Link, type LinkProps } from \"react-router\";\nimport { MissingRouterContext } from \"./MissingRouterContext\";\n\nconst oldNdlaRegex = /(.*)\\/?node\\/(\\d+).*/;\n\nconst isExternalLink = (to?: LinkProps[\"to\"]) =>\n typeof to === \"string\" &&\n (to.startsWith(\"https://\") || to.startsWith(\"http://\") || to.startsWith(\"mailto:\") || to.endsWith(\".xml\"));\n\nexport const isOldNdlaLink = (to?: LinkProps[\"to\"]) => typeof to === \"string\" && to.match(oldNdlaRegex) !== null;\n\nexport interface SafeLinkProps extends LinkProps, StyledProps {\n ref?: RefObject<HTMLAnchorElement | null>;\n asAnchor?: boolean;\n disabled?: boolean;\n unstyled?: boolean;\n}\n\nconst StyledLink = styled(Link, {}, { baseComponent: true });\n\n// Fallback to normal link if app is missing RouterContext, link is external or is old ndla link\n\nexport const SafeLink = forwardRef<HTMLAnchorElement, SafeLinkProps>(\n ({ to, replace, state, disabled, unstyled, children, tabIndex, asAnchor, reloadDocument, ...rest }, ref) => {\n const isMissingRouterContext = useContext(MissingRouterContext);\n const unstyledProps = unstyled ? { \"data-unstyled\": \"\" } : {};\n\n if (isMissingRouterContext || isExternalLink(to) || isOldNdlaLink(to) || asAnchor || disabled) {\n const href = typeof to === \"string\" ? to : \"#\";\n return (\n <styled.a\n href={disabled ? undefined : href}\n role={disabled ? \"link\" : undefined}\n aria-disabled={disabled}\n ref={ref}\n tabIndex={tabIndex}\n {...unstyledProps}\n {...rest}\n >\n {children}\n </styled.a>\n );\n }\n\n return (\n // RR6 link immediately fails if to is somehow undefined, so we provide an empty fallback to recover.\n <StyledLink\n ref={ref}\n tabIndex={tabIndex ?? 0}\n to={to ?? \"\"}\n state={state}\n reloadDocument={reloadDocument}\n replace={replace}\n {...unstyledProps}\n {...rest}\n >\n {children}\n </StyledLink>\n );\n },\n);\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAM,eAAe;AAErB,MAAM,kBAAkB,OACtB,OAAO,OAAO,aACb,GAAG,WAAW,WAAW,IAAI,GAAG,WAAW,UAAU,IAAI,GAAG,WAAW,UAAU,IAAI,GAAG,SAAS,OAAO;AAE3G,MAAa,iBAAiB,OAAyB,OAAO,OAAO,YAAY,GAAG,MAAM,aAAa,KAAK;AAS5G,MAAM,cAAA,GAAA,wBAAA,QAAoBA,aAAAA,MAAM,EAAE,EAAE,EAAE,eAAe,MAAM,CAAC;AAI5D,MAAa,YAAA,GAAA,MAAA,aACV,EAAE,IAAI,SAAS,OAAO,UAAU,UAAU,UAAU,UAAU,UAAU,gBAAgB,GAAG,QAAQ,QAAQ;CAC1G,MAAM,0BAAA,GAAA,MAAA,YAAoCC,6BAAAA,qBAAqB;CAC/D,MAAM,gBAAgB,WAAW,EAAE,iBAAiB,IAAI,GAAG,EAAE;AAE7D,KAAI,0BAA0B,eAAe,GAAG,IAAI,cAAc,GAAG,IAAI,YAAY,UAAU;EAC7F,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK;AAC3C,SACE,iBAAA,GAAA,kBAAA,KAACC,wBAAAA,OAAO,GAAR;GACE,MAAM,WAAW,KAAA,IAAY;GAC7B,MAAM,WAAW,SAAS,KAAA;GAC1B,iBAAe;GACV;GACK;GACV,GAAI;GACJ,GAAI;GAEH;GACQ,CAAA;;AAIf,QAEE,iBAAA,GAAA,kBAAA,KAAC,YAAD;EACO;EACL,UAAU,YAAY;EACtB,IAAI,MAAM;EACH;EACS;EACP;EACT,GAAI;EACJ,GAAI;EAEH;EACU,CAAA;EAGlB"}
1
+ {"version":3,"file":"SafeLink.js","names":["Link","MissingRouterContext","styled"],"sources":["../src/SafeLink.tsx"],"sourcesContent":["/**\n * Copyright (c) 2019-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport type { StyledProps } from \"@ndla/styled-system/types\";\nimport { forwardRef, useContext, type RefObject } from \"react\";\nimport { Link, type LinkProps } from \"react-router\";\nimport { MissingRouterContext } from \"./MissingRouterContext\";\n\nconst oldNdlaRegex = /(.*)\\/?node\\/(\\d+).*/;\n\nconst isExternalLink = (to?: LinkProps[\"to\"]) =>\n typeof to === \"string\" &&\n (to.startsWith(\"https://\") || to.startsWith(\"http://\") || to.startsWith(\"mailto:\") || to.endsWith(\".xml\"));\n\nexport const isOldNdlaLink = (to?: LinkProps[\"to\"]) => typeof to === \"string\" && to.match(oldNdlaRegex) !== null;\n\nexport interface SafeLinkProps extends LinkProps, StyledProps {\n ref?: RefObject<HTMLAnchorElement | null>;\n asAnchor?: boolean;\n disabled?: boolean;\n unstyled?: boolean;\n}\n\nconst StyledLink = styled(Link, {}, { baseComponent: true });\n\n// Fallback to normal link if app is missing RouterContext, link is external or is old ndla link\n\nexport const SafeLink = forwardRef<HTMLAnchorElement, SafeLinkProps>(\n ({ to, replace, state, disabled, unstyled, children, tabIndex, asAnchor, reloadDocument, ...rest }, ref) => {\n const isMissingRouterContext = useContext(MissingRouterContext);\n const unstyledProps = unstyled ? { \"data-unstyled\": \"\" } : {};\n\n if (isMissingRouterContext || isExternalLink(to) || isOldNdlaLink(to) || asAnchor || disabled) {\n const href = typeof to === \"string\" ? to : \"#\";\n return (\n <styled.a\n href={disabled ? undefined : href}\n role={disabled ? \"link\" : undefined}\n aria-disabled={disabled}\n ref={ref}\n tabIndex={tabIndex}\n {...unstyledProps}\n {...rest}\n >\n {children}\n </styled.a>\n );\n }\n\n return (\n // RR6 link immediately fails if to is somehow undefined, so we provide an empty fallback to recover.\n <StyledLink\n ref={ref}\n tabIndex={tabIndex ?? 0}\n to={to ?? \"\"}\n state={state}\n reloadDocument={reloadDocument}\n replace={replace}\n {...unstyledProps}\n {...rest}\n >\n {children}\n </StyledLink>\n );\n },\n);\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAM,eAAe;AAErB,MAAM,kBAAkB,OACtB,OAAO,OAAO,aACb,GAAG,WAAW,UAAU,KAAK,GAAG,WAAW,SAAS,KAAK,GAAG,WAAW,SAAS,KAAK,GAAG,SAAS,MAAM;AAE1G,MAAa,iBAAiB,OAAyB,OAAO,OAAO,YAAY,GAAG,MAAM,YAAY,MAAM;AAS5G,MAAM,cAAA,GAAA,wBAAA,QAAoBA,aAAAA,MAAM,CAAC,GAAG,EAAE,eAAe,KAAK,CAAC;AAI3D,MAAa,YAAA,GAAA,MAAA,aACV,EAAE,IAAI,SAAS,OAAO,UAAU,UAAU,UAAU,UAAU,UAAU,gBAAgB,GAAG,QAAQ,QAAQ;CAC1G,MAAM,0BAAA,GAAA,MAAA,YAAoCC,6BAAAA,oBAAoB;CAC9D,MAAM,gBAAgB,WAAW,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAE5D,IAAI,0BAA0B,eAAe,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,UAAU;EAC7F,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK;EAC3C,OACE,iBAAA,GAAA,kBAAA,KAACC,wBAAAA,OAAO,GAAR;GACE,MAAM,WAAW,KAAA,IAAY;GAC7B,MAAM,WAAW,SAAS,KAAA;GAC1B,iBAAe;GACV;GACK;GACV,GAAI;GACJ,GAAI;GAEH;EACO,CAAA;CAEd;CAEA,OAEE,iBAAA,GAAA,kBAAA,KAAC,YAAD;EACO;EACL,UAAU,YAAY;EACtB,IAAI,MAAM;EACH;EACS;EACP;EACT,GAAI;EACJ,GAAI;EAEH;CACS,CAAA;AAEhB,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"SafeLinkButton.js","names":["SafeLink","css","buttonBaseRecipe","buttonRecipe"],"sources":["../src/SafeLinkButton.tsx"],"sourcesContent":["/**\n * Copyright (c) 2019-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { buttonBaseRecipe, buttonRecipe, type ButtonVariantProps } from \"@ndla/primitives\";\nimport { css } from \"@ndla/styled-system/css\";\nimport { forwardRef, type ReactNode } from \"react\";\nimport { SafeLink, type SafeLinkProps } from \"./SafeLink\";\n\nexport interface SafeLinkButtonProps extends SafeLinkProps, ButtonVariantProps {\n children: ReactNode;\n}\n\nexport const SafeLinkButton = forwardRef<HTMLAnchorElement, SafeLinkButtonProps>(\n ({ variant, size, css: cssProp, ...props }, ref) => (\n <SafeLink\n {...props}\n css={css.raw(\n buttonBaseRecipe.raw({ variant }),\n variant !== \"link\" ? buttonRecipe.raw({ size }) : undefined,\n cssProp,\n )}\n ref={ref}\n />\n ),\n);\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAa,kBAAA,GAAA,MAAA,aACV,EAAE,SAAS,MAAM,KAAK,SAAS,GAAG,SAAS,QAC1C,iBAAA,GAAA,kBAAA,KAACA,iBAAAA,UAAD;CACE,GAAI;CACJ,KAAKC,wBAAAA,IAAI,IACPC,iBAAAA,iBAAiB,IAAI,EAAE,SAAS,CAAC,EACjC,YAAY,SAASC,iBAAAA,aAAa,IAAI,EAAE,MAAM,CAAC,GAAG,KAAA,GAClD,QACD;CACI;CACL,CAAA,CAEL"}
1
+ {"version":3,"file":"SafeLinkButton.js","names":["SafeLink","css","buttonBaseRecipe","buttonRecipe"],"sources":["../src/SafeLinkButton.tsx"],"sourcesContent":["/**\n * Copyright (c) 2019-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { buttonBaseRecipe, buttonRecipe, type ButtonVariantProps } from \"@ndla/primitives\";\nimport { css } from \"@ndla/styled-system/css\";\nimport { forwardRef, type ReactNode } from \"react\";\nimport { SafeLink, type SafeLinkProps } from \"./SafeLink\";\n\nexport interface SafeLinkButtonProps extends SafeLinkProps, ButtonVariantProps {\n children: ReactNode;\n}\n\nexport const SafeLinkButton = forwardRef<HTMLAnchorElement, SafeLinkButtonProps>(\n ({ variant, size, css: cssProp, ...props }, ref) => (\n <SafeLink\n {...props}\n css={css.raw(\n buttonBaseRecipe.raw({ variant }),\n variant !== \"link\" ? buttonRecipe.raw({ size }) : undefined,\n cssProp,\n )}\n ref={ref}\n />\n ),\n);\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAa,kBAAA,GAAA,MAAA,aACV,EAAE,SAAS,MAAM,KAAK,SAAS,GAAG,SAAS,QAC1C,iBAAA,GAAA,kBAAA,KAACA,iBAAAA,UAAD;CACE,GAAI;CACJ,KAAKC,wBAAAA,IAAI,IACPC,iBAAAA,iBAAiB,IAAI,EAAE,QAAQ,CAAC,GAChC,YAAY,SAASC,iBAAAA,aAAa,IAAI,EAAE,KAAK,CAAC,IAAI,KAAA,GAClD,OACF;CACK;AACN,CAAA,CAEL"}
@@ -1 +1 @@
1
- {"version":3,"file":"SafeLinkIconButton.js","names":["SafeLink","css","buttonBaseRecipe","iconButtonRecipe"],"sources":["../src/SafeLinkIconButton.tsx"],"sourcesContent":["/**\n * Copyright (c) 2022-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { buttonBaseRecipe, iconButtonRecipe, type IconButtonVariantProps } from \"@ndla/primitives\";\nimport { css } from \"@ndla/styled-system/css\";\nimport { forwardRef, type ReactNode } from \"react\";\nimport { SafeLink, type SafeLinkProps } from \"./SafeLink\";\n\nexport interface SafeLinkIconButtonProps extends SafeLinkProps, IconButtonVariantProps {\n children: ReactNode;\n}\n\nexport const SafeLinkIconButton = forwardRef<HTMLAnchorElement, SafeLinkIconButtonProps>(\n ({ variant, size, css: cssProp, ...props }, ref) => (\n <SafeLink\n {...props}\n css={css.raw(buttonBaseRecipe.raw({ variant }), iconButtonRecipe.raw({ size }), cssProp)}\n ref={ref}\n />\n ),\n);\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAa,sBAAA,GAAA,MAAA,aACV,EAAE,SAAS,MAAM,KAAK,SAAS,GAAG,SAAS,QAC1C,iBAAA,GAAA,kBAAA,KAACA,iBAAAA,UAAD;CACE,GAAI;CACJ,KAAKC,wBAAAA,IAAI,IAAIC,iBAAAA,iBAAiB,IAAI,EAAE,SAAS,CAAC,EAAEC,iBAAAA,iBAAiB,IAAI,EAAE,MAAM,CAAC,EAAE,QAAQ;CACnF;CACL,CAAA,CAEL"}
1
+ {"version":3,"file":"SafeLinkIconButton.js","names":["SafeLink","css","buttonBaseRecipe","iconButtonRecipe"],"sources":["../src/SafeLinkIconButton.tsx"],"sourcesContent":["/**\n * Copyright (c) 2022-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { buttonBaseRecipe, iconButtonRecipe, type IconButtonVariantProps } from \"@ndla/primitives\";\nimport { css } from \"@ndla/styled-system/css\";\nimport { forwardRef, type ReactNode } from \"react\";\nimport { SafeLink, type SafeLinkProps } from \"./SafeLink\";\n\nexport interface SafeLinkIconButtonProps extends SafeLinkProps, IconButtonVariantProps {\n children: ReactNode;\n}\n\nexport const SafeLinkIconButton = forwardRef<HTMLAnchorElement, SafeLinkIconButtonProps>(\n ({ variant, size, css: cssProp, ...props }, ref) => (\n <SafeLink\n {...props}\n css={css.raw(buttonBaseRecipe.raw({ variant }), iconButtonRecipe.raw({ size }), cssProp)}\n ref={ref}\n />\n ),\n);\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAa,sBAAA,GAAA,MAAA,aACV,EAAE,SAAS,MAAM,KAAK,SAAS,GAAG,SAAS,QAC1C,iBAAA,GAAA,kBAAA,KAACA,iBAAAA,UAAD;CACE,GAAI;CACJ,KAAKC,wBAAAA,IAAI,IAAIC,iBAAAA,iBAAiB,IAAI,EAAE,QAAQ,CAAC,GAAGC,iBAAAA,iBAAiB,IAAI,EAAE,KAAK,CAAC,GAAG,OAAO;CAClF;AACN,CAAA,CAEL"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ndla/safelink",
3
3
  "type": "module",
4
- "version": "7.0.132-alpha.0",
4
+ "version": "7.0.133-alpha.0",
5
5
  "description": "SafeLink component for NDLA",
6
6
  "license": "GPL-3.0",
7
7
  "exports": {
@@ -32,7 +32,7 @@
32
32
  "es"
33
33
  ],
34
34
  "dependencies": {
35
- "@ndla/primitives": "^1.0.129-alpha.0",
35
+ "@ndla/primitives": "^1.0.130-alpha.0",
36
36
  "@ndla/styled-system": "^0.0.49"
37
37
  },
38
38
  "devDependencies": {
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "471ee3863b03f1cc6a48d09ab624fbd1a5613c6e"
50
+ "gitHead": "609d5d044ece059de95a3142847ad9ab8737f468"
51
51
  }