dsh-apis-plugin 0.1.3 → 0.1.4
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/client.js +18 -36
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// 浏览器半侧:在「插件配置」标签页为 dsh-apis-plugin
|
|
2
|
-
//
|
|
1
|
+
// 浏览器半侧:在「插件配置」标签页为 dsh-apis-plugin 命名空间注册一张展示卡片
|
|
2
|
+
// 接口的增删以 api.cfg 为唯一来源:这里只读展示列表,编辑请改 api.cfg 后点「加载API」重扫
|
|
3
|
+
// 样式与 DOM 结构对齐原生 PluginCard(li 卡片 + SVG 箭头 + footer)
|
|
3
4
|
window.__ModuleLoader__.load({
|
|
4
5
|
id: "dsh-apis-plugin",
|
|
5
6
|
factory: (require) => {
|
|
@@ -37,10 +38,9 @@ window.__ModuleLoader__.load({
|
|
|
37
38
|
.apis-rowLabelWide{width:auto;white-space:nowrap}
|
|
38
39
|
.apis-hr{width:100%;height:0;border:0;border-top:.5px solid var(--dsw-alias-border-l2);margin:0}
|
|
39
40
|
.apis-input{box-sizing:border-box;flex:1;min-width:0;font:inherit;color:var(--dsw-alias-label-primary);background:transparent;border:.5px solid var(--dsw-alias-border-l4);border-radius:8px;padding:6px 10px}
|
|
40
|
-
.apis-
|
|
41
|
-
.apis-
|
|
42
|
-
.apis-
|
|
43
|
-
.apis-add:hover:not(:disabled){color:var(--dsw-alias-label-primary)}
|
|
41
|
+
.apis-item{display:flex;align-items:center;gap:8px;min-width:0}
|
|
42
|
+
.apis-itemText{flex:1;min-width:0;font-size:13px;color:var(--dsw-alias-label-primary);font-family:ui-monospace,SFMono-Regular,Consolas,monospace;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;padding:6px 10px;border:.5px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-3)}
|
|
43
|
+
.apis-empty{color:var(--dsw-alias-label-tertiary);font-size:13px;padding:4px 0}
|
|
44
44
|
`;
|
|
45
45
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=dsh-apis-plugin]") === null) {
|
|
46
46
|
const tag = document.createElement("style");
|
|
@@ -81,7 +81,6 @@ window.__ModuleLoader__.load({
|
|
|
81
81
|
|
|
82
82
|
function ApisCard(props) {
|
|
83
83
|
const state = props.useApisCard((s) => s);
|
|
84
|
-
const [draft, setDraft] = react.useState(null); // string[],null 表示未编辑
|
|
85
84
|
const [dirDraft, setDirDraft] = react.useState(null); // 文档目录,null 表示未编辑
|
|
86
85
|
const [saving, setSaving] = react.useState(false);
|
|
87
86
|
const [loading, setLoading] = react.useState(false); // 加载API 扫描中
|
|
@@ -90,21 +89,18 @@ window.__ModuleLoader__.load({
|
|
|
90
89
|
const [open, setOpen] = react.useState(false); // 折叠态只显示标题行
|
|
91
90
|
const ready = state.status === "ready" && state.writable;
|
|
92
91
|
|
|
93
|
-
/**
|
|
94
|
-
const list =
|
|
95
|
-
const dirty = draft !== null;
|
|
92
|
+
/** 只读展示的接口列表:来自 api.cfg(服务端扫描回写) */
|
|
93
|
+
const list = (state.value?.endpoints ?? []).map(String);
|
|
96
94
|
/** 当前展示的文档目录:编辑中取 dirDraft,否则取已保存值 */
|
|
97
95
|
const savedDir = state.value?.apiDir ?? "";
|
|
98
96
|
const shownDir = dirDraft ?? savedDir;
|
|
99
97
|
const dirDirty = dirDraft !== null && dirDraft !== savedDir;
|
|
100
98
|
|
|
101
99
|
async function save() {
|
|
102
|
-
if (saving || !ready ||
|
|
100
|
+
if (saving || !ready || !dirDirty) return;
|
|
103
101
|
setSaving(true);
|
|
104
|
-
|
|
105
|
-
if (dirty) await scope.set("endpoints", draft);
|
|
102
|
+
await scope.set("apiDir", dirDraft); // 只存目录,扫描交给「加载API」
|
|
106
103
|
setSaving(false);
|
|
107
|
-
setDraft(null);
|
|
108
104
|
setDirDraft(null);
|
|
109
105
|
setSaved(true); // 显示「已保存」提示,2 秒后消失
|
|
110
106
|
setTimeout(() => setSaved(false), 2000);
|
|
@@ -125,21 +121,12 @@ window.__ModuleLoader__.load({
|
|
|
125
121
|
}
|
|
126
122
|
}
|
|
127
123
|
|
|
128
|
-
//
|
|
124
|
+
// 只读单行:接口N 标签 + 路径文本
|
|
129
125
|
const row = (v, i) => react_jsx_runtime.jsxs("div", {
|
|
130
|
-
className: "apis-
|
|
126
|
+
className: "apis-item",
|
|
131
127
|
children: [
|
|
132
128
|
react_jsx_runtime.jsx("div", { className: "apis-rowLabel", children: `接口${i + 1}` }),
|
|
133
|
-
react_jsx_runtime.jsx("
|
|
134
|
-
value: v, disabled: !ready || saving,
|
|
135
|
-
onChange: (e) => setDraft(list.map((x, j) => (j === i ? e.target.value : x))),
|
|
136
|
-
className: "apis-input",
|
|
137
|
-
}),
|
|
138
|
-
react_jsx_runtime.jsx("button", {
|
|
139
|
-
type: "button", disabled: !ready || saving, "aria-label": `删除接口${i + 1}`,
|
|
140
|
-
onClick: () => setDraft(list.filter((_, j) => j !== i)),
|
|
141
|
-
className: "apis-remove", children: "✕",
|
|
142
|
-
}),
|
|
129
|
+
react_jsx_runtime.jsx("span", { className: "apis-itemText", title: v, children: v }),
|
|
143
130
|
],
|
|
144
131
|
});
|
|
145
132
|
|
|
@@ -156,7 +143,7 @@ window.__ModuleLoader__.load({
|
|
|
156
143
|
children: [
|
|
157
144
|
react_jsx_runtime.jsxs("div", { className: "apis-headText", children: [
|
|
158
145
|
react_jsx_runtime.jsx("span", { className: "apis-name", children: "通用接口管理插件" }),
|
|
159
|
-
react_jsx_runtime.jsx("span", { className: "apis-description", children: "
|
|
146
|
+
react_jsx_runtime.jsx("span", { className: "apis-description", children: "接口列表(来源:api.cfg)" }),
|
|
160
147
|
] }),
|
|
161
148
|
react_jsx_runtime.jsx(Chevron, { open }),
|
|
162
149
|
],
|
|
@@ -181,22 +168,17 @@ window.__ModuleLoader__.load({
|
|
|
181
168
|
] }),
|
|
182
169
|
react_jsx_runtime.jsx("hr", { className: "apis-hr" }),
|
|
183
170
|
!state.writable && react_jsx_runtime.jsx("span", { className: "apis-description", children: "只读" }),
|
|
184
|
-
list.map(row),
|
|
185
|
-
react_jsx_runtime.jsx("button", {
|
|
186
|
-
type: "button", disabled: !ready || saving,
|
|
187
|
-
onClick: () => setDraft([...list, ""]),
|
|
188
|
-
className: "apis-add", children: "+ 添加接口",
|
|
189
|
-
}),
|
|
171
|
+
list.length ? list.map(row) : react_jsx_runtime.jsx("span", { className: "apis-empty", children: "暂无接口:请在 API 目录下的 api.cfg 中配置 apis,然后点击「加载API」" }),
|
|
190
172
|
react_jsx_runtime.jsxs("div", { className: "apis-footer", children: [
|
|
191
173
|
// 保存成功后的短暂提示(占按钮行左侧)
|
|
192
174
|
react_jsx_runtime.jsx("span", { className: "apis-saved", children: saved ? "已保存" : "" }),
|
|
193
175
|
react_jsx_runtime.jsx("button", {
|
|
194
|
-
type: "button", disabled:
|
|
195
|
-
onClick: () =>
|
|
176
|
+
type: "button", disabled: !dirDirty || saving,
|
|
177
|
+
onClick: () => setDirDraft(null),
|
|
196
178
|
className: "apis-btn apis-discard", children: "放弃修改",
|
|
197
179
|
}),
|
|
198
180
|
react_jsx_runtime.jsx("button", {
|
|
199
|
-
type: "button", disabled: !ready ||
|
|
181
|
+
type: "button", disabled: !ready || !dirDirty || saving,
|
|
200
182
|
onClick: save, children: saving ? "保存中…" : "保存",
|
|
201
183
|
className: "apis-btn apis-save",
|
|
202
184
|
}),
|