@coding-script/script-engine 0.0.4 → 0.0.5

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.
@@ -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: func.description ? `${sig} — ${func.description}` : sig,
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, ")")), func.description && /*#__PURE__*/ react.createElement("div", {
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.FC<ToolbarButtonProps>;
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: hovered ? hoverBackgroundColor : backgroundColor,
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 };
@@ -155,28 +155,19 @@ const Toolbar = ({ title, theme, onThemeChange, enableThemeToggle, enableFormat,
155
155
  style: {
156
156
  marginRight: 'auto'
157
157
  }
158
- }), descLines.length > 0 && /*#__PURE__*/ react.createElement("button", {
158
+ }), descLines.length > 0 && /*#__PURE__*/ react.createElement(ToolbarButton, {
159
159
  ref: descBtnRef,
160
- onClick: ()=>setShowDesc((v)=>!v),
161
- style: {
162
- display: 'inline-flex',
163
- alignItems: 'center',
164
- gap: 4,
165
- padding: '4px 10px',
166
- borderRadius: 4,
167
- border: `1px solid ${isDark ? '#2d5a27' : '#b7eb8f'}`,
168
- background: showDesc ? isDark ? '#3a7033' : '#d4ecd3' : isDark ? '#2d5a27' : '#e6f4e5',
169
- color: isDark ? '#98c379' : '#389e0d',
170
- cursor: 'pointer',
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, {
160
+ label: /*#__PURE__*/ react.createElement(react.Fragment, null, /*#__PURE__*/ react.createElement(QuestionIcon, {
161
+ color: "currentColor"
162
+ }), "脚本说明"),
163
+ title: showDesc ? '隐藏脚本说明' : '查看脚本说明',
164
+ backgroundColor: isDark ? '#2d5a27' : '#e6f4e5',
165
+ hoverBackgroundColor: isDark ? '#3a7033' : '#d4ecd3',
166
+ textColor: isDark ? '#98c379' : '#389e0d',
167
+ borderColor: isDark ? '#2d5a27' : '#b7eb8f',
168
+ active: showDesc,
169
+ onClick: ()=>setShowDesc((v)=>!v)
170
+ }), enableThemeToggle && /*#__PURE__*/ react.createElement(ToolbarButton, {
180
171
  label: isDark ? '🌞 浅色模式' : '🌙 深色模式',
181
172
  title: isDark ? '切换到浅色主题' : '切换到深色主题',
182
173
  backgroundColor: btnBg,
@@ -6,15 +6,17 @@ export interface ToolbarButtonProps {
6
6
  /** 鼠标悬停提示文字(原生 title 属性) */
7
7
  title: string;
8
8
  /** 按钮背景色 */
9
- backgroundColor: string;
9
+ backgroundColor?: string;
10
10
  /** 鼠标悬停时的背景色 */
11
- hoverBackgroundColor: string;
11
+ hoverBackgroundColor?: string;
12
12
  /** 文字颜色 */
13
- textColor: string;
13
+ textColor?: string;
14
14
  /** 边框颜色 */
15
- borderColor: string;
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coding-script/script-engine",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "script-engine components",
5
5
  "keywords": [
6
6
  "coding-script",