@clipbus/plugin-sdk 0.9.9 → 0.10.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 +94 -27
- package/CHANGELOG.md +84 -0
- package/README.md +11 -3
- package/SPECIFICATION.md +3 -2
- package/dist/dom/index.cjs +29 -34
- package/dist/dom/index.js +29 -34
- package/dist/dom/topicAdapter.d.ts +1 -1
- package/dist/generated/capabilities.generated.d.ts +355 -0
- package/dist/generated/data.generated.d.ts +33 -0
- package/dist/generated/hostClients.generated.d.ts +8 -5
- package/dist/generated/hostEvents.generated.d.ts +68 -0
- package/dist/generated/nodeIPC.generated.d.ts +106 -0
- package/dist/generated/{runtime.definePlugin.generated.d.ts → runtime.registry.generated.d.ts} +2 -2
- package/dist/generated/ui.clipbus.generated.d.ts +19 -20
- package/dist/generated/wireConstants.generated.d.ts +21 -0
- package/dist/internal/capabilities.d.ts +1 -1
- package/dist/internal/hostEvents.d.ts +15 -0
- package/dist/internal/pluginCall.d.ts +11 -0
- package/dist/internal/pluginContext.d.ts +6 -0
- package/dist/preview/index.cjs +41 -48
- package/dist/preview/index.js +41 -48
- package/dist/preview/wire.d.ts +2 -2
- package/dist/runtime/defineMessage.d.ts +1 -1
- package/dist/runtime/definePlugin.d.ts +2 -0
- package/dist/runtime/index.cjs +10 -82
- package/dist/runtime/index.d.cts +7 -1
- package/dist/runtime/index.d.ts +7 -1
- package/dist/runtime/index.js +9 -80
- package/dist/ui/index.cjs +107 -169
- package/dist/ui/index.d.cts +5 -1
- package/dist/ui/index.d.ts +5 -1
- package/dist/ui/index.js +107 -169
- package/dist/validate/index.d.cts +5 -4
- package/dist/validate/index.d.ts +5 -4
- package/docs/authoring.md +1 -1
- package/docs/capability-detection.md +2 -2
- package/docs/entry.md +4 -3
- package/docs/item-context.md +5 -3
- package/docs/permissions.md +1 -1
- package/package.json +6 -4
- package/dist/generated/INDEX.runtime.generated.d.ts +0 -6
- package/dist/generated/INDEX.ui.generated.d.ts +0 -4
- package/dist/generated/capabilityClients.generated.d.ts +0 -231
- package/dist/generated/hostBootstrap.generated.d.ts +0 -23
- package/dist/generated/runtime.host.generated.d.ts +0 -39
- package/dist/generated/topicSubscribers.generated.d.ts +0 -39
- package/dist/generated/ui.bootstrap.generated.d.ts +0 -17
- package/dist/internal/ipcBus.d.ts +0 -48
- package/dist/internal/runtimeInvokeClient.d.ts +0 -3
package/dist/runtime/index.js
CHANGED
|
@@ -1,76 +1,9 @@
|
|
|
1
|
-
// src/
|
|
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
|
-
materializeInputImagePath: () => ipcBus.request("action.materializeInputImagePath", {}),
|
|
54
|
-
allocateOutputFilePath: (payload) => ipcBus.request("action.allocateOutputFilePath", payload)
|
|
55
|
-
},
|
|
56
|
-
settings: {
|
|
57
|
-
get: (payload) => ipcBus.request("settings.get", payload),
|
|
58
|
-
getAll: () => ipcBus.request("settings.getAll", {})
|
|
59
|
-
},
|
|
60
|
-
console: {
|
|
61
|
-
log: (payload) => ipcBus.request("console.log", payload)
|
|
62
|
-
},
|
|
63
|
-
locale: {
|
|
64
|
-
get: () => ipcBus.request("locale.get", {})
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// src/generated/runtime.definePlugin.generated.ts
|
|
1
|
+
// src/runtime/definePlugin.ts
|
|
69
2
|
function definePlugin(definition) {
|
|
70
3
|
if ("setup" in definition) {
|
|
71
4
|
return {
|
|
72
|
-
setup() {
|
|
73
|
-
const registry = definition.setup();
|
|
5
|
+
setup(context) {
|
|
6
|
+
const registry = definition.setup(context);
|
|
74
7
|
validateRegistry(registry);
|
|
75
8
|
return registry;
|
|
76
9
|
}
|
|
@@ -82,14 +15,11 @@ function definePlugin(definition) {
|
|
|
82
15
|
} };
|
|
83
16
|
}
|
|
84
17
|
function validateRegistry(registry) {
|
|
85
|
-
for (const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
for (const [id, handler] of Object.entries(registry.actions ?? {})) {
|
|
91
|
-
if (handler && typeof handler === "object" && "invokeOperation" in handler) {
|
|
92
|
-
throw new Error(`actions["${id}"]: invokeOperation has been removed.`);
|
|
18
|
+
for (const key of ["attachmentRenderers", "actions"]) {
|
|
19
|
+
for (const [id, handler] of Object.entries(registry[key] ?? {})) {
|
|
20
|
+
if (handler && typeof handler === "object" && "invokeOperation" in handler) {
|
|
21
|
+
throw new Error(`${key}["${id}"]: invokeOperation has been removed.`);
|
|
22
|
+
}
|
|
93
23
|
}
|
|
94
24
|
}
|
|
95
25
|
}
|
|
@@ -136,6 +66,5 @@ export {
|
|
|
136
66
|
CapabilityUnsupportedError,
|
|
137
67
|
actionResult,
|
|
138
68
|
defineMessage,
|
|
139
|
-
definePlugin
|
|
140
|
-
host
|
|
69
|
+
definePlugin
|
|
141
70
|
};
|
package/dist/ui/index.cjs
CHANGED
|
@@ -31,6 +31,14 @@ module.exports = __toCommonJS(index_exports);
|
|
|
31
31
|
var STRUCTURED_ERROR_PREFIX = "__clipbus_structured_error__:";
|
|
32
32
|
var CAPABILITIES_GLOBAL = "__CLIPBUS_PLUGIN_CAPABILITIES__";
|
|
33
33
|
var CAPABILITY_UNSUPPORTED_ERROR_NAME = "PluginCapabilityUnsupported";
|
|
34
|
+
var PLUGIN_CALL_HANDLER_NAME = "clipbusPluginCall";
|
|
35
|
+
var WIRE_ERROR_NAMES = {
|
|
36
|
+
methodNotFound: "PluginRuntimeMethodNotFound",
|
|
37
|
+
handlerNotFound: "PluginRuntimeHandlerNotFound",
|
|
38
|
+
invocationExpired: "PluginRuntimeInvocationExpired",
|
|
39
|
+
hostCallLimitExceeded: "PluginRuntimeHostCallLimitExceeded",
|
|
40
|
+
hostBridgeUnavailable: "PluginHostBridgeUnavailable"
|
|
41
|
+
};
|
|
34
42
|
|
|
35
43
|
// src/internal/capabilities.ts
|
|
36
44
|
var CapabilityUnsupportedError = class extends Error {
|
|
@@ -65,35 +73,36 @@ function mapToCapabilityError(err, unsupportedName) {
|
|
|
65
73
|
return err;
|
|
66
74
|
}
|
|
67
75
|
|
|
68
|
-
// src/internal/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const handler = globalThis.webkit?.messageHandlers?.[HANDLER_NAME];
|
|
76
|
+
// src/internal/pluginCall.ts
|
|
77
|
+
async function callPluginMethod(method, payload) {
|
|
78
|
+
const handler = globalThis.webkit?.messageHandlers?.[PLUGIN_CALL_HANDLER_NAME];
|
|
72
79
|
if (!handler) {
|
|
73
|
-
|
|
80
|
+
const err = new Error("clipbus." + method + " is only available inside a Clipbus plugin WebView");
|
|
81
|
+
err.name = WIRE_ERROR_NAMES.hostBridgeUnavailable;
|
|
82
|
+
throw err;
|
|
74
83
|
}
|
|
75
84
|
const normalized = JSON.parse(JSON.stringify(payload));
|
|
76
|
-
let reply;
|
|
77
85
|
try {
|
|
78
|
-
|
|
86
|
+
return await handler.postMessage({ method, payload: normalized });
|
|
79
87
|
} catch (err) {
|
|
80
88
|
throw parseReplyError(err);
|
|
81
89
|
}
|
|
90
|
+
}
|
|
91
|
+
async function callRuntimeInvoke(payload) {
|
|
92
|
+
if (!globalThis.webkit?.messageHandlers?.[PLUGIN_CALL_HANDLER_NAME]) {
|
|
93
|
+
throw new Error("runtime.invoke is only available inside a Clipbus plugin WebView");
|
|
94
|
+
}
|
|
95
|
+
const reply = await callPluginMethod("runtime.invoke", payload);
|
|
82
96
|
return reply?.response;
|
|
83
97
|
}
|
|
84
98
|
function parseReplyError(raw) {
|
|
85
99
|
const message = extractMessage(raw);
|
|
86
100
|
if (message.startsWith(STRUCTURED_ERROR_PREFIX)) {
|
|
87
|
-
const json = message.slice(STRUCTURED_ERROR_PREFIX.length);
|
|
88
101
|
try {
|
|
89
|
-
const parsed = JSON.parse(
|
|
102
|
+
const parsed = JSON.parse(message.slice(STRUCTURED_ERROR_PREFIX.length));
|
|
90
103
|
const err = new Error(typeof parsed.message === "string" ? parsed.message : "");
|
|
91
|
-
if (typeof parsed.name === "string" && parsed.name.length > 0)
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
if (parsed.data !== void 0) {
|
|
95
|
-
err.data = parsed.data;
|
|
96
|
-
}
|
|
104
|
+
if (typeof parsed.name === "string" && parsed.name.length > 0) err.name = parsed.name;
|
|
105
|
+
if (parsed.data !== void 0) err.data = parsed.data;
|
|
97
106
|
return mapToCapabilityError(err, CAPABILITY_UNSUPPORTED_ERROR_NAME);
|
|
98
107
|
} catch {
|
|
99
108
|
return new Error(message);
|
|
@@ -111,44 +120,20 @@ function extractMessage(raw) {
|
|
|
111
120
|
return String(raw);
|
|
112
121
|
}
|
|
113
122
|
|
|
114
|
-
// src/generated/
|
|
115
|
-
var
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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 callAssetCurrentActionInputImageUrl = () => callPluginMethod("asset.currentActionInputImageUrl", {});
|
|
136
|
-
var callAssetCurrentActionInputPathReferenceImageUrl = (payload) => callPluginMethod("asset.currentActionInputPathReferenceImageUrl", payload);
|
|
137
|
-
var callClipboardCopyText = (payload) => callPluginMethod("clipboard.copyText", payload);
|
|
138
|
-
var callNavigationOpenUrl = (payload) => callPluginMethod("navigation.openUrl", payload);
|
|
139
|
-
var callNavigationRevealInFinder = (payload) => callPluginMethod("navigation.revealInFinder", payload);
|
|
140
|
-
var callNavigationOpenFilePath = (payload) => callPluginMethod("navigation.openFilePath", payload);
|
|
141
|
-
var callActionSetButtons = (payload) => callPluginMethod("action.setButtons", payload);
|
|
142
|
-
var callActionComplete = (payload) => callPluginMethod("action.complete", payload);
|
|
143
|
-
var callAttachmentRendererSetButtons = (payload) => callPluginMethod("attachmentRenderer.setButtons", payload);
|
|
144
|
-
var callWindowSetHeight = (payload) => callPluginMethod("window.setHeight", payload);
|
|
145
|
-
var callWindowAutoFit = () => callPluginMethod("window.autoFit", {});
|
|
146
|
-
var callInfoPanelOpen = (payload) => callPluginMethod("infoPanel.open", payload);
|
|
147
|
-
var callInfoPanelClose = (payload) => callPluginMethod("infoPanel.close", payload);
|
|
148
|
-
var callSettingsGet = (payload) => callPluginMethod("settings.get", payload);
|
|
149
|
-
var callSettingsGetAll = () => callPluginMethod("settings.getAll", {});
|
|
150
|
-
var callConsoleLog = (payload) => callPluginMethod("console.log", payload);
|
|
151
|
-
var callTextInputStateChanged = (payload) => callPluginMethod("textInput.stateChanged", payload);
|
|
123
|
+
// src/generated/hostEvents.generated.ts
|
|
124
|
+
var HOST_EVENT_WINDOW_GLOBALS = {
|
|
125
|
+
"clipbus-plugin-context": "__CLIPBUS_PLUGIN_CONTEXT__",
|
|
126
|
+
"clipbus-plugin-item": "__CLIPBUS_PLUGIN_ITEM__",
|
|
127
|
+
"clipbus-plugin-attachment": "__CLIPBUS_PLUGIN_ATTACHMENT__",
|
|
128
|
+
"clipbus-plugin-draft": "__CLIPBUS_PLUGIN_DRAFT__",
|
|
129
|
+
"clipbus-plugin-action-input": "__CLIPBUS_PLUGIN_ACTION_INPUT__",
|
|
130
|
+
"clipbus-plugin-theme": "__CLIPBUS_PLUGIN_THEME__",
|
|
131
|
+
"clipbus-plugin-attachment-host-invoke": null,
|
|
132
|
+
"clipbus-plugin-action-host-invoke": null,
|
|
133
|
+
"clipbus-plugin-info-panel-on-action": null,
|
|
134
|
+
"clipbus-plugin-info-panel-on-close": null,
|
|
135
|
+
"clipbus-plugin-locale": "__CLIPBUS_PLUGIN_LOCALE__"
|
|
136
|
+
};
|
|
152
137
|
|
|
153
138
|
// src/internal/topic.ts
|
|
154
139
|
function createTopic(initial) {
|
|
@@ -193,95 +178,36 @@ function readWindowGlobal(key) {
|
|
|
193
178
|
return window[key];
|
|
194
179
|
}
|
|
195
180
|
|
|
196
|
-
// src/
|
|
197
|
-
function
|
|
198
|
-
const handler = (e) => listener(e.detail);
|
|
199
|
-
globalThis.addEventListener("clipbus-plugin-context", handler);
|
|
200
|
-
return () => globalThis.removeEventListener("clipbus-plugin-context", handler);
|
|
201
|
-
}
|
|
202
|
-
function onItem(listener) {
|
|
203
|
-
const handler = (e) => listener(e.detail);
|
|
204
|
-
globalThis.addEventListener("clipbus-plugin-item", handler);
|
|
205
|
-
return () => globalThis.removeEventListener("clipbus-plugin-item", handler);
|
|
206
|
-
}
|
|
207
|
-
function onAttachment(listener) {
|
|
208
|
-
const handler = (e) => listener(e.detail);
|
|
209
|
-
globalThis.addEventListener("clipbus-plugin-attachment", handler);
|
|
210
|
-
return () => globalThis.removeEventListener("clipbus-plugin-attachment", handler);
|
|
211
|
-
}
|
|
212
|
-
function onDraft(listener) {
|
|
213
|
-
const handler = (e) => listener(e.detail);
|
|
214
|
-
globalThis.addEventListener("clipbus-plugin-draft", handler);
|
|
215
|
-
return () => globalThis.removeEventListener("clipbus-plugin-draft", handler);
|
|
216
|
-
}
|
|
217
|
-
function onActionInput(listener) {
|
|
181
|
+
// src/internal/hostEvents.ts
|
|
182
|
+
function onHostEvent(name, listener) {
|
|
218
183
|
const handler = (e) => listener(e.detail);
|
|
219
|
-
globalThis.addEventListener(
|
|
220
|
-
return () => globalThis.removeEventListener(
|
|
184
|
+
globalThis.addEventListener(name, handler);
|
|
185
|
+
return () => globalThis.removeEventListener(name, handler);
|
|
221
186
|
}
|
|
222
|
-
function
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
globalThis.addEventListener("clipbus-plugin-attachment-host-invoke", handler);
|
|
230
|
-
return () => globalThis.removeEventListener("clipbus-plugin-attachment-host-invoke", handler);
|
|
231
|
-
}
|
|
232
|
-
function onActionHostInvoke(listener) {
|
|
233
|
-
const handler = (e) => listener(e.detail);
|
|
234
|
-
globalThis.addEventListener("clipbus-plugin-action-host-invoke", handler);
|
|
235
|
-
return () => globalThis.removeEventListener("clipbus-plugin-action-host-invoke", handler);
|
|
187
|
+
function createHostTopic(name) {
|
|
188
|
+
const windowGlobal = HOST_EVENT_WINDOW_GLOBALS[name];
|
|
189
|
+
const topic = createTopic(
|
|
190
|
+
windowGlobal === null ? void 0 : readWindowGlobal(windowGlobal)
|
|
191
|
+
);
|
|
192
|
+
onHostEvent(name, (payload) => topic.set(payload));
|
|
193
|
+
return topic;
|
|
236
194
|
}
|
|
237
|
-
function
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
return
|
|
241
|
-
}
|
|
242
|
-
function onInfoPanelOnClose(listener) {
|
|
243
|
-
const handler = (e) => listener(e.detail);
|
|
244
|
-
globalThis.addEventListener("clipbus-plugin-info-panel-on-close", handler);
|
|
245
|
-
return () => globalThis.removeEventListener("clipbus-plugin-info-panel-on-close", handler);
|
|
246
|
-
}
|
|
247
|
-
function onLocale(listener) {
|
|
248
|
-
const handler = (e) => listener(e.detail);
|
|
249
|
-
globalThis.addEventListener("clipbus-plugin-locale", handler);
|
|
250
|
-
return () => globalThis.removeEventListener("clipbus-plugin-locale", handler);
|
|
195
|
+
function createHostStream(name) {
|
|
196
|
+
const stream = createStream();
|
|
197
|
+
onHostEvent(name, (payload) => stream.emit(payload));
|
|
198
|
+
return stream;
|
|
251
199
|
}
|
|
252
200
|
|
|
253
|
-
// src/
|
|
254
|
-
var _pluginContextTopic = createTopic(readWindowGlobal("__CLIPBUS_PLUGIN_CONTEXT__"));
|
|
255
|
-
onContext((p) => _pluginContextTopic.set(p));
|
|
256
|
-
var _itemTopic = createTopic(readWindowGlobal("__CLIPBUS_PLUGIN_ITEM__"));
|
|
257
|
-
onItem((p) => _itemTopic.set(p));
|
|
258
|
-
var _itemAttachmentTopic = createTopic(readWindowGlobal("__CLIPBUS_PLUGIN_ATTACHMENT__"));
|
|
259
|
-
onAttachment((p) => _itemAttachmentTopic.set(p));
|
|
260
|
-
var _actionDraftTopic = createTopic(readWindowGlobal("__CLIPBUS_PLUGIN_DRAFT__"));
|
|
261
|
-
onDraft((p) => _actionDraftTopic.set(p));
|
|
262
|
-
var _actionInputTopic = createTopic(readWindowGlobal("__CLIPBUS_PLUGIN_ACTION_INPUT__"));
|
|
263
|
-
onActionInput((p) => _actionInputTopic.set(p));
|
|
264
|
-
var _themeTopic = createTopic(readWindowGlobal("__CLIPBUS_PLUGIN_THEME__"));
|
|
265
|
-
onTheme((p) => _themeTopic.set(p));
|
|
266
|
-
var _attachmentRendererOnHostInvokeStream = createStream();
|
|
267
|
-
onAttachmentHostInvoke((p) => _attachmentRendererOnHostInvokeStream.emit(p));
|
|
268
|
-
var _actionOnHostInvokeStream = createStream();
|
|
269
|
-
onActionHostInvoke((p) => _actionOnHostInvokeStream.emit(p));
|
|
270
|
-
var _infoPanelOnActionStream = createStream();
|
|
271
|
-
onInfoPanelOnAction((p) => _infoPanelOnActionStream.emit(p));
|
|
272
|
-
var _infoPanelOnCloseStream = createStream();
|
|
273
|
-
onInfoPanelOnClose((p) => _infoPanelOnCloseStream.emit(p));
|
|
274
|
-
var _localeTopic = createTopic(readWindowGlobal("__CLIPBUS_PLUGIN_LOCALE__"));
|
|
275
|
-
onLocale((p) => _localeTopic.set(p));
|
|
201
|
+
// src/internal/pluginContext.ts
|
|
276
202
|
var PluginContextError = class extends Error {
|
|
277
203
|
constructor(message) {
|
|
278
204
|
super(message);
|
|
279
205
|
this.name = "PluginContextError";
|
|
280
206
|
}
|
|
281
207
|
};
|
|
282
|
-
function guardContext(expected, run) {
|
|
208
|
+
function guardContext(contextTopic, expected, run) {
|
|
283
209
|
return (...args) => {
|
|
284
|
-
const current =
|
|
210
|
+
const current = contextTopic.current()?.mode;
|
|
285
211
|
if (current !== expected) {
|
|
286
212
|
throw new PluginContextError(
|
|
287
213
|
`This verb is not available in the current plugin context (expected: ${expected}, got: ${current || "unknown"})`
|
|
@@ -292,90 +218,102 @@ function guardContext(expected, run) {
|
|
|
292
218
|
}
|
|
293
219
|
|
|
294
220
|
// src/generated/ui.clipbus.generated.ts
|
|
221
|
+
var pluginContextTopic = createHostTopic("clipbus-plugin-context");
|
|
222
|
+
var itemTopic = createHostTopic("clipbus-plugin-item");
|
|
223
|
+
var itemAttachmentTopic = createHostTopic("clipbus-plugin-attachment");
|
|
224
|
+
var actionDraftTopic = createHostTopic("clipbus-plugin-draft");
|
|
225
|
+
var actionInputTopic = createHostTopic("clipbus-plugin-action-input");
|
|
226
|
+
var themeTopic = createHostTopic("clipbus-plugin-theme");
|
|
227
|
+
var attachmentRendererOnHostInvokeStream = createHostStream("clipbus-plugin-attachment-host-invoke");
|
|
228
|
+
var actionOnHostInvokeStream = createHostStream("clipbus-plugin-action-host-invoke");
|
|
229
|
+
var infoPanelOnActionStream = createHostStream("clipbus-plugin-info-panel-on-action");
|
|
230
|
+
var infoPanelOnCloseStream = createHostStream("clipbus-plugin-info-panel-on-close");
|
|
231
|
+
var localeTopic = createHostTopic("clipbus-plugin-locale");
|
|
295
232
|
var clipbus = {
|
|
296
233
|
capabilities: createCapabilitiesApi(() => readInjectedCapabilities(globalThis, CAPABILITIES_GLOBAL)),
|
|
297
234
|
runtime: {
|
|
298
|
-
invoke: (payload) =>
|
|
235
|
+
invoke: (payload) => callRuntimeInvoke(payload)
|
|
299
236
|
},
|
|
300
237
|
item: {
|
|
301
|
-
current:
|
|
302
|
-
on:
|
|
303
|
-
readAttachment: (payload) =>
|
|
238
|
+
current: itemTopic.current,
|
|
239
|
+
on: itemTopic.on,
|
|
240
|
+
readAttachment: (payload) => callPluginMethod("item.readAttachment", payload),
|
|
304
241
|
attachment: {
|
|
305
|
-
current:
|
|
306
|
-
on:
|
|
242
|
+
current: itemAttachmentTopic.current,
|
|
243
|
+
on: itemAttachmentTopic.on
|
|
307
244
|
}
|
|
308
245
|
},
|
|
309
246
|
asset: {
|
|
310
|
-
currentItemImageUrl: () =>
|
|
311
|
-
pathReferenceImageUrl: (payload) =>
|
|
312
|
-
currentActionInputImageUrl: guardContext("action", () =>
|
|
313
|
-
currentActionInputPathReferenceImageUrl: guardContext("action", (payload) =>
|
|
247
|
+
currentItemImageUrl: () => callPluginMethod("asset.currentItemImageUrl", {}),
|
|
248
|
+
pathReferenceImageUrl: (payload) => callPluginMethod("asset.pathReferenceImageUrl", payload),
|
|
249
|
+
currentActionInputImageUrl: guardContext(pluginContextTopic, "action", () => callPluginMethod("asset.currentActionInputImageUrl", {})),
|
|
250
|
+
currentActionInputPathReferenceImageUrl: guardContext(pluginContextTopic, "action", (payload) => callPluginMethod("asset.currentActionInputPathReferenceImageUrl", payload))
|
|
314
251
|
},
|
|
315
252
|
clipboard: {
|
|
316
|
-
copyText: (payload) =>
|
|
253
|
+
copyText: (payload) => callPluginMethod("clipboard.copyText", payload)
|
|
317
254
|
},
|
|
318
255
|
navigation: {
|
|
319
|
-
openUrl: (payload) =>
|
|
320
|
-
revealInFinder: (payload) =>
|
|
321
|
-
openFilePath: (payload) =>
|
|
256
|
+
openUrl: (payload) => callPluginMethod("navigation.openUrl", payload),
|
|
257
|
+
revealInFinder: (payload) => callPluginMethod("navigation.revealInFinder", payload),
|
|
258
|
+
openFilePath: (payload) => callPluginMethod("navigation.openFilePath", payload)
|
|
322
259
|
},
|
|
323
260
|
action: {
|
|
324
|
-
setButtons: guardContext("action", (payload) =>
|
|
325
|
-
complete: guardContext("action", (payload) =>
|
|
261
|
+
setButtons: guardContext(pluginContextTopic, "action", (payload) => callPluginMethod("action.setButtons", payload)),
|
|
262
|
+
complete: guardContext(pluginContextTopic, "action", (payload) => callPluginMethod("action.complete", payload)),
|
|
326
263
|
draft: {
|
|
327
|
-
current:
|
|
328
|
-
on:
|
|
264
|
+
current: actionDraftTopic.current,
|
|
265
|
+
on: actionDraftTopic.on
|
|
329
266
|
},
|
|
330
267
|
input: {
|
|
331
|
-
current:
|
|
332
|
-
on:
|
|
268
|
+
current: actionInputTopic.current,
|
|
269
|
+
on: actionInputTopic.on
|
|
333
270
|
},
|
|
334
271
|
onHostInvoke: {
|
|
335
|
-
on:
|
|
272
|
+
on: actionOnHostInvokeStream.on
|
|
336
273
|
}
|
|
337
274
|
},
|
|
338
275
|
attachmentRenderer: {
|
|
339
|
-
setButtons: guardContext("attachmentRenderer", (payload) =>
|
|
276
|
+
setButtons: guardContext(pluginContextTopic, "attachmentRenderer", (payload) => callPluginMethod("attachmentRenderer.setButtons", payload)),
|
|
340
277
|
onHostInvoke: {
|
|
341
|
-
on:
|
|
278
|
+
on: attachmentRendererOnHostInvokeStream.on
|
|
342
279
|
}
|
|
343
280
|
},
|
|
344
281
|
window: {
|
|
345
|
-
setHeight: (payload) =>
|
|
346
|
-
autoFit: () =>
|
|
282
|
+
setHeight: (payload) => callPluginMethod("window.setHeight", payload),
|
|
283
|
+
autoFit: () => callPluginMethod("window.autoFit", {})
|
|
347
284
|
},
|
|
348
285
|
infoPanel: {
|
|
349
|
-
open: (payload) =>
|
|
350
|
-
close: (payload) =>
|
|
286
|
+
open: (payload) => callPluginMethod("infoPanel.open", payload),
|
|
287
|
+
close: (payload) => callPluginMethod("infoPanel.close", payload),
|
|
351
288
|
onAction: {
|
|
352
|
-
on:
|
|
289
|
+
on: infoPanelOnActionStream.on
|
|
353
290
|
},
|
|
354
291
|
onClose: {
|
|
355
|
-
on:
|
|
292
|
+
on: infoPanelOnCloseStream.on
|
|
356
293
|
}
|
|
357
294
|
},
|
|
358
295
|
settings: {
|
|
359
|
-
get: (payload) =>
|
|
360
|
-
getAll: () =>
|
|
296
|
+
get: (payload) => callPluginMethod("settings.get", payload),
|
|
297
|
+
getAll: () => callPluginMethod("settings.getAll", {})
|
|
361
298
|
},
|
|
362
299
|
console: {
|
|
363
|
-
log: (payload) =>
|
|
300
|
+
log: (payload) => callPluginMethod("console.log", payload),
|
|
301
|
+
diagnostic: (payload) => callPluginMethod("console.diagnostic", payload)
|
|
364
302
|
},
|
|
365
303
|
textInput: {
|
|
366
|
-
stateChanged: (payload) =>
|
|
304
|
+
stateChanged: (payload) => callPluginMethod("textInput.stateChanged", payload)
|
|
367
305
|
},
|
|
368
306
|
pluginContext: {
|
|
369
|
-
current:
|
|
370
|
-
on:
|
|
307
|
+
current: pluginContextTopic.current,
|
|
308
|
+
on: pluginContextTopic.on
|
|
371
309
|
},
|
|
372
310
|
theme: {
|
|
373
|
-
current:
|
|
374
|
-
on:
|
|
311
|
+
current: themeTopic.current,
|
|
312
|
+
on: themeTopic.on
|
|
375
313
|
},
|
|
376
314
|
locale: {
|
|
377
|
-
current:
|
|
378
|
-
on:
|
|
315
|
+
current: localeTopic.current,
|
|
316
|
+
on: localeTopic.on
|
|
379
317
|
}
|
|
380
318
|
};
|
|
381
319
|
|
package/dist/ui/index.d.cts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { clipbus } from '../generated/ui.clipbus.generated.js';
|
|
2
|
+
export { PluginContextError } from '../internal/pluginContext.js';
|
|
2
3
|
export { defineMessage } from './defineMessage.js';
|
|
3
4
|
export type { UIMessageContract } from './defineMessage.js';
|
|
4
5
|
export { CapabilityUnsupportedError } from '../internal/capabilities.js';
|
|
6
|
+
export type * from '../generated/data.generated.js';
|
|
7
|
+
export type * from '../generated/capabilities.generated.js';
|
|
8
|
+
export type { PluginContextPayload, PluginLocalePayload } from '../generated/hostEvents.generated.js';
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { clipbus } from '../generated/ui.clipbus.generated.js';
|
|
2
|
+
export { PluginContextError } from '../internal/pluginContext.js';
|
|
2
3
|
export { defineMessage } from './defineMessage.js';
|
|
3
4
|
export type { UIMessageContract } from './defineMessage.js';
|
|
4
5
|
export { CapabilityUnsupportedError } from '../internal/capabilities.js';
|
|
6
|
+
export type * from '../generated/data.generated.js';
|
|
7
|
+
export type * from '../generated/capabilities.generated.js';
|
|
8
|
+
export type { PluginContextPayload, PluginLocalePayload } from '../generated/hostEvents.generated.js';
|