dsh-apis-plugin 0.3.0 → 0.3.1
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 +2 -2
- package/client.js +42 -62
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
## 安装
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
dsh plugin --profile web add dsh-apis-plugin@0.3.
|
|
14
|
+
dsh plugin --profile web add dsh-apis-plugin@0.3.1
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## 配置
|
|
@@ -68,7 +68,7 @@ apis=
|
|
|
68
68
|
|
|
69
69
|
## 使用
|
|
70
70
|
|
|
71
|
-
### Web UI(设置 →
|
|
71
|
+
### Web UI(设置 → 接口管理)
|
|
72
72
|
|
|
73
73
|
| 操作 | 说明 |
|
|
74
74
|
|---|---|
|
package/client.js
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 浏览器半侧:在设置弹窗注册「接口管理」菜单项(DSH 0.1.7+ 的 settings.section 槽位)
|
|
2
2
|
// 接口的增删以 cfg 文件为唯一来源:这里只读展示集合手风琴,编辑请改 cfg 后点「扫描」重扫
|
|
3
|
-
// API 目录失焦或点「扫描」时经 configForms
|
|
3
|
+
// API 目录失焦或点「扫描」时经 configForms 表单写入,由宿主持久化到 profile 的 cordis.patch.yml
|
|
4
4
|
window.__ModuleLoader__.load({
|
|
5
5
|
id: "dsh-apis-plugin",
|
|
6
6
|
factory: (require) => {
|
|
7
7
|
const { jsx, jsxs } = require("react/jsx-runtime");
|
|
8
8
|
const react = require("react");
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/** 本设置页读写的 settings 命名空间,须与宿主侧 index.js 按 cordis.patch.yml 的 id 回写一致(亦即 Host 插件条目 id) */
|
|
11
11
|
const NS = "dsh-apis-plugin";
|
|
12
12
|
|
|
13
|
-
/** bind
|
|
13
|
+
/** bind 后的配置表单与快照 store(apply 时赋值):读快照、写字段都经由它 */
|
|
14
14
|
let form;
|
|
15
|
+
let store;
|
|
15
16
|
|
|
16
17
|
// 精简样式(类名自持,不依赖原生卡片哈希类)
|
|
17
18
|
const css = `
|
|
18
|
-
.apis-
|
|
19
|
-
.apis-card:hover{border-color:var(--dsw-alias-label-dimmed)}
|
|
20
|
-
.apis-header{width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:0 0;border:0;display:flex;align-items:center;gap:12px;padding:14px 16px}
|
|
19
|
+
.apis-section{display:grid;gap:12px;align-content:start;padding:4px 2px}
|
|
21
20
|
.apis-headText{flex:1;display:flex;flex-direction:column;gap:4px;min-width:0}
|
|
22
|
-
.apis-title{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}
|
|
23
21
|
.apis-desc,.apis-count,.apis-empty{color:var(--dsw-alias-label-tertiary);font-size:13px}
|
|
24
22
|
.apis-count{font-size:12px;flex:none;white-space:nowrap}
|
|
25
23
|
.apis-chevron{flex:none;color:var(--dsw-alias-label-tertiary);transition:transform .16s}
|
|
26
|
-
.apis-body{border-top:.5px solid var(--dsw-alias-border-l2);margin:0 16px;padding:12px 0 8px;display:grid;gap:10px}
|
|
27
24
|
.apis-row,.apis-item{display:flex;align-items:center;gap:8px;min-width:0}
|
|
28
25
|
.apis-label{flex:none;font-size:13px;color:var(--dsw-alias-label-primary);white-space:nowrap}
|
|
29
26
|
.apis-input{flex:1;min-width:0;box-sizing:border-box;font:inherit;color:var(--dsw-alias-label-primary);background:transparent;border:.5px solid var(--dsw-alias-border-l4);border-radius:8px;padding:6px 10px}
|
|
@@ -74,12 +71,11 @@ window.__ModuleLoader__.load({
|
|
|
74
71
|
});
|
|
75
72
|
}
|
|
76
73
|
|
|
77
|
-
function
|
|
78
|
-
const state =
|
|
74
|
+
function ApisSection() {
|
|
75
|
+
const state = react.useSyncExternalStore(store.subscribe, store.getSnapshot);
|
|
79
76
|
const [dirDraft, setDirDraft] = react.useState(null); // 文档目录,null 表示未编辑
|
|
80
77
|
const [loading, setLoading] = react.useState(false); // 扫描进行中
|
|
81
78
|
const [loaded, setLoaded] = react.useState(false); // 扫描完成后短暂提示
|
|
82
|
-
const [open, setOpen] = react.useState(false); // 卡片折叠态
|
|
83
79
|
const [openGroups, setOpenGroups] = react.useState({}); // 集合手风琴展开态(key: 集合名)
|
|
84
80
|
const ready = state.status === "ready" && state.writable;
|
|
85
81
|
|
|
@@ -148,66 +144,50 @@ window.__ModuleLoader__.load({
|
|
|
148
144
|
}
|
|
149
145
|
}
|
|
150
146
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
jsxs("
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
onBlur: () => {
|
|
172
|
-
if (dirDirty && ready && form) form.set("apiDir", dirDraft).catch(() => {});
|
|
173
|
-
setDirDraft(null);
|
|
174
|
-
},
|
|
175
|
-
onKeyDown: (e) => e.key === "Enter" && e.currentTarget.blur(),
|
|
176
|
-
placeholder: "集合父目录(扫描各子文件夹下的 *.cfg,以其中 host 为集合名),留空扫描即清空列表",
|
|
177
|
-
className: "apis-input",
|
|
178
|
-
}),
|
|
179
|
-
jsx("button", {
|
|
180
|
-
type: "button", disabled: !ready || loading, onClick: scan,
|
|
181
|
-
className: "apis-btn", children: loading ? "扫描中…" : "扫描",
|
|
182
|
-
}),
|
|
183
|
-
loaded && jsx("span", { className: "apis-count", children: "已扫描" }),
|
|
184
|
-
] }),
|
|
185
|
-
!state.writable && jsx("span", { className: "apis-desc", children: "只读" }),
|
|
186
|
-
groups.length
|
|
187
|
-
? groups.map(group)
|
|
188
|
-
: list.length
|
|
189
|
-
? list.map(row)
|
|
190
|
-
: jsx("span", { className: "apis-empty", children: "暂无接口:请在 API 目录下的各集合 cfg 文件中配置 host、baseUrl 与 apis,然后点击「扫描」" }),
|
|
147
|
+
// 设置页主体:API配置目录行 + 集合手风琴(无集合时回退平铺列表)
|
|
148
|
+
return jsxs("div", { className: "apis-section", children: [
|
|
149
|
+
jsxs("div", { className: "apis-row", children: [
|
|
150
|
+
jsx("div", { className: "apis-label", children: "API配置" }),
|
|
151
|
+
jsx("input", {
|
|
152
|
+
value: shownDir, disabled: !ready || loading,
|
|
153
|
+
onChange: (e) => setDirDraft(e.target.value),
|
|
154
|
+
onBlur: () => {
|
|
155
|
+
if (dirDirty && ready && form) form.set("apiDir", dirDraft).catch(() => {});
|
|
156
|
+
setDirDraft(null);
|
|
157
|
+
},
|
|
158
|
+
onKeyDown: (e) => e.key === "Enter" && e.currentTarget.blur(),
|
|
159
|
+
placeholder: "集合父目录(扫描各子文件夹下的 *.cfg,以其中 host 为集合名),留空扫描即清空列表",
|
|
160
|
+
className: "apis-input",
|
|
161
|
+
}),
|
|
162
|
+
jsx("button", {
|
|
163
|
+
type: "button", disabled: !ready || loading, onClick: scan,
|
|
164
|
+
className: "apis-btn", children: loading ? "扫描中…" : "扫描",
|
|
165
|
+
}),
|
|
166
|
+
loaded && jsx("span", { className: "apis-count", children: "已扫描" }),
|
|
191
167
|
] }),
|
|
168
|
+
!state.writable && jsx("span", { className: "apis-desc", children: "只读" }),
|
|
169
|
+
groups.length
|
|
170
|
+
? groups.map(group)
|
|
171
|
+
: list.length
|
|
172
|
+
? list.map(row)
|
|
173
|
+
: jsx("span", { className: "apis-empty", children: "暂无接口:请在 API 目录下的各集合 cfg 文件中配置 host、baseUrl 与 apis,然后点击「扫描」" }),
|
|
192
174
|
] });
|
|
193
175
|
}
|
|
194
176
|
|
|
195
177
|
/** 需要的浏览器侧服务:configForms 由 ui-settings 提供,封装 Host settings 的读快照与写字段 */
|
|
196
178
|
const inject = ["slots", "configForms"];
|
|
197
179
|
|
|
198
|
-
/**
|
|
199
|
-
* 以本插件包名为 key 注册到 plugins.bundle.config 槽位:
|
|
200
|
-
* DSH 0.1.7+ 的「插件」页会把 keyed 槽位的卡片渲染在对应包的详情页配置区
|
|
201
|
-
*/
|
|
180
|
+
/** 注册设置弹窗的「接口管理」菜单项:settings.section 列表槽位,菜单取 {id, order, label},选中后渲染组件 */
|
|
202
181
|
function apply(ctx) {
|
|
203
182
|
form = ctx.configForms.get(NS);
|
|
204
|
-
|
|
183
|
+
store = createStore(form.getSnapshot());
|
|
205
184
|
ctx.effect(() => form.subscribe(() => store.set(form.getSnapshot())));
|
|
206
|
-
ctx.effect(() => ctx.slots.inject("
|
|
207
|
-
name: "
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
185
|
+
ctx.effect(() => ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
186
|
+
name: "settings.section",
|
|
187
|
+
id: "dsh-apis-plugin",
|
|
188
|
+
order: 30,
|
|
189
|
+
label: "接口管理",
|
|
190
|
+
}, ApisSection)));
|
|
211
191
|
}
|
|
212
192
|
|
|
213
193
|
return { apply, inject };
|