@efolusi/meridian 1.21.9 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/ai/Citation.js +44 -22
- package/ai/Confirmation.js +2 -2
- package/ai/PromptComposer.d.ts +4 -0
- package/ai/PromptComposer.js +7 -1
- package/ai/RichComposer.js +3 -0
- package/ai/SourceCard.js +12 -4
- package/ai/UsageMeter.d.ts +3 -1
- package/ai/UsageMeter.js +8 -2
- package/ai/WebPreview.js +12 -4
- package/code/CodeBlock.js +26 -7
- package/code/CopyField.js +24 -9
- package/components.css +141 -58
- package/data/BarChart.d.ts +4 -0
- package/data/BarChart.js +28 -4
- package/data/Chart.d.ts +1 -1
- package/data/Chart.js +5 -2
- package/data/DonutChart.d.ts +4 -0
- package/data/DonutChart.js +38 -8
- package/data/LineChart.d.ts +4 -0
- package/data/LineChart.js +29 -7
- package/data/Table.d.ts +1 -0
- package/data/Table.js +35 -19
- package/dates/Calendar.js +43 -15
- package/dates/TimePicker.js +18 -3
- package/display/Toolbar.js +1 -0
- package/display/TreeList.js +20 -13
- package/feedback/AlertDialog.js +12 -12
- package/feedback/Dialog.js +17 -12
- package/feedback/Toast.js +5 -2
- package/feedback/Tooltip.js +5 -1
- package/files/FileDrop.d.ts +5 -1
- package/files/FileDrop.js +28 -1
- package/forms/ButtonTile.js +2 -0
- package/forms/Combobox.js +21 -5
- package/forms/NumberInput.js +21 -4
- package/forms/Questionnaire.js +1 -1
- package/forms/Slider.js +2 -1
- package/forms/Switch.js +14 -3
- package/index.js +3 -3
- package/navigation/NavigationMenu.js +17 -5
- package/navigation/PageControl.js +1 -0
- package/navigation/SegmentedControl.js +1 -0
- package/navigation/SideNav.js +2 -0
- package/navigation/Sidebar.js +74 -11
- package/navigation/SkipLink.d.ts +2 -1
- package/navigation/SkipLink.js +16 -4
- package/overlay/Command.js +1 -0
- package/overlay/ContextMenu.js +32 -10
- package/overlay/Drawer.d.ts +1 -0
- package/overlay/Drawer.js +19 -2
- package/overlay/DropdownMenu.js +32 -10
- package/overlay/HoverCard.js +8 -13
- package/overlay/Popover.js +46 -10
- package/overlay/Portal.js +67 -2
- package/package.json +1 -1
- package/tailwind.preset.cjs +34 -13
- package/tokens/base.css +5 -0
- package/tokens/colors.css +7 -3
- package/tokens.json +427 -95
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Third-party notices
|
|
2
2
|
|
|
3
|
-
Meridian's own source (components, tokens, blocks, showcases, starters, docs) is MIT licensed
|
|
3
|
+
Meridian's own source (components, tokens, blocks, showcases, starters, docs) is MIT licensed (see [LICENSE])(LICENSE). The repository also redistributes the following third-party assets under their own licenses. Their license texts ship alongside the assets and must travel with any redistribution.
|
|
4
4
|
|
|
5
5
|
## Fonts (SIL Open Font License 1.1)
|
|
6
6
|
|
package/ai/Citation.js
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { Icon } from "../icons/Icon.js";
|
|
5
|
+
// Source and preview URLs usually come from model or tool output, so a
|
|
6
|
+
// javascript:, vbscript: or data: URL must never reach an href or iframe src.
|
|
7
|
+
// Relative, fragment, http(s) and mailto URLs pass through unchanged.
|
|
8
|
+
function safeUrl(url) {
|
|
9
|
+
if (url == null || url === '') return undefined;
|
|
10
|
+
const s = String(url);
|
|
11
|
+
const scheme = /^\s*([a-z][a-z0-9+.-]*):/i.exec(s.replace(/[\u0000-\u001F\u007F]/g, ''));
|
|
12
|
+
return !scheme || /^(https?|mailto)$/i.test(scheme[1]) ? s : undefined;
|
|
13
|
+
}
|
|
5
14
|
export function Citation({
|
|
6
15
|
index,
|
|
7
16
|
href,
|
|
@@ -16,6 +25,7 @@ export function Citation({
|
|
|
16
25
|
const [i, setI] = React.useState(0);
|
|
17
26
|
const t = React.useRef(null);
|
|
18
27
|
const list = sources && sources.length ? sources : null;
|
|
28
|
+
const link = safeUrl(href);
|
|
19
29
|
const enter = () => {
|
|
20
30
|
if (!list) return;
|
|
21
31
|
clearTimeout(t.current);
|
|
@@ -27,11 +37,11 @@ export function Citation({
|
|
|
27
37
|
};
|
|
28
38
|
React.useEffect(() => () => clearTimeout(t.current), []);
|
|
29
39
|
const chip = /*#__PURE__*/React.createElement("a", {
|
|
30
|
-
href:
|
|
40
|
+
href: link || list && list[0] && safeUrl(list[0].url) || '#',
|
|
31
41
|
title: title,
|
|
32
42
|
onClick: onClick,
|
|
33
|
-
target:
|
|
34
|
-
rel:
|
|
43
|
+
target: link ? '_blank' : undefined,
|
|
44
|
+
rel: link ? 'noopener' : undefined,
|
|
35
45
|
className: `ef-citation${className ? ' ' + className : ''}`,
|
|
36
46
|
style: list ? null : style,
|
|
37
47
|
"aria-label": title ? 'Source ' + index + ': ' + title : 'Source ' + index
|
|
@@ -42,7 +52,16 @@ export function Citation({
|
|
|
42
52
|
className: "ef-citation__wrap",
|
|
43
53
|
style: style,
|
|
44
54
|
onMouseEnter: enter,
|
|
45
|
-
onMouseLeave: leave
|
|
55
|
+
onMouseLeave: leave,
|
|
56
|
+
onFocus: enter,
|
|
57
|
+
onBlur: leave,
|
|
58
|
+
onKeyDown: e => {
|
|
59
|
+
if (e.key === 'Escape' && open) {
|
|
60
|
+
e.stopPropagation();
|
|
61
|
+
clearTimeout(t.current);
|
|
62
|
+
setOpen(false);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
46
65
|
}), chip, open ? /*#__PURE__*/React.createElement("span", {
|
|
47
66
|
className: "ef-citation__pop",
|
|
48
67
|
role: "dialog"
|
|
@@ -98,22 +117,25 @@ export function SourceList({
|
|
|
98
117
|
style: style
|
|
99
118
|
}), /*#__PURE__*/React.createElement("div", {
|
|
100
119
|
className: "ef-sources__head"
|
|
101
|
-
}, title), sources.map((s, i) =>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
}, title), sources.map((s, i) => {
|
|
121
|
+
const url = safeUrl(s.url);
|
|
122
|
+
return /*#__PURE__*/React.createElement("a", {
|
|
123
|
+
key: s.index || i,
|
|
124
|
+
className: "ef-sources__item",
|
|
125
|
+
href: url || '#',
|
|
126
|
+
target: url ? '_blank' : undefined,
|
|
127
|
+
rel: url ? 'noopener' : undefined
|
|
128
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
129
|
+
className: "ef-sources__num"
|
|
130
|
+
}, s.index || i + 1), /*#__PURE__*/React.createElement("span", {
|
|
131
|
+
className: "ef-sources__title"
|
|
132
|
+
}, s.title), s.domain ? /*#__PURE__*/React.createElement("span", {
|
|
133
|
+
className: "ef-sources__domain"
|
|
134
|
+
}, s.domain) : null, /*#__PURE__*/React.createElement("span", {
|
|
135
|
+
className: "ef-sources__ext"
|
|
136
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
137
|
+
name: "external-link",
|
|
138
|
+
size: 12
|
|
139
|
+
})));
|
|
140
|
+
}));
|
|
119
141
|
}
|
package/ai/Confirmation.js
CHANGED
|
@@ -12,8 +12,8 @@ export function Confirmation({
|
|
|
12
12
|
icon,
|
|
13
13
|
approveLabel = 'Approve',
|
|
14
14
|
rejectLabel = 'Reject',
|
|
15
|
-
approvedNote = 'Approved
|
|
16
|
-
rejectedNote = 'Rejected
|
|
15
|
+
approvedNote = 'Approved. Continuing.',
|
|
16
|
+
rejectedNote = 'Rejected. The agent will skip this.',
|
|
17
17
|
children,
|
|
18
18
|
style,
|
|
19
19
|
className,
|
package/ai/PromptComposer.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export interface PromptComposerProps {
|
|
|
15
15
|
onStop?: (e: React.MouseEvent) => void;
|
|
16
16
|
/** @default 'Ask the agent anything…' */
|
|
17
17
|
placeholder?: string;
|
|
18
|
+
/** Accessible name for the textarea (not the wrapper). @default placeholder */
|
|
19
|
+
'aria-label'?: string;
|
|
20
|
+
/** Id of a visible label for the textarea; overrides aria-label */
|
|
21
|
+
'aria-labelledby'?: string;
|
|
18
22
|
/** @default 2 */
|
|
19
23
|
rows?: number;
|
|
20
24
|
disabled?: boolean;
|
package/ai/PromptComposer.js
CHANGED
|
@@ -17,6 +17,8 @@ export const PromptComposer = /*#__PURE__*/React.forwardRef(function PromptCompo
|
|
|
17
17
|
disabled,
|
|
18
18
|
attachments,
|
|
19
19
|
hint,
|
|
20
|
+
'aria-label': ariaLabel,
|
|
21
|
+
'aria-labelledby': ariaLabelledby,
|
|
20
22
|
style,
|
|
21
23
|
className,
|
|
22
24
|
...rest
|
|
@@ -51,9 +53,11 @@ export const PromptComposer = /*#__PURE__*/React.forwardRef(function PromptCompo
|
|
|
51
53
|
placeholder: placeholder,
|
|
52
54
|
value: v,
|
|
53
55
|
disabled: disabled,
|
|
56
|
+
"aria-label": ariaLabelledby ? undefined : ariaLabel || placeholder,
|
|
57
|
+
"aria-labelledby": ariaLabelledby,
|
|
54
58
|
onChange: e => set(e.target.value, e),
|
|
55
59
|
onKeyDown: e => {
|
|
56
|
-
if (e.key === 'Enter' && !e.shiftKey) {
|
|
60
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) {
|
|
57
61
|
e.preventDefault();
|
|
58
62
|
send();
|
|
59
63
|
}
|
|
@@ -73,6 +77,7 @@ export const PromptComposer = /*#__PURE__*/React.forwardRef(function PromptCompo
|
|
|
73
77
|
}) : null, hint ? /*#__PURE__*/React.createElement("span", {
|
|
74
78
|
className: "ef-composer__hint"
|
|
75
79
|
}, hint) : null, busy ? /*#__PURE__*/React.createElement("button", {
|
|
80
|
+
type: "button",
|
|
76
81
|
className: "ef-composer__send",
|
|
77
82
|
"aria-label": "Stop generating",
|
|
78
83
|
onClick: onStop,
|
|
@@ -82,6 +87,7 @@ export const PromptComposer = /*#__PURE__*/React.forwardRef(function PromptCompo
|
|
|
82
87
|
size: 13,
|
|
83
88
|
strokeWidth: 2.5
|
|
84
89
|
})) : /*#__PURE__*/React.createElement("button", {
|
|
90
|
+
type: "button",
|
|
85
91
|
className: "ef-composer__send",
|
|
86
92
|
"aria-label": "Send",
|
|
87
93
|
disabled: disabled || !v.trim(),
|
package/ai/RichComposer.js
CHANGED
|
@@ -203,6 +203,9 @@ export function RichComposer({
|
|
|
203
203
|
"data-placeholder": placeholder,
|
|
204
204
|
role: "textbox",
|
|
205
205
|
"aria-multiline": "true",
|
|
206
|
+
"aria-label": placeholder,
|
|
207
|
+
"aria-placeholder": placeholder,
|
|
208
|
+
"aria-disabled": disabled || undefined,
|
|
206
209
|
spellCheck: false,
|
|
207
210
|
onInput: refresh,
|
|
208
211
|
onKeyUp: refresh,
|
package/ai/SourceCard.js
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { Icon } from "../icons/Icon.js";
|
|
5
|
+
// Model-supplied URL: only http(s), mailto and relative pass (see Citation.jsx).
|
|
6
|
+
function safeUrl(url) {
|
|
7
|
+
if (url == null || url === '') return undefined;
|
|
8
|
+
const s = String(url);
|
|
9
|
+
const scheme = /^\s*([a-z][a-z0-9+.-]*):/i.exec(s.replace(/[\u0000-\u001F\u007F]/g, ''));
|
|
10
|
+
return !scheme || /^(https?|mailto)$/i.test(scheme[1]) ? s : undefined;
|
|
11
|
+
}
|
|
5
12
|
export function SourceCard({
|
|
6
13
|
href,
|
|
7
14
|
title,
|
|
@@ -16,13 +23,14 @@ export function SourceCard({
|
|
|
16
23
|
className,
|
|
17
24
|
...rest
|
|
18
25
|
}) {
|
|
19
|
-
const
|
|
26
|
+
const link = safeUrl(href);
|
|
27
|
+
const Tag = link || onClick ? 'a' : 'div';
|
|
20
28
|
return /*#__PURE__*/React.createElement(Tag, _extends({}, rest, {
|
|
21
29
|
className: `ef-sourcecard${variant === 'plain' ? ' ef-sourcecard--plain' : ''}${className ? ' ' + className : ''}`,
|
|
22
30
|
style: style,
|
|
23
|
-
href:
|
|
24
|
-
target:
|
|
25
|
-
rel:
|
|
31
|
+
href: link,
|
|
32
|
+
target: link ? '_blank' : undefined,
|
|
33
|
+
rel: link ? 'noreferrer noopener' : undefined,
|
|
26
34
|
onClick: onClick
|
|
27
35
|
}), thumbnail ? /*#__PURE__*/React.createElement("img", {
|
|
28
36
|
className: "ef-sourcecard__thumb",
|
package/ai/UsageMeter.d.ts
CHANGED
|
@@ -13,8 +13,10 @@ export interface UsageMeterProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
13
13
|
warnAt?: number;
|
|
14
14
|
/** Count the figure and bar up on mount/change */
|
|
15
15
|
animated?: boolean;
|
|
16
|
-
/** Figure formatter @default
|
|
16
|
+
/** Figure formatter @default Intl.NumberFormat(locale), whole numbers */
|
|
17
17
|
format?: (v: number) => string;
|
|
18
|
+
/** BCP 47 locale for number formatting (fixed default keeps server and browser output identical) @default 'en-US' */
|
|
19
|
+
locale?: string;
|
|
18
20
|
style?: React.CSSProperties;
|
|
19
21
|
className?: string;
|
|
20
22
|
}
|
package/ai/UsageMeter.js
CHANGED
|
@@ -12,6 +12,7 @@ export function UsageMeter({
|
|
|
12
12
|
warnAt = 0.8,
|
|
13
13
|
animated,
|
|
14
14
|
format,
|
|
15
|
+
locale = 'en-US',
|
|
15
16
|
style,
|
|
16
17
|
className,
|
|
17
18
|
...rest
|
|
@@ -36,7 +37,11 @@ export function UsageMeter({
|
|
|
36
37
|
return () => cancelAnimationFrame(raf);
|
|
37
38
|
}, [used, animated]);
|
|
38
39
|
const ratio = limit > 0 ? used / limit : 0;
|
|
39
|
-
|
|
40
|
+
// Fixed default locale: the runtime default would differ between server and browser.
|
|
41
|
+
const nf = new Intl.NumberFormat(locale, {
|
|
42
|
+
maximumFractionDigits: 0
|
|
43
|
+
});
|
|
44
|
+
const fmt = format || (v => nf.format(Math.round(v)));
|
|
40
45
|
const tone = ratio >= 1 ? ' ef-usage--over' : ratio >= warnAt ? ' ef-usage--warn' : '';
|
|
41
46
|
const shownRatio = limit > 0 ? shown / limit : 0;
|
|
42
47
|
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
@@ -51,9 +56,10 @@ export function UsageMeter({
|
|
|
51
56
|
}, fmt(shown), " / ", fmt(limit), unit ? ' ' + unit : '')), /*#__PURE__*/React.createElement("div", {
|
|
52
57
|
className: "ef-usage__track",
|
|
53
58
|
role: "progressbar",
|
|
54
|
-
"aria-valuenow": Math.round(ratio * 100),
|
|
59
|
+
"aria-valuenow": Math.round(Math.min(1, Math.max(0, ratio)) * 100),
|
|
55
60
|
"aria-valuemin": 0,
|
|
56
61
|
"aria-valuemax": 100,
|
|
62
|
+
"aria-valuetext": `${fmt(used)} / ${fmt(limit)}${unit ? " " + unit : ""}`,
|
|
57
63
|
"aria-label": label
|
|
58
64
|
}, /*#__PURE__*/React.createElement("span", {
|
|
59
65
|
className: "ef-usage__fill",
|
package/ai/WebPreview.js
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { Icon } from "../icons/Icon.js";
|
|
5
|
+
// Model-supplied URL: only http(s), mailto and relative pass (see Citation.jsx).
|
|
6
|
+
function safeUrl(url) {
|
|
7
|
+
if (url == null || url === '') return undefined;
|
|
8
|
+
const s = String(url);
|
|
9
|
+
const scheme = /^\s*([a-z][a-z0-9+.-]*):/i.exec(s.replace(/[\u0000-\u001F\u007F]/g, ''));
|
|
10
|
+
return !scheme || /^(https?|mailto)$/i.test(scheme[1]) ? s : undefined;
|
|
11
|
+
}
|
|
5
12
|
const VIEWPORTS = [{
|
|
6
13
|
id: 'desktop',
|
|
7
14
|
icon: 'monitor',
|
|
@@ -45,6 +52,7 @@ export function WebPreview({
|
|
|
45
52
|
setUrl(next);
|
|
46
53
|
if (onUrlChange) onUrlChange(next);
|
|
47
54
|
};
|
|
55
|
+
const safe = safeUrl(url);
|
|
48
56
|
const width = (VIEWPORTS.find(v => v.id === vp) || {}).width;
|
|
49
57
|
const LOG_ICON = {
|
|
50
58
|
warn: 'triangle-alert',
|
|
@@ -110,7 +118,7 @@ export function WebPreview({
|
|
|
110
118
|
}, errs) : null), /*#__PURE__*/React.createElement("a", {
|
|
111
119
|
className: "ef-webprev__btn",
|
|
112
120
|
"aria-label": "Open in new tab",
|
|
113
|
-
href:
|
|
121
|
+
href: safe,
|
|
114
122
|
target: "_blank",
|
|
115
123
|
rel: "noreferrer noopener"
|
|
116
124
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
@@ -126,10 +134,10 @@ export function WebPreview({
|
|
|
126
134
|
style: width ? {
|
|
127
135
|
width
|
|
128
136
|
} : null
|
|
129
|
-
}, children) :
|
|
130
|
-
key:
|
|
137
|
+
}, children) : safe ? /*#__PURE__*/React.createElement("iframe", {
|
|
138
|
+
key: safe + '-' + key,
|
|
131
139
|
className: "ef-webprev__frame",
|
|
132
|
-
src:
|
|
140
|
+
src: safe,
|
|
133
141
|
title: "Web preview",
|
|
134
142
|
sandbox: "allow-scripts allow-same-origin allow-forms allow-popups",
|
|
135
143
|
style: width ? {
|
package/code/CodeBlock.js
CHANGED
|
@@ -13,7 +13,17 @@ export function CodeBlock({
|
|
|
13
13
|
className,
|
|
14
14
|
...rest
|
|
15
15
|
}) {
|
|
16
|
-
|
|
16
|
+
// 'idle' | 'done' | 'failed': only a resolved clipboard write counts as copied.
|
|
17
|
+
const [copied, setCopied] = React.useState('idle');
|
|
18
|
+
const timer = React.useRef(null);
|
|
19
|
+
const live = React.useRef(true);
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
live.current = true;
|
|
22
|
+
return () => {
|
|
23
|
+
live.current = false;
|
|
24
|
+
clearTimeout(timer.current);
|
|
25
|
+
};
|
|
26
|
+
}, []);
|
|
17
27
|
const [open, setOpen] = React.useState(false);
|
|
18
28
|
const [full, setFull] = React.useState(null);
|
|
19
29
|
const ref = React.useRef(null);
|
|
@@ -29,9 +39,14 @@ export function CodeBlock({
|
|
|
29
39
|
}, [clip]);
|
|
30
40
|
const copy = () => {
|
|
31
41
|
const text = ref.current ? ref.current.textContent : '';
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
const write = typeof navigator !== 'undefined' && navigator.clipboard ? navigator.clipboard.writeText(text) : Promise.reject(new Error('no clipboard'));
|
|
43
|
+
const settle = result => {
|
|
44
|
+
if (!live.current) return;
|
|
45
|
+
setCopied(result);
|
|
46
|
+
clearTimeout(timer.current);
|
|
47
|
+
timer.current = setTimeout(() => setCopied('idle'), 1600);
|
|
48
|
+
};
|
|
49
|
+
write.then(() => settle('done'), () => settle('failed'));
|
|
35
50
|
};
|
|
36
51
|
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
37
52
|
className: `ef-code${className ? ' ' + className : ''}`,
|
|
@@ -41,12 +56,16 @@ export function CodeBlock({
|
|
|
41
56
|
}, /*#__PURE__*/React.createElement("span", {
|
|
42
57
|
className: "ef-code__lang"
|
|
43
58
|
}, title || lang), /*#__PURE__*/React.createElement("button", {
|
|
44
|
-
|
|
59
|
+
type: "button",
|
|
60
|
+
className: `ef-code__copy${copied !== 'idle' ? ' ef-code__copy--' + copied : ''}`,
|
|
45
61
|
onClick: copy
|
|
46
62
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
47
|
-
name: copied ? 'check' : 'copy',
|
|
63
|
+
name: copied === 'done' ? 'check' : copied === 'failed' ? 'circle-alert' : 'copy',
|
|
48
64
|
size: 13
|
|
49
|
-
}), copied ? 'Copied' : 'Copy')
|
|
65
|
+
}), copied === 'done' ? 'Copied' : copied === 'failed' ? 'Copy failed' : 'Copy'), /*#__PURE__*/React.createElement("span", {
|
|
66
|
+
className: "ef-code__sr",
|
|
67
|
+
role: "status"
|
|
68
|
+
}, copied === 'done' ? 'Copied to clipboard' : copied === 'failed' ? 'Copy failed' : '')), clip ? /*#__PURE__*/React.createElement("div", {
|
|
50
69
|
className: "ef-code__win",
|
|
51
70
|
style: {
|
|
52
71
|
height: full === null ? open ? undefined : clipHeight : open ? full : Math.min(full, clipHeight)
|
package/code/CopyField.js
CHANGED
|
@@ -12,14 +12,26 @@ export function CopyField({
|
|
|
12
12
|
...rest
|
|
13
13
|
}) {
|
|
14
14
|
const [show, setShow] = React.useState(!secret);
|
|
15
|
-
|
|
15
|
+
// 'idle' | 'done' | 'failed': only a resolved clipboard write counts as copied.
|
|
16
|
+
const [copied, setCopied] = React.useState('idle');
|
|
16
17
|
const timer = React.useRef(null);
|
|
17
|
-
|
|
18
|
+
const live = React.useRef(true);
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
live.current = true;
|
|
21
|
+
return () => {
|
|
22
|
+
live.current = false;
|
|
23
|
+
clearTimeout(timer.current);
|
|
24
|
+
};
|
|
25
|
+
}, []);
|
|
18
26
|
const copy = () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
const write = typeof navigator !== 'undefined' && navigator.clipboard ? navigator.clipboard.writeText(String(value)) : Promise.reject(new Error('no clipboard'));
|
|
28
|
+
const settle = result => {
|
|
29
|
+
if (!live.current) return;
|
|
30
|
+
setCopied(result);
|
|
31
|
+
clearTimeout(timer.current);
|
|
32
|
+
timer.current = setTimeout(() => setCopied('idle'), 1600);
|
|
33
|
+
};
|
|
34
|
+
write.then(() => settle('done'), () => settle('failed'));
|
|
23
35
|
};
|
|
24
36
|
const shown = show ? value : '•'.repeat(Math.min(24, String(value).length));
|
|
25
37
|
const box = /*#__PURE__*/React.createElement("span", {
|
|
@@ -32,11 +44,14 @@ export function CopyField({
|
|
|
32
44
|
size: "sm",
|
|
33
45
|
onClick: () => setShow(s => !s)
|
|
34
46
|
}) : null, /*#__PURE__*/React.createElement(IconButton, {
|
|
35
|
-
icon: copied ? 'check' : 'copy',
|
|
36
|
-
label:
|
|
47
|
+
icon: copied === 'done' ? 'check' : copied === 'failed' ? 'circle-alert' : 'copy',
|
|
48
|
+
label: copied === 'done' ? 'Copied' : copied === 'failed' ? 'Copy failed' : 'Copy',
|
|
37
49
|
size: "sm",
|
|
38
50
|
onClick: copy
|
|
39
|
-
})
|
|
51
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
52
|
+
className: "ef-copyfield__sr",
|
|
53
|
+
role: "status"
|
|
54
|
+
}, copied === 'done' ? 'Copied to clipboard' : copied === 'failed' ? 'Copy failed' : ''));
|
|
40
55
|
if (!label) return /*#__PURE__*/React.cloneElement(box, {
|
|
41
56
|
...rest,
|
|
42
57
|
className: 'ef-copyfield__box' + (className ? ' ' + className : ''),
|