dsh-workbuddy-files 0.1.1 → 0.1.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/lib/client.js +95 -69
- package/package.json +1 -1
- package/src/client/app.ts +34 -6
package/lib/client.js
CHANGED
|
@@ -901,80 +901,106 @@
|
|
|
901
901
|
return {
|
|
902
902
|
name: "workbuddy-files",
|
|
903
903
|
apply(ctx) {
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
const inputTriggers = get("inputTriggers");
|
|
909
|
-
const conversationEvents = get("conversationEvents");
|
|
910
|
-
const styles = get("styles");
|
|
911
|
-
if (slots === void 0) return;
|
|
912
|
-
const insertStyles = () => styles !== void 0 ? styles.insert(CSS) : () => {};
|
|
913
|
-
const effect = ctx.effect.bind(ctx);
|
|
914
|
-
effect(insertStyles, "workbuddy: styles");
|
|
915
|
-
const bus = createDropBus();
|
|
916
|
-
let rootCache = null;
|
|
917
|
-
dropsHome().then((r) => {
|
|
918
|
-
rootCache = r;
|
|
919
|
-
});
|
|
920
|
-
const ensureRoot = async () => {
|
|
921
|
-
if (rootCache !== null) return rootCache;
|
|
922
|
-
const r = await dropsHome();
|
|
923
|
-
rootCache = r;
|
|
924
|
-
return r;
|
|
925
|
-
};
|
|
926
|
-
const enqueueUpload = (jobs, batch) => {
|
|
927
|
-
runUploadJobs(jobs, batch).then(({ ok, failed }) => {
|
|
928
|
-
if (failed.length > 0) bus.toast("缓存失败 " + failed.length + " 项:" + failed.slice(0, 2).join(";") + (failed.length > 2 ? "…" : ""), "error");
|
|
929
|
-
else if (ok > 0) bus.toast("后台缓存完成:" + ok + " 个文件已就绪");
|
|
930
|
-
}).catch((err) => {
|
|
931
|
-
bus.toast("后台缓存失败:" + String(err?.message ?? err), "error");
|
|
932
|
-
});
|
|
933
|
-
};
|
|
934
|
-
const handlers = createDropHandlers({
|
|
935
|
-
bus,
|
|
936
|
-
insert: createInsertPipeline({
|
|
937
|
-
sessions,
|
|
938
|
-
conversation,
|
|
939
|
-
toast: bus.toast
|
|
940
|
-
}),
|
|
941
|
-
ensureRoot,
|
|
942
|
-
enqueueUpload
|
|
943
|
-
});
|
|
944
|
-
effect(() => handlers.installListeners(), "workbuddy: window listeners");
|
|
945
|
-
if (inputTriggers !== void 0) {
|
|
946
|
-
const source = createAtSource();
|
|
947
|
-
effect(() => inputTriggers.registerSource(source), "workbuddy: @ source");
|
|
904
|
+
try {
|
|
905
|
+
applyClient(ctx, React);
|
|
906
|
+
} catch (err) {
|
|
907
|
+
console.error("[workbuddy-files] client apply 异常:", err);
|
|
948
908
|
}
|
|
949
|
-
if (conversationEvents !== void 0) effect(() => {
|
|
950
|
-
const d1 = conversationEvents.register(boundaryDef);
|
|
951
|
-
const d2 = conversationEvents.register(fileRefsDef);
|
|
952
|
-
return () => {
|
|
953
|
-
if (typeof d1 === "function") d1();
|
|
954
|
-
if (typeof d2 === "function") d2();
|
|
955
|
-
};
|
|
956
|
-
}, "workbuddy: conversation definitions");
|
|
957
|
-
slots.inject("shell.overlay", () => slots.register({
|
|
958
|
-
name: "shell.overlay",
|
|
959
|
-
id: "workbuddy-drop",
|
|
960
|
-
order: 300,
|
|
961
|
-
label: "WorkBuddy 拖拽遮罩"
|
|
962
|
-
}, createOverlayComponent(React, bus)));
|
|
963
|
-
slots.inject("conversation.input.left", () => slots.register({
|
|
964
|
-
name: "conversation.input.left",
|
|
965
|
-
id: "workbuddy-pick",
|
|
966
|
-
order: 0,
|
|
967
|
-
label: "引用文件/文件夹"
|
|
968
|
-
}, createPickButtonComponent(React, bus, handlers)));
|
|
969
|
-
slots.inject("conversation.chat.turnTail", () => slots.register({
|
|
970
|
-
name: "conversation.chat.turnTail",
|
|
971
|
-
select: selectTurnFileRefs
|
|
972
|
-
}, createFileCardsComponent(React)));
|
|
973
|
-
console.log("[workbuddy-files] client 就绪:拖入即插气泡 + 后台缓存 / 统一遮罩 / 文件卡片");
|
|
974
909
|
}
|
|
975
910
|
};
|
|
976
911
|
};
|
|
977
912
|
}
|
|
913
|
+
function applyClient(ctx, React) {
|
|
914
|
+
const get = (name) => ctx.get(name);
|
|
915
|
+
const sessions = get("sessions");
|
|
916
|
+
const slots = get("slots");
|
|
917
|
+
const conversation = get("conversation");
|
|
918
|
+
const inputTriggers = get("inputTriggers");
|
|
919
|
+
const conversationEvents = get("conversationEvents");
|
|
920
|
+
const styles = get("styles");
|
|
921
|
+
if (slots === void 0) return;
|
|
922
|
+
const injectCssViaHead = (css) => {
|
|
923
|
+
if (typeof document === "undefined") return;
|
|
924
|
+
const tagId = "dsh-workbuddy-files/styles";
|
|
925
|
+
if (document.querySelector("style[data-plugin-css=\"" + tagId + "\"]") !== null) return;
|
|
926
|
+
const tag = document.createElement("style");
|
|
927
|
+
tag.dataset.plugin = "dsh-workbuddy-files";
|
|
928
|
+
tag.dataset.pluginCss = tagId;
|
|
929
|
+
tag.textContent = css;
|
|
930
|
+
document.head.appendChild(tag);
|
|
931
|
+
};
|
|
932
|
+
const insertStyles = () => {
|
|
933
|
+
if (styles !== void 0) return styles.insert(CSS);
|
|
934
|
+
injectCssViaHead(CSS);
|
|
935
|
+
return () => {};
|
|
936
|
+
};
|
|
937
|
+
const effect = ctx.effect.bind(ctx);
|
|
938
|
+
effect(insertStyles, "workbuddy: styles");
|
|
939
|
+
console.log("[workbuddy-files] client apply 开始:services slots=" + (slots !== void 0) + " conversation=" + (conversation !== void 0) + " inputTriggers=" + (inputTriggers !== void 0) + " conversationEvents=" + (conversationEvents !== void 0) + " styles=" + (styles !== void 0));
|
|
940
|
+
const bus = createDropBus();
|
|
941
|
+
let rootCache = null;
|
|
942
|
+
dropsHome().then((r) => {
|
|
943
|
+
rootCache = r;
|
|
944
|
+
});
|
|
945
|
+
const ensureRoot = async () => {
|
|
946
|
+
if (rootCache !== null) return rootCache;
|
|
947
|
+
const r = await dropsHome();
|
|
948
|
+
rootCache = r;
|
|
949
|
+
return r;
|
|
950
|
+
};
|
|
951
|
+
const enqueueUpload = (jobs, batch) => {
|
|
952
|
+
runUploadJobs(jobs, batch).then(({ ok, failed }) => {
|
|
953
|
+
if (failed.length > 0) bus.toast("缓存失败 " + failed.length + " 项:" + failed.slice(0, 2).join(";") + (failed.length > 2 ? "…" : ""), "error");
|
|
954
|
+
else if (ok > 0) bus.toast("后台缓存完成:" + ok + " 个文件已就绪");
|
|
955
|
+
}).catch((err) => {
|
|
956
|
+
bus.toast("后台缓存失败:" + String(err?.message ?? err), "error");
|
|
957
|
+
});
|
|
958
|
+
};
|
|
959
|
+
const handlers = createDropHandlers({
|
|
960
|
+
bus,
|
|
961
|
+
insert: createInsertPipeline({
|
|
962
|
+
sessions,
|
|
963
|
+
conversation,
|
|
964
|
+
toast: bus.toast
|
|
965
|
+
}),
|
|
966
|
+
ensureRoot,
|
|
967
|
+
enqueueUpload
|
|
968
|
+
});
|
|
969
|
+
effect(() => {
|
|
970
|
+
const off = handlers.installListeners();
|
|
971
|
+
console.log("[workbuddy-files] 窗口拖拽/粘贴监听已注册");
|
|
972
|
+
return off;
|
|
973
|
+
}, "workbuddy: window listeners");
|
|
974
|
+
if (inputTriggers !== void 0) {
|
|
975
|
+
const source = createAtSource();
|
|
976
|
+
effect(() => inputTriggers.registerSource(source), "workbuddy: @ source");
|
|
977
|
+
}
|
|
978
|
+
if (conversationEvents !== void 0) effect(() => {
|
|
979
|
+
const d1 = conversationEvents.register(boundaryDef);
|
|
980
|
+
const d2 = conversationEvents.register(fileRefsDef);
|
|
981
|
+
return () => {
|
|
982
|
+
if (typeof d1 === "function") d1();
|
|
983
|
+
if (typeof d2 === "function") d2();
|
|
984
|
+
};
|
|
985
|
+
}, "workbuddy: conversation definitions");
|
|
986
|
+
slots.inject("shell.overlay", () => slots.register({
|
|
987
|
+
name: "shell.overlay",
|
|
988
|
+
id: "workbuddy-drop",
|
|
989
|
+
order: 300,
|
|
990
|
+
label: "WorkBuddy 拖拽遮罩"
|
|
991
|
+
}, createOverlayComponent(React, bus)));
|
|
992
|
+
slots.inject("conversation.input.left", () => slots.register({
|
|
993
|
+
name: "conversation.input.left",
|
|
994
|
+
id: "workbuddy-pick",
|
|
995
|
+
order: 0,
|
|
996
|
+
label: "引用文件/文件夹"
|
|
997
|
+
}, createPickButtonComponent(React, bus, handlers)));
|
|
998
|
+
slots.inject("conversation.chat.turnTail", () => slots.register({
|
|
999
|
+
name: "conversation.chat.turnTail",
|
|
1000
|
+
select: selectTurnFileRefs
|
|
1001
|
+
}, createFileCardsComponent(React)));
|
|
1002
|
+
console.log("[workbuddy-files] client 就绪:拖入即插气泡 + 后台缓存 / 统一遮罩 / 文件卡片");
|
|
1003
|
+
}
|
|
978
1004
|
//#endregion
|
|
979
1005
|
//#region src/client/index.ts
|
|
980
1006
|
window.__ModuleLoader__.load({
|
package/package.json
CHANGED
package/src/client/app.ts
CHANGED
|
@@ -35,7 +35,18 @@ export function makeFactory() {
|
|
|
35
35
|
return {
|
|
36
36
|
name: 'workbuddy-files',
|
|
37
37
|
apply(ctx) {
|
|
38
|
-
|
|
38
|
+
try {
|
|
39
|
+
applyClient(ctx, React)
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.error('[workbuddy-files] client apply 异常:', err)
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function applyClient(ctx: Record<string, unknown>, React: ReactLike): void {
|
|
49
|
+
const get = (name: string) => (ctx.get as (n: string) => unknown)(name)
|
|
39
50
|
|
|
40
51
|
// ---- 能力探测(缺失则优雅退出)----
|
|
41
52
|
const sessions = get('sessions') as never
|
|
@@ -54,9 +65,25 @@ export function makeFactory() {
|
|
|
54
65
|
if (slots === undefined) return
|
|
55
66
|
|
|
56
67
|
// ---- 包内样式 ----
|
|
57
|
-
|
|
68
|
+
// 正式插件包没有动态版的 styles 内置服务:回退到 document.head style 注入(dsh-pet 同款)
|
|
69
|
+
const injectCssViaHead = (css: string): void => {
|
|
70
|
+
if (typeof document === 'undefined') return
|
|
71
|
+
const tagId = 'dsh-workbuddy-files/styles'
|
|
72
|
+
if (document.querySelector('style[data-plugin-css="' + tagId + '"]') !== null) return
|
|
73
|
+
const tag = document.createElement('style')
|
|
74
|
+
tag.dataset.plugin = 'dsh-workbuddy-files'
|
|
75
|
+
tag.dataset.pluginCss = tagId
|
|
76
|
+
tag.textContent = css
|
|
77
|
+
document.head.appendChild(tag)
|
|
78
|
+
}
|
|
79
|
+
const insertStyles = () => {
|
|
80
|
+
if (styles !== undefined) return styles.insert(CSS)
|
|
81
|
+
injectCssViaHead(CSS)
|
|
82
|
+
return () => {}
|
|
83
|
+
}
|
|
58
84
|
const effect = (ctx.effect as (fn: () => (() => void) | undefined, label?: string) => void).bind(ctx)
|
|
59
85
|
effect(insertStyles, 'workbuddy: styles')
|
|
86
|
+
console.log('[workbuddy-files] client apply 开始:services slots=' + (slots !== undefined) + ' conversation=' + (conversation !== undefined) + ' inputTriggers=' + (inputTriggers !== undefined) + ' conversationEvents=' + (conversationEvents !== undefined) + ' styles=' + (styles !== undefined))
|
|
60
87
|
|
|
61
88
|
// ---- 共享实例 ----
|
|
62
89
|
const bus = createDropBus()
|
|
@@ -89,7 +116,11 @@ export function makeFactory() {
|
|
|
89
116
|
|
|
90
117
|
// ---- 拖拽 / 粘贴处理 + 窗口级监听 ----
|
|
91
118
|
const handlers = createDropHandlers({ bus, insert, ensureRoot, enqueueUpload })
|
|
92
|
-
effect(() =>
|
|
119
|
+
effect(() => {
|
|
120
|
+
const off = handlers.installListeners()
|
|
121
|
+
console.log('[workbuddy-files] 窗口拖拽/粘贴监听已注册')
|
|
122
|
+
return off
|
|
123
|
+
}, 'workbuddy: window listeners')
|
|
93
124
|
|
|
94
125
|
// ---- @ 触发源(文件缓存分组)----
|
|
95
126
|
if (inputTriggers !== undefined) {
|
|
@@ -124,7 +155,4 @@ export function makeFactory() {
|
|
|
124
155
|
))
|
|
125
156
|
|
|
126
157
|
console.log('[workbuddy-files] client 就绪:拖入即插气泡 + 后台缓存 / 统一遮罩 / 文件卡片')
|
|
127
|
-
},
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
158
|
}
|