@ndla/safelink 7.0.127-alpha.0 → 7.0.129-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,5 +1,4 @@
1
1
  import { createContext } from "react";
2
-
3
2
  //#region src/MissingRouterContext.ts
4
3
  /**
5
4
  * Copyright (c) 2019-present, NDLA.
@@ -9,7 +8,7 @@ import { createContext } from "react";
9
8
  *
10
9
  */
11
10
  const MissingRouterContext = createContext(false);
12
-
13
11
  //#endregion
14
12
  export { MissingRouterContext };
13
+
15
14
  //# sourceMappingURL=MissingRouterContext.mjs.map
@@ -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,MAAM"}
package/es/SafeLink.mjs CHANGED
@@ -3,7 +3,6 @@ import { forwardRef, useContext } from "react";
3
3
  import { styled } from "@ndla/styled-system/jsx";
4
4
  import { Link } from "react-router";
5
5
  import { jsx } from "react/jsx-runtime";
6
-
7
6
  //#region src/SafeLink.tsx
8
7
  /**
9
8
  * Copyright (c) 2019-present, NDLA.
@@ -44,7 +43,7 @@ const SafeLink = forwardRef(({ to, replace, state, disabled, unstyled, children,
44
43
  children
45
44
  });
46
45
  });
47
-
48
46
  //#endregion
49
47
  export { SafeLink };
48
+
50
49
  //# sourceMappingURL=SafeLink.mjs.map
@@ -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, type HTMLAttributes, type MutableRefObject, type ReactNode, useContext } 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\ntype Props = {\n ref?: MutableRefObject<HTMLAnchorElement | null>;\n asAnchor?: boolean;\n children?: ReactNode;\n disabled?: boolean;\n unstyled?: boolean;\n};\n\nexport type SafeLinkProps = Props & LinkProps & StyledProps & HTMLAttributes<HTMLElement>;\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;AAY5G,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;GACN,MAAM,WAAW,SAAY;GAC7B,MAAM,WAAW,SAAS;GAC1B,iBAAe;GACV;GACK;GACV,GAAI;GACJ,GAAI;GAEH;IACQ;;AAIf,QAEE,oBAAC;EACM;EACL,UAAU,YAAY;EACtB,IAAI,MAAM;EACH;EACS;EACP;EACT,GAAI;EACJ,GAAI;EAEH;GACU;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,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"}
@@ -3,7 +3,6 @@ import { forwardRef } from "react";
3
3
  import { buttonBaseRecipe, buttonRecipe } from "@ndla/primitives";
4
4
  import { css } from "@ndla/styled-system/css";
5
5
  import { jsx } from "react/jsx-runtime";
6
-
7
6
  //#region src/SafeLinkButton.tsx
8
7
  /**
9
8
  * Copyright (c) 2019-present, NDLA.
@@ -17,7 +16,7 @@ const SafeLinkButton = forwardRef(({ variant, size, css: cssProp, ...props }, re
17
16
  css: css.raw(buttonBaseRecipe.raw({ variant }), variant !== "link" ? buttonRecipe.raw({ size }) : void 0, cssProp),
18
17
  ref
19
18
  }));
20
-
21
19
  //#endregion
22
20
  export { SafeLinkButton };
21
+
23
22
  //# sourceMappingURL=SafeLinkButton.mjs.map
@@ -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;CACC,GAAI;CACJ,KAAK,IAAI,IACP,iBAAiB,IAAI,EAAE,SAAS,CAAC,EACjC,YAAY,SAAS,aAAa,IAAI,EAAE,MAAM,CAAC,GAAG,QAClD,QACD;CACI;EACL,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,SAAS,CAAC,EACjC,YAAY,SAAS,aAAa,IAAI,EAAE,MAAM,CAAC,GAAG,KAAA,GAClD,QACD;CACI;CACL,CAAA,CAEL"}
@@ -3,7 +3,6 @@ import { forwardRef } from "react";
3
3
  import { buttonBaseRecipe, iconButtonRecipe } from "@ndla/primitives";
4
4
  import { css } from "@ndla/styled-system/css";
5
5
  import { jsx } from "react/jsx-runtime";
6
-
7
6
  //#region src/SafeLinkIconButton.tsx
8
7
  /**
9
8
  * Copyright (c) 2022-present, NDLA.
@@ -17,7 +16,7 @@ const SafeLinkIconButton = forwardRef(({ variant, size, css: cssProp, ...props }
17
16
  css: css.raw(buttonBaseRecipe.raw({ variant }), iconButtonRecipe.raw({ size }), cssProp),
18
17
  ref
19
18
  }));
20
-
21
19
  //#endregion
22
20
  export { SafeLinkIconButton };
21
+
23
22
  //# sourceMappingURL=SafeLinkIconButton.mjs.map
@@ -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;CACC,GAAI;CACJ,KAAK,IAAI,IAAI,iBAAiB,IAAI,EAAE,SAAS,CAAC,EAAE,iBAAiB,IAAI,EAAE,MAAM,CAAC,EAAE,QAAQ;CACnF;EACL,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,SAAS,CAAC,EAAE,iBAAiB,IAAI,EAAE,MAAM,CAAC,EAAE,QAAQ;CACnF;CACL,CAAA,CAEL"}
package/es/index.mjs CHANGED
@@ -2,5 +2,4 @@ import { MissingRouterContext } from "./MissingRouterContext.mjs";
2
2
  import { SafeLink } from "./SafeLink.mjs";
3
3
  import { SafeLinkButton } from "./SafeLinkButton.mjs";
4
4
  import { SafeLinkIconButton } from "./SafeLinkIconButton.mjs";
5
-
6
- export { MissingRouterContext, SafeLink, SafeLinkButton, SafeLinkIconButton };
5
+ export { MissingRouterContext, SafeLink, SafeLinkButton, SafeLinkIconButton };
@@ -1,5 +1,3 @@
1
- let react = require("react");
2
-
3
1
  //#region src/MissingRouterContext.ts
4
2
  /**
5
3
  * Copyright (c) 2019-present, NDLA.
@@ -8,8 +6,8 @@ let react = require("react");
8
6
  * LICENSE file in the root directory of this source tree.
9
7
  *
10
8
  */
11
- const MissingRouterContext = (0, react.createContext)(false);
12
-
9
+ const MissingRouterContext = (0, require("react").createContext)(false);
13
10
  //#endregion
14
11
  exports.MissingRouterContext = MissingRouterContext;
12
+
15
13
  //# sourceMappingURL=MissingRouterContext.js.map
@@ -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,gDAAqC,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,oBAAA,eAAqC,MAAM"}
package/lib/SafeLink.d.ts CHANGED
@@ -6,16 +6,13 @@
6
6
  *
7
7
  */
8
8
  import type { StyledProps } from "@ndla/styled-system/types";
9
- import { type HTMLAttributes, type MutableRefObject, type ReactNode } from "react";
9
+ import { type RefObject } from "react";
10
10
  import { type LinkProps } from "react-router";
11
11
  export declare const isOldNdlaLink: (to?: LinkProps["to"]) => boolean;
12
- type Props = {
13
- ref?: MutableRefObject<HTMLAnchorElement | null>;
12
+ export interface SafeLinkProps extends LinkProps, StyledProps {
13
+ ref?: RefObject<HTMLAnchorElement | null>;
14
14
  asAnchor?: boolean;
15
- children?: ReactNode;
16
15
  disabled?: boolean;
17
16
  unstyled?: boolean;
18
- };
19
- export type SafeLinkProps = Props & LinkProps & StyledProps & HTMLAttributes<HTMLElement>;
17
+ }
20
18
  export declare const SafeLink: import("react").ForwardRefExoticComponent<Omit<SafeLinkProps, "ref"> & import("react").RefAttributes<HTMLAnchorElement>>;
21
- export {};
package/lib/SafeLink.js CHANGED
@@ -1,9 +1,8 @@
1
- const require_MissingRouterContext = require('./MissingRouterContext.js');
1
+ const require_MissingRouterContext = require("./MissingRouterContext.js");
2
2
  let react = require("react");
3
3
  let _ndla_styled_system_jsx = require("@ndla/styled-system/jsx");
4
4
  let react_router = require("react-router");
5
5
  let react_jsx_runtime = require("react/jsx-runtime");
6
-
7
6
  //#region src/SafeLink.tsx
8
7
  /**
9
8
  * Copyright (c) 2019-present, NDLA.
@@ -44,7 +43,7 @@ const SafeLink = (0, react.forwardRef)(({ to, replace, state, disabled, unstyled
44
43
  children
45
44
  });
46
45
  });
47
-
48
46
  //#endregion
49
47
  exports.SafeLink = SafeLink;
48
+
50
49
  //# sourceMappingURL=SafeLink.js.map
@@ -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, type HTMLAttributes, type MutableRefObject, type ReactNode, useContext } 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\ntype Props = {\n ref?: MutableRefObject<HTMLAnchorElement | null>;\n asAnchor?: boolean;\n children?: ReactNode;\n disabled?: boolean;\n unstyled?: boolean;\n};\n\nexport type SafeLinkProps = Props & LinkProps & StyledProps & HTMLAttributes<HTMLElement>;\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;AAY5G,MAAM,iDAAoBA,mBAAM,EAAE,EAAE,EAAE,eAAe,MAAM,CAAC;AAI5D,MAAa,kCACV,EAAE,IAAI,SAAS,OAAO,UAAU,UAAU,UAAU,UAAU,UAAU,gBAAgB,GAAG,QAAQ,QAAQ;CAC1G,MAAM,+CAAoCC,kDAAqB;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,2CAACC,+BAAO;GACN,MAAM,WAAW,SAAY;GAC7B,MAAM,WAAW,SAAS;GAC1B,iBAAe;GACV;GACK;GACV,GAAI;GACJ,GAAI;GAEH;IACQ;;AAIf,QAEE,2CAAC;EACM;EACL,UAAU,YAAY;EACtB,IAAI,MAAM;EACH;EACS;EACP;EACT,GAAI;EACJ,GAAI;EAEH;GACU;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,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,9 +1,8 @@
1
- const require_SafeLink = require('./SafeLink.js');
1
+ const require_SafeLink = require("./SafeLink.js");
2
2
  let react = require("react");
3
3
  let _ndla_primitives = require("@ndla/primitives");
4
4
  let _ndla_styled_system_css = require("@ndla/styled-system/css");
5
5
  let react_jsx_runtime = require("react/jsx-runtime");
6
-
7
6
  //#region src/SafeLinkButton.tsx
8
7
  /**
9
8
  * Copyright (c) 2019-present, NDLA.
@@ -17,7 +16,7 @@ const SafeLinkButton = (0, react.forwardRef)(({ variant, size, css: cssProp, ...
17
16
  css: _ndla_styled_system_css.css.raw(_ndla_primitives.buttonBaseRecipe.raw({ variant }), variant !== "link" ? _ndla_primitives.buttonRecipe.raw({ size }) : void 0, cssProp),
18
17
  ref
19
18
  }));
20
-
21
19
  //#endregion
22
20
  exports.SafeLinkButton = SafeLinkButton;
21
+
23
22
  //# sourceMappingURL=SafeLinkButton.js.map
@@ -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,wCACV,EAAE,SAAS,MAAM,KAAK,SAAS,GAAG,SAAS,QAC1C,2CAACA;CACC,GAAI;CACJ,KAAKC,4BAAI,IACPC,kCAAiB,IAAI,EAAE,SAAS,CAAC,EACjC,YAAY,SAASC,8BAAa,IAAI,EAAE,MAAM,CAAC,GAAG,QAClD,QACD;CACI;EACL,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,SAAS,CAAC,EACjC,YAAY,SAASC,iBAAAA,aAAa,IAAI,EAAE,MAAM,CAAC,GAAG,KAAA,GAClD,QACD;CACI;CACL,CAAA,CAEL"}
@@ -1,9 +1,8 @@
1
- const require_SafeLink = require('./SafeLink.js');
1
+ const require_SafeLink = require("./SafeLink.js");
2
2
  let react = require("react");
3
3
  let _ndla_primitives = require("@ndla/primitives");
4
4
  let _ndla_styled_system_css = require("@ndla/styled-system/css");
5
5
  let react_jsx_runtime = require("react/jsx-runtime");
6
-
7
6
  //#region src/SafeLinkIconButton.tsx
8
7
  /**
9
8
  * Copyright (c) 2022-present, NDLA.
@@ -17,7 +16,7 @@ const SafeLinkIconButton = (0, react.forwardRef)(({ variant, size, css: cssProp,
17
16
  css: _ndla_styled_system_css.css.raw(_ndla_primitives.buttonBaseRecipe.raw({ variant }), _ndla_primitives.iconButtonRecipe.raw({ size }), cssProp),
18
17
  ref
19
18
  }));
20
-
21
19
  //#endregion
22
20
  exports.SafeLinkIconButton = SafeLinkIconButton;
21
+
23
22
  //# sourceMappingURL=SafeLinkIconButton.js.map
@@ -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,4CACV,EAAE,SAAS,MAAM,KAAK,SAAS,GAAG,SAAS,QAC1C,2CAACA;CACC,GAAI;CACJ,KAAKC,4BAAI,IAAIC,kCAAiB,IAAI,EAAE,SAAS,CAAC,EAAEC,kCAAiB,IAAI,EAAE,MAAM,CAAC,EAAE,QAAQ;CACnF;EACL,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,SAAS,CAAC,EAAEC,iBAAAA,iBAAiB,IAAI,EAAE,MAAM,CAAC,EAAE,QAAQ;CACnF;CACL,CAAA,CAEL"}
package/lib/index.js CHANGED
@@ -1,10 +1,9 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_MissingRouterContext = require('./MissingRouterContext.js');
3
- const require_SafeLink = require('./SafeLink.js');
4
- const require_SafeLinkButton = require('./SafeLinkButton.js');
5
- const require_SafeLinkIconButton = require('./SafeLinkIconButton.js');
6
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_MissingRouterContext = require("./MissingRouterContext.js");
3
+ const require_SafeLink = require("./SafeLink.js");
4
+ const require_SafeLinkButton = require("./SafeLinkButton.js");
5
+ const require_SafeLinkIconButton = require("./SafeLinkIconButton.js");
7
6
  exports.MissingRouterContext = require_MissingRouterContext.MissingRouterContext;
8
7
  exports.SafeLink = require_SafeLink.SafeLink;
9
8
  exports.SafeLinkButton = require_SafeLinkButton.SafeLinkButton;
10
- exports.SafeLinkIconButton = require_SafeLinkIconButton.SafeLinkIconButton;
9
+ exports.SafeLinkIconButton = require_SafeLinkIconButton.SafeLinkIconButton;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ndla/safelink",
3
3
  "type": "module",
4
- "version": "7.0.127-alpha.0",
4
+ "version": "7.0.129-alpha.0",
5
5
  "description": "SafeLink component for NDLA",
6
6
  "license": "GPL-3.0",
7
7
  "exports": {
@@ -32,11 +32,11 @@
32
32
  "es"
33
33
  ],
34
34
  "dependencies": {
35
- "@ndla/primitives": "^1.0.124-alpha.0",
36
- "@ndla/styled-system": "^0.0.47"
35
+ "@ndla/primitives": "^1.0.126-alpha.0",
36
+ "@ndla/styled-system": "^0.0.48"
37
37
  },
38
38
  "devDependencies": {
39
- "@ndla/preset-panda": "^0.0.74",
39
+ "@ndla/preset-panda": "^0.0.75",
40
40
  "@pandacss/dev": "^1.7.0"
41
41
  },
42
42
  "peerDependencies": {
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "bbf5ac47d4046c3da40fe11aa3d653f5d6812b9f"
50
+ "gitHead": "74f4af9223bd5cbd27679b44b3cab1fcf4d26c76"
51
51
  }