@ndla/ui 55.0.12-alpha.0 → 55.0.13-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.
- package/dist/all-aout.js +0 -0
- package/dist/all.css +1 -0
- package/dist/panda.buildinfo.json +170 -0
- package/dist/styles.css +686 -0
- package/es/Article/Article.js +3 -4
- package/es/Article/ArticleByline.js +9 -9
- package/es/Article/ArticleFootNotes.js +4 -4
- package/es/AudioPlayer/AudioPlayer.js +142 -163
- package/es/AudioPlayer/Controls.js +187 -203
- package/es/AudioPlayer/SpeechControl.js +13 -11
- package/es/BlogPost/BlogPost.js +85 -23
- package/es/CampaignBlock/CampaignBlock.js +3 -4
- package/es/CodeBlock/CodeBlock.js +88 -96
- package/es/ContactBlock/ContactBlock.js +54 -40
- package/es/ContentLoader/index.js +7 -7
- package/es/CopyParagraphButton/CopyParagraphButton.js +4 -4
- package/es/Embed/AudioEmbed.js +5 -9
- package/es/Embed/BrightcoveEmbed.js +12 -15
- package/es/Embed/CodeEmbed.js +58 -10
- package/es/Embed/ConceptEmbed.js +15 -20
- package/es/Embed/ContentLinkEmbed.js +1 -1
- package/es/Embed/EmbedErrorPlaceholder.js +32 -17
- package/es/Embed/ExternalEmbed.js +7 -10
- package/es/Embed/FootnoteEmbed.js +3 -3
- package/es/Embed/H5pEmbed.js +1 -2
- package/es/Embed/IframeEmbed.js +8 -9
- package/es/Embed/ImageEmbed.js +167 -122
- package/es/Embed/RelatedContentEmbed.js +8 -10
- package/es/Embed/UuDisclaimerEmbed.js +2 -2
- package/es/Embed/conceptComponents.js +9 -9
- package/es/ErrorMessage/ErrorMessage.js +1 -1
- package/es/FactBox/FactBox.js +2 -2
- package/es/FileList/File.js +1 -1
- package/es/FileList/Format.js +3 -3
- package/es/FrontpageArticle/FrontpageArticle.js +1 -1
- package/es/Gloss/Gloss.js +9 -11
- package/es/Gloss/GlossExample.js +3 -4
- package/es/Grid/Grid.js +1 -1
- package/es/Image/Image.js +7 -8
- package/es/Image/ImageLink.js +1 -1
- package/es/KeyFigure/KeyFigure.js +2 -2
- package/es/LanguageSelector/LanguageSelector.js +2 -2
- package/es/LetterFilter/LetterFilter.js +1 -1
- package/es/LicenseByline/EmbedByline.js +5 -6
- package/es/LicenseByline/LicenseDescription.js +1 -1
- package/es/LicenseByline/LicenseLink.js +1 -2
- package/es/Messages/MessageBox.js +1 -1
- package/es/Notion/Notion.js +2 -2
- package/es/Notion/NotionImage.js +12 -57
- package/es/RelatedArticleList/RelatedArticleList.js +3 -3
- package/es/ResourceBox/ResourceBox.js +12 -17
- package/es/Search/ActiveFilters.js +1 -1
- package/es/Search/ContentTypeResult.js +9 -6
- package/es/Search/ContentTypeResultStyles.js +1 -1
- package/es/Search/IsPathToHighlight.js +1 -1
- package/es/Search/SearchField.js +6 -8
- package/es/Search/SearchResult.js +14 -19
- package/es/Search/SearchResultSleeve.js +14 -16
- package/es/SnackBar/SnackbarProvider.js +8 -11
- package/es/TagSelector/TagSelector.js +1 -1
- package/es/TagSelector/ariaMessages.js +6 -6
- package/es/TreeStructure/AddFolderButton.js +4 -6
- package/es/TreeStructure/ComboboxButton.js +4 -7
- package/es/TreeStructure/FolderItem.js +12 -15
- package/es/TreeStructure/FolderItems.js +3 -3
- package/es/TreeStructure/TreeStructure.js +9 -12
- package/es/TreeStructure/helperFunctions.js +1 -1
- package/es/ZendeskButton/ZendeskButton.js +55 -0
- package/es/i18n/formatNestedMessages.js +1 -1
- package/es/index.js +2 -1
- package/es/locale/messages-en.js +9 -8
- package/es/locale/messages-nb.js +9 -8
- package/es/locale/messages-nn.js +9 -8
- package/es/locale/messages-se.js +9 -8
- package/es/locale/messages-sma.js +9 -8
- package/es/styles.css +686 -0
- package/es/utils/relativeUrl.js +3 -3
- package/lib/Article/Article.js +3 -4
- package/lib/Article/ArticleByline.js +9 -9
- package/lib/Article/ArticleFootNotes.js +4 -4
- package/lib/AudioPlayer/AudioPlayer.d.ts +1 -2
- package/lib/AudioPlayer/AudioPlayer.js +142 -162
- package/lib/AudioPlayer/Controls.js +190 -205
- package/lib/AudioPlayer/SpeechControl.js +13 -11
- package/lib/BlogPost/BlogPost.d.ts +2 -2
- package/lib/BlogPost/BlogPost.js +85 -24
- package/lib/CampaignBlock/CampaignBlock.js +3 -4
- package/lib/CodeBlock/CodeBlock.d.ts +5 -8
- package/lib/CodeBlock/CodeBlock.js +88 -96
- package/lib/ContactBlock/ContactBlock.js +55 -43
- package/lib/ContentLoader/index.js +7 -7
- package/lib/CopyParagraphButton/CopyParagraphButton.js +4 -4
- package/lib/Embed/AudioEmbed.js +5 -9
- package/lib/Embed/BrightcoveEmbed.js +12 -15
- package/lib/Embed/CodeEmbed.js +56 -8
- package/lib/Embed/ConceptEmbed.js +15 -20
- package/lib/Embed/ContentLinkEmbed.js +1 -1
- package/lib/Embed/EmbedErrorPlaceholder.d.ts +4 -3
- package/lib/Embed/EmbedErrorPlaceholder.js +32 -18
- package/lib/Embed/ExternalEmbed.js +7 -10
- package/lib/Embed/FootnoteEmbed.js +3 -3
- package/lib/Embed/H5pEmbed.js +1 -2
- package/lib/Embed/IframeEmbed.js +8 -9
- package/lib/Embed/ImageEmbed.d.ts +1 -2
- package/lib/Embed/ImageEmbed.js +167 -123
- package/lib/Embed/RelatedContentEmbed.js +8 -10
- package/lib/Embed/UuDisclaimerEmbed.js +2 -2
- package/lib/Embed/conceptComponents.js +9 -9
- package/lib/ErrorMessage/ErrorMessage.js +1 -1
- package/lib/FactBox/FactBox.js +2 -2
- package/lib/FileList/File.js +1 -1
- package/lib/FileList/Format.js +3 -3
- package/lib/FrontpageArticle/FrontpageArticle.js +1 -1
- package/lib/Gloss/Gloss.js +9 -11
- package/lib/Gloss/GlossExample.js +3 -4
- package/lib/Grid/Grid.js +1 -1
- package/lib/Image/Image.js +7 -8
- package/lib/Image/ImageLink.js +1 -1
- package/lib/KeyFigure/KeyFigure.js +2 -2
- package/lib/LanguageSelector/LanguageSelector.js +2 -2
- package/lib/LetterFilter/LetterFilter.js +1 -1
- package/lib/LicenseByline/EmbedByline.js +5 -6
- package/lib/LicenseByline/LicenseDescription.js +1 -1
- package/lib/LicenseByline/LicenseLink.js +1 -2
- package/lib/Messages/MessageBox.js +1 -1
- package/lib/Notion/Notion.js +2 -2
- package/lib/Notion/NotionImage.d.ts +1 -11
- package/lib/Notion/NotionImage.js +12 -59
- package/lib/RelatedArticleList/RelatedArticleList.js +3 -3
- package/lib/ResourceBox/ResourceBox.js +13 -18
- package/lib/Search/ActiveFilters.js +1 -1
- package/lib/Search/ContentTypeResult.js +9 -6
- package/lib/Search/ContentTypeResultStyles.js +1 -1
- package/lib/Search/IsPathToHighlight.js +1 -1
- package/lib/Search/SearchField.js +6 -8
- package/lib/Search/SearchResult.js +14 -19
- package/lib/Search/SearchResultSleeve.js +14 -16
- package/lib/SnackBar/SnackbarProvider.js +8 -11
- package/lib/TagSelector/TagSelector.js +1 -1
- package/lib/TagSelector/ariaMessages.js +6 -6
- package/lib/TreeStructure/AddFolderButton.js +4 -6
- package/lib/TreeStructure/ComboboxButton.js +4 -7
- package/lib/TreeStructure/FolderItem.js +12 -15
- package/lib/TreeStructure/FolderItems.js +3 -3
- package/lib/TreeStructure/TreeStructure.js +9 -12
- package/lib/TreeStructure/helperFunctions.js +1 -1
- package/lib/ZendeskButton/ZendeskButton.d.ts +19 -0
- package/lib/ZendeskButton/ZendeskButton.js +61 -0
- package/lib/i18n/formatNestedMessages.js +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +7 -0
- package/lib/locale/messages-en.d.ts +1 -0
- package/lib/locale/messages-en.js +9 -8
- package/lib/locale/messages-nb.d.ts +1 -0
- package/lib/locale/messages-nb.js +9 -8
- package/lib/locale/messages-nn.d.ts +1 -0
- package/lib/locale/messages-nn.js +9 -8
- package/lib/locale/messages-se.d.ts +1 -0
- package/lib/locale/messages-se.js +9 -8
- package/lib/locale/messages-sma.d.ts +1 -0
- package/lib/locale/messages-sma.js +9 -8
- package/lib/styles.css +686 -0
- package/lib/types.d.ts +1 -0
- package/lib/utils/relativeUrl.js +3 -3
- package/package.json +17 -12
- package/src/AudioPlayer/AudioPlayer.tsx +139 -176
- package/src/AudioPlayer/Controls.tsx +210 -250
- package/src/AudioPlayer/SpeechControl.tsx +9 -7
- package/src/BlogPost/BlogPost.tsx +82 -58
- package/src/CodeBlock/CodeBlock.stories.tsx +0 -43
- package/src/CodeBlock/CodeBlock.tsx +91 -202
- package/src/ContactBlock/ContactBlock.tsx +10 -2
- package/src/Embed/CodeEmbed.stories.tsx +95 -0
- package/src/Embed/CodeEmbed.tsx +62 -7
- package/src/Embed/ConceptEmbed.tsx +1 -9
- package/src/Embed/EmbedErrorPlaceholder.tsx +31 -28
- package/src/Embed/ImageEmbed.stories.tsx +53 -11
- package/src/Embed/ImageEmbed.tsx +162 -166
- package/src/Notion/NotionImage.tsx +4 -54
- package/src/ResourceBox/ResourceBox.tsx +3 -15
- package/src/Search/ContentTypeResult.tsx +9 -3
- package/src/Search/SearchResultSleeve.tsx +5 -2
- package/src/ZendeskButton/ZendeskButton.tsx +58 -0
- package/src/index.ts +4 -0
- package/src/locale/messages-en.ts +1 -0
- package/src/locale/messages-nb.ts +1 -0
- package/src/locale/messages-nn.ts +1 -0
- package/src/locale/messages-se.ts +1 -0
- package/src/locale/messages-sma.ts +1 -0
- package/src/types.ts +2 -0
- package/src/Image/__tests__/Image-test.tsx +0 -66
- package/src/Image/__tests__/__snapshots__/Image-test.tsx.snap +0 -194
|
@@ -29,9 +29,9 @@ const ContentLoader = _ref => {
|
|
|
29
29
|
} = _ref;
|
|
30
30
|
const idClip = (0, _util.uuid)();
|
|
31
31
|
const idGradient = (0, _util.uuid)();
|
|
32
|
-
const viewBox = viewBoxProp === undefined ?
|
|
32
|
+
const viewBox = viewBoxProp === undefined ? `0 0 ${width} ${height}` : viewBoxProp;
|
|
33
33
|
return (0, _jsxRuntime.jsxs)("svg", {
|
|
34
|
-
viewBox: viewBox
|
|
34
|
+
viewBox: viewBox ?? undefined,
|
|
35
35
|
version: "1.1",
|
|
36
36
|
preserveAspectRatio: preserveAspectRatio,
|
|
37
37
|
className: className,
|
|
@@ -40,9 +40,9 @@ const ContentLoader = _ref => {
|
|
|
40
40
|
width: typeof width === "string" ? width : undefined,
|
|
41
41
|
children: [(0, _jsxRuntime.jsx)("rect", {
|
|
42
42
|
style: {
|
|
43
|
-
fill:
|
|
43
|
+
fill: `url(#${idGradient})`
|
|
44
44
|
},
|
|
45
|
-
clipPath:
|
|
45
|
+
clipPath: `url(#${idClip})`,
|
|
46
46
|
x: "0",
|
|
47
47
|
y: "0",
|
|
48
48
|
width: width,
|
|
@@ -59,7 +59,7 @@ const ContentLoader = _ref => {
|
|
|
59
59
|
children: (0, _jsxRuntime.jsx)("animate", {
|
|
60
60
|
attributeName: "offset",
|
|
61
61
|
values: "-2; 1",
|
|
62
|
-
dur:
|
|
62
|
+
dur: `${speed}s`,
|
|
63
63
|
repeatCount: "indefinite"
|
|
64
64
|
})
|
|
65
65
|
}), (0, _jsxRuntime.jsx)("stop", {
|
|
@@ -68,7 +68,7 @@ const ContentLoader = _ref => {
|
|
|
68
68
|
children: (0, _jsxRuntime.jsx)("animate", {
|
|
69
69
|
attributeName: "offset",
|
|
70
70
|
values: "-1.5; 1.5",
|
|
71
|
-
dur:
|
|
71
|
+
dur: `${speed}s`,
|
|
72
72
|
repeatCount: "indefinite"
|
|
73
73
|
})
|
|
74
74
|
}), (0, _jsxRuntime.jsx)("stop", {
|
|
@@ -77,7 +77,7 @@ const ContentLoader = _ref => {
|
|
|
77
77
|
children: (0, _jsxRuntime.jsx)("animate", {
|
|
78
78
|
attributeName: "offset",
|
|
79
79
|
values: "-1; 2",
|
|
80
|
-
dur:
|
|
80
|
+
dur: `${speed}s`,
|
|
81
81
|
repeatCount: "indefinite"
|
|
82
82
|
})
|
|
83
83
|
})]
|
|
@@ -57,9 +57,9 @@ const CopyParagraphButton = _ref => {
|
|
|
57
57
|
const {
|
|
58
58
|
location
|
|
59
59
|
} = window;
|
|
60
|
-
const newHash =
|
|
61
|
-
const port = location.port ?
|
|
62
|
-
const urlToCopy =
|
|
60
|
+
const newHash = `#${sanitizedTitle}`;
|
|
61
|
+
const port = location.port ? `:${location.port}` : "";
|
|
62
|
+
const urlToCopy = `${location.protocol}//${location.hostname}${port}${location.pathname}${location.search}${newHash}`;
|
|
63
63
|
(0, _util.copyTextToClipboard)(urlToCopy);
|
|
64
64
|
}, [sanitizedTitle]);
|
|
65
65
|
const tooltip = hasCopied ? t("article.copyPageLinkCopied") : t("article.copyHeaderLink");
|
|
@@ -68,7 +68,7 @@ const CopyParagraphButton = _ref => {
|
|
|
68
68
|
tooltip: tooltip,
|
|
69
69
|
children: (0, _jsxRuntime.jsx)(IconButton, {
|
|
70
70
|
onClick: onCopyClick,
|
|
71
|
-
"aria-label":
|
|
71
|
+
"aria-label": `${tooltip}: ${copyText}`,
|
|
72
72
|
children: (0, _jsxRuntime.jsx)(_common.Link, {})
|
|
73
73
|
})
|
|
74
74
|
}), (0, _jsxRuntime.jsx)("h2", {
|
package/lib/Embed/AudioEmbed.js
CHANGED
|
@@ -18,13 +18,9 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
const getFirstNonEmptyLicenseCredits = authors =>
|
|
22
|
-
var _Object$values$find;
|
|
23
|
-
return (_Object$values$find = Object.values(authors).find(i => i.length > 0)) !== null && _Object$values$find !== void 0 ? _Object$values$find : [];
|
|
24
|
-
};
|
|
21
|
+
const getFirstNonEmptyLicenseCredits = authors => Object.values(authors).find(i => i.length > 0) ?? [];
|
|
25
22
|
exports.getFirstNonEmptyLicenseCredits = getFirstNonEmptyLicenseCredits;
|
|
26
23
|
const AudioEmbed = _ref => {
|
|
27
|
-
var _data$podcastMeta, _data$podcastMeta$int, _data$podcastMeta2, _data$manuscript;
|
|
28
24
|
let {
|
|
29
25
|
embed,
|
|
30
26
|
lang
|
|
@@ -47,9 +43,9 @@ const AudioEmbed = _ref => {
|
|
|
47
43
|
}
|
|
48
44
|
const subtitle = data.series ? {
|
|
49
45
|
title: data.series.title.title,
|
|
50
|
-
url:
|
|
46
|
+
url: `/podkast/${data.series.id}`
|
|
51
47
|
} : undefined;
|
|
52
|
-
const coverPhoto =
|
|
48
|
+
const coverPhoto = data.podcastMeta?.coverPhoto;
|
|
53
49
|
const img = coverPhoto && {
|
|
54
50
|
url: coverPhoto.url,
|
|
55
51
|
alt: coverPhoto.altText
|
|
@@ -58,10 +54,10 @@ const AudioEmbed = _ref => {
|
|
|
58
54
|
type: "full",
|
|
59
55
|
lang: lang,
|
|
60
56
|
children: [(0, _jsxRuntime.jsx)(_AudioPlayer.default, {
|
|
61
|
-
description:
|
|
57
|
+
description: data.podcastMeta?.introduction ?? "",
|
|
62
58
|
img: img,
|
|
63
59
|
src: data.audioFile.url,
|
|
64
|
-
textVersion:
|
|
60
|
+
textVersion: data.manuscript?.manuscript.length ? (0, _jsxRuntime.jsx)("span", {
|
|
65
61
|
dangerouslySetInnerHTML: {
|
|
66
62
|
__html: data.manuscript.manuscript
|
|
67
63
|
}
|
|
@@ -43,13 +43,12 @@ const makeIframeString = function (url, width, height) {
|
|
|
43
43
|
const strippedWidth = typeof width === "number" ? width : width.replace(/\s*px/, "");
|
|
44
44
|
const strippedHeight = typeof height === "number" ? height : height.replace(/\s*px/, "");
|
|
45
45
|
const urlOrTitle = title || url;
|
|
46
|
-
return
|
|
46
|
+
return `<iframe title="${urlOrTitle}" aria-label="${urlOrTitle}" src="${url}" width="${strippedWidth}" height="${strippedHeight}" allowfullscreen scrolling="no" frameborder="0" loading="lazy"></iframe>`;
|
|
47
47
|
};
|
|
48
48
|
exports.makeIframeString = makeIframeString;
|
|
49
49
|
const isNumeric = value => !Number.isNaN(value - Number.parseFloat(value));
|
|
50
50
|
exports.isNumeric = isNumeric;
|
|
51
51
|
const getIframeProps = (data, sources) => {
|
|
52
|
-
var _source$height, _source$width;
|
|
53
52
|
const {
|
|
54
53
|
account,
|
|
55
54
|
videoid,
|
|
@@ -57,13 +56,12 @@ const getIframeProps = (data, sources) => {
|
|
|
57
56
|
} = data;
|
|
58
57
|
const source = sources.filter(s => s.width && s.height).toSorted((a, b) => a.height - b.height)[0];
|
|
59
58
|
return {
|
|
60
|
-
src:
|
|
61
|
-
height:
|
|
62
|
-
width:
|
|
59
|
+
src: `https://players.brightcove.net/${account}/${player}_default/index.html?videoId=${videoid}`,
|
|
60
|
+
height: source?.height ?? "480",
|
|
61
|
+
width: source?.width ?? "640"
|
|
63
62
|
};
|
|
64
63
|
};
|
|
65
64
|
const BrightcoveEmbed = _ref => {
|
|
66
|
-
var _data$link, _data$link2, _ref2, _embedData$alt3, _ref3, _embedData$alt4;
|
|
67
65
|
let {
|
|
68
66
|
embed,
|
|
69
67
|
isConcept,
|
|
@@ -77,7 +75,7 @@ const BrightcoveEmbed = _ref => {
|
|
|
77
75
|
const {
|
|
78
76
|
embedData
|
|
79
77
|
} = embed;
|
|
80
|
-
const fallbackTitle =
|
|
78
|
+
const fallbackTitle = `${t("embed.type.video")}: ${embedData.videoid}`;
|
|
81
79
|
const parsedDescription = (0, _react.useMemo)(() => {
|
|
82
80
|
if (embed.embedData.caption || renderContext === "article") {
|
|
83
81
|
return embed.embedData.caption ? (0, _htmlReactParser.default)(embed.embedData.caption) : undefined;
|
|
@@ -89,19 +87,18 @@ const BrightcoveEmbed = _ref => {
|
|
|
89
87
|
const iframe = iframeRef.current;
|
|
90
88
|
if (iframe) {
|
|
91
89
|
const [width, height] = [parseInt(iframe.width), parseInt(iframe.height)];
|
|
92
|
-
iframe.style.aspectRatio =
|
|
90
|
+
iframe.style.aspectRatio = `${width}/${height}`;
|
|
93
91
|
iframe.width = "";
|
|
94
92
|
iframe.height = "";
|
|
95
93
|
}
|
|
96
94
|
}, []);
|
|
97
95
|
if (embed.status === "error") {
|
|
98
|
-
var _embedData$alt, _embedData$alt2;
|
|
99
96
|
return (0, _jsxRuntime.jsx)(_EmbedErrorPlaceholder.default, {
|
|
100
97
|
type: "video",
|
|
101
98
|
children: (0, _jsxRuntime.jsx)(BrightcoveIframe, {
|
|
102
99
|
ref: iframeRef,
|
|
103
|
-
title:
|
|
104
|
-
"aria-label":
|
|
100
|
+
title: embedData.alt ?? fallbackTitle,
|
|
101
|
+
"aria-label": embedData.alt ?? fallbackTitle,
|
|
105
102
|
frameBorder: "0",
|
|
106
103
|
...getIframeProps(embedData, []),
|
|
107
104
|
allowFullScreen: true
|
|
@@ -111,7 +108,7 @@ const BrightcoveEmbed = _ref => {
|
|
|
111
108
|
const {
|
|
112
109
|
data
|
|
113
110
|
} = embed;
|
|
114
|
-
const linkedVideoId = isNumeric(
|
|
111
|
+
const linkedVideoId = isNumeric(data.link?.text) ? data.link?.text : undefined;
|
|
115
112
|
const originalVideoProps = getIframeProps(embedData, data.sources);
|
|
116
113
|
const alternativeVideoProps = linkedVideoId ? getIframeProps({
|
|
117
114
|
...embedData,
|
|
@@ -124,8 +121,8 @@ const BrightcoveEmbed = _ref => {
|
|
|
124
121
|
children: (0, _jsxRuntime.jsx)(BrightcoveIframe, {
|
|
125
122
|
ref: iframeRef,
|
|
126
123
|
className: "original",
|
|
127
|
-
title:
|
|
128
|
-
"aria-label":
|
|
124
|
+
title: embedData.alt ?? data.name ?? fallbackTitle,
|
|
125
|
+
"aria-label": embedData.alt ?? data.name ?? fallbackTitle,
|
|
129
126
|
frameBorder: "0",
|
|
130
127
|
...(alternativeVideoProps && !showOriginalVideo ? alternativeVideoProps : originalVideoProps),
|
|
131
128
|
allowFullScreen: true
|
|
@@ -140,7 +137,7 @@ const BrightcoveEmbed = _ref => {
|
|
|
140
137
|
shape: "pill",
|
|
141
138
|
size: "small",
|
|
142
139
|
onClick: () => setShowOriginalVideo(p => !p),
|
|
143
|
-
children: t(
|
|
140
|
+
children: t(`figure.button.${!showOriginalVideo ? "original" : "alternative"}`)
|
|
144
141
|
})
|
|
145
142
|
})]
|
|
146
143
|
});
|
package/lib/Embed/CodeEmbed.js
CHANGED
|
@@ -4,8 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactI18next = require("react-i18next");
|
|
9
|
+
var _action = require("@ndla/icons/action");
|
|
10
|
+
var _editor = require("@ndla/icons/editor");
|
|
11
|
+
var _primitives = require("@ndla/primitives");
|
|
12
|
+
var _jsx2 = require("@ndla/styled-system/jsx");
|
|
13
|
+
var _util = require("@ndla/util");
|
|
7
14
|
var _CodeBlock = require("../CodeBlock");
|
|
8
|
-
var _Figure = require("../Figure");
|
|
9
15
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
16
|
/**
|
|
11
17
|
* Copyright (c) 2023-present, NDLA.
|
|
@@ -15,18 +21,60 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
15
21
|
*
|
|
16
22
|
*/
|
|
17
23
|
|
|
24
|
+
// TODO: We need an error state for this
|
|
25
|
+
|
|
26
|
+
const StyledFigCaption = (0, _jsx2.styled)("figcaption", {
|
|
27
|
+
base: {
|
|
28
|
+
textStyle: "label.large",
|
|
29
|
+
fontWeight: "bold"
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const StyledFigure = (0, _jsx2.styled)(_primitives.Figure, {
|
|
33
|
+
base: {
|
|
34
|
+
// We apply margin here to allow for the float and size props on figure to work as intended.
|
|
35
|
+
"& > *:not(:where(:first-child))": {
|
|
36
|
+
marginBlockStart: "xsmall"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const getTitleFromFormat = format => {
|
|
41
|
+
const selectedLanguage = _CodeBlock.codeLanguageOptions.find(item => item.format === format);
|
|
42
|
+
if (selectedLanguage) {
|
|
43
|
+
return selectedLanguage.title;
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
};
|
|
18
47
|
const CodeEmbed = _ref => {
|
|
19
48
|
let {
|
|
20
49
|
embed
|
|
21
50
|
} = _ref;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
51
|
+
const [isCopied, setIsCopied] = (0, _react.useState)(false);
|
|
52
|
+
const {
|
|
53
|
+
t
|
|
54
|
+
} = (0, _reactI18next.useTranslation)();
|
|
55
|
+
(0, _react.useEffect)(() => {
|
|
56
|
+
if (isCopied) {
|
|
57
|
+
const timer = setInterval(() => setIsCopied(false), 3000);
|
|
58
|
+
// ensure interval is cleared - also if unmounted
|
|
59
|
+
return () => {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}, [isCopied]);
|
|
64
|
+
return (0, _jsxRuntime.jsxs)(StyledFigure, {
|
|
65
|
+
children: [(0, _jsxRuntime.jsx)(StyledFigCaption, {
|
|
66
|
+
children: embed.embedData.title || getTitleFromFormat(embed.embedData.codeFormat)
|
|
67
|
+
}), (0, _jsxRuntime.jsx)(_CodeBlock.CodeBlock, {
|
|
26
68
|
highlightedCode: embed.status === "success" ? embed.data.highlightedCode : "",
|
|
27
|
-
format: embed.embedData.codeFormat
|
|
28
|
-
|
|
29
|
-
|
|
69
|
+
format: embed.embedData.codeFormat
|
|
70
|
+
}), (0, _jsxRuntime.jsxs)(_primitives.Button, {
|
|
71
|
+
variant: "secondary",
|
|
72
|
+
onClick: () => {
|
|
73
|
+
(0, _util.copyTextToClipboard)(embed.status === "success" ? embed.data.decodedContent : "");
|
|
74
|
+
setIsCopied(true);
|
|
75
|
+
},
|
|
76
|
+
children: [isCopied ? (0, _jsxRuntime.jsx)(_editor.Done, {}) : (0, _jsxRuntime.jsx)(_action.Copy, {}), isCopied ? t("codeBlock.copiedCode") : t("codeBlock.copyCode")]
|
|
77
|
+
})]
|
|
30
78
|
});
|
|
31
79
|
};
|
|
32
80
|
var _default = exports.default = CodeEmbed;
|