@navikt/ds-react 3.3.0 → 3.3.1
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/cjs/util/copy.js +18 -63
- package/esm/util/copy.d.ts +1 -1
- package/esm/util/copy.js +18 -63
- package/esm/util/copy.js.map +1 -1
- package/package.json +2 -2
- package/src/button/button.stories.tsx +3 -3
- package/src/util/copy.ts +8 -75
package/cjs/util/copy.js
CHANGED
|
@@ -1,73 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
3
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const defaultMessage = "Kopier til utklippstavle: #{key}, Enter";
|
|
5
|
-
function format(message) {
|
|
6
|
-
const copyKey = (/mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl") + "+C";
|
|
7
|
-
return message.replace(/#{\s*key\s*}/g, copyKey);
|
|
8
|
-
}
|
|
9
12
|
function copy(text) {
|
|
10
|
-
|
|
11
|
-
debug = process.env.NODE_ENV !== "production";
|
|
12
|
-
try {
|
|
13
|
-
range = document.createRange();
|
|
14
|
-
selection = document.getSelection();
|
|
15
|
-
mark = document.createElement("span");
|
|
16
|
-
mark.textContent = text;
|
|
17
|
-
// avoid screen readers from reading out loud the text
|
|
18
|
-
mark.ariaHidden = "true";
|
|
19
|
-
// reset user styles for span element
|
|
20
|
-
mark.style.all = "unset";
|
|
21
|
-
// prevents scrolling to the end of the page
|
|
22
|
-
mark.style.position = "fixed";
|
|
23
|
-
mark.style.top = 0;
|
|
24
|
-
mark.style.clip = "rect(0, 0, 0, 0)";
|
|
25
|
-
// used to preserve spaces and line breaks
|
|
26
|
-
mark.style.whiteSpace = "pre";
|
|
27
|
-
// do not inherit user-select (it may be `none`)
|
|
28
|
-
mark.style.webkitUserSelect = "text";
|
|
29
|
-
mark.style.MozUserSelect = "text";
|
|
30
|
-
mark.style.msUserSelect = "text";
|
|
31
|
-
mark.style.userSelect = "text";
|
|
32
|
-
mark.addEventListener("copy", function (e) {
|
|
33
|
-
e.stopPropagation();
|
|
34
|
-
});
|
|
35
|
-
document.body.appendChild(mark);
|
|
36
|
-
range.selectNodeContents(mark);
|
|
37
|
-
selection.addRange(range);
|
|
38
|
-
const successful = document.execCommand("copy");
|
|
39
|
-
if (!successful) {
|
|
40
|
-
throw new Error("copy command was unsuccessful");
|
|
41
|
-
}
|
|
42
|
-
success = true;
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
debug && console.error("unable to copy using execCommand: ", err);
|
|
46
|
-
debug && console.warn("trying IE specific stuff");
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
14
|
try {
|
|
48
|
-
|
|
49
|
-
success = true;
|
|
15
|
+
yield navigator.clipboard.writeText(text);
|
|
50
16
|
}
|
|
51
17
|
catch (err) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
message = format(defaultMessage);
|
|
55
|
-
window.prompt(message, text);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
finally {
|
|
59
|
-
if (selection) {
|
|
60
|
-
if (typeof selection.removeRange == "function") {
|
|
61
|
-
selection.removeRange(range);
|
|
18
|
+
if (process.env.NODE_ENV !== "production") {
|
|
19
|
+
console.error("Unable to copy using Clipboard API", err);
|
|
62
20
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (mark) {
|
|
68
|
-
document.body.removeChild(mark);
|
|
21
|
+
// Fallback for browsers that do not support the Clipboard API.
|
|
22
|
+
const copyKey = /mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl";
|
|
23
|
+
const message = `Kopier til utklippstavle: ${copyKey}+C, Enter`;
|
|
24
|
+
window.prompt(message, text);
|
|
69
25
|
}
|
|
70
|
-
}
|
|
71
|
-
return success;
|
|
26
|
+
});
|
|
72
27
|
}
|
|
73
28
|
exports.default = copy;
|
package/esm/util/copy.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function copy(text:
|
|
1
|
+
export default function copy(text: string): Promise<void>;
|
package/esm/util/copy.js
CHANGED
|
@@ -1,71 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
7
10
|
export default function copy(text) {
|
|
8
|
-
|
|
9
|
-
debug = process.env.NODE_ENV !== "production";
|
|
10
|
-
try {
|
|
11
|
-
range = document.createRange();
|
|
12
|
-
selection = document.getSelection();
|
|
13
|
-
mark = document.createElement("span");
|
|
14
|
-
mark.textContent = text;
|
|
15
|
-
// avoid screen readers from reading out loud the text
|
|
16
|
-
mark.ariaHidden = "true";
|
|
17
|
-
// reset user styles for span element
|
|
18
|
-
mark.style.all = "unset";
|
|
19
|
-
// prevents scrolling to the end of the page
|
|
20
|
-
mark.style.position = "fixed";
|
|
21
|
-
mark.style.top = 0;
|
|
22
|
-
mark.style.clip = "rect(0, 0, 0, 0)";
|
|
23
|
-
// used to preserve spaces and line breaks
|
|
24
|
-
mark.style.whiteSpace = "pre";
|
|
25
|
-
// do not inherit user-select (it may be `none`)
|
|
26
|
-
mark.style.webkitUserSelect = "text";
|
|
27
|
-
mark.style.MozUserSelect = "text";
|
|
28
|
-
mark.style.msUserSelect = "text";
|
|
29
|
-
mark.style.userSelect = "text";
|
|
30
|
-
mark.addEventListener("copy", function (e) {
|
|
31
|
-
e.stopPropagation();
|
|
32
|
-
});
|
|
33
|
-
document.body.appendChild(mark);
|
|
34
|
-
range.selectNodeContents(mark);
|
|
35
|
-
selection.addRange(range);
|
|
36
|
-
const successful = document.execCommand("copy");
|
|
37
|
-
if (!successful) {
|
|
38
|
-
throw new Error("copy command was unsuccessful");
|
|
39
|
-
}
|
|
40
|
-
success = true;
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
debug && console.error("unable to copy using execCommand: ", err);
|
|
44
|
-
debug && console.warn("trying IE specific stuff");
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
12
|
try {
|
|
46
|
-
|
|
47
|
-
success = true;
|
|
13
|
+
yield navigator.clipboard.writeText(text);
|
|
48
14
|
}
|
|
49
15
|
catch (err) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
message = format(defaultMessage);
|
|
53
|
-
window.prompt(message, text);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
finally {
|
|
57
|
-
if (selection) {
|
|
58
|
-
if (typeof selection.removeRange == "function") {
|
|
59
|
-
selection.removeRange(range);
|
|
16
|
+
if (process.env.NODE_ENV !== "production") {
|
|
17
|
+
console.error("Unable to copy using Clipboard API", err);
|
|
60
18
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (mark) {
|
|
66
|
-
document.body.removeChild(mark);
|
|
19
|
+
// Fallback for browsers that do not support the Clipboard API.
|
|
20
|
+
const copyKey = /mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl";
|
|
21
|
+
const message = `Kopier til utklippstavle: ${copyKey}+C, Enter`;
|
|
22
|
+
window.prompt(message, text);
|
|
67
23
|
}
|
|
68
|
-
}
|
|
69
|
-
return success;
|
|
24
|
+
});
|
|
70
25
|
}
|
|
71
26
|
//# sourceMappingURL=copy.js.map
|
package/esm/util/copy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy.js","sourceRoot":"","sources":["../../src/util/copy.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"copy.js","sourceRoot":"","sources":["../../src/util/copy.ts"],"names":[],"mappings":";;;;;;;;;AAAA,MAAM,CAAC,OAAO,UAAgB,IAAI,CAAC,IAAY;;QAC7C,IAAI;YACF,MAAM,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;SAC3C;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;gBACzC,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,GAAG,CAAC,CAAC;aAC1D;YAED,+DAA+D;YAC/D,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;YACrE,MAAM,OAAO,GAAG,6BAA6B,OAAO,WAAW,CAAC;YAChE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;SAC9B;IACH,CAAC;CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "Aksel react-components for NAV designsystem",
|
|
5
5
|
"author": "Aksel | NAV designsystem team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@floating-ui/react": "0.24.1",
|
|
41
|
-
"@navikt/aksel-icons": "^3.3.
|
|
41
|
+
"@navikt/aksel-icons": "^3.3.1",
|
|
42
42
|
"@radix-ui/react-tabs": "1.0.0",
|
|
43
43
|
"@radix-ui/react-toggle-group": "1.0.0",
|
|
44
44
|
"clsx": "^1.2.1",
|
|
@@ -123,7 +123,7 @@ export const Link = () => (
|
|
|
123
123
|
|
|
124
124
|
export const Loading = {
|
|
125
125
|
render: () => (
|
|
126
|
-
<div className="colgap">
|
|
126
|
+
<div className="colgap chromatic-ignore">
|
|
127
127
|
<div className="rowgap">
|
|
128
128
|
{variants.map((variant) => (
|
|
129
129
|
<Button key={variant} variant={variant} loading>
|
|
@@ -153,7 +153,7 @@ export const Loading = {
|
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
export const Icon = () => (
|
|
156
|
-
<div className="colgap">
|
|
156
|
+
<div className="colgap ">
|
|
157
157
|
<div className="rowgap">
|
|
158
158
|
{variants.map((variant) => (
|
|
159
159
|
<Button
|
|
@@ -250,7 +250,7 @@ export const Disabled = () => (
|
|
|
250
250
|
|
|
251
251
|
export const LoadingWithAs = {
|
|
252
252
|
render: () => (
|
|
253
|
-
<div className="colgap">
|
|
253
|
+
<div className="colgap chromatic-ignore">
|
|
254
254
|
<div className="rowgap">
|
|
255
255
|
{variants.map((variant) => (
|
|
256
256
|
<Button key={variant} variant={variant} loading size="small">
|
package/src/util/copy.ts
CHANGED
|
@@ -1,81 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const defaultMessage = "Kopier til utklippstavle: #{key}, Enter";
|
|
4
|
-
|
|
5
|
-
function format(message) {
|
|
6
|
-
const copyKey = (/mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl") + "+C";
|
|
7
|
-
return message.replace(/#{\s*key\s*}/g, copyKey);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default function copy(text) {
|
|
11
|
-
let debug,
|
|
12
|
-
message,
|
|
13
|
-
range,
|
|
14
|
-
selection,
|
|
15
|
-
mark,
|
|
16
|
-
success = false;
|
|
17
|
-
debug = process.env.NODE_ENV !== "production";
|
|
1
|
+
export default async function copy(text: string): Promise<void> {
|
|
18
2
|
try {
|
|
19
|
-
|
|
20
|
-
selection = document.getSelection();
|
|
21
|
-
|
|
22
|
-
mark = document.createElement("span");
|
|
23
|
-
mark.textContent = text;
|
|
24
|
-
// avoid screen readers from reading out loud the text
|
|
25
|
-
mark.ariaHidden = "true";
|
|
26
|
-
// reset user styles for span element
|
|
27
|
-
mark.style.all = "unset";
|
|
28
|
-
// prevents scrolling to the end of the page
|
|
29
|
-
mark.style.position = "fixed";
|
|
30
|
-
mark.style.top = 0;
|
|
31
|
-
mark.style.clip = "rect(0, 0, 0, 0)";
|
|
32
|
-
// used to preserve spaces and line breaks
|
|
33
|
-
mark.style.whiteSpace = "pre";
|
|
34
|
-
// do not inherit user-select (it may be `none`)
|
|
35
|
-
mark.style.webkitUserSelect = "text";
|
|
36
|
-
mark.style.MozUserSelect = "text";
|
|
37
|
-
mark.style.msUserSelect = "text";
|
|
38
|
-
mark.style.userSelect = "text";
|
|
39
|
-
mark.addEventListener("copy", function (e) {
|
|
40
|
-
e.stopPropagation();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
document.body.appendChild(mark);
|
|
44
|
-
|
|
45
|
-
range.selectNodeContents(mark);
|
|
46
|
-
selection.addRange(range);
|
|
47
|
-
|
|
48
|
-
const successful = document.execCommand("copy");
|
|
49
|
-
if (!successful) {
|
|
50
|
-
throw new Error("copy command was unsuccessful");
|
|
51
|
-
}
|
|
52
|
-
success = true;
|
|
3
|
+
await navigator.clipboard.writeText(text);
|
|
53
4
|
} catch (err) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
(window as any).clipboardData.setData("text", text);
|
|
58
|
-
|
|
59
|
-
success = true;
|
|
60
|
-
} catch (err) {
|
|
61
|
-
debug && console.error("unable to copy using clipboardData: ", err);
|
|
62
|
-
debug && console.error("falling back to prompt");
|
|
63
|
-
message = format(defaultMessage);
|
|
64
|
-
window.prompt(message, text);
|
|
65
|
-
}
|
|
66
|
-
} finally {
|
|
67
|
-
if (selection) {
|
|
68
|
-
if (typeof selection.removeRange == "function") {
|
|
69
|
-
selection.removeRange(range);
|
|
70
|
-
} else {
|
|
71
|
-
selection.removeAllRanges();
|
|
72
|
-
}
|
|
5
|
+
if (process.env.NODE_ENV !== "production") {
|
|
6
|
+
console.error("Unable to copy using Clipboard API", err);
|
|
73
7
|
}
|
|
74
8
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
9
|
+
// Fallback for browsers that do not support the Clipboard API.
|
|
10
|
+
const copyKey = /mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl";
|
|
11
|
+
const message = `Kopier til utklippstavle: ${copyKey}+C, Enter`;
|
|
12
|
+
window.prompt(message, text);
|
|
78
13
|
}
|
|
79
|
-
|
|
80
|
-
return success;
|
|
81
14
|
}
|