@coding-script/script-engine 0.0.4 → 0.0.6
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/autocomplete/completion-source.js +3 -1
- package/dist/components/function-row.js +8 -2
- package/dist/components/toolbar-button.d.ts +1 -1
- package/dist/components/toolbar-button.js +7 -4
- package/dist/components/toolbar.js +18 -40
- package/dist/types/index.d.ts +6 -4
- package/package.json +1 -1
|
@@ -15,10 +15,12 @@ function buildMemberCompletions(typeInfo) {
|
|
|
15
15
|
});
|
|
16
16
|
for (const func of typeInfo.functions){
|
|
17
17
|
const sig = formatFunctionSignature(func);
|
|
18
|
+
const ret = func.returnType ? ` → ${func.returnType}` : '';
|
|
19
|
+
const detail = func.description ? `${sig}${ret} — ${func.description}` : `${sig}${ret}`;
|
|
18
20
|
options.push({
|
|
19
21
|
label: func.name,
|
|
20
22
|
type: 'function',
|
|
21
|
-
detail
|
|
23
|
+
detail,
|
|
22
24
|
info: func.description || void 0,
|
|
23
25
|
apply: `${func.name}()`,
|
|
24
26
|
boost: -1
|
|
@@ -2,7 +2,7 @@ import react, { useState } from "react";
|
|
|
2
2
|
const FunctionRow = ({ func, colors })=>{
|
|
3
3
|
const [hovered, setHovered] = useState(false);
|
|
4
4
|
const params = func.parameters.map((p)=>`${p.name}: ${p.dataType}`).join(', ');
|
|
5
|
-
const sig = `${func.name}(${params})`;
|
|
5
|
+
const sig = `${func.name}(${params})${func.returnType ? ` → ${func.returnType}` : ''}`;
|
|
6
6
|
return /*#__PURE__*/ react.createElement("div", {
|
|
7
7
|
style: {
|
|
8
8
|
padding: '4px 12px 4px 28px',
|
|
@@ -35,7 +35,13 @@ const FunctionRow = ({ func, colors })=>{
|
|
|
35
35
|
color: colors.textSecondary,
|
|
36
36
|
fontSize: 11
|
|
37
37
|
}
|
|
38
|
-
}, "(", params, ")")
|
|
38
|
+
}, "(", params, ")"), func.returnType && /*#__PURE__*/ react.createElement("span", {
|
|
39
|
+
style: {
|
|
40
|
+
color: colors.typeColor,
|
|
41
|
+
fontSize: 11,
|
|
42
|
+
marginLeft: 'auto'
|
|
43
|
+
}
|
|
44
|
+
}, "→ ", func.returnType)), func.description && /*#__PURE__*/ react.createElement("div", {
|
|
39
45
|
style: {
|
|
40
46
|
fontSize: 11,
|
|
41
47
|
color: colors.textSecondary,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ToolbarButtonProps } from '../types';
|
|
3
|
-
export declare const ToolbarButton: React.
|
|
3
|
+
export declare const ToolbarButton: React.ForwardRefExoticComponent<ToolbarButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import react, { useState } from "react";
|
|
2
|
-
const ToolbarButton = ({ label, title, backgroundColor, hoverBackgroundColor, textColor, borderColor, onClick })=>{
|
|
1
|
+
import react, { forwardRef, useState } from "react";
|
|
2
|
+
const ToolbarButton = /*#__PURE__*/ forwardRef(({ label, title, backgroundColor, hoverBackgroundColor, textColor, borderColor, onClick, active }, ref)=>{
|
|
3
3
|
const [hovered, setHovered] = useState(false);
|
|
4
|
+
const bg = active ? hoverBackgroundColor : hovered ? hoverBackgroundColor : backgroundColor;
|
|
4
5
|
return /*#__PURE__*/ react.createElement("button", {
|
|
6
|
+
ref: ref,
|
|
5
7
|
onClick: onClick,
|
|
6
8
|
onMouseEnter: ()=>setHovered(true),
|
|
7
9
|
onMouseLeave: ()=>setHovered(false),
|
|
@@ -9,7 +11,7 @@ const ToolbarButton = ({ label, title, backgroundColor, hoverBackgroundColor, te
|
|
|
9
11
|
display: 'inline-flex',
|
|
10
12
|
alignItems: 'center',
|
|
11
13
|
gap: 4,
|
|
12
|
-
background:
|
|
14
|
+
background: bg,
|
|
13
15
|
border: `1px solid ${borderColor}`,
|
|
14
16
|
color: textColor,
|
|
15
17
|
cursor: 'pointer',
|
|
@@ -22,5 +24,6 @@ const ToolbarButton = ({ label, title, backgroundColor, hoverBackgroundColor, te
|
|
|
22
24
|
},
|
|
23
25
|
title: title
|
|
24
26
|
}, label);
|
|
25
|
-
};
|
|
27
|
+
});
|
|
28
|
+
ToolbarButton.displayName = 'ToolbarButton';
|
|
26
29
|
export { ToolbarButton };
|
|
@@ -51,17 +51,6 @@ function calcTooltipPos(anchorRect, el) {
|
|
|
51
51
|
maxHeight: Math.max(maxHeight, 80)
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
const KV_RE = /^([^:]+):\s*([\s\S]+)$/;
|
|
55
|
-
function renderDescLine(line, accent) {
|
|
56
|
-
const m = line.match(KV_RE);
|
|
57
|
-
if (m) return /*#__PURE__*/ react.createElement("span", null, /*#__PURE__*/ react.createElement("span", {
|
|
58
|
-
style: {
|
|
59
|
-
color: accent,
|
|
60
|
-
fontWeight: 600
|
|
61
|
-
}
|
|
62
|
-
}, m[1]), /*#__PURE__*/ react.createElement("span", null, ": ", m[2]));
|
|
63
|
-
return line;
|
|
64
|
-
}
|
|
65
54
|
const QuestionIcon = ({ color })=>/*#__PURE__*/ react.createElement("svg", {
|
|
66
55
|
width: "13",
|
|
67
56
|
height: "13",
|
|
@@ -125,7 +114,7 @@ const Toolbar = ({ title, theme, onThemeChange, enableThemeToggle, enableFormat,
|
|
|
125
114
|
}, [
|
|
126
115
|
description
|
|
127
116
|
]);
|
|
128
|
-
const
|
|
117
|
+
const descHtml = description ? description.replace(/\\n/g, '\n').replace(/\n/g, '<br>') : '';
|
|
129
118
|
const handleThemeToggle = ()=>{
|
|
130
119
|
const next = isDark ? 'light' : 'dark';
|
|
131
120
|
onThemeChange?.(next);
|
|
@@ -155,28 +144,19 @@ const Toolbar = ({ title, theme, onThemeChange, enableThemeToggle, enableFormat,
|
|
|
155
144
|
style: {
|
|
156
145
|
marginRight: 'auto'
|
|
157
146
|
}
|
|
158
|
-
}),
|
|
147
|
+
}), descHtml && /*#__PURE__*/ react.createElement(ToolbarButton, {
|
|
159
148
|
ref: descBtnRef,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
fontSize: 12,
|
|
172
|
-
lineHeight: 1.4,
|
|
173
|
-
whiteSpace: 'nowrap',
|
|
174
|
-
transition: 'background 0.15s'
|
|
175
|
-
},
|
|
176
|
-
title: showDesc ? '隐藏脚本说明' : '查看脚本说明'
|
|
177
|
-
}, /*#__PURE__*/ react.createElement(QuestionIcon, {
|
|
178
|
-
color: "currentColor"
|
|
179
|
-
}), "脚本说明"), enableThemeToggle && /*#__PURE__*/ react.createElement(ToolbarButton, {
|
|
149
|
+
label: /*#__PURE__*/ react.createElement(react.Fragment, null, /*#__PURE__*/ react.createElement(QuestionIcon, {
|
|
150
|
+
color: "currentColor"
|
|
151
|
+
}), "脚本说明"),
|
|
152
|
+
title: showDesc ? '隐藏脚本说明' : '查看脚本说明',
|
|
153
|
+
backgroundColor: isDark ? '#2d5a27' : '#e6f4e5',
|
|
154
|
+
hoverBackgroundColor: isDark ? '#3a7033' : '#d4ecd3',
|
|
155
|
+
textColor: isDark ? '#98c379' : '#389e0d',
|
|
156
|
+
borderColor: isDark ? '#2d5a27' : '#b7eb8f',
|
|
157
|
+
active: showDesc,
|
|
158
|
+
onClick: ()=>setShowDesc((v)=>!v)
|
|
159
|
+
}), enableThemeToggle && /*#__PURE__*/ react.createElement(ToolbarButton, {
|
|
180
160
|
label: isDark ? '🌞 浅色模式' : '🌙 深色模式',
|
|
181
161
|
title: isDark ? '切换到浅色主题' : '切换到深色主题',
|
|
182
162
|
backgroundColor: btnBg,
|
|
@@ -225,7 +205,7 @@ const Toolbar = ({ title, theme, onThemeChange, enableThemeToggle, enableFormat,
|
|
|
225
205
|
textColor: item.textColor,
|
|
226
206
|
borderColor: item.borderColor,
|
|
227
207
|
onClick: item.onClick
|
|
228
|
-
})), toolbarExtra, showDesc && tipPos &&
|
|
208
|
+
})), toolbarExtra, showDesc && tipPos && descHtml && /*#__PURE__*/ react.createElement("div", {
|
|
229
209
|
ref: tipRef,
|
|
230
210
|
style: {
|
|
231
211
|
position: 'fixed',
|
|
@@ -245,12 +225,10 @@ const Toolbar = ({ title, theme, onThemeChange, enableThemeToggle, enableFormat,
|
|
|
245
225
|
zIndex: 9999,
|
|
246
226
|
boxShadow: '0 4px 16px rgba(0,0,0,0.3)',
|
|
247
227
|
pointerEvents: 'auto'
|
|
228
|
+
},
|
|
229
|
+
dangerouslySetInnerHTML: {
|
|
230
|
+
__html: descHtml
|
|
248
231
|
}
|
|
249
|
-
}
|
|
250
|
-
key: i,
|
|
251
|
-
style: {
|
|
252
|
-
marginBottom: i < descLines.length - 1 ? 4 : 0
|
|
253
|
-
}
|
|
254
|
-
}, renderDescLine(line, colors.accent)))));
|
|
232
|
+
}));
|
|
255
233
|
};
|
|
256
234
|
export { Toolbar };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,15 +6,17 @@ export interface ToolbarButtonProps {
|
|
|
6
6
|
/** 鼠标悬停提示文字(原生 title 属性) */
|
|
7
7
|
title: string;
|
|
8
8
|
/** 按钮背景色 */
|
|
9
|
-
backgroundColor
|
|
9
|
+
backgroundColor?: string;
|
|
10
10
|
/** 鼠标悬停时的背景色 */
|
|
11
|
-
hoverBackgroundColor
|
|
11
|
+
hoverBackgroundColor?: string;
|
|
12
12
|
/** 文字颜色 */
|
|
13
|
-
textColor
|
|
13
|
+
textColor?: string;
|
|
14
14
|
/** 边框颜色 */
|
|
15
|
-
borderColor
|
|
15
|
+
borderColor?: string;
|
|
16
16
|
/** 点击回调 */
|
|
17
17
|
onClick: () => void;
|
|
18
|
+
/** 是否处于激活状态(可选,激活时使用 hoverBackgroundColor 作为背景色) */
|
|
19
|
+
active?: boolean;
|
|
18
20
|
}
|
|
19
21
|
/** 工具栏自定义按钮项(用于 toolbar 数组) */
|
|
20
22
|
export interface ToolbarItem extends ToolbarButtonProps {
|