dsh-apis-plugin 0.1.4 → 0.1.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.
Files changed (2) hide show
  1. package/client.js +12 -31
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // 浏览器半侧:在「插件配置」标签页为 dsh-apis-plugin 命名空间注册一张展示卡片
2
2
  // 接口的增删以 api.cfg 为唯一来源:这里只读展示列表,编辑请改 api.cfg 后点「加载API」重扫
3
- // 样式与 DOM 结构对齐原生 PluginCard(li 卡片 + SVG 箭头 + footer)
3
+ // API 目录失焦或点「加载API」时自动保存,无页脚按钮
4
+ // 样式与 DOM 结构对齐原生 PluginCard(li 卡片 + SVG 箭头)
4
5
  window.__ModuleLoader__.load({
5
6
  id: "dsh-apis-plugin",
6
7
  factory: (require) => {
@@ -26,13 +27,11 @@ window.__ModuleLoader__.load({
26
27
  .apis-description{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}
27
28
  .apis-chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}
28
29
  .apis-body{border-top:.5px solid var(--dsw-alias-border-l2);margin:0 16px;padding:12px 0 8px;display:grid;gap:10px}
29
- .apis-footer{border-top:.5px solid var(--dsw-alias-border-l2);justify-content:flex-end;align-items:center;gap:8px;padding:12px 0 4px;display:flex}
30
- .apis-saved{color:var(--dsw-alias-label-tertiary);margin-right:auto;font-size:12px}
30
+ .apis-saved{color:var(--dsw-alias-label-tertiary);font-size:12px;white-space:nowrap}
31
31
  .apis-btn{appearance:none;font:inherit;cursor:pointer;border:1px solid transparent;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}
32
32
  .apis-btn:disabled{opacity:.4;cursor:default}
33
33
  .apis-discard{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
34
34
  .apis-discard:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
35
- .apis-save{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
36
35
  .apis-row{display:flex;align-items:center;gap:8px}
37
36
  .apis-rowLabel{width:44px;flex-shrink:0;font-size:13px;color:var(--dsw-alias-label-primary)}
38
37
  .apis-rowLabelWide{width:auto;white-space:nowrap}
@@ -82,9 +81,7 @@ window.__ModuleLoader__.load({
82
81
  function ApisCard(props) {
83
82
  const state = props.useApisCard((s) => s);
84
83
  const [dirDraft, setDirDraft] = react.useState(null); // 文档目录,null 表示未编辑
85
- const [saving, setSaving] = react.useState(false);
86
84
  const [loading, setLoading] = react.useState(false); // 加载API 扫描中
87
- const [saved, setSaved] = react.useState(false); // 保存成功后短暂提示
88
85
  const [loaded, setLoaded] = react.useState(false); // 加载API 完成后短暂提示
89
86
  const [open, setOpen] = react.useState(false); // 折叠态只显示标题行
90
87
  const ready = state.status === "ready" && state.writable;
@@ -96,14 +93,10 @@ window.__ModuleLoader__.load({
96
93
  const shownDir = dirDraft ?? savedDir;
97
94
  const dirDirty = dirDraft !== null && dirDraft !== savedDir;
98
95
 
99
- async function save() {
100
- if (saving || !ready || !dirDirty) return;
101
- setSaving(true);
102
- await scope.set("apiDir", dirDraft); // 只存目录,扫描交给「加载API」
103
- setSaving(false);
96
+ /** 目录失焦时自动保存(点「加载API」也会先写入目录) */
97
+ function commitDir() {
98
+ if (dirDirty && ready) scope.set("apiDir", dirDraft);
104
99
  setDirDraft(null);
105
- setSaved(true); // 显示「已保存」提示,2 秒后消失
106
- setTimeout(() => setSaved(false), 2000);
107
100
  }
108
101
 
109
102
  /** 加载API:把目录写入配置并翻转 scanToken,服务端 watch 重扫 apis.txt 后回写接口列表 */
@@ -148,19 +141,21 @@ window.__ModuleLoader__.load({
148
141
  react_jsx_runtime.jsx(Chevron, { open }),
149
142
  ],
150
143
  }),
151
- // 展开体:API配置目录行 + 分隔线 + 接口行列表 + 底部操作条
144
+ // 展开体:API配置目录行 + 分隔线 + 接口行列表(只读)
152
145
  open && react_jsx_runtime.jsxs("div", { className: "apis-body", children: [
153
- // API配置:文档目录(apis.txt / api_doc.md 所在目录)+ 加载API 重扫按钮
146
+ // API配置:文档目录(api.cfg / api_doc.md 所在目录,失焦自动保存)+ 加载API 重扫按钮
154
147
  react_jsx_runtime.jsxs("div", { className: "apis-row", children: [
155
148
  react_jsx_runtime.jsx("div", { className: "apis-rowLabel apis-rowLabelWide", children: "API配置" }),
156
149
  react_jsx_runtime.jsx("input", {
157
- value: shownDir, disabled: !ready || saving || loading,
150
+ value: shownDir, disabled: !ready || loading,
158
151
  onChange: (e) => setDirDraft(e.target.value),
152
+ onBlur: commitDir,
153
+ onKeyDown: (e) => { if (e.key === "Enter") e.currentTarget.blur(); },
159
154
  placeholder: "api.cfg / api_doc.md 所在目录",
160
155
  className: "apis-input",
161
156
  }),
162
157
  react_jsx_runtime.jsx("button", {
163
- type: "button", disabled: !ready || saving || loading || !shownDir.trim(),
158
+ type: "button", disabled: !ready || loading || !shownDir.trim(),
164
159
  onClick: loadApis,
165
160
  className: "apis-btn apis-discard", children: loading ? "扫描中…" : "加载API",
166
161
  }),
@@ -169,20 +164,6 @@ window.__ModuleLoader__.load({
169
164
  react_jsx_runtime.jsx("hr", { className: "apis-hr" }),
170
165
  !state.writable && react_jsx_runtime.jsx("span", { className: "apis-description", children: "只读" }),
171
166
  list.length ? list.map(row) : react_jsx_runtime.jsx("span", { className: "apis-empty", children: "暂无接口:请在 API 目录下的 api.cfg 中配置 apis,然后点击「加载API」" }),
172
- react_jsx_runtime.jsxs("div", { className: "apis-footer", children: [
173
- // 保存成功后的短暂提示(占按钮行左侧)
174
- react_jsx_runtime.jsx("span", { className: "apis-saved", children: saved ? "已保存" : "" }),
175
- react_jsx_runtime.jsx("button", {
176
- type: "button", disabled: !dirDirty || saving,
177
- onClick: () => setDirDraft(null),
178
- className: "apis-btn apis-discard", children: "放弃修改",
179
- }),
180
- react_jsx_runtime.jsx("button", {
181
- type: "button", disabled: !ready || !dirDirty || saving,
182
- onClick: save, children: saving ? "保存中…" : "保存",
183
- className: "apis-btn apis-save",
184
- }),
185
- ] }),
186
167
  ] }),
187
168
  ],
188
169
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-apis-plugin",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "通用接口管理插件:把任意一套 HTTP 接口注册成 agent 可用的文档查询与请求双工具",
5
5
  "type": "module",
6
6
  "license": "MIT",