@cntrl-site/sdk-nextjs 0.0.10 → 0.0.13

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.
@@ -0,0 +1,15 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="HtmlUnknownAttribute" enabled="true" level="WARNING" enabled_by_default="true">
5
+ <option name="myValues">
6
+ <value>
7
+ <list size="1">
8
+ <item index="0" class="java.lang.String" itemvalue="jsx" />
9
+ </list>
10
+ </value>
11
+ </option>
12
+ <option name="myCustomValuesEnabled" value="true" />
13
+ </inspection_tool>
14
+ </profile>
15
+ </component>
Binary file
@@ -2,5 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LinkWrapper = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- const LinkWrapper = ({ url, children }) => (url ? (0, jsx_runtime_1.jsx)("a", { href: url, target: "_blank", rel: "noreferrer", children: children }) : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }));
5
+ const LinkWrapper = ({ url, children }) => {
6
+ return url ? ((0, jsx_runtime_1.jsx)("a", { href: !url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('/') ? `//${url}` : url, target: url.startsWith('/') ? '_self' : '_blank', rel: "noreferrer", children: children })) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }));
7
+ };
6
8
  exports.LinkWrapper = LinkWrapper;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RichTextConverter = exports.FontStyles = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const core_1 = require("@cntrl-site/core");
6
+ const LinkWrapper_1 = require("../components/LinkWrapper");
6
7
  exports.FontStyles = {
7
8
  'normal': {},
8
9
  'bold': { 'font-weight': 'bold' },
@@ -81,7 +82,7 @@ class RichTextConverter {
81
82
  offset = entity.end;
82
83
  }
83
84
  if (entity.link) {
84
- kids.push((0, jsx_runtime_1.jsx)("a", { target: "_blank", href: entity.link, rel: "noreferrer", children: entityKids }, entity.start));
85
+ kids.push((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: entity.link, children: entityKids }, entity.start));
85
86
  continue;
86
87
  }
87
88
  kids.push(...entityKids);
@@ -184,7 +185,7 @@ class RichTextConverter {
184
185
  const { value, name } = draftStyle;
185
186
  const map = {
186
187
  'COLOR': { 'color': value },
187
- 'TYPEFACE': { 'font-family': `"${value}"` },
188
+ 'TYPEFACE': { 'font-family': `${value}` },
188
189
  'FONTSTYLE': value ? { ...exports.FontStyles[value] } : {},
189
190
  'FONTWEIGHT': { 'font-weight': value },
190
191
  'FONTSIZE': { 'font-size': `${parseFloat(value) * 100}vw` },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.0.10",
3
+ "version": "0.0.13",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.js",
@@ -21,8 +21,8 @@
21
21
  },
22
22
  "homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
23
23
  "dependencies": {
24
- "@cntrl-site/core": "^1.0.7",
25
- "@cntrl-site/sdk": "^0.0.3",
24
+ "@cntrl-site/core": "^1.0.9",
25
+ "@cntrl-site/sdk": "^0.0.7",
26
26
  "html-react-parser": "^3.0.1",
27
27
  "styled-jsx": "^5.0.2"
28
28
  },
@@ -1,9 +1,22 @@
1
- import React, { ReactElement } from 'react';
1
+ import React, { MouseEvent, ReactElement, ReactNode, useEffect } from 'react';
2
2
 
3
3
  interface Props {
4
4
  url?: string;
5
- children: ReactElement;
5
+ children: ReactElement | ReactNode[];
6
6
  }
7
7
 
8
- export const LinkWrapper: React.FC<Props> = ({ url, children }) => (
9
- url ? <a href={url} target="_blank" rel="noreferrer">{children}</a> : <>{children}</>);
8
+ export const LinkWrapper: React.FC<Props> = ({ url, children }) => {
9
+ return url ? (
10
+ <a
11
+ href={!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('/') ? `//${url}`: url}
12
+ target={url.startsWith('/') ? '_self' : '_blank'}
13
+ rel="noreferrer"
14
+ >
15
+ {children}
16
+ </a>
17
+ ) : (
18
+ <>{children}</>
19
+ );
20
+ };
21
+
22
+
@@ -8,6 +8,7 @@ import {
8
8
  getClosestLayoutValue,
9
9
  getLayoutMediaQuery
10
10
  } from '@cntrl-site/core';
11
+ import { LinkWrapper } from '../components/LinkWrapper';
11
12
 
12
13
  interface StyleGroup {
13
14
  start: number;
@@ -110,7 +111,7 @@ export class RichTextConverter {
110
111
  offset = entity.end;
111
112
  }
112
113
  if (entity.link) {
113
- kids.push(<a key={entity.start} target="_blank" href={entity.link} rel="noreferrer">{entityKids}</a>);
114
+ kids.push(<LinkWrapper key={entity.start} url={entity.link} >{entityKids}</LinkWrapper>);
114
115
  continue;
115
116
  }
116
117
  kids.push(...entityKids);
@@ -216,7 +217,7 @@ export class RichTextConverter {
216
217
  const { value, name } = draftStyle;
217
218
  const map: Record<string, Record<string, string | undefined>> = {
218
219
  'COLOR': { 'color': value },
219
- 'TYPEFACE': { 'font-family': `"${value}"` },
220
+ 'TYPEFACE': { 'font-family': `${value}` },
220
221
  'FONTSTYLE': value ? { ...FontStyles[value] } : {},
221
222
  'FONTWEIGHT': { 'font-weight': value },
222
223
  'FONTSIZE': { 'font-size': `${parseFloat(value!) * 100}vw` },