@clipbus/plugin-sdk 0.7.0
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/API.md +641 -0
- package/LICENSE +21 -0
- package/README.md +466 -0
- package/SPECIFICATION.md +355 -0
- package/dist/dom/autoFit.d.ts +15 -0
- package/dist/dom/consolePatch.d.ts +1 -0
- package/dist/dom/index.cjs +211 -0
- package/dist/dom/index.d.cts +6 -0
- package/dist/dom/index.d.ts +6 -0
- package/dist/dom/index.js +188 -0
- package/dist/dom/textInputState.d.ts +1 -0
- package/dist/dom/topicAdapter.d.ts +30 -0
- package/dist/generated/INDEX.runtime.generated.d.ts +6 -0
- package/dist/generated/INDEX.ui.generated.d.ts +4 -0
- package/dist/generated/capabilityClients.generated.d.ts +199 -0
- package/dist/generated/data.generated.d.ts +193 -0
- package/dist/generated/hostClients.generated.d.ts +38 -0
- package/dist/generated/runtime.actionResult.generated.d.ts +28 -0
- package/dist/generated/runtime.definePlugin.generated.d.ts +16 -0
- package/dist/generated/runtime.handlers.generated.d.ts +20 -0
- package/dist/generated/runtime.host.generated.d.ts +34 -0
- package/dist/generated/topicSubscribers.generated.d.ts +32 -0
- package/dist/generated/ui.bootstrap.generated.d.ts +15 -0
- package/dist/generated/ui.clipbus.generated.d.ts +79 -0
- package/dist/generated/wireConstants.generated.d.ts +3 -0
- package/dist/internal/capabilities.d.ts +31 -0
- package/dist/internal/index.cjs +68 -0
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/internalConsole.d.ts +7 -0
- package/dist/internal/ipcBus.d.ts +48 -0
- package/dist/internal/runtimeInvokeClient.d.ts +3 -0
- package/dist/internal/topic.d.ts +20 -0
- package/dist/runtime/defineMessage.d.ts +6 -0
- package/dist/runtime/index.cjs +163 -0
- package/dist/runtime/index.d.cts +4 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +132 -0
- package/dist/shared/defineMessage.d.ts +7 -0
- package/dist/ui/defineMessage.d.ts +7 -0
- package/dist/ui/index.cjs +362 -0
- package/dist/ui/index.d.cts +4 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +339 -0
- package/docs/README.md +34 -0
- package/docs/authoring.md +288 -0
- package/docs/capability-detection.md +105 -0
- package/docs/concepts.md +80 -0
- package/docs/entry.md +137 -0
- package/docs/faq.md +65 -0
- package/docs/item-context.md +186 -0
- package/docs/manifest.md +149 -0
- package/docs/permissions.md +32 -0
- package/docs/rpc.md +84 -0
- package/package.json +76 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// src/internal/internalConsole.ts
|
|
2
|
+
function pick(method) {
|
|
3
|
+
if (typeof globalThis === "undefined") return () => {
|
|
4
|
+
};
|
|
5
|
+
const g = globalThis;
|
|
6
|
+
const fn = g.console?.[method];
|
|
7
|
+
if (typeof fn !== "function") return () => {
|
|
8
|
+
};
|
|
9
|
+
return fn.bind(g.console);
|
|
10
|
+
}
|
|
11
|
+
var internalConsole = Object.freeze({
|
|
12
|
+
log: pick("log"),
|
|
13
|
+
warn: pick("warn"),
|
|
14
|
+
error: pick("error")
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// src/internal/ipcBus.ts
|
|
18
|
+
var _instance = null;
|
|
19
|
+
var ipcBus = new Proxy({}, {
|
|
20
|
+
get(_target, prop) {
|
|
21
|
+
if (!_instance) {
|
|
22
|
+
throw new Error("[clipbus-plugin] ipcBus accessed before configureIpcBus() was called.");
|
|
23
|
+
}
|
|
24
|
+
return _instance[prop];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// src/generated/runtime.host.generated.ts
|
|
29
|
+
var host = {
|
|
30
|
+
item: {
|
|
31
|
+
setTags: (payload) => ipcBus.request("item.setTags", payload),
|
|
32
|
+
addTags: (payload) => ipcBus.request("item.addTags", payload),
|
|
33
|
+
removeTags: (payload) => ipcBus.request("item.removeTags", payload),
|
|
34
|
+
setPinned: (payload) => ipcBus.request("item.setPinned", payload),
|
|
35
|
+
setAttachments: (payload) => ipcBus.request("item.setAttachments", payload),
|
|
36
|
+
setSearchExtension: (payload) => ipcBus.request("item.setSearchExtension", payload),
|
|
37
|
+
materializeImagePath: () => ipcBus.request("item.materializeImagePath", {}),
|
|
38
|
+
readAttachment: (payload) => ipcBus.request("item.readAttachment", payload)
|
|
39
|
+
},
|
|
40
|
+
asset: {
|
|
41
|
+
registerImage: (payload) => ipcBus.request("asset.registerImage", payload)
|
|
42
|
+
},
|
|
43
|
+
clipboard: {
|
|
44
|
+
copyText: (payload) => ipcBus.request("clipboard.copyText", payload)
|
|
45
|
+
},
|
|
46
|
+
navigation: {
|
|
47
|
+
openUrl: (payload) => ipcBus.request("navigation.openUrl", payload),
|
|
48
|
+
revealInFinder: (payload) => ipcBus.request("navigation.revealInFinder", payload),
|
|
49
|
+
openFilePath: (payload) => ipcBus.request("navigation.openFilePath", payload)
|
|
50
|
+
},
|
|
51
|
+
action: {
|
|
52
|
+
allocateImageTempPath: (payload) => ipcBus.request("action.allocateImageTempPath", payload)
|
|
53
|
+
},
|
|
54
|
+
settings: {
|
|
55
|
+
get: (payload) => ipcBus.request("settings.get", payload),
|
|
56
|
+
getAll: () => ipcBus.request("settings.getAll", {})
|
|
57
|
+
},
|
|
58
|
+
console: {
|
|
59
|
+
log: (payload) => ipcBus.request("console.log", payload)
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/generated/runtime.definePlugin.generated.ts
|
|
64
|
+
function definePlugin(definition) {
|
|
65
|
+
if ("setup" in definition) {
|
|
66
|
+
return {
|
|
67
|
+
setup() {
|
|
68
|
+
const registry = definition.setup();
|
|
69
|
+
validateRegistry(registry);
|
|
70
|
+
return registry;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
validateRegistry(definition);
|
|
75
|
+
return { setup() {
|
|
76
|
+
return definition;
|
|
77
|
+
} };
|
|
78
|
+
}
|
|
79
|
+
function validateRegistry(registry) {
|
|
80
|
+
for (const [id, handler] of Object.entries(registry.attachmentRenderers ?? {})) {
|
|
81
|
+
if (handler && typeof handler === "object" && "invokeOperation" in handler) {
|
|
82
|
+
throw new Error(`attachmentRenderers["${id}"]: invokeOperation has been removed.`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
for (const [id, handler] of Object.entries(registry.actions ?? {})) {
|
|
86
|
+
if (handler && typeof handler === "object" && "invokeOperation" in handler) {
|
|
87
|
+
throw new Error(`actions["${id}"]: invokeOperation has been removed.`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/generated/runtime.actionResult.generated.ts
|
|
93
|
+
var actionResult = {
|
|
94
|
+
text: (text, options) => ({
|
|
95
|
+
result: { resultKind: "text", text },
|
|
96
|
+
userMessage: options?.userMessage
|
|
97
|
+
}),
|
|
98
|
+
image: (imageTempPath, options) => ({
|
|
99
|
+
result: { resultKind: "image", imageTempPath, ...options && "imageFormatHint" in options ? { imageFormatHint: options.imageFormatHint } : {} },
|
|
100
|
+
userMessage: options?.userMessage
|
|
101
|
+
}),
|
|
102
|
+
none: (options) => ({
|
|
103
|
+
result: { resultKind: "none" },
|
|
104
|
+
userMessage: options?.userMessage
|
|
105
|
+
})
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/runtime/defineMessage.ts
|
|
109
|
+
function defineMessage(key) {
|
|
110
|
+
return {
|
|
111
|
+
key,
|
|
112
|
+
handle: (fn) => [key, ((req, ctx) => fn(req, ctx))]
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/internal/capabilities.ts
|
|
117
|
+
var CapabilityUnsupportedError = class extends Error {
|
|
118
|
+
capability;
|
|
119
|
+
constructor(capability) {
|
|
120
|
+
super(`Capability not supported by host: ${capability}`);
|
|
121
|
+
this.name = "CapabilityUnsupportedError";
|
|
122
|
+
this.capability = capability;
|
|
123
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
export {
|
|
127
|
+
CapabilityUnsupportedError,
|
|
128
|
+
actionResult,
|
|
129
|
+
defineMessage,
|
|
130
|
+
definePlugin,
|
|
131
|
+
host
|
|
132
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MessageContract } from '../shared/defineMessage.js';
|
|
2
|
+
export interface UIMessageContract<TReq, TResp> extends MessageContract<TReq, TResp> {
|
|
3
|
+
invoke(payload: TReq, options?: {
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
}): Promise<TResp>;
|
|
6
|
+
}
|
|
7
|
+
export declare function defineMessage<TReq, TResp>(key: string): UIMessageContract<TReq, TResp>;
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/ui/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
CapabilityUnsupportedError: () => CapabilityUnsupportedError,
|
|
24
|
+
PluginContextError: () => PluginContextError,
|
|
25
|
+
clipbus: () => clipbus,
|
|
26
|
+
defineMessage: () => defineMessage
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/generated/wireConstants.generated.ts
|
|
31
|
+
var STRUCTURED_ERROR_PREFIX = "__clipbus_structured_error__:";
|
|
32
|
+
var CAPABILITIES_GLOBAL = "__CLIPBUS_PLUGIN_CAPABILITIES__";
|
|
33
|
+
var CAPABILITY_UNSUPPORTED_ERROR_NAME = "PluginCapabilityUnsupported";
|
|
34
|
+
|
|
35
|
+
// src/internal/capabilities.ts
|
|
36
|
+
var CapabilityUnsupportedError = class extends Error {
|
|
37
|
+
capability;
|
|
38
|
+
constructor(capability) {
|
|
39
|
+
super(`Capability not supported by host: ${capability}`);
|
|
40
|
+
this.name = "CapabilityUnsupportedError";
|
|
41
|
+
this.capability = capability;
|
|
42
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
function readInjectedCapabilities(global, key) {
|
|
46
|
+
const obj = global;
|
|
47
|
+
const raw = obj?.[key];
|
|
48
|
+
if (Array.isArray(raw?.capabilities)) {
|
|
49
|
+
return new Set(raw.capabilities);
|
|
50
|
+
}
|
|
51
|
+
return /* @__PURE__ */ new Set();
|
|
52
|
+
}
|
|
53
|
+
function createCapabilitiesApi(getSet) {
|
|
54
|
+
return {
|
|
55
|
+
has: (name) => getSet().has(name)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function mapToCapabilityError(err, unsupportedName) {
|
|
59
|
+
if (err.name === unsupportedName) {
|
|
60
|
+
const cap = err.data?.capability ?? "";
|
|
61
|
+
return new CapabilityUnsupportedError(cap);
|
|
62
|
+
}
|
|
63
|
+
const m = /^Unknown method:\s*(.+)$/.exec(err.message);
|
|
64
|
+
if (m) return new CapabilityUnsupportedError(m[1]);
|
|
65
|
+
return err;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/internal/runtimeInvokeClient.ts
|
|
69
|
+
var HANDLER_NAME = "clipbusPluginCall";
|
|
70
|
+
async function callRuntimeInvokeStrict(payload) {
|
|
71
|
+
const handler = globalThis.webkit?.messageHandlers?.[HANDLER_NAME];
|
|
72
|
+
if (!handler) {
|
|
73
|
+
throw new Error("runtime.invoke is only available inside a Clipbus plugin WebView");
|
|
74
|
+
}
|
|
75
|
+
const normalized = JSON.parse(JSON.stringify(payload));
|
|
76
|
+
let reply;
|
|
77
|
+
try {
|
|
78
|
+
reply = await handler.postMessage({ method: "runtime.invoke", payload: normalized });
|
|
79
|
+
} catch (err) {
|
|
80
|
+
throw parseReplyError(err);
|
|
81
|
+
}
|
|
82
|
+
return reply?.response;
|
|
83
|
+
}
|
|
84
|
+
function parseReplyError(raw) {
|
|
85
|
+
const message = extractMessage(raw);
|
|
86
|
+
if (message.startsWith(STRUCTURED_ERROR_PREFIX)) {
|
|
87
|
+
const json = message.slice(STRUCTURED_ERROR_PREFIX.length);
|
|
88
|
+
try {
|
|
89
|
+
const parsed = JSON.parse(json);
|
|
90
|
+
const err = new Error(typeof parsed.message === "string" ? parsed.message : "");
|
|
91
|
+
if (typeof parsed.name === "string" && parsed.name.length > 0) {
|
|
92
|
+
err.name = parsed.name;
|
|
93
|
+
}
|
|
94
|
+
if (parsed.data !== void 0) {
|
|
95
|
+
err.data = parsed.data;
|
|
96
|
+
}
|
|
97
|
+
return mapToCapabilityError(err, CAPABILITY_UNSUPPORTED_ERROR_NAME);
|
|
98
|
+
} catch {
|
|
99
|
+
return new Error(message);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return mapToCapabilityError(new Error(message), CAPABILITY_UNSUPPORTED_ERROR_NAME);
|
|
103
|
+
}
|
|
104
|
+
function extractMessage(raw) {
|
|
105
|
+
if (typeof raw === "string") return raw;
|
|
106
|
+
if (raw instanceof Error) return raw.message;
|
|
107
|
+
if (raw && typeof raw === "object" && "message" in raw) {
|
|
108
|
+
const m = raw.message;
|
|
109
|
+
if (typeof m === "string") return m;
|
|
110
|
+
}
|
|
111
|
+
return String(raw);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/generated/capabilityClients.generated.ts
|
|
115
|
+
var HANDLER_NAME2 = "clipbusPluginCall";
|
|
116
|
+
async function callPluginMethod(method, payload) {
|
|
117
|
+
const handler = globalThis.webkit?.messageHandlers?.[HANDLER_NAME2];
|
|
118
|
+
if (!handler) {
|
|
119
|
+
const err = new Error("clipbus." + method + " is only available inside a Clipbus plugin WebView");
|
|
120
|
+
err.name = "PluginHostBridgeUnavailable";
|
|
121
|
+
throw err;
|
|
122
|
+
}
|
|
123
|
+
const normalized = JSON.parse(JSON.stringify(payload));
|
|
124
|
+
let reply;
|
|
125
|
+
try {
|
|
126
|
+
reply = await handler.postMessage({ method, payload: normalized });
|
|
127
|
+
} catch (err) {
|
|
128
|
+
throw parseReplyError(err);
|
|
129
|
+
}
|
|
130
|
+
return reply;
|
|
131
|
+
}
|
|
132
|
+
var callItemReadAttachment = (payload) => callPluginMethod("item.readAttachment", payload);
|
|
133
|
+
var callAssetCurrentItemImageUrl = () => callPluginMethod("asset.currentItemImageUrl", {});
|
|
134
|
+
var callAssetPathReferenceImageUrl = (payload) => callPluginMethod("asset.pathReferenceImageUrl", payload);
|
|
135
|
+
var callClipboardCopyText = (payload) => callPluginMethod("clipboard.copyText", payload);
|
|
136
|
+
var callNavigationOpenUrl = (payload) => callPluginMethod("navigation.openUrl", payload);
|
|
137
|
+
var callNavigationRevealInFinder = (payload) => callPluginMethod("navigation.revealInFinder", payload);
|
|
138
|
+
var callNavigationOpenFilePath = (payload) => callPluginMethod("navigation.openFilePath", payload);
|
|
139
|
+
var callActionSetButtons = (payload) => callPluginMethod("action.setButtons", payload);
|
|
140
|
+
var callActionComplete = (payload) => callPluginMethod("action.complete", payload);
|
|
141
|
+
var callAttachmentRendererSetButtons = (payload) => callPluginMethod("attachmentRenderer.setButtons", payload);
|
|
142
|
+
var callWindowSetHeight = (payload) => callPluginMethod("window.setHeight", payload);
|
|
143
|
+
var callWindowAutoFit = () => callPluginMethod("window.autoFit", {});
|
|
144
|
+
var callInfoPanelOpen = (payload) => callPluginMethod("infoPanel.open", payload);
|
|
145
|
+
var callInfoPanelClose = (payload) => callPluginMethod("infoPanel.close", payload);
|
|
146
|
+
var callSettingsGet = (payload) => callPluginMethod("settings.get", payload);
|
|
147
|
+
var callSettingsGetAll = () => callPluginMethod("settings.getAll", {});
|
|
148
|
+
var callConsoleLog = (payload) => callPluginMethod("console.log", payload);
|
|
149
|
+
var callTextInputStateChanged = (payload) => callPluginMethod("textInput.stateChanged", payload);
|
|
150
|
+
|
|
151
|
+
// src/internal/topic.ts
|
|
152
|
+
function createTopic(initial) {
|
|
153
|
+
let value = initial;
|
|
154
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
155
|
+
return {
|
|
156
|
+
current: () => value,
|
|
157
|
+
on(listener) {
|
|
158
|
+
listeners.add(listener);
|
|
159
|
+
return () => listeners.delete(listener);
|
|
160
|
+
},
|
|
161
|
+
set(next) {
|
|
162
|
+
value = next;
|
|
163
|
+
for (const l of listeners) {
|
|
164
|
+
try {
|
|
165
|
+
l(value);
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function createStream() {
|
|
173
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
174
|
+
return {
|
|
175
|
+
on(listener) {
|
|
176
|
+
listeners.add(listener);
|
|
177
|
+
return () => listeners.delete(listener);
|
|
178
|
+
},
|
|
179
|
+
emit(event) {
|
|
180
|
+
for (const l of listeners) {
|
|
181
|
+
try {
|
|
182
|
+
l(event);
|
|
183
|
+
} catch {
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function readWindowGlobal(key) {
|
|
190
|
+
if (typeof window === "undefined") return void 0;
|
|
191
|
+
return window[key];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// src/generated/topicSubscribers.generated.ts
|
|
195
|
+
function onContext(listener) {
|
|
196
|
+
const handler = (e) => listener(e.detail);
|
|
197
|
+
globalThis.addEventListener("clipbus-plugin-context", handler);
|
|
198
|
+
return () => globalThis.removeEventListener("clipbus-plugin-context", handler);
|
|
199
|
+
}
|
|
200
|
+
function onItem(listener) {
|
|
201
|
+
const handler = (e) => listener(e.detail);
|
|
202
|
+
globalThis.addEventListener("clipbus-plugin-item", handler);
|
|
203
|
+
return () => globalThis.removeEventListener("clipbus-plugin-item", handler);
|
|
204
|
+
}
|
|
205
|
+
function onAttachment(listener) {
|
|
206
|
+
const handler = (e) => listener(e.detail);
|
|
207
|
+
globalThis.addEventListener("clipbus-plugin-attachment", handler);
|
|
208
|
+
return () => globalThis.removeEventListener("clipbus-plugin-attachment", handler);
|
|
209
|
+
}
|
|
210
|
+
function onDraft(listener) {
|
|
211
|
+
const handler = (e) => listener(e.detail);
|
|
212
|
+
globalThis.addEventListener("clipbus-plugin-draft", handler);
|
|
213
|
+
return () => globalThis.removeEventListener("clipbus-plugin-draft", handler);
|
|
214
|
+
}
|
|
215
|
+
function onTheme(listener) {
|
|
216
|
+
const handler = (e) => listener(e.detail);
|
|
217
|
+
globalThis.addEventListener("clipbus-plugin-theme", handler);
|
|
218
|
+
return () => globalThis.removeEventListener("clipbus-plugin-theme", handler);
|
|
219
|
+
}
|
|
220
|
+
function onAttachmentHostInvoke(listener) {
|
|
221
|
+
const handler = (e) => listener(e.detail);
|
|
222
|
+
globalThis.addEventListener("clipbus-plugin-attachment-host-invoke", handler);
|
|
223
|
+
return () => globalThis.removeEventListener("clipbus-plugin-attachment-host-invoke", handler);
|
|
224
|
+
}
|
|
225
|
+
function onActionHostInvoke(listener) {
|
|
226
|
+
const handler = (e) => listener(e.detail);
|
|
227
|
+
globalThis.addEventListener("clipbus-plugin-action-host-invoke", handler);
|
|
228
|
+
return () => globalThis.removeEventListener("clipbus-plugin-action-host-invoke", handler);
|
|
229
|
+
}
|
|
230
|
+
function onInfoPanelOnAction(listener) {
|
|
231
|
+
const handler = (e) => listener(e.detail);
|
|
232
|
+
globalThis.addEventListener("clipbus-plugin-info-panel-on-action", handler);
|
|
233
|
+
return () => globalThis.removeEventListener("clipbus-plugin-info-panel-on-action", handler);
|
|
234
|
+
}
|
|
235
|
+
function onInfoPanelOnClose(listener) {
|
|
236
|
+
const handler = (e) => listener(e.detail);
|
|
237
|
+
globalThis.addEventListener("clipbus-plugin-info-panel-on-close", handler);
|
|
238
|
+
return () => globalThis.removeEventListener("clipbus-plugin-info-panel-on-close", handler);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/generated/ui.bootstrap.generated.ts
|
|
242
|
+
var _pluginContextTopic = createTopic(readWindowGlobal("__CLIPBUS_PLUGIN_CONTEXT__"));
|
|
243
|
+
onContext((p) => _pluginContextTopic.set(p));
|
|
244
|
+
var _itemTopic = createTopic(readWindowGlobal("__CLIPBUS_PLUGIN_ITEM__"));
|
|
245
|
+
onItem((p) => _itemTopic.set(p));
|
|
246
|
+
var _itemAttachmentTopic = createTopic(readWindowGlobal("__CLIPBUS_PLUGIN_ATTACHMENT__"));
|
|
247
|
+
onAttachment((p) => _itemAttachmentTopic.set(p));
|
|
248
|
+
var _actionDraftTopic = createTopic(readWindowGlobal("__CLIPBUS_PLUGIN_DRAFT__"));
|
|
249
|
+
onDraft((p) => _actionDraftTopic.set(p));
|
|
250
|
+
var _themeTopic = createTopic(readWindowGlobal("__CLIPBUS_PLUGIN_THEME__"));
|
|
251
|
+
onTheme((p) => _themeTopic.set(p));
|
|
252
|
+
var _attachmentRendererOnHostInvokeStream = createStream();
|
|
253
|
+
onAttachmentHostInvoke((p) => _attachmentRendererOnHostInvokeStream.emit(p));
|
|
254
|
+
var _actionOnHostInvokeStream = createStream();
|
|
255
|
+
onActionHostInvoke((p) => _actionOnHostInvokeStream.emit(p));
|
|
256
|
+
var _infoPanelOnActionStream = createStream();
|
|
257
|
+
onInfoPanelOnAction((p) => _infoPanelOnActionStream.emit(p));
|
|
258
|
+
var _infoPanelOnCloseStream = createStream();
|
|
259
|
+
onInfoPanelOnClose((p) => _infoPanelOnCloseStream.emit(p));
|
|
260
|
+
var PluginContextError = class extends Error {
|
|
261
|
+
constructor(message) {
|
|
262
|
+
super(message);
|
|
263
|
+
this.name = "PluginContextError";
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
function guardContext(expected, run) {
|
|
267
|
+
return (...args) => {
|
|
268
|
+
const current = _pluginContextTopic.current()?.mode;
|
|
269
|
+
if (current !== expected) {
|
|
270
|
+
throw new PluginContextError(
|
|
271
|
+
`This verb is not available in the current plugin context (expected: ${expected}, got: ${current || "unknown"})`
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
return run(...args);
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/generated/ui.clipbus.generated.ts
|
|
279
|
+
var clipbus = {
|
|
280
|
+
capabilities: createCapabilitiesApi(() => readInjectedCapabilities(globalThis, CAPABILITIES_GLOBAL)),
|
|
281
|
+
runtime: {
|
|
282
|
+
invoke: (payload) => callRuntimeInvokeStrict(payload)
|
|
283
|
+
},
|
|
284
|
+
item: {
|
|
285
|
+
current: () => _itemTopic.current(),
|
|
286
|
+
on: (fn) => _itemTopic.on(fn),
|
|
287
|
+
readAttachment: (payload) => callItemReadAttachment(payload),
|
|
288
|
+
attachment: {
|
|
289
|
+
current: () => _itemAttachmentTopic.current(),
|
|
290
|
+
on: (fn) => _itemAttachmentTopic.on(fn)
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
asset: {
|
|
294
|
+
currentItemImageUrl: () => callAssetCurrentItemImageUrl(),
|
|
295
|
+
pathReferenceImageUrl: (payload) => callAssetPathReferenceImageUrl(payload)
|
|
296
|
+
},
|
|
297
|
+
clipboard: {
|
|
298
|
+
copyText: (payload) => callClipboardCopyText(payload)
|
|
299
|
+
},
|
|
300
|
+
navigation: {
|
|
301
|
+
openUrl: (payload) => callNavigationOpenUrl(payload),
|
|
302
|
+
revealInFinder: (payload) => callNavigationRevealInFinder(payload),
|
|
303
|
+
openFilePath: (payload) => callNavigationOpenFilePath(payload)
|
|
304
|
+
},
|
|
305
|
+
action: {
|
|
306
|
+
setButtons: guardContext("action", (payload) => callActionSetButtons(payload)),
|
|
307
|
+
complete: guardContext("action", (payload) => callActionComplete(payload)),
|
|
308
|
+
draft: {
|
|
309
|
+
current: () => _actionDraftTopic.current(),
|
|
310
|
+
on: (fn) => _actionDraftTopic.on(fn)
|
|
311
|
+
},
|
|
312
|
+
onHostInvoke: {
|
|
313
|
+
on: (fn) => _actionOnHostInvokeStream.on(fn)
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
attachmentRenderer: {
|
|
317
|
+
setButtons: guardContext("attachmentRenderer", (payload) => callAttachmentRendererSetButtons(payload)),
|
|
318
|
+
onHostInvoke: {
|
|
319
|
+
on: (fn) => _attachmentRendererOnHostInvokeStream.on(fn)
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
window: {
|
|
323
|
+
setHeight: (payload) => callWindowSetHeight(payload),
|
|
324
|
+
autoFit: () => callWindowAutoFit()
|
|
325
|
+
},
|
|
326
|
+
infoPanel: {
|
|
327
|
+
open: (payload) => callInfoPanelOpen(payload),
|
|
328
|
+
close: (payload) => callInfoPanelClose(payload),
|
|
329
|
+
onAction: {
|
|
330
|
+
on: (fn) => _infoPanelOnActionStream.on(fn)
|
|
331
|
+
},
|
|
332
|
+
onClose: {
|
|
333
|
+
on: (fn) => _infoPanelOnCloseStream.on(fn)
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
settings: {
|
|
337
|
+
get: (payload) => callSettingsGet(payload),
|
|
338
|
+
getAll: () => callSettingsGetAll()
|
|
339
|
+
},
|
|
340
|
+
console: {
|
|
341
|
+
log: (payload) => callConsoleLog(payload)
|
|
342
|
+
},
|
|
343
|
+
textInput: {
|
|
344
|
+
stateChanged: (payload) => callTextInputStateChanged(payload)
|
|
345
|
+
},
|
|
346
|
+
pluginContext: {
|
|
347
|
+
current: () => _pluginContextTopic.current(),
|
|
348
|
+
on: (fn) => _pluginContextTopic.on(fn)
|
|
349
|
+
},
|
|
350
|
+
theme: {
|
|
351
|
+
current: () => _themeTopic.current(),
|
|
352
|
+
on: (fn) => _themeTopic.on(fn)
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
// src/ui/defineMessage.ts
|
|
357
|
+
function defineMessage(key) {
|
|
358
|
+
return {
|
|
359
|
+
key,
|
|
360
|
+
invoke: async (payload, options) => await clipbus.runtime.invoke({ key, payload, timeoutMs: options?.timeoutMs })
|
|
361
|
+
};
|
|
362
|
+
}
|