@ndla/ui 3.0.15 → 3.1.1-alpha.14
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/es/Article/ArticleContent.js +2 -0
- package/es/CopyParagraphButton/CopyParagraphButton.js +111 -0
- package/es/CopyParagraphButton/index.js +11 -0
- package/es/CopyParagraphButton/initCopyParagraphButtons.js +32 -0
- package/es/index.js +2 -1
- package/es/locale/messages-en.js +2 -1
- package/es/locale/messages-nb.js +3 -2
- package/es/locale/messages-nn.js +1 -0
- package/lib/Article/ArticleContent.js +3 -0
- package/lib/CopyParagraphButton/CopyParagraphButton.d.ts +13 -0
- package/lib/CopyParagraphButton/CopyParagraphButton.js +123 -0
- package/lib/CopyParagraphButton/index.d.ts +11 -0
- package/lib/CopyParagraphButton/index.js +34 -0
- package/lib/CopyParagraphButton/initCopyParagraphButtons.d.ts +2 -0
- package/lib/CopyParagraphButton/initCopyParagraphButtons.js +46 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +10 -1
- package/lib/locale/messages-en.d.ts +1 -0
- package/lib/locale/messages-en.js +2 -1
- package/lib/locale/messages-nb.d.ts +1 -0
- package/lib/locale/messages-nb.js +3 -2
- package/lib/locale/messages-nn.d.ts +1 -0
- package/lib/locale/messages-nn.js +1 -0
- package/package.json +3 -3
- package/src/Article/ArticleContent.tsx +2 -0
- package/src/CopyParagraphButton/CopyParagraphButton.tsx +88 -0
- package/src/CopyParagraphButton/index.tsx +13 -0
- package/src/CopyParagraphButton/initCopyParagraphButtons.tsx +27 -0
- package/src/index.ts +2 -0
- package/src/locale/messages-en.ts +2 -1
- package/src/locale/messages-nb.ts +3 -2
- package/src/locale/messages-nn.ts +1 -0
|
@@ -15,6 +15,7 @@ import React, { useEffect } from 'react';
|
|
|
15
15
|
import { initArticleScripts, removeEventListenerForResize // @ts-ignore
|
|
16
16
|
} from '@ndla/article-scripts';
|
|
17
17
|
import { initAudioPlayers } from '../AudioPlayer';
|
|
18
|
+
import { initCopyParagraphButtons } from '../CopyParagraphButton';
|
|
18
19
|
import { jsx as ___EmotionJSX } from "@emotion/core";
|
|
19
20
|
|
|
20
21
|
var ArticleContent = function ArticleContent(_ref) {
|
|
@@ -26,6 +27,7 @@ var ArticleContent = function ArticleContent(_ref) {
|
|
|
26
27
|
removeEventListenerForResize();
|
|
27
28
|
initArticleScripts();
|
|
28
29
|
initAudioPlayers(locale);
|
|
30
|
+
initCopyParagraphButtons();
|
|
29
31
|
return function () {
|
|
30
32
|
removeEventListenerForResize();
|
|
31
33
|
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import _styled from "@emotion/styled-base";
|
|
2
|
+
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
|
|
5
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
|
|
9
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
10
|
+
|
|
11
|
+
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
12
|
+
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
|
|
15
|
+
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Copyright (c) 2021-present, NDLA.
|
|
19
|
+
*
|
|
20
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
21
|
+
* LICENSE file in the root directory of this source tree.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
import React, { useEffect, useState } from 'react';
|
|
25
|
+
import { Link } from '@ndla/icons/common';
|
|
26
|
+
import { useTranslation } from 'react-i18next'; // @ts-ignore
|
|
27
|
+
|
|
28
|
+
import Tooltip from '@ndla/tooltip';
|
|
29
|
+
import { copyTextToClipboard } from '@ndla/util';
|
|
30
|
+
import { jsx as ___EmotionJSX } from "@emotion/core";
|
|
31
|
+
|
|
32
|
+
var IconButton = _styled("button", {
|
|
33
|
+
target: "e18czas70",
|
|
34
|
+
label: "IconButton"
|
|
35
|
+
})(process.env.NODE_ENV === "production" ? {
|
|
36
|
+
name: "1eoah0f",
|
|
37
|
+
styles: "float:left;position:relative;left:-3em;top:0.1em;background:none;border:0;z-index:1;transition:0.2s;opacity:0;& svg{width:30px;height:30px;}"
|
|
38
|
+
} : {
|
|
39
|
+
name: "1eoah0f",
|
|
40
|
+
styles: "float:left;position:relative;left:-3em;top:0.1em;background:none;border:0;z-index:1;transition:0.2s;opacity:0;& svg{width:30px;height:30px;}",
|
|
41
|
+
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkNvcHlQYXJhZ3Jhc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BDb3B5UGFyYWdyYXBoQnV0dG9uO1xuIl19 */",
|
|
42
|
+
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
var ContainerDiv = _styled("div", {
|
|
46
|
+
target: "e18czas71",
|
|
47
|
+
label: "ContainerDiv"
|
|
48
|
+
})(process.env.NODE_ENV === "production" ? {
|
|
49
|
+
name: "25spe5",
|
|
50
|
+
styles: "&:hover button{cursor:pointer;opacity:0.5;}& h2{position:relative;left:-2em;}"
|
|
51
|
+
} : {
|
|
52
|
+
name: "25spe5",
|
|
53
|
+
styles: "&:hover button{cursor:pointer;opacity:0.5;}& h2{position:relative;left:-2em;}",
|
|
54
|
+
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkNvcHlQYXJhZ3JhcGhCdXR0b24udHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQWtDK0IiLCJmaWxlIjoiQ29weVBhcmFncmFwaEJ1dHRvbi50c3giLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIENvcHlyaWdodCAoYykgMjAyMS1wcmVzZW50LCBORExBLlxuICpcbiAqIFRoaXMgc291cmNlIGNvZGUgaXMgbGljZW5zZWQgdW5kZXIgdGhlIEdQTHYzIGxpY2Vuc2UgZm91bmQgaW4gdGhlXG4gKiBMSUNFTlNFIGZpbGUgaW4gdGhlIHJvb3QgZGlyZWN0b3J5IG9mIHRoaXMgc291cmNlIHRyZWUuXG4gKlxuICovXG5cbmltcG9ydCBSZWFjdCwgeyB1c2VFZmZlY3QsIHVzZVN0YXRlIH0gZnJvbSAncmVhY3QnO1xuXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCc7XG5pbXBvcnQgeyBMaW5rIH0gZnJvbSAnQG5kbGEvaWNvbnMvY29tbW9uJztcbmltcG9ydCB7IHVzZVRyYW5zbGF0aW9uIH0gZ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YS1oZWFkZXItY29weS1jb250YWluZXIgZGF0YS10aXRsZT17dGl0bGV9PlxuICAgICAgPEljb25CdXR0b24gb25DbGljaz17b25Db3B5Q2xpY2t9IGRhdGEtdGl0bGU9e3Nhbml0aXplZFRpdGxlfT5cbiAgICAgICAgPFRvb2x0aXAgdG9vbHRpcD17dG9vbHRpcH0+XG4gICAgICAgICAgPExpbmsgdGl0bGU9eycnfSAvPlxuICAgICAgICA8L1Rvb2x0aXA+XG4gICAgICA8L0ljb25CdXR0b24+XG4gICAgICA8aDIgaWQ9e3Nhbml0aXplZFRpdGxlfSB0YWJJbmRleD17MH0gZGFuZ2Vyb3VzbHlTZXRJbm5lckhUTUw9e3sgX19odG1sOiBjb250ZW50IHx8ICcnIH19PjwvaDI+XG4gICAgPC9Db250YWluZXJEaXY+XG4gICk7XG59O1xuXG5leHBvcnQgZGVmYXVsdCBDb3B5UGFyYWdyYXBoQnV0dG9uO1xuIl19 */",
|
|
55
|
+
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
var CopyParagraphButton = function CopyParagraphButton(_ref) {
|
|
59
|
+
var title = _ref.title,
|
|
60
|
+
content = _ref.content;
|
|
61
|
+
|
|
62
|
+
var _useTranslation = useTranslation(),
|
|
63
|
+
t = _useTranslation.t;
|
|
64
|
+
|
|
65
|
+
var _useState = useState(false),
|
|
66
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
67
|
+
hasCopied = _useState2[0],
|
|
68
|
+
setHasCopied = _useState2[1];
|
|
69
|
+
|
|
70
|
+
useEffect(function () {
|
|
71
|
+
if (hasCopied) {
|
|
72
|
+
setTimeout(function () {
|
|
73
|
+
return setHasCopied(false);
|
|
74
|
+
}, 3000);
|
|
75
|
+
}
|
|
76
|
+
}, [hasCopied]);
|
|
77
|
+
if (!title) return null;
|
|
78
|
+
|
|
79
|
+
var onCopyClick = function onCopyClick(event) {
|
|
80
|
+
setHasCopied(true);
|
|
81
|
+
var copyId = event.currentTarget.getAttribute('data-title');
|
|
82
|
+
var _window = window,
|
|
83
|
+
location = _window.location;
|
|
84
|
+
var newHash = "#".concat(copyId);
|
|
85
|
+
var port = location.port ? ":".concat(location.port) : '';
|
|
86
|
+
var urlToCopy = "".concat(location.protocol, "//").concat(location.hostname).concat(port).concat(location.pathname).concat(location.search).concat(newHash);
|
|
87
|
+
copyTextToClipboard(urlToCopy);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
var sanitizedTitle = encodeURIComponent(title.replace(/ /g, '-'));
|
|
91
|
+
var tooltip = hasCopied ? t('article.copyPageLinkCopied') : t('article.copyHeaderLink');
|
|
92
|
+
return ___EmotionJSX(ContainerDiv, {
|
|
93
|
+
"data-header-copy-container": true,
|
|
94
|
+
"data-title": title
|
|
95
|
+
}, ___EmotionJSX(IconButton, {
|
|
96
|
+
onClick: onCopyClick,
|
|
97
|
+
"data-title": sanitizedTitle
|
|
98
|
+
}, ___EmotionJSX(Tooltip, {
|
|
99
|
+
tooltip: tooltip
|
|
100
|
+
}, ___EmotionJSX(Link, {
|
|
101
|
+
title: ''
|
|
102
|
+
}))), ___EmotionJSX("h2", {
|
|
103
|
+
id: sanitizedTitle,
|
|
104
|
+
tabIndex: 0,
|
|
105
|
+
dangerouslySetInnerHTML: {
|
|
106
|
+
__html: content || ''
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export default CopyParagraphButton;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2021-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 CopyParagraphButton from './CopyParagraphButton';
|
|
9
|
+
import initCopyParagraphButtons from './initCopyParagraphButtons';
|
|
10
|
+
export { CopyParagraphButton, initCopyParagraphButtons };
|
|
11
|
+
export default CopyParagraphButton;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2021-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 React from 'react';
|
|
9
|
+
import ReactDOM from 'react-dom';
|
|
10
|
+
import CopyParagraphButton from './CopyParagraphButton';
|
|
11
|
+
import { jsx as ___EmotionJSX } from "@emotion/core";
|
|
12
|
+
|
|
13
|
+
var forEachElement = function forEachElement(selector, callback) {
|
|
14
|
+
var nodeList = document.querySelectorAll(selector);
|
|
15
|
+
|
|
16
|
+
for (var i = 0; i < nodeList.length; i += 1) {
|
|
17
|
+
callback(nodeList[i], i);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
var initCopyParagraphButtons = function initCopyParagraphButtons() {
|
|
22
|
+
forEachElement('[data-header-copy-container]', function (el) {
|
|
23
|
+
var title = el.getAttribute('data-title');
|
|
24
|
+
var content = el.innerHTML;
|
|
25
|
+
ReactDOM.hydrate(___EmotionJSX(CopyParagraphButton, {
|
|
26
|
+
title: title,
|
|
27
|
+
content: content
|
|
28
|
+
}), el);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default initCopyParagraphButtons;
|
package/es/index.js
CHANGED
|
@@ -46,4 +46,5 @@ export { i18nInstance, formatNestedMessages, formatMessage } from './i18n';
|
|
|
46
46
|
export { default as ResourceGroup } from './ResourceGroup';
|
|
47
47
|
export { default as LayoutItem, OneColumn, PageContainer, Content } from './Layout';
|
|
48
48
|
export { SubjectAbout, SubjectArchive, SubjectCarousel, SubjectChildContent, SubjectContent, SubjectFilter, SubjectFlexChild, SubjectFlexWrapper, SubjectHeader, SubjectLinks, SubjectNewContent, SubjectSecondaryContent, SubjectSectionTitle, SubjectShortcuts, SubjectSidebarWrapper, SubjectSocialContent, SubjectSocialSection, SubjectTopics, SubjectBanner } from './Subject';
|
|
49
|
-
export { default as ContentCard } from './ContentCard';
|
|
49
|
+
export { default as ContentCard } from './ContentCard';
|
|
50
|
+
export { default as CopyParagraphButton } from './CopyParagraphButton';
|
package/es/locale/messages-en.js
CHANGED
|
@@ -132,7 +132,7 @@ var messages = _objectSpread(_objectSpread({
|
|
|
132
132
|
showingCompetenceGoalSearchPhrase: 'Showing results for competence goals {text}',
|
|
133
133
|
searchPhraseSuggestion: 'Search instead for:',
|
|
134
134
|
notionLabels: 'Used in',
|
|
135
|
-
notionsHeading: '
|
|
135
|
+
notionsHeading: 'Explanations',
|
|
136
136
|
notionsRemove: 'Remove',
|
|
137
137
|
showVideo: 'Watch video',
|
|
138
138
|
showNotion: 'Show notion'
|
|
@@ -298,6 +298,7 @@ var messages = _objectSpread(_objectSpread({
|
|
|
298
298
|
multipleAuthorsLabelAriaConjunction: 'and',
|
|
299
299
|
copyPageLink: 'Copy page-link',
|
|
300
300
|
copyPageLinkCopied: 'Link copied',
|
|
301
|
+
copyHeaderLink: 'Copy link to header',
|
|
301
302
|
conjunction: 'and',
|
|
302
303
|
supplierLabel: 'Rightsholder: {{name}}',
|
|
303
304
|
multipleSuppliersLabel: 'Rightsholders: {{names}}',
|
package/es/locale/messages-nb.js
CHANGED
|
@@ -298,6 +298,7 @@ var messages = _objectSpread(_objectSpread({
|
|
|
298
298
|
multipleAuthorsLabelAriaConjunction: 'og',
|
|
299
299
|
copyPageLink: 'Kopier lenke til siden',
|
|
300
300
|
copyPageLinkCopied: 'Lenke kopiert',
|
|
301
|
+
copyHeaderLink: 'Kopier lenke til overskriften',
|
|
301
302
|
conjunction: 'og',
|
|
302
303
|
supplierLabel: 'Rettighetshaver: {{name}}',
|
|
303
304
|
multipleSuppliersLabel: 'Rettighetshavere: {{names}}',
|
|
@@ -731,8 +732,8 @@ var messages = _objectSpread(_objectSpread({
|
|
|
731
732
|
showLongerDescription: 'Vis hele emnebeskrivelsen',
|
|
732
733
|
showShorterDescription: 'Skjul emnebeskrivelsen',
|
|
733
734
|
topics: 'Emner',
|
|
734
|
-
additionalTopic: '
|
|
735
|
-
additionalTopics: '
|
|
735
|
+
additionalTopic: 'Tilleggsemne',
|
|
736
|
+
additionalTopics: 'Tilleggsemner',
|
|
736
737
|
loadingText: 'Laster emne'
|
|
737
738
|
},
|
|
738
739
|
multidisciplinarySubject: {
|
package/es/locale/messages-nn.js
CHANGED
|
@@ -298,6 +298,7 @@ var messages = _objectSpread(_objectSpread({
|
|
|
298
298
|
multipleAuthorsLabelAriaConjunction: 'og',
|
|
299
299
|
copyPageLink: 'Kopier lenke til sida',
|
|
300
300
|
copyPageLinkCopied: 'Lenke kopiert',
|
|
301
|
+
copyHeaderLink: 'Kopier lenke til overskrifta',
|
|
301
302
|
conjunction: 'og',
|
|
302
303
|
supplierLabel: 'Rettshavar: {{name}}',
|
|
303
304
|
multipleSuppliersLabel: 'Rettshavarar: {{names}}',
|
|
@@ -13,6 +13,8 @@ var _articleScripts = require("@ndla/article-scripts");
|
|
|
13
13
|
|
|
14
14
|
var _AudioPlayer = require("../AudioPlayer");
|
|
15
15
|
|
|
16
|
+
var _CopyParagraphButton = require("../CopyParagraphButton");
|
|
17
|
+
|
|
16
18
|
var _core = require("@emotion/core");
|
|
17
19
|
|
|
18
20
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
@@ -34,6 +36,7 @@ var ArticleContent = function ArticleContent(_ref) {
|
|
|
34
36
|
(0, _articleScripts.removeEventListenerForResize)();
|
|
35
37
|
(0, _articleScripts.initArticleScripts)();
|
|
36
38
|
(0, _AudioPlayer.initAudioPlayers)(locale);
|
|
39
|
+
(0, _CopyParagraphButton.initCopyParagraphButtons)();
|
|
37
40
|
return function () {
|
|
38
41
|
(0, _articleScripts.removeEventListenerForResize)();
|
|
39
42
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2021-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
|
+
interface Props {
|
|
9
|
+
title?: string | null;
|
|
10
|
+
content?: string | null;
|
|
11
|
+
}
|
|
12
|
+
declare const CopyParagraphButton: ({ title, content }: Props) => JSX.Element | null;
|
|
13
|
+
export default CopyParagraphButton;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _styledBase = _interopRequireDefault(require("@emotion/styled-base"));
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
|
|
14
|
+
var _common = require("@ndla/icons/common");
|
|
15
|
+
|
|
16
|
+
var _reactI18next = require("react-i18next");
|
|
17
|
+
|
|
18
|
+
var _tooltip = _interopRequireDefault(require("@ndla/tooltip"));
|
|
19
|
+
|
|
20
|
+
var _util = require("@ndla/util");
|
|
21
|
+
|
|
22
|
+
var _core = require("@emotion/core");
|
|
23
|
+
|
|
24
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
25
|
+
|
|
26
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
29
|
+
|
|
30
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
31
|
+
|
|
32
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
33
|
+
|
|
34
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
35
|
+
|
|
36
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
37
|
+
|
|
38
|
+
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
39
|
+
|
|
40
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
41
|
+
|
|
42
|
+
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
|
|
43
|
+
|
|
44
|
+
var IconButton = (0, _styledBase["default"])("button", {
|
|
45
|
+
target: "e18czas70",
|
|
46
|
+
label: "IconButton"
|
|
47
|
+
})(process.env.NODE_ENV === "production" ? {
|
|
48
|
+
name: "1eoah0f",
|
|
49
|
+
styles: "float:left;position:relative;left:-3em;top:0.1em;background:none;border:0;z-index:1;transition:0.2s;opacity:0;& svg{width:30px;height:30px;}"
|
|
50
|
+
} : {
|
|
51
|
+
name: "1eoah0f",
|
|
52
|
+
styles: "float:left;position:relative;left:-3em;top:0.1em;background:none;border:0;z-index:1;transition:0.2s;opacity:0;& svg{width:30px;height:30px;}",
|
|
53
|
+
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkNvcHlQYXJhZ3JhcGhCdXR0b24udHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQWlCZ0MiLCJmaWxlIjoiQ29weVBhcmFncmFwaEJ1dHRvbi50c3giLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIENvcHlyaWdodCAoYykgMjAyMS1wcmVzZW50LCBORExBLlxuICpcbiAqIFRoaXMgc291cmNlIGNvZGUgaXMgbGljZW5zZWQgdW5kZXIgdGhlIEdQTHYzIGxpY2Vuc2UgZm91bmQgaW4gdGhlXG4gKiBMSUNFTlNFIGZpbGUgaW4gd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h1cmxUb0NvcHkpO1xuICB9O1xuXG4gIGNvbnN0IHNhbml0aXplZFRpdGxlID0gZW5jb2RlVVJJQ29tcG9uZW50KHRpdGxlLnJlcGxhY2UoLyAvZywgJy0nKSk7XG4gIGNvbnN0IHRvb2x0aXAgPSBoYXNDb3BpZWQgPyB0KCdhcnRpY2xlLmNvcHlQYWdlTGlua0NvcGllZCcpIDogdCgnYXJ0aWNsZS5jb3B5SGVhZGVyTGluaycpO1xuICByZXR1cm4gKFxuICAgIDxDb250YWluZXJEaXYgZGF0YS1oZWFkZXItY29weS1jb250YWluZXIgZGF0YS10aXRsZT17dGl0bGV9PlxuICAgICAgPEljb25CdXR0b24gb25DbGljaz17b25Db3B5Q2xpY2t9IGRhdGEtdGl0bGU9e3Nhbml0aXplZFRpdGxlfT5cbiAgICAgICAgPFRvb2x0aXAgdG9vbHRpcD17dG9vbHRpcH0+XG4gICAgICAgICAgPExpbmsgdGl0bGU9eycnfSAvPlxuICAgICAgICA8L1Rvb2x0aXA+XG4gICAgICA8L0ljb25CdXR0b24+XG4gICAgICA8aDIgaWQ9e3Nhbml0aXplZFRpdGxlfSB0YWJJbmRleD17MH0gZGFuZ2Vyb3VzbHlTZXRJbm5lckhUTUw9e3sgX19odG1sOiBjb250ZW50IHx8ICcnIH19PjwvaDI+XG4gICAgPC9Db250YWluZXJEaXY+XG4gICk7XG59O1xuXG5leHBvcnQgZGVmYXVsdCBDb3B5UGFyYWdyYXBoQnV0dG9uO1xuIl19 */",
|
|
54
|
+
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
55
|
+
});
|
|
56
|
+
var ContainerDiv = (0, _styledBase["default"])("div", {
|
|
57
|
+
target: "e18czas71",
|
|
58
|
+
label: "ContainerDiv"
|
|
59
|
+
})(process.env.NODE_ENV === "production" ? {
|
|
60
|
+
name: "25spe5",
|
|
61
|
+
styles: "&:hover button{cursor:pointer;opacity:0.5;}& h2{position:relative;left:-2em;}"
|
|
62
|
+
} : {
|
|
63
|
+
name: "25spe5",
|
|
64
|
+
styles: "&:hover button{cursor:pointer;opacity:0.5;}& h2{position:relative;left:-2em;}",
|
|
65
|
+
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkNvcHlQYXJhZ3JhcGhCdXR0b24udHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQWtDK0IiLCJmaWxlIjoiQ29weVBhcmFncmFwaEJ1dHRvbi50c3giLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIENvcHlyaWdodCAoYykgMjAyMS1wcmVzZW50LCBORExBLlxuICpcbiAqIFRoaXMgc291cmNlIGNvZGUgaXMgbGljZW5zZWQgdW5kZXIgdGhlIEdQTHYzIGxpY2Vuc2UgZm91bmQgaW4gdGhlXG4gKiBMSUNFTlNFIGZpbGUgaW4gdGhlIHJvb3QgZGlyZWN0b3J5IG9mIHRoaXMgc291cmNlIHRyZWUuXG4gKlxuICovXG5cbmltcG9ydCBSZWFjdCwgeyB1c2VFZmZlY3QsIHVzZVN0YXRlIH0gZnJvbSAncmVhY3QnO1xuXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCc7XG5pbXBvcnQgeyBMaW5rIH0gZnJvbSAnQG5kbGEvaWNvbnMvY29tbW9uJztcbmltcG9ydCB7IHVzZVRyYW5zbGF0aW9uIH0gZnJvbSAncmVhY3QtaTE4bmV4dCc7XG4vLyBAdHMtaWdub3JlXG5pbXBvcnQgVG9vbHRpcCBmcm9tICdAbmRsYS90b29sdGlwJztcbmltcG9ydCB7IGNvcHlUZXh0VG9DbGlwYm9hcmQgfSBmcm9tICdAbmRsYS91dGlsJztcblxuY29uc3QgSWNvbkJ1dHRvbiA9IHN0eWxlZC5idXR0b25gXG4gIGZsb2F0OiBsZWZ0O1xuICBwb3NpdGlvbjogcmVsYXRpdmU7XG4gIGxlZnQ6IC0zZW07XG4gIHRvcDogMC4xZW07XG4g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ZFRpdGxlfSB0YWJJbmRleD17MH0gZGFuZ2Vyb3VzbHlTZXRJbm5lckhUTUw9e3sgX19odG1sOiBjb250ZW50IHx8ICcnIH19PjwvaDI+XG4gICAgPC9Db250YWluZXJEaXY+XG4gICk7XG59O1xuXG5leHBvcnQgZGVmYXVsdCBDb3B5UGFyYWdyYXBoQnV0dG9uO1xuIl19 */",
|
|
66
|
+
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
var CopyParagraphButton = function CopyParagraphButton(_ref) {
|
|
70
|
+
var title = _ref.title,
|
|
71
|
+
content = _ref.content;
|
|
72
|
+
|
|
73
|
+
var _useTranslation = (0, _reactI18next.useTranslation)(),
|
|
74
|
+
t = _useTranslation.t;
|
|
75
|
+
|
|
76
|
+
var _useState = (0, _react.useState)(false),
|
|
77
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
78
|
+
hasCopied = _useState2[0],
|
|
79
|
+
setHasCopied = _useState2[1];
|
|
80
|
+
|
|
81
|
+
(0, _react.useEffect)(function () {
|
|
82
|
+
if (hasCopied) {
|
|
83
|
+
setTimeout(function () {
|
|
84
|
+
return setHasCopied(false);
|
|
85
|
+
}, 3000);
|
|
86
|
+
}
|
|
87
|
+
}, [hasCopied]);
|
|
88
|
+
if (!title) return null;
|
|
89
|
+
|
|
90
|
+
var onCopyClick = function onCopyClick(event) {
|
|
91
|
+
setHasCopied(true);
|
|
92
|
+
var copyId = event.currentTarget.getAttribute('data-title');
|
|
93
|
+
var _window = window,
|
|
94
|
+
location = _window.location;
|
|
95
|
+
var newHash = "#".concat(copyId);
|
|
96
|
+
var port = location.port ? ":".concat(location.port) : '';
|
|
97
|
+
var urlToCopy = "".concat(location.protocol, "//").concat(location.hostname).concat(port).concat(location.pathname).concat(location.search).concat(newHash);
|
|
98
|
+
(0, _util.copyTextToClipboard)(urlToCopy);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
var sanitizedTitle = encodeURIComponent(title.replace(/ /g, '-'));
|
|
102
|
+
var tooltip = hasCopied ? t('article.copyPageLinkCopied') : t('article.copyHeaderLink');
|
|
103
|
+
return (0, _core.jsx)(ContainerDiv, {
|
|
104
|
+
"data-header-copy-container": true,
|
|
105
|
+
"data-title": title
|
|
106
|
+
}, (0, _core.jsx)(IconButton, {
|
|
107
|
+
onClick: onCopyClick,
|
|
108
|
+
"data-title": sanitizedTitle
|
|
109
|
+
}, (0, _core.jsx)(_tooltip["default"], {
|
|
110
|
+
tooltip: tooltip
|
|
111
|
+
}, (0, _core.jsx)(_common.Link, {
|
|
112
|
+
title: ''
|
|
113
|
+
}))), (0, _core.jsx)("h2", {
|
|
114
|
+
id: sanitizedTitle,
|
|
115
|
+
tabIndex: 0,
|
|
116
|
+
dangerouslySetInnerHTML: {
|
|
117
|
+
__html: content || ''
|
|
118
|
+
}
|
|
119
|
+
}));
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
var _default = CopyParagraphButton;
|
|
123
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2021-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 CopyParagraphButton from './CopyParagraphButton';
|
|
9
|
+
import initCopyParagraphButtons from './initCopyParagraphButtons';
|
|
10
|
+
export { CopyParagraphButton, initCopyParagraphButtons };
|
|
11
|
+
export default CopyParagraphButton;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CopyParagraphButton", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _CopyParagraphButton["default"];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "initCopyParagraphButtons", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _initCopyParagraphButtons["default"];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
exports["default"] = void 0;
|
|
19
|
+
|
|
20
|
+
var _CopyParagraphButton = _interopRequireDefault(require("./CopyParagraphButton"));
|
|
21
|
+
|
|
22
|
+
var _initCopyParagraphButtons = _interopRequireDefault(require("./initCopyParagraphButtons"));
|
|
23
|
+
|
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Copyright (c) 2021-present, NDLA.
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
30
|
+
* LICENSE file in the root directory of this source tree.
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
var _default = _CopyParagraphButton["default"];
|
|
34
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
11
|
+
|
|
12
|
+
var _CopyParagraphButton = _interopRequireDefault(require("./CopyParagraphButton"));
|
|
13
|
+
|
|
14
|
+
var _core = require("@emotion/core");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Copyright (c) 2021-present, NDLA.
|
|
20
|
+
*
|
|
21
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
22
|
+
* LICENSE file in the root directory of this source tree.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
var forEachElement = function forEachElement(selector, callback) {
|
|
26
|
+
var nodeList = document.querySelectorAll(selector);
|
|
27
|
+
|
|
28
|
+
for (var i = 0; i < nodeList.length; i += 1) {
|
|
29
|
+
callback(nodeList[i], i);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var initCopyParagraphButtons = function initCopyParagraphButtons() {
|
|
34
|
+
forEachElement('[data-header-copy-container]', function (el) {
|
|
35
|
+
var title = el.getAttribute('data-title');
|
|
36
|
+
var content = el.innerHTML;
|
|
37
|
+
|
|
38
|
+
_reactDom["default"].hydrate((0, _core.jsx)(_CopyParagraphButton["default"], {
|
|
39
|
+
title: title,
|
|
40
|
+
content: content
|
|
41
|
+
}), el);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
var _default = initCopyParagraphButtons;
|
|
46
|
+
exports["default"] = _default;
|
package/lib/index.d.ts
CHANGED
|
@@ -46,3 +46,4 @@ export { default as ResourceGroup } from './ResourceGroup';
|
|
|
46
46
|
export { default as LayoutItem, OneColumn, PageContainer, Content } from './Layout';
|
|
47
47
|
export { SubjectAbout, SubjectArchive, SubjectCarousel, SubjectChildContent, SubjectContent, SubjectFilter, SubjectFlexChild, SubjectFlexWrapper, SubjectHeader, SubjectLinks, SubjectNewContent, SubjectSecondaryContent, SubjectSectionTitle, SubjectShortcuts, SubjectSidebarWrapper, SubjectSocialContent, SubjectSocialSection, SubjectTopics, SubjectBanner, } from './Subject';
|
|
48
48
|
export { default as ContentCard } from './ContentCard';
|
|
49
|
+
export { default as CopyParagraphButton } from './CopyParagraphButton';
|
package/lib/index.js
CHANGED
|
@@ -103,7 +103,8 @@ var _exportNames = {
|
|
|
103
103
|
SubjectSocialSection: true,
|
|
104
104
|
SubjectTopics: true,
|
|
105
105
|
SubjectBanner: true,
|
|
106
|
-
ContentCard: true
|
|
106
|
+
ContentCard: true,
|
|
107
|
+
CopyParagraphButton: true
|
|
107
108
|
};
|
|
108
109
|
Object.defineProperty(exports, "ArticleByline", {
|
|
109
110
|
enumerable: true,
|
|
@@ -693,6 +694,12 @@ Object.defineProperty(exports, "ContentCard", {
|
|
|
693
694
|
return _ContentCard["default"];
|
|
694
695
|
}
|
|
695
696
|
});
|
|
697
|
+
Object.defineProperty(exports, "CopyParagraphButton", {
|
|
698
|
+
enumerable: true,
|
|
699
|
+
get: function get() {
|
|
700
|
+
return _CopyParagraphButton["default"];
|
|
701
|
+
}
|
|
702
|
+
});
|
|
696
703
|
|
|
697
704
|
var _indexJavascript = require("./index-javascript");
|
|
698
705
|
|
|
@@ -781,6 +788,8 @@ var _Subject = require("./Subject");
|
|
|
781
788
|
|
|
782
789
|
var _ContentCard = _interopRequireDefault(require("./ContentCard"));
|
|
783
790
|
|
|
791
|
+
var _CopyParagraphButton = _interopRequireDefault(require("./CopyParagraphButton"));
|
|
792
|
+
|
|
784
793
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
785
794
|
|
|
786
795
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
@@ -137,7 +137,7 @@ var messages = _objectSpread(_objectSpread({
|
|
|
137
137
|
showingCompetenceGoalSearchPhrase: 'Showing results for competence goals {text}',
|
|
138
138
|
searchPhraseSuggestion: 'Search instead for:',
|
|
139
139
|
notionLabels: 'Used in',
|
|
140
|
-
notionsHeading: '
|
|
140
|
+
notionsHeading: 'Explanations',
|
|
141
141
|
notionsRemove: 'Remove',
|
|
142
142
|
showVideo: 'Watch video',
|
|
143
143
|
showNotion: 'Show notion'
|
|
@@ -303,6 +303,7 @@ var messages = _objectSpread(_objectSpread({
|
|
|
303
303
|
multipleAuthorsLabelAriaConjunction: 'and',
|
|
304
304
|
copyPageLink: 'Copy page-link',
|
|
305
305
|
copyPageLinkCopied: 'Link copied',
|
|
306
|
+
copyHeaderLink: 'Copy link to header',
|
|
306
307
|
conjunction: 'and',
|
|
307
308
|
supplierLabel: 'Rightsholder: {{name}}',
|
|
308
309
|
multipleSuppliersLabel: 'Rightsholders: {{names}}',
|
|
@@ -303,6 +303,7 @@ var messages = _objectSpread(_objectSpread({
|
|
|
303
303
|
multipleAuthorsLabelAriaConjunction: 'og',
|
|
304
304
|
copyPageLink: 'Kopier lenke til siden',
|
|
305
305
|
copyPageLinkCopied: 'Lenke kopiert',
|
|
306
|
+
copyHeaderLink: 'Kopier lenke til overskriften',
|
|
306
307
|
conjunction: 'og',
|
|
307
308
|
supplierLabel: 'Rettighetshaver: {{name}}',
|
|
308
309
|
multipleSuppliersLabel: 'Rettighetshavere: {{names}}',
|
|
@@ -736,8 +737,8 @@ var messages = _objectSpread(_objectSpread({
|
|
|
736
737
|
showLongerDescription: 'Vis hele emnebeskrivelsen',
|
|
737
738
|
showShorterDescription: 'Skjul emnebeskrivelsen',
|
|
738
739
|
topics: 'Emner',
|
|
739
|
-
additionalTopic: '
|
|
740
|
-
additionalTopics: '
|
|
740
|
+
additionalTopic: 'Tilleggsemne',
|
|
741
|
+
additionalTopics: 'Tilleggsemner',
|
|
741
742
|
loadingText: 'Laster emne'
|
|
742
743
|
},
|
|
743
744
|
multidisciplinarySubject: {
|
|
@@ -303,6 +303,7 @@ var messages = _objectSpread(_objectSpread({
|
|
|
303
303
|
multipleAuthorsLabelAriaConjunction: 'og',
|
|
304
304
|
copyPageLink: 'Kopier lenke til sida',
|
|
305
305
|
copyPageLinkCopied: 'Lenke kopiert',
|
|
306
|
+
copyHeaderLink: 'Kopier lenke til overskrifta',
|
|
306
307
|
conjunction: 'og',
|
|
307
308
|
supplierLabel: 'Rettshavar: {{name}}',
|
|
308
309
|
multipleSuppliersLabel: 'Rettshavarar: {{names}}',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/ui",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1-alpha.14+c84c6d76a",
|
|
4
4
|
"description": "UI component library for NDLA.",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@ndla/safelink": "^1.0.5",
|
|
42
42
|
"@ndla/switch": "^0.0.32",
|
|
43
43
|
"@ndla/tabs": "^1.0.8",
|
|
44
|
-
"@ndla/tooltip": "^0.2.
|
|
44
|
+
"@ndla/tooltip": "^0.2.47",
|
|
45
45
|
"@ndla/util": "^2.0.0",
|
|
46
46
|
"@reach/menu-button": "^0.12.1",
|
|
47
47
|
"@reach/slider": "^0.12.1",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"publishConfig": {
|
|
93
93
|
"access": "public"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "c84c6d76a76fe8e928479e6585e856283df01e57"
|
|
96
96
|
}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
} from '@ndla/article-scripts';
|
|
15
15
|
import { initAudioPlayers } from '../AudioPlayer';
|
|
16
|
+
import { initCopyParagraphButtons } from '../CopyParagraphButton';
|
|
16
17
|
import { Locale } from '../types';
|
|
17
18
|
|
|
18
19
|
type Props = {
|
|
@@ -24,6 +25,7 @@ const ArticleContent = ({ content, locale, ...rest }: Props) => {
|
|
|
24
25
|
removeEventListenerForResize();
|
|
25
26
|
initArticleScripts();
|
|
26
27
|
initAudioPlayers(locale);
|
|
28
|
+
initCopyParagraphButtons();
|
|
27
29
|
return () => {
|
|
28
30
|
removeEventListenerForResize();
|
|
29
31
|
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2021-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 React, { useEffect, useState } from 'react';
|
|
10
|
+
|
|
11
|
+
import styled from '@emotion/styled';
|
|
12
|
+
import { Link } from '@ndla/icons/common';
|
|
13
|
+
import { useTranslation } from 'react-i18next';
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
import Tooltip from '@ndla/tooltip';
|
|
16
|
+
import { copyTextToClipboard } from '@ndla/util';
|
|
17
|
+
|
|
18
|
+
const IconButton = styled.button`
|
|
19
|
+
float: left;
|
|
20
|
+
position: relative;
|
|
21
|
+
left: -3em;
|
|
22
|
+
top: 0.1em;
|
|
23
|
+
background: none;
|
|
24
|
+
border: 0;
|
|
25
|
+
z-index: 1;
|
|
26
|
+
transition: 0.2s;
|
|
27
|
+
opacity: 0;
|
|
28
|
+
|
|
29
|
+
& svg {
|
|
30
|
+
width: 30px;
|
|
31
|
+
height: 30px;
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
const ContainerDiv = styled.div`
|
|
36
|
+
&:hover button {
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
opacity: 0.5;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
& h2 {
|
|
42
|
+
position: relative;
|
|
43
|
+
left: -2em;
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
interface Props {
|
|
48
|
+
title?: string | null;
|
|
49
|
+
content?: string | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const CopyParagraphButton = ({ title, content }: Props) => {
|
|
53
|
+
const { t } = useTranslation();
|
|
54
|
+
const [hasCopied, setHasCopied] = useState(false);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (hasCopied) {
|
|
57
|
+
setTimeout(() => setHasCopied(false), 3000);
|
|
58
|
+
}
|
|
59
|
+
}, [hasCopied]);
|
|
60
|
+
|
|
61
|
+
if (!title) return null;
|
|
62
|
+
|
|
63
|
+
const onCopyClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>): void => {
|
|
64
|
+
setHasCopied(true);
|
|
65
|
+
const copyId = event.currentTarget.getAttribute('data-title');
|
|
66
|
+
const { location } = window;
|
|
67
|
+
const newHash = `#${copyId}`;
|
|
68
|
+
const port = location.port ? `:${location.port}` : '';
|
|
69
|
+
const urlToCopy = `${location.protocol}//${location.hostname}${port}${location.pathname}${location.search}${newHash}`;
|
|
70
|
+
|
|
71
|
+
copyTextToClipboard(urlToCopy);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const sanitizedTitle = encodeURIComponent(title.replace(/ /g, '-'));
|
|
75
|
+
const tooltip = hasCopied ? t('article.copyPageLinkCopied') : t('article.copyHeaderLink');
|
|
76
|
+
return (
|
|
77
|
+
<ContainerDiv data-header-copy-container data-title={title}>
|
|
78
|
+
<IconButton onClick={onCopyClick} data-title={sanitizedTitle}>
|
|
79
|
+
<Tooltip tooltip={tooltip}>
|
|
80
|
+
<Link title={''} />
|
|
81
|
+
</Tooltip>
|
|
82
|
+
</IconButton>
|
|
83
|
+
<h2 id={sanitizedTitle} tabIndex={0} dangerouslySetInnerHTML={{ __html: content || '' }}></h2>
|
|
84
|
+
</ContainerDiv>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default CopyParagraphButton;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2021-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 CopyParagraphButton from './CopyParagraphButton';
|
|
10
|
+
import initCopyParagraphButtons from './initCopyParagraphButtons';
|
|
11
|
+
|
|
12
|
+
export { CopyParagraphButton, initCopyParagraphButtons };
|
|
13
|
+
export default CopyParagraphButton;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2021-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 React from 'react';
|
|
9
|
+
import ReactDOM from 'react-dom';
|
|
10
|
+
import CopyParagraphButton from './CopyParagraphButton';
|
|
11
|
+
|
|
12
|
+
const forEachElement = (selector: string, callback: Function) => {
|
|
13
|
+
const nodeList = document.querySelectorAll(selector);
|
|
14
|
+
for (let i = 0; i < nodeList.length; i += 1) {
|
|
15
|
+
callback(nodeList[i], i);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const initCopyParagraphButtons = () => {
|
|
20
|
+
forEachElement('[data-header-copy-container]', (el: HTMLElement) => {
|
|
21
|
+
const title = el.getAttribute('data-title');
|
|
22
|
+
const content = el.innerHTML;
|
|
23
|
+
ReactDOM.hydrate(<CopyParagraphButton title={title} content={content} />, el);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default initCopyParagraphButtons;
|
package/src/index.ts
CHANGED
|
@@ -134,7 +134,7 @@ const messages = {
|
|
|
134
134
|
showingCompetenceGoalSearchPhrase: 'Showing results for competence goals {text}',
|
|
135
135
|
searchPhraseSuggestion: 'Search instead for:',
|
|
136
136
|
notionLabels: 'Used in',
|
|
137
|
-
notionsHeading: '
|
|
137
|
+
notionsHeading: 'Explanations',
|
|
138
138
|
notionsRemove: 'Remove',
|
|
139
139
|
showVideo: 'Watch video',
|
|
140
140
|
showNotion: 'Show notion',
|
|
@@ -327,6 +327,7 @@ const messages = {
|
|
|
327
327
|
multipleAuthorsLabelAriaConjunction: 'and',
|
|
328
328
|
copyPageLink: 'Copy page-link',
|
|
329
329
|
copyPageLinkCopied: 'Link copied',
|
|
330
|
+
copyHeaderLink: 'Copy link to header',
|
|
330
331
|
conjunction: 'and',
|
|
331
332
|
supplierLabel: 'Rightsholder: {{name}}',
|
|
332
333
|
multipleSuppliersLabel: 'Rightsholders: {{names}}',
|
|
@@ -326,6 +326,7 @@ const messages = {
|
|
|
326
326
|
multipleAuthorsLabelAriaConjunction: 'og',
|
|
327
327
|
copyPageLink: 'Kopier lenke til siden',
|
|
328
328
|
copyPageLinkCopied: 'Lenke kopiert',
|
|
329
|
+
copyHeaderLink: 'Kopier lenke til overskriften',
|
|
329
330
|
conjunction: 'og',
|
|
330
331
|
supplierLabel: 'Rettighetshaver: {{name}}',
|
|
331
332
|
multipleSuppliersLabel: 'Rettighetshavere: {{names}}',
|
|
@@ -764,8 +765,8 @@ const messages = {
|
|
|
764
765
|
showLongerDescription: 'Vis hele emnebeskrivelsen',
|
|
765
766
|
showShorterDescription: 'Skjul emnebeskrivelsen',
|
|
766
767
|
topics: 'Emner',
|
|
767
|
-
additionalTopic: '
|
|
768
|
-
additionalTopics: '
|
|
768
|
+
additionalTopic: 'Tilleggsemne',
|
|
769
|
+
additionalTopics: 'Tilleggsemner',
|
|
769
770
|
loadingText: 'Laster emne',
|
|
770
771
|
},
|
|
771
772
|
multidisciplinarySubject: {
|
|
@@ -327,6 +327,7 @@ const messages = {
|
|
|
327
327
|
multipleAuthorsLabelAriaConjunction: 'og',
|
|
328
328
|
copyPageLink: 'Kopier lenke til sida',
|
|
329
329
|
copyPageLinkCopied: 'Lenke kopiert',
|
|
330
|
+
copyHeaderLink: 'Kopier lenke til overskrifta',
|
|
330
331
|
conjunction: 'og',
|
|
331
332
|
supplierLabel: 'Rettshavar: {{name}}',
|
|
332
333
|
multipleSuppliersLabel: 'Rettshavarar: {{names}}',
|