@ndla/ui 56.0.123-alpha.0 → 56.0.124-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.
Files changed (347) hide show
  1. package/es/Article/Article.js +122 -194
  2. package/es/Article/Article.js.map +1 -0
  3. package/es/Article/ArticleByline.js +121 -170
  4. package/es/Article/ArticleByline.js.map +1 -0
  5. package/es/Article/ArticleFootNotes.js +38 -58
  6. package/es/Article/ArticleFootNotes.js.map +1 -0
  7. package/es/AudioPlayer/AudioPlayer.js +151 -212
  8. package/es/AudioPlayer/AudioPlayer.js.map +1 -0
  9. package/es/AudioPlayer/Controls.js +246 -324
  10. package/es/AudioPlayer/Controls.js.map +1 -0
  11. package/es/AudioPlayer/SpeechControl.js +36 -52
  12. package/es/AudioPlayer/SpeechControl.js.map +1 -0
  13. package/es/AudioPlayer/index.js +7 -9
  14. package/es/AudioPlayer/index.js.map +1 -0
  15. package/es/Breadcrumb/Breadcrumb.js +42 -58
  16. package/es/Breadcrumb/Breadcrumb.js.map +1 -0
  17. package/es/Breadcrumb/BreadcrumbItem.js +33 -59
  18. package/es/Breadcrumb/BreadcrumbItem.js.map +1 -0
  19. package/es/Breadcrumb/HomeBreadcrumb.js +41 -74
  20. package/es/Breadcrumb/HomeBreadcrumb.js.map +1 -0
  21. package/es/Breadcrumb/index.js +8 -10
  22. package/es/Breadcrumb/index.js.map +1 -0
  23. package/es/CampaignBlock/CampaignBlock.js +124 -173
  24. package/es/CampaignBlock/CampaignBlock.js.map +1 -0
  25. package/es/CodeBlock/CodeBlock.js +21 -31
  26. package/es/CodeBlock/CodeBlock.js.map +1 -0
  27. package/es/CodeBlock/codeLanguageOptions.js +112 -82
  28. package/es/CodeBlock/codeLanguageOptions.js.map +1 -0
  29. package/es/Concept/Concept.js +46 -68
  30. package/es/Concept/Concept.js.map +1 -0
  31. package/es/ContactBlock/ContactBlock.js +137 -191
  32. package/es/ContactBlock/ContactBlock.js.map +1 -0
  33. package/es/ContentTypeBadge/ContentTypeBadge.js +38 -47
  34. package/es/ContentTypeBadge/ContentTypeBadge.js.map +1 -0
  35. package/es/ContentTypeBlockQuote/ContentTypeBlockQuote.js +21 -28
  36. package/es/ContentTypeBlockQuote/ContentTypeBlockQuote.js.map +1 -0
  37. package/es/ContentTypeFramedContent/ContentTypeFramedContent.js +21 -28
  38. package/es/ContentTypeFramedContent/ContentTypeFramedContent.js.map +1 -0
  39. package/es/ContentTypeHero/ContentTypeHero.js +36 -47
  40. package/es/ContentTypeHero/ContentTypeHero.js.map +1 -0
  41. package/es/CopyParagraphButton/CopyParagraphButton.js +57 -78
  42. package/es/CopyParagraphButton/CopyParagraphButton.js.map +1 -0
  43. package/es/CopyParagraphButton/index.js +7 -10
  44. package/es/CopyParagraphButton/index.js.map +1 -0
  45. package/es/Embed/AudioEmbed.js +49 -73
  46. package/es/Embed/AudioEmbed.js.map +1 -0
  47. package/es/Embed/BrightcoveEmbed.js +90 -127
  48. package/es/Embed/BrightcoveEmbed.js.map +1 -0
  49. package/es/Embed/CodeEmbed.js +55 -73
  50. package/es/Embed/CodeEmbed.js.map +1 -0
  51. package/es/Embed/ConceptEmbed.js +72 -117
  52. package/es/Embed/ConceptEmbed.js.map +1 -0
  53. package/es/Embed/ConceptInlineTriggerButton.js +39 -44
  54. package/es/Embed/ConceptInlineTriggerButton.js.map +1 -0
  55. package/es/Embed/ContentLinkEmbed.js +29 -49
  56. package/es/Embed/ContentLinkEmbed.js.map +1 -0
  57. package/es/Embed/CopyrightEmbed.js +21 -31
  58. package/es/Embed/CopyrightEmbed.js.map +1 -0
  59. package/es/Embed/EmbedErrorPlaceholder.js +40 -55
  60. package/es/Embed/EmbedErrorPlaceholder.js.map +1 -0
  61. package/es/Embed/EmbedWrapper.js +21 -46
  62. package/es/Embed/EmbedWrapper.js.map +1 -0
  63. package/es/Embed/ExternalEmbed.js +50 -70
  64. package/es/Embed/ExternalEmbed.js.map +1 -0
  65. package/es/Embed/FootnoteEmbed.js +25 -42
  66. package/es/Embed/FootnoteEmbed.js.map +1 -0
  67. package/es/Embed/GlossEmbed.js +49 -77
  68. package/es/Embed/GlossEmbed.js.map +1 -0
  69. package/es/Embed/H5pEmbed.js +35 -58
  70. package/es/Embed/H5pEmbed.js.map +1 -0
  71. package/es/Embed/IframeEmbed.js +65 -89
  72. package/es/Embed/IframeEmbed.js.map +1 -0
  73. package/es/Embed/ImageEmbed.js +167 -225
  74. package/es/Embed/ImageEmbed.js.map +1 -0
  75. package/es/Embed/InlineTriggerButton.js +20 -32
  76. package/es/Embed/InlineTriggerButton.js.map +1 -0
  77. package/es/Embed/RelatedContentEmbed.js +36 -53
  78. package/es/Embed/RelatedContentEmbed.js.map +1 -0
  79. package/es/Embed/UnknownEmbed.js +18 -29
  80. package/es/Embed/UnknownEmbed.js.map +1 -0
  81. package/es/Embed/UuDisclaimerEmbed.js +51 -85
  82. package/es/Embed/UuDisclaimerEmbed.js.map +1 -0
  83. package/es/ErrorMessage/ErrorMessage.js +51 -92
  84. package/es/ErrorMessage/ErrorMessage.js.map +1 -0
  85. package/es/ErrorMessage/index.js +7 -9
  86. package/es/ErrorMessage/index.js.map +1 -0
  87. package/es/FactBox/FactBox.js +114 -170
  88. package/es/FactBox/FactBox.js.map +1 -0
  89. package/es/FactBox/index.js +7 -9
  90. package/es/FactBox/index.js.map +1 -0
  91. package/es/FileList/File.js +70 -95
  92. package/es/FileList/File.js.map +1 -0
  93. package/es/FileList/FileList.js +31 -46
  94. package/es/FileList/FileList.js.map +1 -0
  95. package/es/FileList/PdfFile.js +27 -49
  96. package/es/FileList/PdfFile.js.map +1 -0
  97. package/es/Gloss/Gloss.js +133 -166
  98. package/es/Gloss/Gloss.js.map +1 -0
  99. package/es/Gloss/GlossExample.js +42 -60
  100. package/es/Gloss/GlossExample.js.map +1 -0
  101. package/es/Grid/Grid.js +63 -91
  102. package/es/Grid/Grid.js.map +1 -0
  103. package/es/Grid/GridParallaxItem.js +19 -30
  104. package/es/Grid/GridParallaxItem.js.map +1 -0
  105. package/es/KeyFigure/KeyFigure.js +44 -61
  106. package/es/KeyFigure/KeyFigure.js.map +1 -0
  107. package/es/LicenseByline/EmbedByline.js +126 -206
  108. package/es/LicenseByline/EmbedByline.js.map +1 -0
  109. package/es/LicenseByline/LicenseLink.js +28 -53
  110. package/es/LicenseByline/LicenseLink.js.map +1 -0
  111. package/es/LinkBlock/LinkBlock.js +70 -99
  112. package/es/LinkBlock/LinkBlock.js.map +1 -0
  113. package/es/LinkBlock/LinkBlockSection.js +20 -32
  114. package/es/LinkBlock/LinkBlockSection.js.map +1 -0
  115. package/es/Pitch/Pitch.js +59 -80
  116. package/es/Pitch/Pitch.js.map +1 -0
  117. package/es/RelatedArticleList/RelatedArticleList.js +91 -129
  118. package/es/RelatedArticleList/RelatedArticleList.js.map +1 -0
  119. package/es/RelatedArticleList/index.js +7 -10
  120. package/es/RelatedArticleList/index.js.map +1 -0
  121. package/es/ResourceBox/ResourceBox.js +71 -96
  122. package/es/ResourceBox/ResourceBox.js.map +1 -0
  123. package/es/TagSelector/TagSelector.js +93 -136
  124. package/es/TagSelector/TagSelector.js.map +1 -0
  125. package/es/ZendeskButton/ZendeskButton.js +38 -52
  126. package/es/ZendeskButton/ZendeskButton.js.map +1 -0
  127. package/es/_virtual/rolldown_runtime.js +11 -0
  128. package/es/i18n/formatNestedMessages.js +16 -24
  129. package/es/i18n/formatNestedMessages.js.map +1 -0
  130. package/es/i18n/i18n.js +25 -31
  131. package/es/i18n/i18n.js.map +1 -0
  132. package/es/i18n/useComponentTranslations.js +147 -203
  133. package/es/i18n/useComponentTranslations.js.map +1 -0
  134. package/es/index.js +64 -44
  135. package/es/locale/messages-en.js +435 -459
  136. package/es/locale/messages-en.js.map +1 -0
  137. package/es/locale/messages-nb.js +435 -459
  138. package/es/locale/messages-nb.js.map +1 -0
  139. package/es/locale/messages-nn.js +435 -459
  140. package/es/locale/messages-nn.js.map +1 -0
  141. package/es/locale/messages-se.js +435 -459
  142. package/es/locale/messages-se.js.map +1 -0
  143. package/es/model/ContentType.js +69 -65
  144. package/es/model/ContentType.js.map +1 -0
  145. package/es/model/SubjectCategories.js +23 -10
  146. package/es/model/SubjectCategories.js.map +1 -0
  147. package/es/model/SubjectTypes.js +21 -9
  148. package/es/model/SubjectTypes.js.map +1 -0
  149. package/es/model/WordClass.js +51 -43
  150. package/es/model/WordClass.js.map +1 -0
  151. package/es/model/index.js +16 -18
  152. package/es/model/index.js.map +1 -0
  153. package/es/utils/licenseAttributes.js +15 -17
  154. package/es/utils/licenseAttributes.js.map +1 -0
  155. package/es/utils/relativeUrl.js +21 -32
  156. package/es/utils/relativeUrl.js.map +1 -0
  157. package/lib/Article/Article.js +130 -203
  158. package/lib/Article/Article.js.map +1 -0
  159. package/lib/Article/ArticleByline.js +125 -179
  160. package/lib/Article/ArticleByline.js.map +1 -0
  161. package/lib/Article/ArticleFootNotes.js +39 -65
  162. package/lib/Article/ArticleFootNotes.js.map +1 -0
  163. package/lib/AudioPlayer/AudioPlayer.js +155 -221
  164. package/lib/AudioPlayer/AudioPlayer.js.map +1 -0
  165. package/lib/AudioPlayer/Controls.js +249 -332
  166. package/lib/AudioPlayer/Controls.js.map +1 -0
  167. package/lib/AudioPlayer/SpeechControl.js +39 -60
  168. package/lib/AudioPlayer/SpeechControl.js.map +1 -0
  169. package/lib/AudioPlayer/index.js +7 -15
  170. package/lib/AudioPlayer/index.js.map +1 -0
  171. package/lib/Breadcrumb/Breadcrumb.js +43 -65
  172. package/lib/Breadcrumb/Breadcrumb.js.map +1 -0
  173. package/lib/Breadcrumb/BreadcrumbItem.js +34 -65
  174. package/lib/Breadcrumb/BreadcrumbItem.js.map +1 -0
  175. package/lib/Breadcrumb/HomeBreadcrumb.js +43 -82
  176. package/lib/Breadcrumb/HomeBreadcrumb.js.map +1 -0
  177. package/lib/Breadcrumb/index.js +8 -22
  178. package/lib/Breadcrumb/index.js.map +1 -0
  179. package/lib/CampaignBlock/CampaignBlock.js +128 -183
  180. package/lib/CampaignBlock/CampaignBlock.js.map +1 -0
  181. package/lib/CodeBlock/CodeBlock.js +23 -38
  182. package/lib/CodeBlock/CodeBlock.js.map +1 -0
  183. package/lib/CodeBlock/codeLanguageOptions.js +112 -87
  184. package/lib/CodeBlock/codeLanguageOptions.js.map +1 -0
  185. package/lib/Concept/Concept.js +48 -75
  186. package/lib/Concept/Concept.js.map +1 -0
  187. package/lib/ContactBlock/ContactBlock.js +141 -200
  188. package/lib/ContactBlock/ContactBlock.js.map +1 -0
  189. package/lib/ContentTypeBadge/ContentTypeBadge.js +40 -54
  190. package/lib/ContentTypeBadge/ContentTypeBadge.js.map +1 -0
  191. package/lib/ContentTypeBlockQuote/ContentTypeBlockQuote.js +23 -35
  192. package/lib/ContentTypeBlockQuote/ContentTypeBlockQuote.js.map +1 -0
  193. package/lib/ContentTypeFramedContent/ContentTypeFramedContent.js +23 -35
  194. package/lib/ContentTypeFramedContent/ContentTypeFramedContent.js.map +1 -0
  195. package/lib/ContentTypeHero/ContentTypeHero.js +37 -54
  196. package/lib/ContentTypeHero/ContentTypeHero.js.map +1 -0
  197. package/lib/CopyParagraphButton/CopyParagraphButton.js +61 -87
  198. package/lib/CopyParagraphButton/CopyParagraphButton.js.map +1 -0
  199. package/lib/CopyParagraphButton/index.js +7 -21
  200. package/lib/CopyParagraphButton/index.js.map +1 -0
  201. package/lib/Embed/AudioEmbed.js +51 -82
  202. package/lib/Embed/AudioEmbed.js.map +1 -0
  203. package/lib/Embed/BrightcoveEmbed.js +93 -138
  204. package/lib/Embed/BrightcoveEmbed.js.map +1 -0
  205. package/lib/Embed/CodeEmbed.js +59 -83
  206. package/lib/Embed/CodeEmbed.js.map +1 -0
  207. package/lib/Embed/ConceptEmbed.js +77 -127
  208. package/lib/Embed/ConceptEmbed.js.map +1 -0
  209. package/lib/Embed/ConceptInlineTriggerButton.js +39 -49
  210. package/lib/Embed/ConceptInlineTriggerButton.js.map +1 -0
  211. package/lib/Embed/ContentLinkEmbed.js +30 -55
  212. package/lib/Embed/ContentLinkEmbed.js.map +1 -0
  213. package/lib/Embed/CopyrightEmbed.js +22 -37
  214. package/lib/Embed/CopyrightEmbed.js.map +1 -0
  215. package/lib/Embed/EmbedErrorPlaceholder.js +42 -62
  216. package/lib/Embed/EmbedErrorPlaceholder.js.map +1 -0
  217. package/lib/Embed/EmbedWrapper.js +24 -54
  218. package/lib/Embed/EmbedWrapper.js.map +1 -0
  219. package/lib/Embed/ExternalEmbed.js +53 -79
  220. package/lib/Embed/ExternalEmbed.js.map +1 -0
  221. package/lib/Embed/FootnoteEmbed.js +26 -48
  222. package/lib/Embed/FootnoteEmbed.js.map +1 -0
  223. package/lib/Embed/GlossEmbed.js +51 -86
  224. package/lib/Embed/GlossEmbed.js.map +1 -0
  225. package/lib/Embed/H5pEmbed.js +37 -66
  226. package/lib/Embed/H5pEmbed.js.map +1 -0
  227. package/lib/Embed/IframeEmbed.js +68 -98
  228. package/lib/Embed/IframeEmbed.js.map +1 -0
  229. package/lib/Embed/ImageEmbed.js +173 -238
  230. package/lib/Embed/ImageEmbed.js.map +1 -0
  231. package/lib/Embed/InlineTriggerButton.js +23 -40
  232. package/lib/Embed/InlineTriggerButton.js.map +1 -0
  233. package/lib/Embed/RelatedContentEmbed.js +37 -59
  234. package/lib/Embed/RelatedContentEmbed.js.map +1 -0
  235. package/lib/Embed/UnknownEmbed.js +19 -35
  236. package/lib/Embed/UnknownEmbed.js.map +1 -0
  237. package/lib/Embed/UuDisclaimerEmbed.js +53 -92
  238. package/lib/Embed/UuDisclaimerEmbed.js.map +1 -0
  239. package/lib/ErrorMessage/ErrorMessage.js +53 -99
  240. package/lib/ErrorMessage/ErrorMessage.js.map +1 -0
  241. package/lib/ErrorMessage/index.js +7 -15
  242. package/lib/ErrorMessage/index.js.map +1 -0
  243. package/lib/FactBox/FactBox.js +118 -180
  244. package/lib/FactBox/FactBox.js.map +1 -0
  245. package/lib/FactBox/index.js +7 -15
  246. package/lib/FactBox/index.js.map +1 -0
  247. package/lib/FileList/File.js +75 -105
  248. package/lib/FileList/File.js.map +1 -0
  249. package/lib/FileList/FileList.js +33 -52
  250. package/lib/FileList/FileList.js.map +1 -0
  251. package/lib/FileList/PdfFile.js +27 -55
  252. package/lib/FileList/PdfFile.js.map +1 -0
  253. package/lib/Gloss/Gloss.js +138 -176
  254. package/lib/Gloss/Gloss.js.map +1 -0
  255. package/lib/Gloss/GlossExample.js +45 -68
  256. package/lib/Gloss/GlossExample.js.map +1 -0
  257. package/lib/Grid/Grid.js +64 -98
  258. package/lib/Grid/Grid.js.map +1 -0
  259. package/lib/Grid/GridParallaxItem.js +19 -36
  260. package/lib/Grid/GridParallaxItem.js.map +1 -0
  261. package/lib/KeyFigure/KeyFigure.js +45 -68
  262. package/lib/KeyFigure/KeyFigure.js.map +1 -0
  263. package/lib/LicenseByline/EmbedByline.js +130 -216
  264. package/lib/LicenseByline/EmbedByline.js.map +1 -0
  265. package/lib/LicenseByline/LicenseLink.js +29 -59
  266. package/lib/LicenseByline/LicenseLink.js.map +1 -0
  267. package/lib/LinkBlock/LinkBlock.js +73 -108
  268. package/lib/LinkBlock/LinkBlock.js.map +1 -0
  269. package/lib/LinkBlock/LinkBlockSection.js +22 -39
  270. package/lib/LinkBlock/LinkBlockSection.js.map +1 -0
  271. package/lib/Pitch/Pitch.js +61 -89
  272. package/lib/Pitch/Pitch.js.map +1 -0
  273. package/lib/RelatedArticleList/RelatedArticleList.js +96 -140
  274. package/lib/RelatedArticleList/RelatedArticleList.js.map +1 -0
  275. package/lib/RelatedArticleList/index.js +7 -20
  276. package/lib/RelatedArticleList/index.js.map +1 -0
  277. package/lib/ResourceBox/ResourceBox.js +73 -104
  278. package/lib/ResourceBox/ResourceBox.js.map +1 -0
  279. package/lib/TagSelector/TagSelector.js +103 -145
  280. package/lib/TagSelector/TagSelector.js.map +1 -0
  281. package/lib/ZendeskButton/ZendeskButton.js +39 -58
  282. package/lib/ZendeskButton/ZendeskButton.js.map +1 -0
  283. package/lib/_virtual/rolldown_runtime.js +42 -0
  284. package/lib/i18n/formatNestedMessages.js +16 -30
  285. package/lib/i18n/formatNestedMessages.js.map +1 -0
  286. package/lib/i18n/i18n.js +28 -38
  287. package/lib/i18n/i18n.js.map +1 -0
  288. package/lib/i18n/useComponentTranslations.js +154 -215
  289. package/lib/i18n/useComponentTranslations.js.map +1 -0
  290. package/lib/index.js +156 -598
  291. package/lib/locale/messages-en.js +436 -466
  292. package/lib/locale/messages-en.js.map +1 -0
  293. package/lib/locale/messages-nb.js +436 -466
  294. package/lib/locale/messages-nb.js.map +1 -0
  295. package/lib/locale/messages-nn.js +436 -466
  296. package/lib/locale/messages-nn.js.map +1 -0
  297. package/lib/locale/messages-se.js +436 -466
  298. package/lib/locale/messages-se.js.map +1 -0
  299. package/lib/model/ContentType.js +90 -70
  300. package/lib/model/ContentType.js.map +1 -0
  301. package/lib/model/SubjectCategories.js +26 -14
  302. package/lib/model/SubjectCategories.js.map +1 -0
  303. package/lib/model/SubjectTypes.js +24 -13
  304. package/lib/model/SubjectTypes.js.map +1 -0
  305. package/lib/model/WordClass.js +55 -48
  306. package/lib/model/WordClass.js.map +1 -0
  307. package/lib/model/index.js +16 -25
  308. package/lib/model/index.js.map +1 -0
  309. package/lib/utils/licenseAttributes.js +14 -22
  310. package/lib/utils/licenseAttributes.js.map +1 -0
  311. package/lib/utils/relativeUrl.js +20 -38
  312. package/lib/utils/relativeUrl.js.map +1 -0
  313. package/package.json +12 -11
  314. package/es/Article/index.js +0 -11
  315. package/es/CampaignBlock/index.js +0 -9
  316. package/es/CodeBlock/index.js +0 -10
  317. package/es/ContactBlock/index.js +0 -9
  318. package/es/ContentTypeHero/index.js +0 -9
  319. package/es/Embed/index.js +0 -25
  320. package/es/Embed/types.js +0 -1
  321. package/es/FileList/index.js +0 -11
  322. package/es/Gloss/index.js +0 -10
  323. package/es/Grid/index.js +0 -10
  324. package/es/KeyFigure/index.js +0 -9
  325. package/es/LicenseByline/index.js +0 -10
  326. package/es/LinkBlock/index.js +0 -10
  327. package/es/Pitch/index.js +0 -9
  328. package/es/ResourceBox/index.js +0 -10
  329. package/es/i18n/index.js +0 -11
  330. package/es/types.js +0 -1
  331. package/lib/Article/index.js +0 -68
  332. package/lib/CampaignBlock/index.js +0 -13
  333. package/lib/CodeBlock/index.js +0 -20
  334. package/lib/ContactBlock/index.js +0 -18
  335. package/lib/ContentTypeHero/index.js +0 -12
  336. package/lib/Embed/index.js +0 -150
  337. package/lib/Embed/types.js +0 -5
  338. package/lib/FileList/index.js +0 -44
  339. package/lib/Gloss/index.js +0 -20
  340. package/lib/Grid/index.js +0 -19
  341. package/lib/KeyFigure/index.js +0 -13
  342. package/lib/LicenseByline/index.js +0 -19
  343. package/lib/LinkBlock/index.js +0 -20
  344. package/lib/Pitch/index.js +0 -12
  345. package/lib/ResourceBox/index.js +0 -13
  346. package/lib/i18n/index.js +0 -68
  347. package/lib/types.js +0 -5
@@ -1,133 +1,96 @@
1
- /**
2
- * Copyright (c) 2023-present, NDLA.
3
- *
4
- * This source code is licensed under the GPLv3 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- import parse from "html-react-parser";
1
+ import { EmbedByline } from "../LicenseByline/EmbedByline.js";
2
+ import { EmbedErrorPlaceholder_default } from "./EmbedErrorPlaceholder.js";
3
+ import { licenseAttributes } from "../utils/licenseAttributes.js";
10
4
  import { useEffect, useMemo, useRef, useState } from "react";
11
- import { useTranslation } from "react-i18next";
12
5
  import { Button, Figure } from "@ndla/primitives";
13
6
  import { styled } from "@ndla/styled-system/jsx";
14
- import EmbedErrorPlaceholder from "./EmbedErrorPlaceholder";
15
- import { EmbedByline } from "../LicenseByline";
16
- import { licenseAttributes } from "../utils/licenseAttributes";
17
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
- const LinkedVideoButton = styled(Button, {
19
- base: {
20
- marginBlockStart: "3xsmall"
21
- }
22
- });
23
- const BrightcoveIframe = styled("iframe", {
24
- base: {
25
- border: 0,
26
- height: "auto",
27
- width: "100%"
28
- }
29
- });
30
- export const makeIframeString = function (url, width, height) {
31
- let title = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
32
- const strippedWidth = typeof width === "number" ? width : width.replace(/\s*px/, "");
33
- const strippedHeight = typeof height === "number" ? height : height.replace(/\s*px/, "");
34
- const urlOrTitle = title || url;
35
- return `<iframe title="${urlOrTitle}" aria-label="${urlOrTitle}" src="${url}" width="${strippedWidth}" height="${strippedHeight}" allowfullscreen scrolling="no" frameborder="0" loading="lazy"></iframe>`;
36
- };
37
- export const isNumeric = value => !Number.isNaN(value - Number.parseFloat(value));
7
+ import parse from "html-react-parser";
8
+ import { useTranslation } from "react-i18next";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+
11
+ //#region src/Embed/BrightcoveEmbed.tsx
12
+ const LinkedVideoButton = styled(Button, { base: { marginBlockStart: "3xsmall" } });
13
+ const BrightcoveIframe = styled("iframe", { base: {
14
+ border: 0,
15
+ height: "auto",
16
+ width: "100%"
17
+ } });
18
+ const isNumeric = (value) => !Number.isNaN(value - Number.parseFloat(value));
38
19
  const getIframeProps = (data, sources) => {
39
- const {
40
- account,
41
- videoid,
42
- player = "default"
43
- } = data;
44
- const source = sources.filter(s => s.width && s.height).toSorted((a, b) => a.height - b.height)[0];
45
- return {
46
- src: `https://players.brightcove.net/${account}/${player}_default/index.html?videoId=${videoid}`,
47
- height: source?.height ?? "480",
48
- width: source?.width ?? "640"
49
- };
20
+ const { account, videoid, player = "default" } = data;
21
+ const source = sources.filter((s) => s.width && s.height).toSorted((a, b) => a.height - b.height)[0];
22
+ return {
23
+ src: `https://players.brightcove.net/${account}/${player}_default/index.html?videoId=${videoid}`,
24
+ height: source?.height ?? "480",
25
+ width: source?.width ?? "640"
26
+ };
50
27
  };
51
- const BrightcoveEmbed = _ref => {
52
- let {
53
- embed,
54
- renderContext = "article",
55
- lang
56
- } = _ref;
57
- const [showOriginalVideo, setShowOriginalVideo] = useState(true);
58
- const {
59
- t
60
- } = useTranslation();
61
- const iframeRef = useRef(null);
62
- const {
63
- embedData
64
- } = embed;
65
- const fallbackTitle = `${t("embed.type.video")}: ${embedData.videoid}`;
66
- const parsedDescription = useMemo(() => {
67
- if (embed.embedData.caption || renderContext === "article") {
68
- return embed.embedData.caption ? parse(embed.embedData.caption) : undefined;
69
- } else if (embed.status === "success" && embed.data.description) {
70
- return parse(embed.data.description);
71
- }
72
- }, [embed, renderContext]);
73
- useEffect(() => {
74
- const iframe = iframeRef.current;
75
- if (iframe) {
76
- const [width, height] = [parseInt(iframe.width), parseInt(iframe.height)];
77
- iframe.style.aspectRatio = `${width}/${height}`;
78
- iframe.width = "";
79
- iframe.height = "";
80
- }
81
- }, []);
82
- if (embed.status === "error") {
83
- return /*#__PURE__*/_jsx(EmbedErrorPlaceholder, {
84
- type: "video",
85
- children: /*#__PURE__*/_jsx(BrightcoveIframe, {
86
- ref: iframeRef,
87
- title: embedData.alt || fallbackTitle,
88
- "aria-label": embedData.alt || fallbackTitle,
89
- ...getIframeProps(embedData, []),
90
- allow: "fullscreen; encrypted-media"
91
- })
92
- });
93
- }
94
- const {
95
- data
96
- } = embed;
97
- const linkedVideoId = isNumeric(data.link?.text) ? data.link?.text : undefined;
98
- const originalVideoProps = getIframeProps(embedData, data.sources);
99
- const alternativeVideoProps = linkedVideoId ? getIframeProps({
100
- ...embedData,
101
- videoid: linkedVideoId
102
- }, data.sources) : undefined;
103
- const licenseProps = licenseAttributes(data?.copyright?.license.license, lang, embedData.pageUrl);
104
- const title = data.name?.trim() ? `${t("embed.type.video")}: ${data.name}` : fallbackTitle;
105
- return /*#__PURE__*/_jsxs(Figure, {
106
- "data-embed-type": "brightcove",
107
- ...licenseProps,
108
- children: [/*#__PURE__*/_jsx("div", {
109
- className: "brightcove-video",
110
- children: /*#__PURE__*/_jsx(BrightcoveIframe, {
111
- ref: iframeRef,
112
- className: "original",
113
- title: title,
114
- "aria-label": title,
115
- ...(alternativeVideoProps && !showOriginalVideo ? alternativeVideoProps : originalVideoProps),
116
- allow: "fullscreen; encrypted-media"
117
- })
118
- }), /*#__PURE__*/_jsx(EmbedByline, {
119
- type: "video",
120
- copyright: data.copyright,
121
- description: parsedDescription,
122
- children: /*#__PURE__*/_jsx("div", {
123
- children: !!linkedVideoId && /*#__PURE__*/_jsx(LinkedVideoButton, {
124
- size: "small",
125
- variant: "secondary",
126
- onClick: () => setShowOriginalVideo(p => !p),
127
- children: t(`figure.button.${!showOriginalVideo ? "original" : "alternative"}`)
128
- })
129
- })
130
- })]
131
- });
28
+ const BrightcoveEmbed = ({ embed, renderContext = "article", lang }) => {
29
+ const [showOriginalVideo, setShowOriginalVideo] = useState(true);
30
+ const { t } = useTranslation();
31
+ const iframeRef = useRef(null);
32
+ const { embedData } = embed;
33
+ const fallbackTitle = `${t("embed.type.video")}: ${embedData.videoid}`;
34
+ const parsedDescription = useMemo(() => {
35
+ if (embed.embedData.caption || renderContext === "article") return embed.embedData.caption ? parse(embed.embedData.caption) : void 0;
36
+ else if (embed.status === "success" && embed.data.description) return parse(embed.data.description);
37
+ }, [embed, renderContext]);
38
+ useEffect(() => {
39
+ const iframe = iframeRef.current;
40
+ if (iframe) {
41
+ const [width, height] = [parseInt(iframe.width), parseInt(iframe.height)];
42
+ iframe.style.aspectRatio = `${width}/${height}`;
43
+ iframe.width = "";
44
+ iframe.height = "";
45
+ }
46
+ }, []);
47
+ if (embed.status === "error") return /* @__PURE__ */ jsx(EmbedErrorPlaceholder_default, {
48
+ type: "video",
49
+ children: /* @__PURE__ */ jsx(BrightcoveIframe, {
50
+ ref: iframeRef,
51
+ title: embedData.alt || fallbackTitle,
52
+ "aria-label": embedData.alt || fallbackTitle,
53
+ ...getIframeProps(embedData, []),
54
+ allow: "fullscreen; encrypted-media"
55
+ })
56
+ });
57
+ const { data } = embed;
58
+ const linkedVideoId = isNumeric(data.link?.text) ? data.link?.text : void 0;
59
+ const originalVideoProps = getIframeProps(embedData, data.sources);
60
+ const alternativeVideoProps = linkedVideoId ? getIframeProps({
61
+ ...embedData,
62
+ videoid: linkedVideoId
63
+ }, data.sources) : void 0;
64
+ const licenseProps = licenseAttributes(data?.copyright?.license.license, lang, embedData.pageUrl);
65
+ const title = data.name?.trim() ? `${t("embed.type.video")}: ${data.name}` : fallbackTitle;
66
+ return /* @__PURE__ */ jsxs(Figure, {
67
+ "data-embed-type": "brightcove",
68
+ ...licenseProps,
69
+ children: [/* @__PURE__ */ jsx("div", {
70
+ className: "brightcove-video",
71
+ children: /* @__PURE__ */ jsx(BrightcoveIframe, {
72
+ ref: iframeRef,
73
+ className: "original",
74
+ title,
75
+ "aria-label": title,
76
+ ...alternativeVideoProps && !showOriginalVideo ? alternativeVideoProps : originalVideoProps,
77
+ allow: "fullscreen; encrypted-media"
78
+ })
79
+ }), /* @__PURE__ */ jsx(EmbedByline, {
80
+ type: "video",
81
+ copyright: data.copyright,
82
+ description: parsedDescription,
83
+ children: /* @__PURE__ */ jsx("div", { children: !!linkedVideoId && /* @__PURE__ */ jsx(LinkedVideoButton, {
84
+ size: "small",
85
+ variant: "secondary",
86
+ onClick: () => setShowOriginalVideo((p) => !p),
87
+ children: t(`figure.button.${!showOriginalVideo ? "original" : "alternative"}`)
88
+ }) })
89
+ })]
90
+ });
132
91
  };
133
- export default BrightcoveEmbed;
92
+ var BrightcoveEmbed_default = BrightcoveEmbed;
93
+
94
+ //#endregion
95
+ export { BrightcoveEmbed_default };
96
+ //# sourceMappingURL=BrightcoveEmbed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrightcoveEmbed.js","names":["value: any","data: BrightcoveEmbedData","sources: BrightcoveVideoSource[]","EmbedErrorPlaceholder"],"sources":["../../src/Embed/BrightcoveEmbed.tsx"],"sourcesContent":["/**\n * Copyright (c) 2023-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 parse from \"html-react-parser\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { Button, Figure } from \"@ndla/primitives\";\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport type { BrightcoveEmbedData, BrightcoveMetaData, BrightcoveVideoSource } from \"@ndla/types-embed\";\nimport EmbedErrorPlaceholder from \"./EmbedErrorPlaceholder\";\nimport type { RenderContext } from \"./types\";\nimport { EmbedByline } from \"../LicenseByline\";\nimport { licenseAttributes } from \"../utils/licenseAttributes\";\n\ninterface Props {\n embed: BrightcoveMetaData;\n renderContext?: RenderContext;\n lang?: string;\n}\n\nconst LinkedVideoButton = styled(Button, {\n base: {\n marginBlockStart: \"3xsmall\",\n },\n});\n\nconst BrightcoveIframe = styled(\"iframe\", {\n base: {\n border: 0,\n height: \"auto\",\n width: \"100%\",\n },\n});\n\nexport const makeIframeString = (url: string, width: string | number, height: string | number, title = \"\") => {\n const strippedWidth = typeof width === \"number\" ? width : width.replace(/\\s*px/, \"\");\n const strippedHeight = typeof height === \"number\" ? height : height.replace(/\\s*px/, \"\");\n const urlOrTitle = title || url;\n return `<iframe title=\"${urlOrTitle}\" aria-label=\"${urlOrTitle}\" src=\"${url}\" width=\"${strippedWidth}\" height=\"${strippedHeight}\" allowfullscreen scrolling=\"no\" frameborder=\"0\" loading=\"lazy\"></iframe>`;\n};\n\nexport const isNumeric = (value: any) => !Number.isNaN(value - Number.parseFloat(value));\n\nconst getIframeProps = (data: BrightcoveEmbedData, sources: BrightcoveVideoSource[]) => {\n const { account, videoid, player = \"default\" } = data;\n\n const source = sources.filter((s) => s.width && s.height).toSorted((a, b) => a!.height! - b.height!)[0];\n\n return {\n src: `https://players.brightcove.net/${account}/${player}_default/index.html?videoId=${videoid}`,\n height: source?.height ?? \"480\",\n width: source?.width ?? \"640\",\n };\n};\nconst BrightcoveEmbed = ({ embed, renderContext = \"article\", lang }: Props) => {\n const [showOriginalVideo, setShowOriginalVideo] = useState(true);\n const { t } = useTranslation();\n const iframeRef = useRef<HTMLIFrameElement>(null);\n const { embedData } = embed;\n const fallbackTitle = `${t(\"embed.type.video\")}: ${embedData.videoid}`;\n const parsedDescription = useMemo(() => {\n if (embed.embedData.caption || renderContext === \"article\") {\n return embed.embedData.caption ? parse(embed.embedData.caption) : undefined;\n } else if (embed.status === \"success\" && embed.data.description) {\n return parse(embed.data.description);\n }\n }, [embed, renderContext]);\n\n useEffect(() => {\n const iframe = iframeRef.current;\n if (iframe) {\n const [width, height] = [parseInt(iframe.width), parseInt(iframe.height)];\n iframe.style.aspectRatio = `${width}/${height}`;\n iframe.width = \"\";\n iframe.height = \"\";\n }\n }, []);\n if (embed.status === \"error\") {\n return (\n <EmbedErrorPlaceholder type=\"video\">\n <BrightcoveIframe\n ref={iframeRef}\n title={embedData.alt || fallbackTitle}\n aria-label={embedData.alt || fallbackTitle}\n {...getIframeProps(embedData, [])}\n allow=\"fullscreen; encrypted-media\"\n />\n </EmbedErrorPlaceholder>\n );\n }\n const { data } = embed;\n\n const linkedVideoId = isNumeric(data.link?.text) ? data.link?.text : undefined;\n\n const originalVideoProps = getIframeProps(embedData, data.sources);\n const alternativeVideoProps = linkedVideoId\n ? getIframeProps({ ...embedData, videoid: linkedVideoId }, data.sources)\n : undefined;\n\n const licenseProps = licenseAttributes(data?.copyright?.license.license, lang, embedData.pageUrl);\n\n const title = data.name?.trim() ? `${t(\"embed.type.video\")}: ${data.name}` : fallbackTitle;\n\n return (\n <Figure data-embed-type=\"brightcove\" {...licenseProps}>\n <div className=\"brightcove-video\">\n <BrightcoveIframe\n ref={iframeRef}\n className=\"original\"\n title={title}\n aria-label={title}\n {...(alternativeVideoProps && !showOriginalVideo ? alternativeVideoProps : originalVideoProps)}\n allow=\"fullscreen; encrypted-media\"\n />\n </div>\n <EmbedByline type=\"video\" copyright={data.copyright!} description={parsedDescription}>\n <div>\n {!!linkedVideoId && (\n <LinkedVideoButton size=\"small\" variant=\"secondary\" onClick={() => setShowOriginalVideo((p) => !p)}>\n {t(`figure.button.${!showOriginalVideo ? \"original\" : \"alternative\"}`)}\n </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ACM;GACP;AAEZ;AAED,8BAAe"}
@@ -1,79 +1,61 @@
1
- /**
2
- * Copyright (c) 2023-present, NDLA.
3
- *
4
- * This source code is licensed under the GPLv3 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
1
+ import { EmbedErrorPlaceholder_default } from "./EmbedErrorPlaceholder.js";
2
+ import { CodeBlock_default } from "../CodeBlock/CodeBlock.js";
3
+ import { codeLanguageOptions } from "../CodeBlock/codeLanguageOptions.js";
9
4
  import { useEffect, useState } from "react";
10
- import { useTranslation } from "react-i18next";
11
- import { FileCopyLine, CheckLine } from "@ndla/icons";
12
5
  import { Button, Figure } from "@ndla/primitives";
13
6
  import { styled } from "@ndla/styled-system/jsx";
7
+ import { useTranslation } from "react-i18next";
8
+ import { CheckLine, FileCopyLine } from "@ndla/icons";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
14
10
  import { copyTextToClipboard } from "@ndla/util";
15
- import EmbedErrorPlaceholder from "./EmbedErrorPlaceholder";
16
- import { CodeBlock, codeLanguageOptions } from "../CodeBlock";
17
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
- const StyledFigCaption = styled("figcaption", {
19
- base: {
20
- textStyle: "label.large",
21
- fontWeight: "bold"
22
- }
23
- });
24
- const StyledFigure = styled(Figure, {
25
- base: {
26
- clear: "both",
27
- // We apply margin here to allow for the float and size props on figure to work as intended.
28
- "& > *:not(:where(:first-child))": {
29
- marginBlockStart: "xsmall"
30
- }
31
- }
32
- });
33
- const getTitleFromFormat = format => {
34
- const selectedLanguage = codeLanguageOptions.find(item => item.format === format);
35
- if (selectedLanguage) {
36
- return selectedLanguage.title;
37
- }
38
- return;
11
+
12
+ //#region src/Embed/CodeEmbed.tsx
13
+ const StyledFigCaption = styled("figcaption", { base: {
14
+ textStyle: "label.large",
15
+ fontWeight: "bold"
16
+ } });
17
+ const StyledFigure = styled(Figure, { base: {
18
+ clear: "both",
19
+ "& > *:not(:where(:first-child))": { marginBlockStart: "xsmall" }
20
+ } });
21
+ const getTitleFromFormat = (format) => {
22
+ const selectedLanguage = codeLanguageOptions.find((item) => item.format === format);
23
+ if (selectedLanguage) return selectedLanguage.title;
24
+ return;
39
25
  };
40
- const CodeEmbed = _ref => {
41
- let {
42
- embed
43
- } = _ref;
44
- const [isCopied, setIsCopied] = useState(false);
45
- const {
46
- t
47
- } = useTranslation();
48
- useEffect(() => {
49
- if (isCopied) {
50
- const timer = setInterval(() => setIsCopied(false), 3000);
51
- // ensure interval is cleared - also if unmounted
52
- return () => {
53
- clearTimeout(timer);
54
- };
55
- }
56
- }, [isCopied]);
57
- if (embed.status === "error") {
58
- return /*#__PURE__*/_jsx(EmbedErrorPlaceholder, {
59
- type: "code"
60
- });
61
- }
62
- return /*#__PURE__*/_jsxs(StyledFigure, {
63
- "data-embed-type": "code-block",
64
- children: [/*#__PURE__*/_jsx(StyledFigCaption, {
65
- children: embed.embedData.title || getTitleFromFormat(embed.embedData.codeFormat)
66
- }), /*#__PURE__*/_jsx(CodeBlock, {
67
- highlightedCode: embed.status === "success" ? embed.data.highlightedCode : "",
68
- format: embed.embedData.codeFormat
69
- }), /*#__PURE__*/_jsxs(Button, {
70
- variant: "secondary",
71
- onClick: () => {
72
- copyTextToClipboard(embed.status === "success" ? embed.data.decodedContent : "");
73
- setIsCopied(true);
74
- },
75
- children: [isCopied ? /*#__PURE__*/_jsx(CheckLine, {}) : /*#__PURE__*/_jsx(FileCopyLine, {}), isCopied ? t("codeBlock.copiedCode") : t("codeBlock.copyCode")]
76
- })]
77
- });
26
+ const CodeEmbed = ({ embed }) => {
27
+ const [isCopied, setIsCopied] = useState(false);
28
+ const { t } = useTranslation();
29
+ useEffect(() => {
30
+ if (isCopied) {
31
+ const timer = setInterval(() => setIsCopied(false), 3e3);
32
+ return () => {
33
+ clearTimeout(timer);
34
+ };
35
+ }
36
+ }, [isCopied]);
37
+ if (embed.status === "error") return /* @__PURE__ */ jsx(EmbedErrorPlaceholder_default, { type: "code" });
38
+ return /* @__PURE__ */ jsxs(StyledFigure, {
39
+ "data-embed-type": "code-block",
40
+ children: [
41
+ /* @__PURE__ */ jsx(StyledFigCaption, { children: embed.embedData.title || getTitleFromFormat(embed.embedData.codeFormat) }),
42
+ /* @__PURE__ */ jsx(CodeBlock_default, {
43
+ highlightedCode: embed.status === "success" ? embed.data.highlightedCode : "",
44
+ format: embed.embedData.codeFormat
45
+ }),
46
+ /* @__PURE__ */ jsxs(Button, {
47
+ variant: "secondary",
48
+ onClick: () => {
49
+ copyTextToClipboard(embed.status === "success" ? embed.data.decodedContent : "");
50
+ setIsCopied(true);
51
+ },
52
+ children: [isCopied ? /* @__PURE__ */ jsx(CheckLine, {}) : /* @__PURE__ */ jsx(FileCopyLine, {}), isCopied ? t("codeBlock.copiedCode") : t("codeBlock.copyCode")]
53
+ })
54
+ ]
55
+ });
78
56
  };
79
- export default CodeEmbed;
57
+ var CodeEmbed_default = CodeEmbed;
58
+
59
+ //#endregion
60
+ export { CodeEmbed_default };
61
+ //# sourceMappingURL=CodeEmbed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeEmbed.js","names":["format: string","item: ICodeLangugeOption","EmbedErrorPlaceholder","CodeBlock"],"sources":["../../src/Embed/CodeEmbed.tsx"],"sourcesContent":["/**\n * Copyright (c) 2023-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 { useEffect, useState } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { FileCopyLine, CheckLine } from \"@ndla/icons\";\nimport { Button, Figure } from \"@ndla/primitives\";\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport type { CodeMetaData } from \"@ndla/types-embed\";\nimport { copyTextToClipboard } from \"@ndla/util\";\nimport EmbedErrorPlaceholder from \"./EmbedErrorPlaceholder\";\nimport { CodeBlock, codeLanguageOptions } from \"../CodeBlock\";\nimport type { ICodeLangugeOption } from \"../CodeBlock/codeLanguageOptions\";\n\ninterface Props {\n embed: CodeMetaData;\n}\n\nconst StyledFigCaption = styled(\"figcaption\", {\n base: {\n textStyle: \"label.large\",\n fontWeight: \"bold\",\n },\n});\n\nconst StyledFigure = styled(Figure, {\n base: {\n clear: \"both\",\n // We apply margin here to allow for the float and size props on figure to work as intended.\n \"& > *:not(:where(:first-child))\": {\n marginBlockStart: \"xsmall\",\n },\n },\n});\n\nconst getTitleFromFormat = (format: string) => {\n const selectedLanguage = codeLanguageOptions.find((item: ICodeLangugeOption) => item.format === format);\n if (selectedLanguage) {\n return selectedLanguage.title;\n }\n return;\n};\n\nconst CodeEmbed = ({ embed }: Props) => {\n const [isCopied, setIsCopied] = useState(false);\n const { t } = useTranslation();\n\n useEffect(() => {\n if (isCopied) {\n const timer = setInterval(() => setIsCopied(false), 3000);\n // ensure interval is cleared - also if unmounted\n return () => {\n clearTimeout(timer);\n };\n }\n }, [isCopied]);\n\n if (embed.status === \"error\") {\n return <EmbedErrorPlaceholder type=\"code\" />;\n }\n\n return (\n <StyledFigure data-embed-type=\"code-block\">\n <StyledFigCaption>{embed.embedData.title || getTitleFromFormat(embed.embedData.codeFormat)}</StyledFigCaption>\n <CodeBlock\n highlightedCode={embed.status === \"success\" ? embed.data.highlightedCode : \"\"}\n format={embed.embedData.codeFormat}\n />\n <Button\n variant=\"secondary\"\n onClick={() => {\n copyTextToClipboard(embed.status === \"success\" ? embed.data.decodedContent : \"\");\n setIsCopied(true);\n }}\n >\n {isCopied ? <CheckLine /> : <FileCopyLine />}\n {isCopied ? t(\"codeBlock.copiedCode\") : t(\"codeBlock.copyCode\")}\n </Button>\n </StyledFigure>\n );\n};\n\nexport default CodeEmbed;\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAM,mBAAmB,OAAO,cAAc,EAC5C,MAAM;CACJ,WAAW;CACX,YAAY;AACb,EACF,EAAC;AAEF,MAAM,eAAe,OAAO,QAAQ,EAClC,MAAM;CACJ,OAAO;CAEP,mCAAmC,EACjC,kBAAkB,SACnB;AACF,EACF,EAAC;AAEF,MAAM,qBAAqB,CAACA,WAAmB;CAC7C,MAAM,mBAAmB,oBAAoB,KAAK,CAACC,SAA6B,KAAK,WAAW,OAAO;AACvG,KAAI,iBACF,QAAO,iBAAiB;AAE1B;AACD;AAED,MAAM,YAAY,CAAC,EAAE,OAAc,KAAK;CACtC,MAAM,CAAC,UAAU,YAAY,GAAG,SAAS,MAAM;CAC/C,MAAM,EAAE,GAAG,GAAG,gBAAgB;AAE9B,WAAU,MAAM;AACd,MAAI,UAAU;GACZ,MAAM,QAAQ,YAAY,MAAM,YAAY,MAAM,EAAE,IAAK;AAEzD,UAAO,MAAM;AACX,iBAAa,MAAM;GACpB;EACF;CACF,GAAE,CAAC,QAAS,EAAC;AAEd,KAAI,MAAM,WAAW,QACnB,wBAAO,IAACC,iCAAsB,MAAK,SAAS;AAG9C,wBACE,KAAC;EAAa,mBAAgB;;mBAC5B,IAAC,8BAAkB,MAAM,UAAU,SAAS,mBAAmB,MAAM,UAAU,WAAW,GAAoB;mBAC9G,IAACC;IACC,iBAAiB,MAAM,WAAW,YAAY,MAAM,KAAK,kBAAkB;IAC3E,QAAQ,MAAM,UAAU;KACxB;mBACF,KAAC;IACC,SAAQ;IACR,SAAS,MAAM;AACb,yBAAoB,MAAM,WAAW,YAAY,MAAM,KAAK,iBAAiB,GAAG;AAChF,iBAAY,KAAK;IAClB;eAEA,2BAAW,IAAC,cAAY,mBAAG,IAAC,iBAAe,EAC3C,WAAW,EAAE,uBAAuB,GAAG,EAAE,qBAAqB;KACxD;;GACI;AAElB;AAED,wBAAe"}
@@ -1,123 +1,78 @@
1
- /**
2
- * Copyright (c) 2024-present, NDLA.
3
- *
4
- * This source code is licensed under the GPLv3 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- import parse from "html-react-parser";
1
+ import { EmbedErrorPlaceholder_default } from "./EmbedErrorPlaceholder.js";
2
+ import { ConceptInlineTriggerButton } from "./ConceptInlineTriggerButton.js";
3
+ import { GlossEmbed } from "./GlossEmbed.js";
4
+ import { Concept } from "../Concept/Concept.js";
10
5
  import { forwardRef, useMemo, useRef } from "react";
11
- import { Portal } from "@ark-ui/react";
12
6
  import { PopoverContent, PopoverRoot, PopoverTrigger } from "@ndla/primitives";
13
7
  import { styled } from "@ndla/styled-system/jsx";
14
- import { ConceptInlineTriggerButton } from "./ConceptInlineTriggerButton";
15
- import EmbedErrorPlaceholder from "./EmbedErrorPlaceholder";
16
- import { GlossEmbed } from "./GlossEmbed";
17
- import { Concept } from "../Concept/Concept";
18
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
- const StyledPopoverContent = styled(PopoverContent, {
20
- base: {
21
- width: "surface.xlarge",
22
- maxHeight: "50vh",
23
- overflowY: "auto"
24
- }
25
- });
26
- export const ConceptEmbed = _ref => {
27
- let {
28
- embed,
29
- renderContext,
30
- lang,
31
- previewAlt
32
- } = _ref;
33
- const parsedContent = useMemo(() => {
34
- if (embed.status === "error" || !embed.data.concept.content) return undefined;
35
- return parse(embed.data.concept.content.htmlContent);
36
- }, [embed]);
37
- if (embed.status === "error" && embed.embedData.type === "inline") {
38
- return /*#__PURE__*/_jsx("span", {
39
- children: embed.embedData.linkText
40
- });
41
- }
42
- if (embed.status === "error") {
43
- // TODO: This could be either concept or gloss. We don't know if it errors out. :)
44
- return /*#__PURE__*/_jsx(EmbedErrorPlaceholder, {
45
- type: "gloss"
46
- });
47
- }
48
- const {
49
- concept,
50
- visualElement
51
- } = embed.data;
8
+ import parse from "html-react-parser";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ import { Portal } from "@ark-ui/react";
52
11
 
53
- // TODO: Consider whether we should do this in article-converter instead.
54
- if (embed.data.concept.glossData) {
55
- return /*#__PURE__*/_jsx(GlossEmbed, {
56
- embed: embed
57
- });
58
- }
59
- if (embed.embedData.type === "inline") {
60
- return /*#__PURE__*/_jsx(InlineConcept, {
61
- previewAlt: previewAlt,
62
- linkText: embed.embedData.linkText,
63
- copyright: concept.copyright,
64
- visualElement: visualElement,
65
- lang: lang,
66
- title: concept.title.title,
67
- source: concept.source,
68
- children: parsedContent
69
- });
70
- }
71
- return /*#__PURE__*/_jsx(BlockConcept, {
72
- previewAlt: previewAlt,
73
- copyright: concept.copyright,
74
- visualElement: visualElement,
75
- lang: lang,
76
- title: renderContext === "embed" ? undefined : concept.title.title,
77
- source: concept.source,
78
- children: parsedContent
79
- });
12
+ //#region src/Embed/ConceptEmbed.tsx
13
+ const StyledPopoverContent = styled(PopoverContent, { base: {
14
+ width: "surface.xlarge",
15
+ maxHeight: "50vh",
16
+ overflowY: "auto"
17
+ } });
18
+ const ConceptEmbed = ({ embed, renderContext, lang, previewAlt }) => {
19
+ const parsedContent = useMemo(() => {
20
+ if (embed.status === "error" || !embed.data.concept.content) return void 0;
21
+ return parse(embed.data.concept.content.htmlContent);
22
+ }, [embed]);
23
+ if (embed.status === "error" && embed.embedData.type === "inline") return /* @__PURE__ */ jsx("span", { children: embed.embedData.linkText });
24
+ if (embed.status === "error") return /* @__PURE__ */ jsx(EmbedErrorPlaceholder_default, { type: "gloss" });
25
+ const { concept, visualElement } = embed.data;
26
+ if (embed.data.concept.glossData) return /* @__PURE__ */ jsx(GlossEmbed, { embed });
27
+ if (embed.embedData.type === "inline") return /* @__PURE__ */ jsx(InlineConcept, {
28
+ previewAlt,
29
+ linkText: embed.embedData.linkText,
30
+ copyright: concept.copyright,
31
+ visualElement,
32
+ lang,
33
+ title: concept.title.title,
34
+ source: concept.source,
35
+ children: parsedContent
36
+ });
37
+ return /* @__PURE__ */ jsx(BlockConcept, {
38
+ previewAlt,
39
+ copyright: concept.copyright,
40
+ visualElement,
41
+ lang,
42
+ title: renderContext === "embed" ? void 0 : concept.title.title,
43
+ source: concept.source,
44
+ children: parsedContent
45
+ });
80
46
  };
81
- export const InlineConcept = /*#__PURE__*/forwardRef((_ref2, ref) => {
82
- let {
83
- linkText,
84
- copyright,
85
- visualElement,
86
- previewAlt,
87
- lang,
88
- children,
89
- title,
90
- source,
91
- ...rest
92
- } = _ref2;
93
- const contentRef = useRef(null);
94
- return /*#__PURE__*/_jsxs(PopoverRoot, {
95
- initialFocusEl: () => contentRef.current,
96
- children: [/*#__PURE__*/_jsx(PopoverTrigger, {
97
- asChild: true,
98
- ref: ref,
99
- ...rest,
100
- children: /*#__PURE__*/_jsx(ConceptInlineTriggerButton, {
101
- children: linkText
102
- })
103
- }), /*#__PURE__*/_jsx(Portal, {
104
- children: /*#__PURE__*/_jsx(StyledPopoverContent, {
105
- ref: contentRef,
106
- children: /*#__PURE__*/_jsx(Concept, {
107
- copyright: copyright,
108
- visualElement: visualElement,
109
- title: title,
110
- lang: lang,
111
- source: source,
112
- previewAlt: previewAlt,
113
- children: children
114
- })
115
- })
116
- })]
117
- });
47
+ const InlineConcept = forwardRef(({ linkText, copyright, visualElement, previewAlt, lang, children, title, source,...rest }, ref) => {
48
+ const contentRef = useRef(null);
49
+ return /* @__PURE__ */ jsxs(PopoverRoot, {
50
+ initialFocusEl: () => contentRef.current,
51
+ children: [/* @__PURE__ */ jsx(PopoverTrigger, {
52
+ asChild: true,
53
+ ref,
54
+ ...rest,
55
+ children: /* @__PURE__ */ jsx(ConceptInlineTriggerButton, { children: linkText })
56
+ }), /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(StyledPopoverContent, {
57
+ ref: contentRef,
58
+ children: /* @__PURE__ */ jsx(Concept, {
59
+ copyright,
60
+ visualElement,
61
+ title,
62
+ lang,
63
+ source,
64
+ previewAlt,
65
+ children
66
+ })
67
+ }) })]
68
+ });
118
69
  });
119
- export const BlockConcept = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/_jsx(Concept, {
120
- ...props,
121
- "data-embed-type": "concept",
122
- ref: ref
123
- }));
70
+ const BlockConcept = forwardRef((props, ref) => /* @__PURE__ */ jsx(Concept, {
71
+ ...props,
72
+ "data-embed-type": "concept",
73
+ ref
74
+ }));
75
+
76
+ //#endregion
77
+ export { BlockConcept, ConceptEmbed, InlineConcept };
78
+ //# sourceMappingURL=ConceptEmbed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConceptEmbed.js","names":["EmbedErrorPlaceholder"],"sources":["../../src/Embed/ConceptEmbed.tsx"],"sourcesContent":["/**\n * Copyright (c) 2024-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 parse from \"html-react-parser\";\nimport { forwardRef, useMemo, useRef } from \"react\";\nimport { Portal } from \"@ark-ui/react\";\nimport { PopoverContent, PopoverRoot, PopoverTrigger } from \"@ndla/primitives\";\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport type { ConceptMetaData } from \"@ndla/types-embed\";\nimport { ConceptInlineTriggerButton } from \"./ConceptInlineTriggerButton\";\nimport EmbedErrorPlaceholder from \"./EmbedErrorPlaceholder\";\nimport { GlossEmbed } from \"./GlossEmbed\";\nimport type { RenderContext } from \"./types\";\nimport { Concept, type ConceptProps } from \"../Concept/Concept\";\n\ninterface BaseProps {\n renderContext?: RenderContext;\n lang?: string;\n previewAlt?: boolean;\n}\n\ninterface Props extends BaseProps {\n embed: ConceptMetaData;\n}\n\nconst StyledPopoverContent = styled(PopoverContent, {\n base: {\n width: \"surface.xlarge\",\n maxHeight: \"50vh\",\n overflowY: \"auto\",\n },\n});\n\nexport const ConceptEmbed = ({ embed, renderContext, lang, previewAlt }: Props) => {\n const parsedContent = useMemo(() => {\n if (embed.status === \"error\" || !embed.data.concept.content) return undefined;\n return parse(embed.data.concept.content.htmlContent);\n }, [embed]);\n\n if (embed.status === \"error\" && embed.embedData.type === \"inline\") {\n return <span>{embed.embedData.linkText}</span>;\n }\n if (embed.status === \"error\") {\n // TODO: This could be either concept or gloss. We don't know if it errors out. :)\n return <EmbedErrorPlaceholder type=\"gloss\" />;\n }\n\n const { concept, visualElement } = embed.data;\n\n // TODO: Consider whether we should do this in article-converter instead.\n if (embed.data.concept.glossData) {\n return <GlossEmbed embed={embed} />;\n }\n\n if (embed.embedData.type === \"inline\") {\n return (\n <InlineConcept\n previewAlt={previewAlt}\n linkText={embed.embedData.linkText}\n copyright={concept.copyright}\n visualElement={visualElement}\n lang={lang}\n title={concept.title.title}\n source={concept.source}\n >\n {parsedContent}\n </InlineConcept>\n );\n }\n\n return (\n <BlockConcept\n previewAlt={previewAlt}\n copyright={concept.copyright}\n visualElement={visualElement}\n lang={lang}\n title={renderContext === \"embed\" ? undefined : concept.title.title}\n source={concept.source}\n >\n {parsedContent}\n </BlockConcept>\n );\n};\n\nexport interface InlineConceptProps extends ConceptProps, BaseProps {\n linkText?: string;\n source?: string;\n}\n\nexport const InlineConcept = forwardRef<HTMLSpanElement, InlineConceptProps>(\n ({ linkText, copyright, visualElement, previewAlt, lang, children, title, source, ...rest }, ref) => {\n const contentRef = useRef<HTMLDivElement>(null);\n return (\n <PopoverRoot initialFocusEl={() => contentRef.current}>\n {/* @ts-expect-error placing ref and rest on popover trigger somehow removes a bug where the popover target becomes a bit bigger */}\n <PopoverTrigger asChild ref={ref} {...rest}>\n <ConceptInlineTriggerButton>{linkText}</ConceptInlineTriggerButton>\n </PopoverTrigger>\n <Portal>\n <StyledPopoverContent ref={contentRef}>\n <Concept\n copyright={copyright}\n visualElement={visualElement}\n title={title}\n lang={lang}\n source={source}\n previewAlt={previewAlt}\n >\n {children}\n </Concept>\n </StyledPopoverContent>\n </Portal>\n </PopoverRoot>\n );\n },\n);\n\nexport interface BlockConceptProps extends ConceptProps {}\n\nexport const BlockConcept = forwardRef<HTMLElement, BlockConceptProps>((props, ref) => (\n <Concept {...props} data-embed-type=\"concept\" ref={ref} />\n));\n"],"mappings":";;;;;;;;;;;;AA8BA,MAAM,uBAAuB,OAAO,gBAAgB,EAClD,MAAM;CACJ,OAAO;CACP,WAAW;CACX,WAAW;AACZ,EACF,EAAC;AAEF,MAAa,eAAe,CAAC,EAAE,OAAO,eAAe,MAAM,YAAmB,KAAK;CACjF,MAAM,gBAAgB,QAAQ,MAA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