@jayyuen66/dsh-scrapling 0.0.1 → 0.0.2
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 +59 -44
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -726,6 +726,19 @@ function localeDictionaries() {
|
|
|
726
726
|
}
|
|
727
727
|
//#endregion
|
|
728
728
|
//#region src/settings-card.ts
|
|
729
|
+
/** 没给值面时读到的那一版:既不在线也不可写,于是卡片画出一张锁住的空表。 */
|
|
730
|
+
const LOADING_STATE = {
|
|
731
|
+
status: "loading",
|
|
732
|
+
writable: false
|
|
733
|
+
};
|
|
734
|
+
/** 值面缺席时的 getSnapshot:永远返回同一个引用,订阅因此不会被反复重建。 */
|
|
735
|
+
function loadingSnapshot() {
|
|
736
|
+
return LOADING_STATE;
|
|
737
|
+
}
|
|
738
|
+
/** 值面缺席时的 subscribe:永远不通知,回收是空操作。 */
|
|
739
|
+
function loadingSubscribe() {
|
|
740
|
+
return () => void 0;
|
|
741
|
+
}
|
|
729
742
|
/** 把任意设置值转成控件能显示的字符串;结构值给空串而不是 `[object Object]`。 */
|
|
730
743
|
function textOf(value) {
|
|
731
744
|
if (typeof value === "string") return value;
|
|
@@ -1018,8 +1031,8 @@ function SettingsCard(props) {
|
|
|
1018
1031
|
const [failure, setFailure] = (0, react.useState)("");
|
|
1019
1032
|
const [saving, setSaving] = (0, react.useState)(false);
|
|
1020
1033
|
const [revealed, setRevealed] = (0, react.useState)([]);
|
|
1034
|
+
const state = (0, react.useSyncExternalStore)(form === void 0 ? loadingSubscribe : form.subscribe, form === void 0 ? loadingSnapshot : form.getSnapshot);
|
|
1021
1035
|
if (props.view !== "page" || form === void 0) return (0, react.createElement)("div", { className: "dss-card" });
|
|
1022
|
-
const { state } = form;
|
|
1023
1036
|
const editable = state.writable && state.status === "ready";
|
|
1024
1037
|
const ops = buildOps(draft.values);
|
|
1025
1038
|
const save = async () => {
|
|
@@ -1300,18 +1313,22 @@ function RowView(props) {
|
|
|
1300
1313
|
"data-tool": toolName
|
|
1301
1314
|
}, ...children);
|
|
1302
1315
|
}
|
|
1303
|
-
/** 本 Client
|
|
1304
|
-
const inject = [
|
|
1316
|
+
/** 本 Client 半注入的服务。三个都得在这儿 —— 见文件头第二条。 */
|
|
1317
|
+
const inject = [
|
|
1318
|
+
"slots",
|
|
1319
|
+
"configForms",
|
|
1320
|
+
"locale"
|
|
1321
|
+
];
|
|
1305
1322
|
/**
|
|
1306
1323
|
* 给每个需要专用结果行的工具登记一行视图。
|
|
1307
1324
|
*
|
|
1308
|
-
* @param
|
|
1325
|
+
* @param ctx - 已就绪 slots 与 locale 的上下文
|
|
1309
1326
|
* @returns 注销全部登记的函数
|
|
1310
1327
|
*/
|
|
1311
|
-
function registerToolViews(
|
|
1312
|
-
const t =
|
|
1328
|
+
function registerToolViews(ctx) {
|
|
1329
|
+
const t = ctx.locale.bind(LOCALE_NS);
|
|
1313
1330
|
const disposers = [];
|
|
1314
|
-
for (const tool of ROW_TOOLS) disposers.push(
|
|
1331
|
+
for (const tool of ROW_TOOLS) disposers.push(ctx.slots.register({
|
|
1315
1332
|
name: "tool.call.toolview",
|
|
1316
1333
|
key: tool,
|
|
1317
1334
|
locale: LOCALE_NS
|
|
@@ -1340,44 +1357,42 @@ function apply(ctx) {
|
|
|
1340
1357
|
disposeRow();
|
|
1341
1358
|
};
|
|
1342
1359
|
}, "dsh-scrapling: client styles");
|
|
1343
|
-
ctx.
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
disposeRows = registerToolViews(scoped);
|
|
1350
|
-
});
|
|
1351
|
-
return () => {
|
|
1352
|
-
disposeRows?.();
|
|
1353
|
-
for (const dispose of disposers) dispose();
|
|
1354
|
-
};
|
|
1355
|
-
}, "dsh-scrapling: dictionaries and tool rows");
|
|
1356
|
-
scoped.inject(["configForms"], (withForms) => {
|
|
1357
|
-
withForms.effect(() => {
|
|
1358
|
-
const form = ctx.configForms.get(SETTINGS_ENTRY_ID);
|
|
1359
|
-
const t = ctx.locale.bind(LOCALE_NS);
|
|
1360
|
-
let disposeCard;
|
|
1361
|
-
scoped.slots.inject("plugins.bundle.config", () => {
|
|
1362
|
-
disposeCard = scoped.slots.register({
|
|
1363
|
-
name: "plugins.bundle.config",
|
|
1364
|
-
key: BUNDLE_PACKAGE_NAME,
|
|
1365
|
-
locale: LOCALE_NS
|
|
1366
|
-
}, (props) => (0, react.createElement)(SettingsCard, {
|
|
1367
|
-
...props,
|
|
1368
|
-
t,
|
|
1369
|
-
form: {
|
|
1370
|
-
state: form.getSnapshot(),
|
|
1371
|
-
mutate: (operations, revision) => form.mutate(operations, revision)
|
|
1372
|
-
}
|
|
1373
|
-
}));
|
|
1374
|
-
});
|
|
1375
|
-
return () => {
|
|
1376
|
-
disposeCard?.();
|
|
1377
|
-
};
|
|
1378
|
-
}, "dsh-scrapling: settings card");
|
|
1360
|
+
ctx.effect(() => {
|
|
1361
|
+
const dictionaries = localeDictionaries();
|
|
1362
|
+
const disposers = [ctx.locale.register(LOCALE_NS, "zh", dictionaries.zh), ctx.locale.register(LOCALE_NS, "en", dictionaries.en)];
|
|
1363
|
+
let disposeRows;
|
|
1364
|
+
ctx.slots.inject("tool.call.toolview", () => {
|
|
1365
|
+
disposeRows = registerToolViews(ctx);
|
|
1379
1366
|
});
|
|
1380
|
-
|
|
1367
|
+
return () => {
|
|
1368
|
+
disposeRows?.();
|
|
1369
|
+
for (const dispose of disposers) dispose();
|
|
1370
|
+
};
|
|
1371
|
+
}, "dsh-scrapling: dictionaries and tool rows");
|
|
1372
|
+
ctx.effect(() => {
|
|
1373
|
+
const form = ctx.configForms.get(SETTINGS_ENTRY_ID);
|
|
1374
|
+
const t = ctx.locale.bind(LOCALE_NS);
|
|
1375
|
+
const source = {
|
|
1376
|
+
getSnapshot: () => form.getSnapshot(),
|
|
1377
|
+
subscribe: (listener) => form.subscribe(listener),
|
|
1378
|
+
mutate: (operations, revision) => form.mutate(operations, revision)
|
|
1379
|
+
};
|
|
1380
|
+
let disposeCard;
|
|
1381
|
+
ctx.slots.inject("plugins.bundle.config", () => {
|
|
1382
|
+
disposeCard = ctx.slots.register({
|
|
1383
|
+
name: "plugins.bundle.config",
|
|
1384
|
+
key: BUNDLE_PACKAGE_NAME,
|
|
1385
|
+
locale: LOCALE_NS
|
|
1386
|
+
}, (props) => (0, react.createElement)(SettingsCard, {
|
|
1387
|
+
...props,
|
|
1388
|
+
t,
|
|
1389
|
+
form: source
|
|
1390
|
+
}));
|
|
1391
|
+
});
|
|
1392
|
+
return () => {
|
|
1393
|
+
disposeCard?.();
|
|
1394
|
+
};
|
|
1395
|
+
}, "dsh-scrapling: settings card");
|
|
1381
1396
|
}
|
|
1382
1397
|
//#endregion
|
|
1383
1398
|
exports.ROW_TOOLS = ROW_TOOLS;
|