@coding-script/script-engine 0.0.2 → 0.0.3

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/README.md CHANGED
@@ -31,6 +31,7 @@ import type { ScriptMetadata } from '@coding-script/script-engine';
31
31
 
32
32
  const metadata: ScriptMetadata = {
33
33
  mainMethod: 'run',
34
+ description: '脚本主入口,接收请求参数并返回执行结果状态码',
34
35
  returnType: 'Integer',
35
36
  binds: [
36
37
  { dataType: 'GroovyBindObject', name: '$request' },
@@ -151,8 +152,10 @@ function App() {
151
152
 
152
153
  ```typescript
153
154
  interface ScriptMetadata {
154
- /** 主函数名称 */
155
- mainMethod: string;
155
+ /** 主函数名称(可选) */
156
+ mainMethod?: string;
157
+ /** 主函数描述信息(可选,提供后在属性面板主函数名旁显示悬浮提示) */
158
+ description?: string;
156
159
  /** 注入变量(如 $request,name 含 $ 前缀) */
157
160
  binds: ScriptBindInfo[];
158
161
  /** 主函数参数 */
@@ -241,4 +244,4 @@ pnpm run dev:app-pc
241
244
 
242
245
  ## License
243
246
 
244
- MIT
247
+ Apache-2.0 license
@@ -1,6 +1,51 @@
1
- import react from "react";
1
+ import react, { useCallback, useEffect, useRef, useState } from "react";
2
2
  import { SectionHeader } from "./section-header.js";
3
- const MainFunctionSection = ({ metadata, colors })=>/*#__PURE__*/ react.createElement("div", null, /*#__PURE__*/ react.createElement(SectionHeader, {
3
+ const TOOLTIP_MARGIN = 6;
4
+ const TOOLTIP_MAX_WIDTH = 380;
5
+ function calcTooltipPos(anchorRect, tooltipEl) {
6
+ const vw = window.innerWidth;
7
+ const vh = window.innerHeight;
8
+ const tooltipH = tooltipEl?.scrollHeight ?? 200;
9
+ const spaceBelow = vh - anchorRect.bottom - TOOLTIP_MARGIN;
10
+ const spaceAbove = anchorRect.top - TOOLTIP_MARGIN;
11
+ const placeBelow = spaceBelow >= Math.min(tooltipH, 260) || spaceBelow >= spaceAbove;
12
+ const top = placeBelow ? anchorRect.bottom + TOOLTIP_MARGIN : Math.max(TOOLTIP_MARGIN, anchorRect.top - tooltipH - TOOLTIP_MARGIN);
13
+ let left = anchorRect.left;
14
+ const maxRight = vw - TOOLTIP_MARGIN;
15
+ if (left + TOOLTIP_MAX_WIDTH > maxRight) left = Math.max(TOOLTIP_MARGIN, maxRight - TOOLTIP_MAX_WIDTH);
16
+ const maxWidth = Math.min(TOOLTIP_MAX_WIDTH, maxRight - left);
17
+ const maxHeight = placeBelow ? spaceBelow - TOOLTIP_MARGIN : spaceAbove - TOOLTIP_MARGIN;
18
+ return {
19
+ top,
20
+ left,
21
+ maxWidth,
22
+ maxHeight: Math.max(maxHeight, 80)
23
+ };
24
+ }
25
+ const MainFunctionSection = ({ metadata, colors })=>{
26
+ const [showTip, setShowTip] = useState(false);
27
+ const [pos, setPos] = useState(null);
28
+ const anchorRef = useRef(null);
29
+ const tooltipRef = useRef(null);
30
+ const updatePos = useCallback(()=>{
31
+ if (!anchorRef.current) return;
32
+ const rect = anchorRef.current.getBoundingClientRect();
33
+ setPos(calcTooltipPos(rect, tooltipRef.current));
34
+ }, []);
35
+ useEffect(()=>{
36
+ if (!showTip) return;
37
+ updatePos();
38
+ window.addEventListener('scroll', updatePos, true);
39
+ window.addEventListener('resize', updatePos);
40
+ return ()=>{
41
+ window.removeEventListener('scroll', updatePos, true);
42
+ window.removeEventListener('resize', updatePos);
43
+ };
44
+ }, [
45
+ showTip,
46
+ updatePos
47
+ ]);
48
+ return /*#__PURE__*/ react.createElement("div", null, /*#__PURE__*/ react.createElement(SectionHeader, {
4
49
  colors: colors,
5
50
  label: "主函数"
6
51
  }), /*#__PURE__*/ react.createElement("div", {
@@ -25,7 +70,30 @@ const MainFunctionSection = ({ metadata, colors })=>/*#__PURE__*/ react.createEl
25
70
  color: colors.text,
26
71
  fontWeight: 500
27
72
  }
28
- }, metadata.mainMethod), /*#__PURE__*/ react.createElement("span", {
73
+ }, metadata.mainMethod), metadata.description && /*#__PURE__*/ react.createElement("span", {
74
+ ref: anchorRef,
75
+ style: {
76
+ display: 'inline-flex',
77
+ cursor: 'help',
78
+ flexShrink: 0
79
+ },
80
+ onMouseEnter: ()=>setShowTip(true),
81
+ onMouseLeave: ()=>setShowTip(false)
82
+ }, /*#__PURE__*/ react.createElement("span", {
83
+ style: {
84
+ display: 'inline-flex',
85
+ alignItems: 'center',
86
+ justifyContent: 'center',
87
+ width: 14,
88
+ height: 14,
89
+ borderRadius: '50%',
90
+ border: `1px solid ${colors.textSecondary}`,
91
+ color: colors.textSecondary,
92
+ fontSize: 10,
93
+ lineHeight: 1,
94
+ fontWeight: 600
95
+ }
96
+ }, "?")), /*#__PURE__*/ react.createElement("span", {
29
97
  style: {
30
98
  color: colors.textSecondary,
31
99
  fontSize: 11
@@ -36,5 +104,30 @@ const MainFunctionSection = ({ metadata, colors })=>/*#__PURE__*/ react.createEl
36
104
  fontSize: 11,
37
105
  marginLeft: 'auto'
38
106
  }
39
- }, "→ ", metadata.returnType))));
107
+ }, "→ ", metadata.returnType))), showTip && pos && metadata.description && /*#__PURE__*/ react.createElement("div", {
108
+ ref: tooltipRef,
109
+ onMouseEnter: ()=>setShowTip(true),
110
+ onMouseLeave: ()=>setShowTip(false),
111
+ style: {
112
+ position: 'fixed',
113
+ top: pos.top,
114
+ left: pos.left,
115
+ maxWidth: pos.maxWidth,
116
+ maxHeight: pos.maxHeight,
117
+ overflowY: 'auto',
118
+ padding: '8px 12px',
119
+ background: colors.headerBg,
120
+ border: `1px solid ${colors.border}`,
121
+ borderRadius: 6,
122
+ color: colors.text,
123
+ fontSize: 12,
124
+ lineHeight: 1.65,
125
+ whiteSpace: 'pre-wrap',
126
+ wordBreak: 'break-word',
127
+ zIndex: 9999,
128
+ boxShadow: '0 4px 16px rgba(0,0,0,0.3)',
129
+ pointerEvents: 'auto'
130
+ }
131
+ }, metadata.description));
132
+ };
40
133
  export { MainFunctionSection };
@@ -41,7 +41,8 @@ export interface ScriptRequestInfo {
41
41
  export interface ScriptMetadata {
42
42
  binds: ScriptBindInfo[];
43
43
  requests: ScriptRequestInfo[];
44
- mainMethod: string;
44
+ description?: string;
45
+ mainMethod?: string;
45
46
  returnType?: string;
46
47
  types: Record<string, ScriptTypeInfo>;
47
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coding-script/script-engine",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "script-engine components",
5
5
  "keywords": [
6
6
  "coding-script",