@ndla/article-converter 1.1.5 → 2.0.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 (41) hide show
  1. package/es/plugins/embed/KeyFigureEmbedPlugin.js +27 -0
  2. package/es/plugins/embed/audioEmbedPlugin.js +2 -1
  3. package/es/plugins/embed/blogPostEmbedPlugin.js +1 -1
  4. package/es/plugins/embed/brightcoveEmbedPlugin.js +4 -2
  5. package/es/plugins/embed/campaignBlockPlugin.js +38 -0
  6. package/es/plugins/embed/conceptEmbedPlugin.js +4 -2
  7. package/es/plugins/embed/imageEmbedPlugin.js +3 -2
  8. package/es/plugins/embed/index.js +5 -3
  9. package/es/plugins/olPlugin.js +2 -2
  10. package/es/plugins/ulPlugin.js +2 -2
  11. package/lib/index.d.ts +1 -1
  12. package/lib/plugins/embed/KeyFigureEmbedPlugin.d.ts +2 -0
  13. package/lib/plugins/embed/KeyFigureEmbedPlugin.js +34 -0
  14. package/lib/plugins/embed/audioEmbedPlugin.js +2 -1
  15. package/lib/plugins/embed/blogPostEmbedPlugin.js +1 -1
  16. package/lib/plugins/embed/brightcoveEmbedPlugin.js +4 -2
  17. package/lib/plugins/embed/campaignBlockPlugin.d.ts +9 -0
  18. package/lib/plugins/embed/campaignBlockPlugin.js +45 -0
  19. package/lib/plugins/embed/conceptEmbedPlugin.js +4 -2
  20. package/lib/plugins/embed/imageEmbedPlugin.js +3 -2
  21. package/lib/plugins/embed/index.js +5 -3
  22. package/lib/plugins/olPlugin.js +2 -2
  23. package/lib/plugins/types.d.ts +5 -0
  24. package/lib/plugins/ulPlugin.js +2 -2
  25. package/package.json +5 -5
  26. package/src/index.ts +1 -1
  27. package/src/plugins/embed/KeyFigureEmbedPlugin.tsx +29 -0
  28. package/src/plugins/embed/audioEmbedPlugin.tsx +1 -1
  29. package/src/plugins/embed/blogPostEmbedPlugin.tsx +1 -1
  30. package/src/plugins/embed/brightcoveEmbedPlugin.tsx +2 -2
  31. package/src/plugins/embed/campaignBlockPlugin.tsx +35 -0
  32. package/src/plugins/embed/conceptEmbedPlugin.tsx +2 -2
  33. package/src/plugins/embed/imageEmbedPlugin.tsx +1 -1
  34. package/src/plugins/embed/index.ts +4 -2
  35. package/src/plugins/olPlugin.tsx +3 -2
  36. package/src/plugins/types.ts +6 -0
  37. package/src/plugins/ulPlugin.tsx +3 -2
  38. package/es/plugins/embed/keyPerformanceIndicatorEmbedPlugin.js +0 -23
  39. package/lib/plugins/embed/keyPerformanceIndicatorEmbedPlugin.d.ts +0 -2
  40. package/lib/plugins/embed/keyPerformanceIndicatorEmbedPlugin.js +0 -30
  41. package/src/plugins/embed/keyPerformanceIndicatorEmbedPlugin.tsx +0 -25
@@ -0,0 +1,27 @@
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 { attributesToProps } from 'html-react-parser';
10
+ import { KeyFigure } from '@ndla/ui';
11
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
12
+ export var keyFigureEmbedPlugin = function keyFigureEmbedPlugin(element, _) {
13
+ var _data$data$metaImage, _data$data$metaImage2;
14
+ var props = attributesToProps(element.attribs);
15
+ var data = JSON.parse(props['data-json']);
16
+ var _data$embedData = data.embedData,
17
+ title = _data$embedData.title,
18
+ subtitle = _data$embedData.subtitle;
19
+ return _jsx(KeyFigure, {
20
+ title: title,
21
+ subtitle: subtitle,
22
+ image: data.status === 'success' ? {
23
+ src: (_data$data$metaImage = data.data.metaImage) === null || _data$data$metaImage === void 0 ? void 0 : _data$data$metaImage.image.imageUrl,
24
+ alt: (_data$data$metaImage2 = data.data.metaImage) === null || _data$data$metaImage2 === void 0 ? void 0 : _data$data$metaImage2.alttext.alttext
25
+ } : undefined
26
+ });
27
+ };
@@ -10,10 +10,11 @@ import { attributesToProps } from 'html-react-parser';
10
10
  import { AudioEmbed } from '@ndla/ui';
11
11
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
12
12
  export var audioEmbedPlugin = function audioEmbedPlugin(element, _, opts) {
13
+ var _opts$components;
13
14
  var props = attributesToProps(element.attribs);
14
15
  var data = JSON.parse(props['data-json']);
15
16
  return _jsx(AudioEmbed, {
16
17
  embed: data,
17
- articlePath: opts.path
18
+ heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton
18
19
  });
19
20
  };
@@ -30,7 +30,7 @@ export var blogPostEmbedPlugin = function blogPostEmbedPlugin(element) {
30
30
  size: size,
31
31
  metaImage: {
32
32
  alt: '',
33
- url: data.status === 'success' ? (_data$data$metaImage$ = (_data$data$metaImage = data.data.metaImage) === null || _data$data$metaImage === void 0 ? void 0 : _data$data$metaImage.imageUrl) !== null && _data$data$metaImage$ !== void 0 ? _data$data$metaImage$ : errorSvgSrc : errorSvgSrc
33
+ url: data.status === 'success' ? (_data$data$metaImage$ = (_data$data$metaImage = data.data.metaImage) === null || _data$data$metaImage === void 0 ? void 0 : _data$data$metaImage.image.imageUrl) !== null && _data$data$metaImage$ !== void 0 ? _data$data$metaImage$ : errorSvgSrc : errorSvgSrc
34
34
  }
35
35
  });
36
36
  };
@@ -9,10 +9,12 @@
9
9
  import { attributesToProps } from 'html-react-parser';
10
10
  import { BrightcoveEmbed } from '@ndla/ui';
11
11
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
12
- export var brightcoveEmbedPlugin = function brightcoveEmbedPlugin(element) {
12
+ export var brightcoveEmbedPlugin = function brightcoveEmbedPlugin(element, _, opts) {
13
+ var _opts$components;
13
14
  var props = attributesToProps(element.attribs);
14
15
  var data = JSON.parse(props['data-json']);
15
16
  return _jsx(BrightcoveEmbed, {
16
- embed: data
17
+ embed: data,
18
+ heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton
17
19
  });
18
20
  };
@@ -0,0 +1,38 @@
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 { attributesToProps } from 'html-react-parser';
10
+ import { CampaignBlock } from '@ndla/ui';
11
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
12
+ export var campaignBlockPlugin = function campaignBlockPlugin(element) {
13
+ var props = attributesToProps(element.attribs);
14
+ var data = JSON.parse(props['data-json']);
15
+ var embed = data.embedData;
16
+ return _jsx(CampaignBlock, {
17
+ title: {
18
+ title: embed.title,
19
+ language: embed.titleLanguage
20
+ },
21
+ description: {
22
+ text: embed.description,
23
+ language: embed.descriptionLanguage
24
+ },
25
+ url: {
26
+ url: embed.url,
27
+ text: embed.urlText
28
+ },
29
+ imageAfter: data.status === 'success' && data.data.imageAfter ? {
30
+ src: data.data.imageAfter.image.imageUrl,
31
+ alt: data.data.imageAfter.alttext.alttext
32
+ } : undefined,
33
+ imageBefore: data.status === 'success' && data.data.imageBefore ? {
34
+ src: data.data.imageBefore.image.imageUrl,
35
+ alt: data.data.imageBefore.alttext.alttext
36
+ } : undefined
37
+ });
38
+ };
@@ -9,11 +9,13 @@
9
9
  import { attributesToProps } from 'html-react-parser';
10
10
  import { ConceptEmbed } from '@ndla/ui';
11
11
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
12
- export var conceptEmbedPlugin = function conceptEmbedPlugin(element) {
12
+ export var conceptEmbedPlugin = function conceptEmbedPlugin(element, _, opts) {
13
+ var _opts$components;
13
14
  var props = attributesToProps(element.attribs);
14
15
  var data = JSON.parse(props['data-json']);
15
16
  return _jsx(ConceptEmbed, {
16
17
  embed: data,
17
- fullWidth: true
18
+ fullWidth: true,
19
+ heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton
18
20
  });
19
21
  };
@@ -10,11 +10,12 @@ import { ImageEmbed } from '@ndla/ui';
10
10
  import { attributesToProps } from 'html-react-parser';
11
11
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
12
12
  export var imageEmbedPlugin = function imageEmbedPlugin(element, _, opts) {
13
+ var _opts$components;
13
14
  var props = attributesToProps(element.attribs);
14
15
  var data = JSON.parse(props['data-json']);
15
16
  return _jsx(ImageEmbed, {
16
17
  embed: data,
17
- articlePath: opts.path,
18
- previewAlt: opts.previewAlt
18
+ previewAlt: opts.previewAlt,
19
+ heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton
19
20
  });
20
21
  };
@@ -20,8 +20,9 @@ import { conceptListEmbedPlugin } from './conceptListEmbedPlugin';
20
20
  import { fileEmbedPlugin } from './fileEmbedPlugin';
21
21
  import { codeEmbedPlugin } from './codeEmbedPlugin';
22
22
  import { blogPostEmbedPlugin } from './blogPostEmbedPlugin';
23
- import { keyPerformanceIndicatorEmbedPlugin } from './keyPerformanceIndicatorEmbedPlugin';
23
+ import { keyFigureEmbedPlugin } from './KeyFigureEmbedPlugin';
24
24
  import { contactBlockEmbedPlugin } from './contactBlockEmbedPlugin';
25
+ import { campaignBlockPlugin } from './campaignBlockPlugin';
25
26
  export var embedPlugins = {
26
27
  image: imageEmbedPlugin,
27
28
  audio: audioEmbedPlugin,
@@ -37,6 +38,7 @@ export var embedPlugins = {
37
38
  'concept-list': conceptListEmbedPlugin,
38
39
  'blog-post': blogPostEmbedPlugin,
39
40
  file: fileEmbedPlugin,
40
- 'key-performance-indicator': keyPerformanceIndicatorEmbedPlugin,
41
- 'contact-block': contactBlockEmbedPlugin
41
+ 'key-figure': keyFigureEmbedPlugin,
42
+ 'contact-block': contactBlockEmbedPlugin,
43
+ 'campaign-block': campaignBlockPlugin
42
44
  };
@@ -12,6 +12,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
12
12
  *
13
13
  */
14
14
 
15
+ import { OrderedList } from '@ndla/ui';
15
16
  import { attributesToProps, domToReact } from 'html-react-parser';
16
17
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
17
18
  export var olPlugin = function olPlugin(node, opts) {
@@ -23,8 +24,7 @@ export var olPlugin = function olPlugin(node, opts) {
23
24
  var classes = [(_node$attribs$class = node.attribs["class"]) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : false, letterClass, numClass].filter(function (c) {
24
25
  return !!c;
25
26
  }).join(' ');
26
- return _jsx("ol", _objectSpread(_objectSpread({}, props), {}, {
27
- "data-type": undefined,
27
+ return _jsx(OrderedList, _objectSpread(_objectSpread({}, props), {}, {
28
28
  className: classes.length ? classes : undefined,
29
29
  children: domToReact(node.children, opts)
30
30
  }));
@@ -12,6 +12,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
12
12
  *
13
13
  */
14
14
 
15
+ import { UnOrderedList } from '@ndla/ui';
15
16
  import { attributesToProps, domToReact } from 'html-react-parser';
16
17
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
17
18
  export var ulPlugin = function ulPlugin(node, opts) {
@@ -21,8 +22,7 @@ export var ulPlugin = function ulPlugin(node, opts) {
21
22
  var classes = [(_node$attribs$class = node.attribs["class"]) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : '', 'o-list--two-columns'].filter(function (c) {
22
23
  return !!c;
23
24
  }).join(' ');
24
- return _jsx("ul", _objectSpread(_objectSpread({}, props), {}, {
25
- "data-type": undefined,
25
+ return _jsx(UnOrderedList, _objectSpread(_objectSpread({}, props), {}, {
26
26
  className: classes,
27
27
  children: domToReact(node.children, opts)
28
28
  }));
package/lib/index.d.ts CHANGED
@@ -7,4 +7,4 @@
7
7
  */
8
8
  export { default as transform } from './transform';
9
9
  export { default as extractEmbedMeta } from './extractEmbedMeta';
10
- export type { TransformOptions } from './plugins/types';
10
+ export type { TransformOptions, DynamicComponents } from './plugins/types';
@@ -0,0 +1,2 @@
1
+ import { PluginType } from '../types';
2
+ export declare const keyFigureEmbedPlugin: PluginType;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.keyFigureEmbedPlugin = void 0;
7
+ var _htmlReactParser = require("html-react-parser");
8
+ var _ui = require("@ndla/ui");
9
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
+ /*
11
+ * Copyright (c) 2023-present, NDLA.
12
+ *
13
+ * This source code is licensed under the GPLv3 license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ *
16
+ */
17
+
18
+ var keyFigureEmbedPlugin = function keyFigureEmbedPlugin(element, _) {
19
+ var _data$data$metaImage, _data$data$metaImage2;
20
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
21
+ var data = JSON.parse(props['data-json']);
22
+ var _data$embedData = data.embedData,
23
+ title = _data$embedData.title,
24
+ subtitle = _data$embedData.subtitle;
25
+ return (0, _jsxRuntime.jsx)(_ui.KeyFigure, {
26
+ title: title,
27
+ subtitle: subtitle,
28
+ image: data.status === 'success' ? {
29
+ src: (_data$data$metaImage = data.data.metaImage) === null || _data$data$metaImage === void 0 ? void 0 : _data$data$metaImage.image.imageUrl,
30
+ alt: (_data$data$metaImage2 = data.data.metaImage) === null || _data$data$metaImage2 === void 0 ? void 0 : _data$data$metaImage2.alttext.alttext
31
+ } : undefined
32
+ });
33
+ };
34
+ exports.keyFigureEmbedPlugin = keyFigureEmbedPlugin;
@@ -16,11 +16,12 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
16
16
  */
17
17
 
18
18
  var audioEmbedPlugin = function audioEmbedPlugin(element, _, opts) {
19
+ var _opts$components;
19
20
  var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
21
  var data = JSON.parse(props['data-json']);
21
22
  return (0, _jsxRuntime.jsx)(_ui.AudioEmbed, {
22
23
  embed: data,
23
- articlePath: opts.path
24
+ heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton
24
25
  });
25
26
  };
26
27
  exports.audioEmbedPlugin = audioEmbedPlugin;
@@ -37,7 +37,7 @@ var blogPostEmbedPlugin = function blogPostEmbedPlugin(element) {
37
37
  size: size,
38
38
  metaImage: {
39
39
  alt: '',
40
- url: data.status === 'success' ? (_data$data$metaImage$ = (_data$data$metaImage = data.data.metaImage) === null || _data$data$metaImage === void 0 ? void 0 : _data$data$metaImage.imageUrl) !== null && _data$data$metaImage$ !== void 0 ? _data$data$metaImage$ : errorSvgSrc : errorSvgSrc
40
+ url: data.status === 'success' ? (_data$data$metaImage$ = (_data$data$metaImage = data.data.metaImage) === null || _data$data$metaImage === void 0 ? void 0 : _data$data$metaImage.image.imageUrl) !== null && _data$data$metaImage$ !== void 0 ? _data$data$metaImage$ : errorSvgSrc : errorSvgSrc
41
41
  }
42
42
  });
43
43
  };
@@ -15,11 +15,13 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
15
15
  *
16
16
  */
17
17
 
18
- var brightcoveEmbedPlugin = function brightcoveEmbedPlugin(element) {
18
+ var brightcoveEmbedPlugin = function brightcoveEmbedPlugin(element, _, opts) {
19
+ var _opts$components;
19
20
  var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
21
  var data = JSON.parse(props['data-json']);
21
22
  return (0, _jsxRuntime.jsx)(_ui.BrightcoveEmbed, {
22
- embed: data
23
+ embed: data,
24
+ heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton
23
25
  });
24
26
  };
25
27
  exports.brightcoveEmbedPlugin = brightcoveEmbedPlugin;
@@ -0,0 +1,9 @@
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
+ import { PluginType } from '../types';
9
+ export declare const campaignBlockPlugin: PluginType;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.campaignBlockPlugin = void 0;
7
+ var _htmlReactParser = require("html-react-parser");
8
+ var _ui = require("@ndla/ui");
9
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
+ /**
11
+ * Copyright (c) 2023-present, NDLA.
12
+ *
13
+ * This source code is licensed under the GPLv3 license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ *
16
+ */
17
+
18
+ var campaignBlockPlugin = function campaignBlockPlugin(element) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ var embed = data.embedData;
22
+ return (0, _jsxRuntime.jsx)(_ui.CampaignBlock, {
23
+ title: {
24
+ title: embed.title,
25
+ language: embed.titleLanguage
26
+ },
27
+ description: {
28
+ text: embed.description,
29
+ language: embed.descriptionLanguage
30
+ },
31
+ url: {
32
+ url: embed.url,
33
+ text: embed.urlText
34
+ },
35
+ imageAfter: data.status === 'success' && data.data.imageAfter ? {
36
+ src: data.data.imageAfter.image.imageUrl,
37
+ alt: data.data.imageAfter.alttext.alttext
38
+ } : undefined,
39
+ imageBefore: data.status === 'success' && data.data.imageBefore ? {
40
+ src: data.data.imageBefore.image.imageUrl,
41
+ alt: data.data.imageBefore.alttext.alttext
42
+ } : undefined
43
+ });
44
+ };
45
+ exports.campaignBlockPlugin = campaignBlockPlugin;
@@ -15,12 +15,14 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
15
15
  *
16
16
  */
17
17
 
18
- var conceptEmbedPlugin = function conceptEmbedPlugin(element) {
18
+ var conceptEmbedPlugin = function conceptEmbedPlugin(element, _, opts) {
19
+ var _opts$components;
19
20
  var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
21
  var data = JSON.parse(props['data-json']);
21
22
  return (0, _jsxRuntime.jsx)(_ui.ConceptEmbed, {
22
23
  embed: data,
23
- fullWidth: true
24
+ fullWidth: true,
25
+ heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton
24
26
  });
25
27
  };
26
28
  exports.conceptEmbedPlugin = conceptEmbedPlugin;
@@ -16,12 +16,13 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
16
16
  */
17
17
 
18
18
  var imageEmbedPlugin = function imageEmbedPlugin(element, _, opts) {
19
+ var _opts$components;
19
20
  var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
21
  var data = JSON.parse(props['data-json']);
21
22
  return (0, _jsxRuntime.jsx)(_ui.ImageEmbed, {
22
23
  embed: data,
23
- articlePath: opts.path,
24
- previewAlt: opts.previewAlt
24
+ previewAlt: opts.previewAlt,
25
+ heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton
25
26
  });
26
27
  };
27
28
  exports.imageEmbedPlugin = imageEmbedPlugin;
@@ -18,8 +18,9 @@ var _conceptListEmbedPlugin = require("./conceptListEmbedPlugin");
18
18
  var _fileEmbedPlugin = require("./fileEmbedPlugin");
19
19
  var _codeEmbedPlugin = require("./codeEmbedPlugin");
20
20
  var _blogPostEmbedPlugin = require("./blogPostEmbedPlugin");
21
- var _keyPerformanceIndicatorEmbedPlugin = require("./keyPerformanceIndicatorEmbedPlugin");
21
+ var _KeyFigureEmbedPlugin = require("./KeyFigureEmbedPlugin");
22
22
  var _contactBlockEmbedPlugin = require("./contactBlockEmbedPlugin");
23
+ var _campaignBlockPlugin = require("./campaignBlockPlugin");
23
24
  /**
24
25
  * Copyright (c) 2023-present, NDLA.
25
26
  *
@@ -43,7 +44,8 @@ var embedPlugins = {
43
44
  'concept-list': _conceptListEmbedPlugin.conceptListEmbedPlugin,
44
45
  'blog-post': _blogPostEmbedPlugin.blogPostEmbedPlugin,
45
46
  file: _fileEmbedPlugin.fileEmbedPlugin,
46
- 'key-performance-indicator': _keyPerformanceIndicatorEmbedPlugin.keyPerformanceIndicatorEmbedPlugin,
47
- 'contact-block': _contactBlockEmbedPlugin.contactBlockEmbedPlugin
47
+ 'key-figure': _KeyFigureEmbedPlugin.keyFigureEmbedPlugin,
48
+ 'contact-block': _contactBlockEmbedPlugin.contactBlockEmbedPlugin,
49
+ 'campaign-block': _campaignBlockPlugin.campaignBlockPlugin
48
50
  };
49
51
  exports.embedPlugins = embedPlugins;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.olPlugin = void 0;
7
+ var _ui = require("@ndla/ui");
7
8
  var _htmlReactParser = require("html-react-parser");
8
9
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
9
10
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
@@ -27,8 +28,7 @@ var olPlugin = function olPlugin(node, opts) {
27
28
  var classes = [(_node$attribs$class = node.attribs["class"]) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : false, letterClass, numClass].filter(function (c) {
28
29
  return !!c;
29
30
  }).join(' ');
30
- return (0, _jsxRuntime.jsx)("ol", _objectSpread(_objectSpread({}, props), {}, {
31
- "data-type": undefined,
31
+ return (0, _jsxRuntime.jsx)(_ui.OrderedList, _objectSpread(_objectSpread({}, props), {}, {
32
32
  className: classes.length ? classes : undefined,
33
33
  children: (0, _htmlReactParser.domToReact)(node.children, opts)
34
34
  }));
@@ -6,12 +6,17 @@
6
6
  *
7
7
  */
8
8
  /// <reference types="react" />
9
+ import { HeartButtonType } from '@ndla/ui';
9
10
  import { Element, HTMLReactParserOptions } from 'html-react-parser';
11
+ export interface DynamicComponents {
12
+ heartButton?: HeartButtonType;
13
+ }
10
14
  export interface TransformOptions {
11
15
  isOembed?: boolean;
12
16
  subject?: string;
13
17
  path?: string;
14
18
  previewAlt?: boolean;
15
19
  frontendDomain?: string;
20
+ components?: DynamicComponents;
16
21
  }
17
22
  export type PluginType = (element: Element, options: HTMLReactParserOptions, metaData: TransformOptions) => JSX.Element | undefined | null;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ulPlugin = void 0;
7
+ var _ui = require("@ndla/ui");
7
8
  var _htmlReactParser = require("html-react-parser");
8
9
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
9
10
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
@@ -25,8 +26,7 @@ var ulPlugin = function ulPlugin(node, opts) {
25
26
  var classes = [(_node$attribs$class = node.attribs["class"]) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : '', 'o-list--two-columns'].filter(function (c) {
26
27
  return !!c;
27
28
  }).join(' ');
28
- return (0, _jsxRuntime.jsx)("ul", _objectSpread(_objectSpread({}, props), {}, {
29
- "data-type": undefined,
29
+ return (0, _jsxRuntime.jsx)(_ui.UnOrderedList, _objectSpread(_objectSpread({}, props), {}, {
30
30
  className: classes,
31
31
  children: (0, _htmlReactParser.domToReact)(node.children, opts)
32
32
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndla/article-converter",
3
- "version": "1.1.5",
3
+ "version": "2.0.0",
4
4
  "description": "Transforms NDLA articles into extended html versions",
5
5
  "license": "GPL-3.0",
6
6
  "main": "lib/index.js",
@@ -27,11 +27,11 @@
27
27
  "src"
28
28
  ],
29
29
  "devDependencies": {
30
- "@ndla/types-embed": "^1.1.1"
30
+ "@ndla/types-embed": "^2.0.0"
31
31
  },
32
32
  "dependencies": {
33
- "@ndla/code": "^2.1.42",
34
- "@ndla/ui": "^36.0.2",
33
+ "@ndla/code": "^2.2.0",
34
+ "@ndla/ui": "^37.0.0",
35
35
  "html-react-parser": "^3.0.8",
36
36
  "lodash": "^4.17.20"
37
37
  },
@@ -44,5 +44,5 @@
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
- "gitHead": "486edbc7b92bc8fc182669cec1c259438215e3cc"
47
+ "gitHead": "3961942d13c313b37bba92395f6a430ed31dc954"
48
48
  }
package/src/index.ts CHANGED
@@ -8,4 +8,4 @@
8
8
 
9
9
  export { default as transform } from './transform';
10
10
  export { default as extractEmbedMeta } from './extractEmbedMeta';
11
- export type { TransformOptions } from './plugins/types';
11
+ export type { TransformOptions, DynamicComponents } from './plugins/types';
@@ -0,0 +1,29 @@
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 { attributesToProps } from 'html-react-parser';
10
+ import { KeyFigureMetaData } from '@ndla/types-embed';
11
+ import { KeyFigure } from '@ndla/ui';
12
+ import { PluginType } from '../types';
13
+
14
+ export const keyFigureEmbedPlugin: PluginType = (element, _) => {
15
+ const props = attributesToProps(element.attribs);
16
+ const data = JSON.parse(props['data-json']) as KeyFigureMetaData;
17
+ const { title, subtitle } = data.embedData;
18
+ return (
19
+ <KeyFigure
20
+ title={title}
21
+ subtitle={subtitle}
22
+ image={
23
+ data.status === 'success'
24
+ ? { src: data.data.metaImage?.image.imageUrl, alt: data.data.metaImage?.alttext.alttext }
25
+ : undefined
26
+ }
27
+ />
28
+ );
29
+ };
@@ -14,5 +14,5 @@ import { PluginType } from '../types';
14
14
  export const audioEmbedPlugin: PluginType = (element, _, opts) => {
15
15
  const props = attributesToProps(element.attribs);
16
16
  const data = JSON.parse(props['data-json']) as AudioMetaData;
17
- return <AudioEmbed embed={data} articlePath={opts.path} />;
17
+ return <AudioEmbed embed={data} heartButton={opts.components?.heartButton} />;
18
18
  };
@@ -25,7 +25,7 @@ export const blogPostEmbedPlugin: PluginType = (element) => {
25
25
  size={size}
26
26
  metaImage={{
27
27
  alt: '',
28
- url: data.status === 'success' ? data.data.metaImage?.imageUrl ?? errorSvgSrc : errorSvgSrc,
28
+ url: data.status === 'success' ? data.data.metaImage?.image.imageUrl ?? errorSvgSrc : errorSvgSrc,
29
29
  }}
30
30
  />
31
31
  );
@@ -11,8 +11,8 @@ import { BrightcoveMetaData } from '@ndla/types-embed';
11
11
  import { BrightcoveEmbed } from '@ndla/ui';
12
12
  import { PluginType } from '../types';
13
13
 
14
- export const brightcoveEmbedPlugin: PluginType = (element) => {
14
+ export const brightcoveEmbedPlugin: PluginType = (element, _, opts) => {
15
15
  const props = attributesToProps(element.attribs);
16
16
  const data = JSON.parse(props['data-json']) as BrightcoveMetaData;
17
- return <BrightcoveEmbed embed={data} />;
17
+ return <BrightcoveEmbed embed={data} heartButton={opts.components?.heartButton} />;
18
18
  };
@@ -0,0 +1,35 @@
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 { attributesToProps } from 'html-react-parser';
10
+ import { CampaignBlockMetaData } from '@ndla/types-embed';
11
+ import { CampaignBlock } from '@ndla/ui';
12
+ import { PluginType } from '../types';
13
+
14
+ export const campaignBlockPlugin: PluginType = (element) => {
15
+ const props = attributesToProps(element.attribs);
16
+ const data = JSON.parse(props['data-json']) as CampaignBlockMetaData;
17
+ const embed = data.embedData;
18
+ return (
19
+ <CampaignBlock
20
+ title={{ title: embed.title, language: embed.titleLanguage }}
21
+ description={{ text: embed.description, language: embed.descriptionLanguage }}
22
+ url={{ url: embed.url, text: embed.urlText }}
23
+ imageAfter={
24
+ data.status === 'success' && data.data.imageAfter
25
+ ? { src: data.data.imageAfter.image.imageUrl, alt: data.data.imageAfter.alttext.alttext }
26
+ : undefined
27
+ }
28
+ imageBefore={
29
+ data.status === 'success' && data.data.imageBefore
30
+ ? { src: data.data.imageBefore.image.imageUrl, alt: data.data.imageBefore.alttext.alttext }
31
+ : undefined
32
+ }
33
+ />
34
+ );
35
+ };
@@ -11,8 +11,8 @@ import { ConceptMetaData } from '@ndla/types-embed';
11
11
  import { ConceptEmbed } from '@ndla/ui';
12
12
  import { PluginType } from '../types';
13
13
 
14
- export const conceptEmbedPlugin: PluginType = (element) => {
14
+ export const conceptEmbedPlugin: PluginType = (element, _, opts) => {
15
15
  const props = attributesToProps(element.attribs);
16
16
  const data = JSON.parse(props['data-json']) as ConceptMetaData;
17
- return <ConceptEmbed embed={data} fullWidth />;
17
+ return <ConceptEmbed embed={data} fullWidth heartButton={opts.components?.heartButton} />;
18
18
  };
@@ -14,5 +14,5 @@ import { PluginType } from '../types';
14
14
  export const imageEmbedPlugin: PluginType = (element, _, opts) => {
15
15
  const props = attributesToProps(element.attribs);
16
16
  const data = JSON.parse(props['data-json']) as ImageMetaData;
17
- return <ImageEmbed embed={data} articlePath={opts.path} previewAlt={opts.previewAlt} />;
17
+ return <ImageEmbed embed={data} previewAlt={opts.previewAlt} heartButton={opts.components?.heartButton} />;
18
18
  };
@@ -21,8 +21,9 @@ import { conceptListEmbedPlugin } from './conceptListEmbedPlugin';
21
21
  import { fileEmbedPlugin } from './fileEmbedPlugin';
22
22
  import { codeEmbedPlugin } from './codeEmbedPlugin';
23
23
  import { blogPostEmbedPlugin } from './blogPostEmbedPlugin';
24
- import { keyPerformanceIndicatorEmbedPlugin } from './keyPerformanceIndicatorEmbedPlugin';
24
+ import { keyFigureEmbedPlugin } from './KeyFigureEmbedPlugin';
25
25
  import { contactBlockEmbedPlugin } from './contactBlockEmbedPlugin';
26
+ import { campaignBlockPlugin } from './campaignBlockPlugin';
26
27
 
27
28
  export const embedPlugins: Record<string, PluginType> = {
28
29
  image: imageEmbedPlugin,
@@ -39,6 +40,7 @@ export const embedPlugins: Record<string, PluginType> = {
39
40
  'concept-list': conceptListEmbedPlugin,
40
41
  'blog-post': blogPostEmbedPlugin,
41
42
  file: fileEmbedPlugin,
42
- 'key-performance-indicator': keyPerformanceIndicatorEmbedPlugin,
43
+ 'key-figure': keyFigureEmbedPlugin,
43
44
  'contact-block': contactBlockEmbedPlugin,
45
+ 'campaign-block': campaignBlockPlugin,
44
46
  };
@@ -6,6 +6,7 @@
6
6
  *
7
7
  */
8
8
 
9
+ import { OrderedList } from '@ndla/ui';
9
10
  import { attributesToProps, domToReact } from 'html-react-parser';
10
11
  import { PluginType } from './types';
11
12
  export const olPlugin: PluginType = (node, opts) => {
@@ -16,8 +17,8 @@ export const olPlugin: PluginType = (node, opts) => {
16
17
  const classes = [node.attribs.class ?? false, letterClass, numClass].filter((c): c is string => !!c).join(' ');
17
18
 
18
19
  return (
19
- <ol {...props} data-type={undefined} className={classes.length ? classes : undefined}>
20
+ <OrderedList {...props} className={classes.length ? classes : undefined}>
20
21
  {domToReact(node.children, opts)}
21
- </ol>
22
+ </OrderedList>
22
23
  );
23
24
  };
@@ -6,14 +6,20 @@
6
6
  *
7
7
  */
8
8
 
9
+ import { HeartButtonType } from '@ndla/ui';
9
10
  import { Element, HTMLReactParserOptions } from 'html-react-parser';
10
11
 
12
+ export interface DynamicComponents {
13
+ heartButton?: HeartButtonType;
14
+ }
15
+
11
16
  export interface TransformOptions {
12
17
  isOembed?: boolean;
13
18
  subject?: string;
14
19
  path?: string;
15
20
  previewAlt?: boolean;
16
21
  frontendDomain?: string;
22
+ components?: DynamicComponents;
17
23
  }
18
24
 
19
25
  export type PluginType = (
@@ -6,6 +6,7 @@
6
6
  *
7
7
  */
8
8
 
9
+ import { UnOrderedList } from '@ndla/ui';
9
10
  import { attributesToProps, domToReact } from 'html-react-parser';
10
11
  import { PluginType } from './types';
11
12
  export const ulPlugin: PluginType = (node, opts) => {
@@ -13,9 +14,9 @@ export const ulPlugin: PluginType = (node, opts) => {
13
14
  const props = attributesToProps(node.attribs);
14
15
  const classes = [node.attribs.class ?? '', 'o-list--two-columns'].filter((c) => !!c).join(' ');
15
16
  return (
16
- <ul {...props} data-type={undefined} className={classes}>
17
+ <UnOrderedList {...props} className={classes}>
17
18
  {domToReact(node.children, opts)}
18
- </ul>
19
+ </UnOrderedList>
19
20
  );
20
21
  }
21
22
 
@@ -1,23 +0,0 @@
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 { KeyPerformanceIndicator } from '@ndla/ui';
10
- import { attributesToProps } from 'html-react-parser';
11
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
12
- export var keyPerformanceIndicatorEmbedPlugin = function keyPerformanceIndicatorEmbedPlugin(element, _, opts) {
13
- var props = attributesToProps(element.attribs);
14
- var data = JSON.parse(props['data-json']);
15
- var _data$embedData = data.embedData,
16
- title = _data$embedData.title,
17
- subTitle = _data$embedData.subTitle;
18
- return _jsx(KeyPerformanceIndicator, {
19
- title: title,
20
- subTitle: subTitle,
21
- image: data.status === 'success' ? data.data.metaImage : undefined
22
- });
23
- };
@@ -1,2 +0,0 @@
1
- import { PluginType } from '../types';
2
- export declare const keyPerformanceIndicatorEmbedPlugin: PluginType;
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.keyPerformanceIndicatorEmbedPlugin = void 0;
7
- var _ui = require("@ndla/ui");
8
- var _htmlReactParser = require("html-react-parser");
9
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
- /*
11
- * Copyright (c) 2023-present, NDLA.
12
- *
13
- * This source code is licensed under the GPLv3 license found in the
14
- * LICENSE file in the root directory of this source tree.
15
- *
16
- */
17
-
18
- var keyPerformanceIndicatorEmbedPlugin = function keyPerformanceIndicatorEmbedPlugin(element, _, opts) {
19
- var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
- var data = JSON.parse(props['data-json']);
21
- var _data$embedData = data.embedData,
22
- title = _data$embedData.title,
23
- subTitle = _data$embedData.subTitle;
24
- return (0, _jsxRuntime.jsx)(_ui.KeyPerformanceIndicator, {
25
- title: title,
26
- subTitle: subTitle,
27
- image: data.status === 'success' ? data.data.metaImage : undefined
28
- });
29
- };
30
- exports.keyPerformanceIndicatorEmbedPlugin = keyPerformanceIndicatorEmbedPlugin;
@@ -1,25 +0,0 @@
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 { KeyPerformanceIndicator } from '@ndla/ui';
10
- import { attributesToProps } from 'html-react-parser';
11
- import { KeyPerformanceIndicatorMetaData } from '@ndla/types-embed';
12
- import { PluginType } from '../types';
13
-
14
- export const keyPerformanceIndicatorEmbedPlugin: PluginType = (element, _, opts) => {
15
- const props = attributesToProps(element.attribs);
16
- const data = JSON.parse(props['data-json']) as KeyPerformanceIndicatorMetaData;
17
- const { title, subTitle } = data.embedData;
18
- return (
19
- <KeyPerformanceIndicator
20
- title={title}
21
- subTitle={subTitle}
22
- image={data.status === 'success' ? data.data.metaImage : undefined}
23
- />
24
- );
25
- };