@ndla/article-converter 9.0.15-alpha.0 → 9.0.17-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.
|
@@ -7,8 +7,14 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { attributesToProps } from "html-react-parser";
|
|
10
|
-
import { ContactBlock } from "@ndla/ui";
|
|
10
|
+
import { ContactBlock, contactBlockBackgrounds } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
|
+
export function isBackground(background) {
|
|
13
|
+
return contactBlockBackgrounds.includes(background ?? "");
|
|
14
|
+
}
|
|
15
|
+
const parseBackground = background => {
|
|
16
|
+
if (isBackground(background)) return background;
|
|
17
|
+
};
|
|
12
18
|
export const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
13
19
|
const props = attributesToProps(element.attribs);
|
|
14
20
|
const embedData = JSON.parse(props["data-json"]);
|
|
@@ -16,21 +22,19 @@ export const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
|
16
22
|
name,
|
|
17
23
|
email,
|
|
18
24
|
description,
|
|
19
|
-
|
|
20
|
-
blobColor,
|
|
25
|
+
background,
|
|
21
26
|
jobTitle,
|
|
22
27
|
alt
|
|
23
28
|
} = embedData.embedData;
|
|
29
|
+
const parsedBackground = parseBackground(background);
|
|
24
30
|
return _jsx(ContactBlock, {
|
|
25
31
|
image: embedData.status === "success" ? embedData.data.image : undefined,
|
|
26
32
|
embedAlt: alt,
|
|
27
33
|
description: description,
|
|
28
34
|
email: email,
|
|
29
|
-
blobColor: blobColor,
|
|
30
35
|
jobTitle: jobTitle,
|
|
31
36
|
name: name,
|
|
32
|
-
blob: blob,
|
|
33
37
|
lang: opts.articleLanguage,
|
|
34
|
-
|
|
38
|
+
backgroundColor: parsedBackground
|
|
35
39
|
});
|
|
36
40
|
};
|
|
@@ -5,5 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
+
import { ContactBlockBackground } from "@ndla/ui";
|
|
8
9
|
import { PluginType } from "../types";
|
|
10
|
+
export declare function isBackground(background?: string): background is ContactBlockBackground;
|
|
9
11
|
export declare const contactBlockEmbedPlugin: PluginType;
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.contactBlockEmbedPlugin = void 0;
|
|
7
|
+
exports.isBackground = isBackground;
|
|
7
8
|
var _htmlReactParser = require("html-react-parser");
|
|
8
9
|
var _ui = require("@ndla/ui");
|
|
9
10
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
@@ -15,6 +16,12 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
15
16
|
*
|
|
16
17
|
*/
|
|
17
18
|
|
|
19
|
+
function isBackground(background) {
|
|
20
|
+
return _ui.contactBlockBackgrounds.includes(background ?? "");
|
|
21
|
+
}
|
|
22
|
+
const parseBackground = background => {
|
|
23
|
+
if (isBackground(background)) return background;
|
|
24
|
+
};
|
|
18
25
|
const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
19
26
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
27
|
const embedData = JSON.parse(props["data-json"]);
|
|
@@ -22,22 +29,20 @@ const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
|
22
29
|
name,
|
|
23
30
|
email,
|
|
24
31
|
description,
|
|
25
|
-
|
|
26
|
-
blobColor,
|
|
32
|
+
background,
|
|
27
33
|
jobTitle,
|
|
28
34
|
alt
|
|
29
35
|
} = embedData.embedData;
|
|
36
|
+
const parsedBackground = parseBackground(background);
|
|
30
37
|
return (0, _jsxRuntime.jsx)(_ui.ContactBlock, {
|
|
31
38
|
image: embedData.status === "success" ? embedData.data.image : undefined,
|
|
32
39
|
embedAlt: alt,
|
|
33
40
|
description: description,
|
|
34
41
|
email: email,
|
|
35
|
-
blobColor: blobColor,
|
|
36
42
|
jobTitle: jobTitle,
|
|
37
43
|
name: name,
|
|
38
|
-
blob: blob,
|
|
39
44
|
lang: opts.articleLanguage,
|
|
40
|
-
|
|
45
|
+
backgroundColor: parsedBackground
|
|
41
46
|
});
|
|
42
47
|
};
|
|
43
48
|
exports.contactBlockEmbedPlugin = contactBlockEmbedPlugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/article-converter",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.17-alpha.0",
|
|
4
4
|
"description": "Transforms NDLA articles into extended html versions",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
],
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@ndla/types-backend": "^0.2.86",
|
|
31
|
-
"@ndla/types-embed": "^
|
|
31
|
+
"@ndla/types-embed": "^5.0.0-alpha.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ndla/primitives": "^0.0.
|
|
35
|
-
"@ndla/ui": "^55.0.
|
|
34
|
+
"@ndla/primitives": "^0.0.20",
|
|
35
|
+
"@ndla/ui": "^55.0.17-alpha.0",
|
|
36
36
|
"html-react-parser": "^5.1.8"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "557f718324916e39e3b04d6a7196679d31056e00"
|
|
51
51
|
}
|
|
@@ -8,25 +8,32 @@
|
|
|
8
8
|
|
|
9
9
|
import { attributesToProps } from "html-react-parser";
|
|
10
10
|
import { ContactBlockMetaData } from "@ndla/types-embed";
|
|
11
|
-
import { ContactBlock } from "@ndla/ui";
|
|
11
|
+
import { ContactBlock, contactBlockBackgrounds, ContactBlockBackground } from "@ndla/ui";
|
|
12
12
|
import { PluginType } from "../types";
|
|
13
13
|
|
|
14
|
+
export function isBackground(background?: string): background is ContactBlockBackground {
|
|
15
|
+
return (contactBlockBackgrounds as readonly string[]).includes(background ?? "");
|
|
16
|
+
}
|
|
17
|
+
const parseBackground = (background: string | undefined): ContactBlockBackground | undefined => {
|
|
18
|
+
if (isBackground(background)) return background;
|
|
19
|
+
};
|
|
20
|
+
|
|
14
21
|
export const contactBlockEmbedPlugin: PluginType = (element, _, opts) => {
|
|
15
22
|
const props = attributesToProps(element.attribs);
|
|
16
23
|
const embedData = JSON.parse(props["data-json"] as string) as ContactBlockMetaData;
|
|
17
|
-
const { name, email, description,
|
|
24
|
+
const { name, email, description, background, jobTitle, alt } = embedData.embedData;
|
|
25
|
+
const parsedBackground = parseBackground(background);
|
|
26
|
+
|
|
18
27
|
return (
|
|
19
28
|
<ContactBlock
|
|
20
29
|
image={embedData.status === "success" ? embedData.data.image : undefined}
|
|
21
30
|
embedAlt={alt}
|
|
22
31
|
description={description}
|
|
23
32
|
email={email}
|
|
24
|
-
blobColor={blobColor}
|
|
25
33
|
jobTitle={jobTitle}
|
|
26
34
|
name={name}
|
|
27
|
-
blob={blob}
|
|
28
35
|
lang={opts.articleLanguage}
|
|
29
|
-
|
|
36
|
+
backgroundColor={parsedBackground}
|
|
30
37
|
/>
|
|
31
38
|
);
|
|
32
39
|
};
|