one-design-next 0.0.70 → 0.0.71
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/dist/artifact/actions.d.ts +17 -0
- package/dist/artifact/actions.js +29 -0
- package/dist/artifact/glow.d.ts +7 -0
- package/dist/artifact/glow.js +17 -0
- package/dist/artifact/icons/ArtifactFileIcon.d.ts +17 -0
- package/dist/artifact/icons/ArtifactFileIcon.js +72 -0
- package/dist/artifact/icons/file-icons.d.ts +80 -0
- package/dist/artifact/icons/file-icons.js +86 -0
- package/dist/artifact/icons/index.d.ts +2 -0
- package/dist/artifact/icons/index.js +2 -0
- package/dist/artifact/icons/medium/csv.svg +25 -0
- package/dist/artifact/icons/medium/docx.svg +25 -0
- package/dist/artifact/icons/medium/file.svg +25 -0
- package/dist/artifact/icons/medium/html.svg +25 -0
- package/dist/artifact/icons/medium/md.svg +25 -0
- package/dist/artifact/icons/medium/pdf.svg +25 -0
- package/dist/artifact/icons/medium/pptx.svg +25 -0
- package/dist/artifact/icons/medium/xlsx.svg +25 -0
- package/dist/artifact/icons/small/csv.svg +19 -0
- package/dist/artifact/icons/small/docx.svg +19 -0
- package/dist/artifact/icons/small/file.svg +19 -0
- package/dist/artifact/icons/small/html.svg +19 -0
- package/dist/artifact/icons/small/md.svg +19 -0
- package/dist/artifact/icons/small/pdf.svg +19 -0
- package/dist/artifact/icons/small/pptx.svg +19 -0
- package/dist/artifact/icons/small/xlsx.svg +19 -0
- package/dist/artifact/index.d.ts +34 -15
- package/dist/artifact/index.js +187 -180
- package/dist/artifact/style/index.css +194 -162
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/artifact/index.js
CHANGED
|
@@ -1,201 +1,208 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
1
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
4
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
+
import { useCallback, useRef, useState } from 'react';
|
|
6
|
+
import HoverFill from "../hover-fill";
|
|
5
7
|
import Icon from "../icon";
|
|
8
|
+
import Tooltip from "../tooltip";
|
|
9
|
+
import { getArtifactAction } from "./actions";
|
|
10
|
+
import { getArtifactGlowColor } from "./glow";
|
|
11
|
+
import { ARTIFACT_DEDICATED_FILE_ICON_TYPES, ArtifactFileIcon } from "./icons";
|
|
6
12
|
import "./style";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
export { getArtifactAction } from "./actions";
|
|
14
|
+
export { ARTIFACT_FILE_GLOW_COLORS, getArtifactGlowColor } from "./glow";
|
|
15
|
+
export { ARTIFACT_DEDICATED_FILE_ICON_TYPES, ARTIFACT_FILE_ICON_MEDIUM_SIZE, ARTIFACT_FILE_ICON_MEDIUM_VIEWBOX, ARTIFACT_FILE_ICON_SMALL_SIZE, ARTIFACT_FILE_ICON_SMALL_VIEWBOX, ARTIFACT_FILE_ICON_TYPES, ArtifactFileIcon, artifactFileIcons, artifactFileIconsMedium, artifactFileIconsSmall, getArtifactFileIconUrl } from "./icons";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Artifact 形态尺寸:
|
|
19
|
+
* - `medium`:Card(默认)— 大号类型 Icon + 标题 / 大小·日期
|
|
20
|
+
* - `small`:Small — 小号类型 Icon + 更紧凑的行高与间距
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function inferFileType(title) {
|
|
24
|
+
var _title$split$pop;
|
|
25
|
+
var ext = title.includes('.') ? (_title$split$pop = title.split('.').pop()) === null || _title$split$pop === void 0 ? void 0 : _title$split$pop.toLowerCase() : undefined;
|
|
26
|
+
if (ext && ARTIFACT_DEDICATED_FILE_ICON_TYPES.includes(ext)) {
|
|
27
|
+
return ext;
|
|
28
|
+
}
|
|
29
|
+
return 'file';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 主名溢出时保留末尾位数(省略中间),扩展名始终完整可见。 */
|
|
33
|
+
var TITLE_NAME_TAIL_KEEP = 4;
|
|
34
|
+
|
|
35
|
+
/** 拆出扩展名 + 主名末尾,便于溢出时 `前缀…后四位.ext`。 */
|
|
36
|
+
function splitTitleParts(title) {
|
|
37
|
+
var lastDot = title.lastIndexOf('.');
|
|
38
|
+
var name = title;
|
|
39
|
+
var extension = null;
|
|
40
|
+
if (lastDot > 0 && lastDot < title.length - 1) {
|
|
41
|
+
var ext = title.slice(lastDot);
|
|
42
|
+
if (ext.length <= 6) {
|
|
43
|
+
name = title.slice(0, lastDot);
|
|
44
|
+
extension = ext;
|
|
22
45
|
}
|
|
23
46
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return
|
|
47
|
+
if (name.length <= TITLE_NAME_TAIL_KEEP) {
|
|
48
|
+
return {
|
|
49
|
+
head: name,
|
|
50
|
+
tail: null,
|
|
51
|
+
extension: extension
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
head: name.slice(0, -TITLE_NAME_TAIL_KEEP),
|
|
56
|
+
tail: name.slice(-TITLE_NAME_TAIL_KEEP),
|
|
57
|
+
extension: extension
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function ArtifactActionCue(_ref) {
|
|
61
|
+
var action = _ref.action;
|
|
62
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
63
|
+
"data-odn-artifact-action": true,
|
|
64
|
+
"data-odn-artifact-action-kind": action.kind,
|
|
65
|
+
"aria-hidden": true,
|
|
66
|
+
title: action.label
|
|
67
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
68
|
+
name: action.icon,
|
|
69
|
+
size: 16
|
|
70
|
+
}));
|
|
32
71
|
}
|
|
33
72
|
|
|
34
73
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
74
|
+
* 对话流内的产物:
|
|
75
|
+
* - medium / Card:左 Icon + 右标题 / 大小·日期;可点 hover 时 Icon 后退缩小、文案左移遮罩,右侧浮出操作预期
|
|
76
|
+
* - small / Small:无底色/描边;hover 用 HoverFill 叠灰底(不展示预览/下载操作预期)
|
|
37
77
|
*/
|
|
38
|
-
export function Artifact(
|
|
39
|
-
var title =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
onOpen = _ref.onOpen;
|
|
78
|
+
export function Artifact(_ref2) {
|
|
79
|
+
var title = _ref2.title,
|
|
80
|
+
fileType = _ref2.fileType,
|
|
81
|
+
fileSize = _ref2.fileSize,
|
|
82
|
+
date = _ref2.date,
|
|
83
|
+
_ref2$size = _ref2.size,
|
|
84
|
+
size = _ref2$size === void 0 ? 'medium' : _ref2$size,
|
|
85
|
+
_ref2$status = _ref2.status,
|
|
86
|
+
status = _ref2$status === void 0 ? 'Done' : _ref2$status,
|
|
87
|
+
onOpen = _ref2.onOpen,
|
|
88
|
+
className = _ref2.className,
|
|
89
|
+
style = _ref2.style;
|
|
51
90
|
var isGenerating = status === 'Generating';
|
|
52
91
|
var isInteractive = !!onOpen && !isGenerating;
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
92
|
+
var resolvedType = fileType !== null && fileType !== void 0 ? fileType : inferFileType(title);
|
|
93
|
+
var iconSize = size;
|
|
94
|
+
var action = getArtifactAction(resolvedType);
|
|
95
|
+
var _splitTitleParts = splitTitleParts(title),
|
|
96
|
+
titleHead = _splitTitleParts.head,
|
|
97
|
+
titleTail = _splitTitleParts.tail,
|
|
98
|
+
titleExtension = _splitTitleParts.extension;
|
|
99
|
+
|
|
100
|
+
// 主名前缀被截断时才展示完整 title 的 Tooltip(hover 时再测,受控避免首进不弹)
|
|
101
|
+
var titleHeadRef = useRef(null);
|
|
102
|
+
var _useState = useState(false),
|
|
58
103
|
_useState2 = _slicedToArray(_useState, 2),
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
var handleMouseLeave = function handleMouseLeave() {
|
|
78
|
-
setSpotlight(function (prev) {
|
|
79
|
-
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
80
|
-
active: false
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
var spotlightStyle = {
|
|
85
|
-
'--odn-artifact-spot-x': "".concat(spotlight.x, "px"),
|
|
86
|
-
'--odn-artifact-spot-y': "".concat(spotlight.y, "px"),
|
|
87
|
-
'--odn-artifact-spot-opacity': spotlight.active && !isGenerating ? 1 : 0
|
|
104
|
+
titleTooltipOpen = _useState2[0],
|
|
105
|
+
setTitleTooltipOpen = _useState2[1];
|
|
106
|
+
var handleTitleMouseEnter = useCallback(function () {
|
|
107
|
+
var el = titleHeadRef.current;
|
|
108
|
+
setTitleTooltipOpen(!!el && el.scrollWidth > el.clientWidth);
|
|
109
|
+
}, []);
|
|
110
|
+
var handleTitleMouseLeave = useCallback(function () {
|
|
111
|
+
setTitleTooltipOpen(false);
|
|
112
|
+
}, []);
|
|
113
|
+
|
|
114
|
+
// Small 形态只展示 Icon + 标题;Card(medium)保留大小 / 日期(或 Generating 文案)
|
|
115
|
+
var showMeta = size !== 'small';
|
|
116
|
+
var metaParts = !showMeta ? [] : isGenerating ? ['生成中'] : [fileSize, date].filter(Boolean);
|
|
117
|
+
// 操作预期仅 Card 可点时展示;Small 不展示
|
|
118
|
+
var showAction = size !== 'small' && isInteractive;
|
|
119
|
+
var handleClick = function handleClick() {
|
|
120
|
+
onOpen === null || onOpen === void 0 || onOpen();
|
|
88
121
|
};
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
122
|
+
var titleNode = /*#__PURE__*/React.createElement(Tooltip, {
|
|
123
|
+
popup: /*#__PURE__*/React.createElement("span", {
|
|
124
|
+
"data-odn-artifact-title-tooltip": true
|
|
125
|
+
}, title)
|
|
126
|
+
// Card 向上;List / Small 向右,避免挡住同列下一项
|
|
127
|
+
,
|
|
128
|
+
placement: size === 'small' ? 'right' : 'top',
|
|
129
|
+
flip: false,
|
|
130
|
+
mouseEnterDelay: 0.15,
|
|
131
|
+
visible: titleTooltipOpen,
|
|
132
|
+
hideOnAncestorScroll: true
|
|
133
|
+
// display:table 让换行后宽度按最长行收缩,避免 max-content+max-width 撑出留白
|
|
134
|
+
,
|
|
135
|
+
popupStyle: {
|
|
136
|
+
display: 'table',
|
|
137
|
+
width: 'auto'
|
|
138
|
+
}
|
|
139
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
140
|
+
"data-odn-artifact-title": true,
|
|
141
|
+
onMouseEnter: handleTitleMouseEnter,
|
|
142
|
+
onMouseLeave: handleTitleMouseLeave
|
|
143
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
144
|
+
ref: titleHeadRef,
|
|
145
|
+
"data-odn-artifact-title-name": true
|
|
146
|
+
}, titleHead), titleTail ? /*#__PURE__*/React.createElement("span", {
|
|
147
|
+
"data-odn-artifact-title-tail": true
|
|
148
|
+
}, titleTail) : null, titleExtension ? /*#__PURE__*/React.createElement("span", {
|
|
149
|
+
"data-odn-artifact-title-ext": true
|
|
150
|
+
}, titleExtension) : null));
|
|
151
|
+
var copy = /*#__PURE__*/React.createElement("span", {
|
|
97
152
|
"data-odn-artifact-copy": true
|
|
98
|
-
}, /*#__PURE__*/React.createElement("
|
|
99
|
-
"data-odn-artifact-
|
|
100
|
-
},
|
|
101
|
-
"
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
153
|
+
}, titleNode, metaParts.length > 0 ? /*#__PURE__*/React.createElement("span", {
|
|
154
|
+
"data-odn-artifact-meta": true
|
|
155
|
+
}, metaParts.map(function (part) {
|
|
156
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
157
|
+
key: part,
|
|
158
|
+
"data-odn-artifact-meta-item": true
|
|
159
|
+
}, part);
|
|
160
|
+
})) : null);
|
|
161
|
+
var glowColor = getArtifactGlowColor(resolvedType);
|
|
162
|
+
var content = /*#__PURE__*/React.createElement(React.Fragment, null, size !== 'small' ? /*#__PURE__*/React.createElement("span", {
|
|
163
|
+
"data-odn-artifact-glow": true,
|
|
106
164
|
"aria-hidden": true
|
|
107
|
-
}, /*#__PURE__*/React.createElement(
|
|
108
|
-
|
|
109
|
-
size: 16
|
|
110
|
-
})))), /*#__PURE__*/React.createElement("div", {
|
|
111
|
-
"data-odn-artifact-visual-wrap": true
|
|
112
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
113
|
-
"data-odn-artifact-visual": true,
|
|
165
|
+
}) : null, /*#__PURE__*/React.createElement("span", {
|
|
166
|
+
"data-odn-artifact-icon": true,
|
|
114
167
|
"aria-hidden": true
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
"
|
|
135
|
-
|
|
136
|
-
}), /*#__PURE__*/React.createElement("span", {
|
|
137
|
-
"data-odn-artifact-visual-block": true,
|
|
138
|
-
"data-odn-artifact-visual-block-c": true
|
|
139
|
-
}), /*#__PURE__*/React.createElement("span", {
|
|
140
|
-
"data-odn-artifact-visual-block": true,
|
|
141
|
-
"data-odn-artifact-visual-block-d": true
|
|
142
|
-
}))), isGenerating && /*#__PURE__*/React.createElement("div", {
|
|
143
|
-
"data-odn-artifact-generating-icon": true
|
|
144
|
-
}, /*#__PURE__*/React.createElement("svg", {
|
|
145
|
-
fill: "none",
|
|
146
|
-
height: "24",
|
|
147
|
-
stroke: "currentColor",
|
|
148
|
-
strokeLinecap: "round",
|
|
149
|
-
strokeLinejoin: "round",
|
|
150
|
-
strokeWidth: "2",
|
|
151
|
-
viewBox: "0 0 24 24",
|
|
152
|
-
width: "24",
|
|
153
|
-
xmlns: "http://www.w3.org/2000/svg"
|
|
154
|
-
}, /*#__PURE__*/React.createElement("path", {
|
|
155
|
-
d: "m18 5-2.414-2.414A2 2 0 0 0 14.172 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2"
|
|
156
|
-
}), /*#__PURE__*/React.createElement(motion.path, {
|
|
157
|
-
d: "M21.378 12.626a1 1 0 0 0-3.004-3.004l-4.01 4.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z",
|
|
158
|
-
initial: "normal",
|
|
159
|
-
animate: "animate",
|
|
160
|
-
variants: PEN_VARIANTS
|
|
161
|
-
}), /*#__PURE__*/React.createElement(motion.path, {
|
|
162
|
-
d: "M8 18h1",
|
|
163
|
-
initial: "normal",
|
|
164
|
-
animate: "animate",
|
|
165
|
-
transition: {
|
|
166
|
-
duration: 0.5,
|
|
167
|
-
repeat: Number.POSITIVE_INFINITY,
|
|
168
|
-
repeatDelay: 0.45
|
|
169
|
-
},
|
|
170
|
-
variants: {
|
|
171
|
-
normal: {
|
|
172
|
-
d: 'M8 18h1'
|
|
173
|
-
},
|
|
174
|
-
animate: {
|
|
175
|
-
d: 'M8 18h5'
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}))))));
|
|
179
|
-
return isInteractive ? /*#__PURE__*/React.createElement("button", {
|
|
180
|
-
type: "button",
|
|
181
|
-
"data-odn-artifact": true,
|
|
168
|
+
}, /*#__PURE__*/React.createElement(ArtifactFileIcon, {
|
|
169
|
+
type: resolvedType,
|
|
170
|
+
size: iconSize
|
|
171
|
+
})), size === 'small' ? copy : /*#__PURE__*/React.createElement("span", {
|
|
172
|
+
"data-odn-artifact-main": true
|
|
173
|
+
}, copy), showAction ? /*#__PURE__*/React.createElement(ArtifactActionCue, {
|
|
174
|
+
action: action
|
|
175
|
+
}) : null);
|
|
176
|
+
var sharedProps = _objectSpread({
|
|
177
|
+
'data-odn-artifact': true,
|
|
178
|
+
'data-odn-artifact-size': size,
|
|
179
|
+
'data-odn-artifact-status': status,
|
|
180
|
+
'data-odn-artifact-file-type': resolvedType,
|
|
181
|
+
'data-odn-artifact-action-kind': showAction ? action.kind : undefined
|
|
182
|
+
}, size === 'small' ? {} : {
|
|
183
|
+
className: className,
|
|
184
|
+
style: _objectSpread(_objectSpread({}, style), {}, _defineProperty({}, '--odn-artifact-glow-color', glowColor))
|
|
185
|
+
});
|
|
186
|
+
var body = isInteractive ? /*#__PURE__*/React.createElement("button", _extends({
|
|
187
|
+
type: "button"
|
|
188
|
+
}, sharedProps, {
|
|
182
189
|
"data-odn-artifact-clickable": true,
|
|
183
|
-
onClick:
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
190
|
+
onClick: handleClick
|
|
191
|
+
}), content) : /*#__PURE__*/React.createElement("div", sharedProps, content);
|
|
192
|
+
|
|
193
|
+
// Small:默认透明;可点时用 HoverFill 叠灰底(对齐 Attachments chip / ChatItem)
|
|
194
|
+
if (size === 'small') {
|
|
195
|
+
return /*#__PURE__*/React.createElement(HoverFill, {
|
|
196
|
+
"data-odn-artifact-small-wrap": true,
|
|
197
|
+
bgClassName: "odn-artifact-small-bg",
|
|
198
|
+
hoverColor: "var(--odn-color-black-4)",
|
|
199
|
+
activeColor: "var(--odn-color-black-5)",
|
|
200
|
+
disabled: !isInteractive,
|
|
201
|
+
className: className,
|
|
202
|
+
style: style
|
|
203
|
+
}, body);
|
|
204
|
+
}
|
|
205
|
+
return body;
|
|
199
206
|
}
|
|
200
207
|
Artifact.displayName = 'Artifact';
|
|
201
208
|
export default Artifact;
|