@eworkbase/sdk 0.8.5 → 0.8.7

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/dist/ui/index.js CHANGED
@@ -1,366 +1,3 @@
1
- import { WindowMessenger, connect } from "penpal";
2
- //#region src/ui/controller.ts
3
- const MAX_CONTENT_HEIGHT = 1e4;
4
- const MAX_FATAL_MESSAGE_LENGTH = 1e3;
5
- const MIN_CONTENT_HEIGHT = 1;
6
- let PluginUiHostMethod = /* @__PURE__ */ function(PluginUiHostMethod) {
7
- PluginUiHostMethod["InteractionDismiss"] = "interaction.dismiss";
8
- PluginUiHostMethod["InteractionRespond"] = "interaction.respond";
9
- PluginUiHostMethod["CommandSubscribe"] = "command.subscribe";
10
- PluginUiHostMethod["CommandCancel"] = "command.cancel";
11
- PluginUiHostMethod["CommandStart"] = "command.start";
12
- PluginUiHostMethod["CommandQuery"] = "command.query";
13
- PluginUiHostMethod["CommandReply"] = "command.reply";
14
- PluginUiHostMethod["CommandClear"] = "command.clear";
15
- PluginUiHostMethod["CommandExecute"] = "command.execute";
16
- PluginUiHostMethod["DialogPrompt"] = "dialog.prompt";
17
- PluginUiHostMethod["DesktopOpen"] = "desktop.open";
18
- PluginUiHostMethod["RepositoryAuthorizePush"] = "repository.authorizePush";
19
- PluginUiHostMethod["RepositoryPush"] = "repository.push";
20
- PluginUiHostMethod["FileSelect"] = "file.select";
21
- PluginUiHostMethod["Navigate"] = "navigate";
22
- PluginUiHostMethod["OutputOpen"] = "output.open";
23
- PluginUiHostMethod["StatusResolve"] = "status.resolve";
24
- PluginUiHostMethod["ToastShow"] = "toast.show";
25
- PluginUiHostMethod["ViewCall"] = "view.call";
26
- PluginUiHostMethod["ViewModified"] = "view.modified";
27
- return PluginUiHostMethod;
28
- }({});
29
- function createPluginUiController(definition, options) {
30
- const onInit = definition?.onInit;
31
- const connectToHost = options?.connectToHost;
32
- const targetWindow = options?.targetWindow;
33
- if (typeof onInit !== "function") throw new TypeError("defineWorkbasePluginUi requires an onInit callback.");
34
- if (!targetWindow || typeof connectToHost !== "function") throw new TypeError("Plugin UI transport is unavailable.");
35
- const state = {
36
- fatalReportPromise: null,
37
- isInitialized: false,
38
- isFillLayout: false,
39
- supportsRepositoryPush: false,
40
- supportsRepositoryPushAuthorization: false,
41
- contentHeight: null,
42
- workspaceId: null,
43
- recoverableHostErrors: /* @__PURE__ */ new WeakSet()
44
- };
45
- const executionListeners = /* @__PURE__ */ new Set();
46
- const fileListeners = /* @__PURE__ */ new Set();
47
- let initialization = 0;
48
- let refreshing = false;
49
- let pending = false;
50
- let lifecycle = null;
51
- const clientMethods = {
52
- filesChanged: async () => {
53
- pending = true;
54
- if (refreshing || initialization || !state.isInitialized) return;
55
- refreshing = true;
56
- try {
57
- while (pending) {
58
- pending = false;
59
- await Promise.all([...fileListeners].map((refresh) => refresh()));
60
- }
61
- } finally {
62
- refreshing = false;
63
- }
64
- },
65
- executionChanged: async (change) => {
66
- if (state.isInitialized) [...executionListeners].forEach((listener) => listener(change));
67
- },
68
- initialize: async (payload) => {
69
- assertInitializationPayload(payload);
70
- state.isInitialized = true;
71
- state.isFillLayout = payload.layout === "fill";
72
- state.workspaceId = payload.workspace.id;
73
- state.supportsRepositoryPush = payload.supportsRepositoryPush === true;
74
- state.supportsRepositoryPushAuthorization = payload.supportsRepositoryPushAuthorization === true;
75
- initialization++;
76
- try {
77
- await onInit(payload);
78
- } finally {
79
- initialization--;
80
- }
81
- if (pending) await clientMethods.filesChanged();
82
- if (state.isFillLayout) return;
83
- lifecycle?.observeContentHeight();
84
- await waitForPluginUiPaint(targetWindow);
85
- await reportContentHeight(hostPromise, {
86
- targetWindow,
87
- state
88
- });
89
- }
90
- };
91
- const connection = connectToHost(clientMethods);
92
- const hostPromise = connection.promise;
93
- const request = createHostRequest(hostPromise, state);
94
- lifecycle = bindPluginUiLifecycle({
95
- connection,
96
- state,
97
- targetWindow
98
- });
99
- const dispose = () => {
100
- executionListeners.clear();
101
- fileListeners.clear();
102
- lifecycle?.dispose();
103
- };
104
- const subscribe = async (onChange) => {
105
- const listener = (change) => onChange(change);
106
- executionListeners.add(listener);
107
- try {
108
- await request("command.subscribe", { enabled: true });
109
- } catch (error) {
110
- executionListeners.delete(listener);
111
- throw error;
112
- }
113
- return async () => {
114
- if (!executionListeners.delete(listener) || executionListeners.size) return;
115
- await request("command.subscribe", { enabled: false });
116
- };
117
- };
118
- const onFilesChanged = (refresh) => {
119
- fileListeners.add(refresh);
120
- return () => {
121
- fileListeners.delete(refresh);
122
- };
123
- };
124
- return createPluginUiApi(request, {
125
- targetWindow,
126
- state,
127
- dispose,
128
- subscribe,
129
- onFilesChanged
130
- });
131
- }
132
- function createHostRequest(hostPromise, state) {
133
- return async (method, params) => {
134
- if (!state.isInitialized) throw new Error("插件界面尚未初始化完成。");
135
- if (method === "repository.push" && !state.supportsRepositoryPush || method === "repository.authorizePush" && !state.supportsRepositoryPushAuthorization) {
136
- const error = /* @__PURE__ */ new Error("当前 Workbase 版本无法在插件内推送,请在工作区同步仓库。");
137
- state.recoverableHostErrors.add(error);
138
- throw error;
139
- }
140
- const response = await (await hostPromise).call(method, params);
141
- if (isRecord(response) && response.ok === true) return response.result;
142
- const error = createHostError(response);
143
- state.recoverableHostErrors.add(error);
144
- throw error;
145
- };
146
- }
147
- function createHostError(response) {
148
- const responseError = isRecord(response) && isRecord(response.error) ? response.error : null;
149
- const message = typeof responseError?.message === "string" ? responseError.message : "宿主操作未完成。";
150
- const code = typeof responseError?.code === "string" ? responseError.code : "host_error";
151
- return Object.assign(new Error(message), { code });
152
- }
153
- function createPluginUiApi(request, { targetWindow, state, dispose, subscribe, onFilesChanged }) {
154
- const commands = Object.freeze({
155
- subscribe,
156
- reply: (executionId) => request("command.reply", { executionId }),
157
- clear: (executionId) => request("command.clear", executionId === void 0 ? {} : { executionId }),
158
- start: (commandId, input, options = {}) => request("command.start", {
159
- commandId,
160
- input,
161
- executionId: options.executionId ?? targetWindow.crypto.randomUUID()
162
- }),
163
- query: (executionId) => request("command.query", { executionId: executionId ?? null }),
164
- cancel: (executionId) => request("command.cancel", { executionId }),
165
- execute: (commandId, input, options = {}) => {
166
- return request("command.execute", {
167
- commandId,
168
- executionId: options.executionId ?? targetWindow.crypto.randomUUID(),
169
- input
170
- });
171
- }
172
- });
173
- const status = Object.freeze({ resolve: (statusId, input) => request("status.resolve", {
174
- input,
175
- statusId
176
- }) });
177
- const view = Object.freeze({
178
- onFilesChanged,
179
- setModified: (modified) => request("view.modified", modified),
180
- call: (method, input) => request("view.call", {
181
- input,
182
- method
183
- })
184
- });
185
- const navigate = (to, { replace = false } = {}) => request("navigate", {
186
- replace,
187
- to
188
- });
189
- const openPluginView = async ({ pluginId, viewId, workspaceId, route, params, replace = false }) => {
190
- const resolvedWorkspaceId = workspaceId ?? state.workspaceId;
191
- const search = new URLSearchParams({ viewId });
192
- if (resolvedWorkspaceId) search.set("workspaceId", resolvedWorkspaceId);
193
- if (route) search.set("route", route);
194
- if (params && Object.keys(params).length > 0) search.set("params", JSON.stringify(params));
195
- await navigate(`/plugins/${encodeURIComponent(pluginId)}?${search.toString()}`, { replace });
196
- };
197
- return Object.freeze({
198
- dispose,
199
- dismiss: () => request("interaction.dismiss", {}),
200
- respond: (value) => request("interaction.respond", { value }),
201
- commands,
202
- desktop: Object.freeze({ open: (options) => request("desktop.open", options) }),
203
- repositories: Object.freeze({
204
- authorizePush: (repositoryIds) => request("repository.authorizePush", repositoryIds),
205
- push: (targets, authorizationId) => request("repository.push", authorizationId === void 0 ? targets : {
206
- targets,
207
- authorizationId
208
- })
209
- }),
210
- navigate,
211
- openPluginView,
212
- openOutput: (options) => request("output.open", options),
213
- selectFiles: (options = {}) => request("file.select", options),
214
- showPrompt: (options) => request("dialog.prompt", options),
215
- showToast: (options) => request("toast.show", options),
216
- status,
217
- view
218
- });
219
- }
220
- function bindPluginUiLifecycle({ connection, state, targetWindow }) {
221
- let resizeFrame = null;
222
- let resizeObserver = null;
223
- let isDisposed = false;
224
- const handleWindowError = (event) => {
225
- if (!event.error && (event.message === "ResizeObserver loop completed with undelivered notifications." || event.message === "ResizeObserver loop limit exceeded")) return;
226
- reportFirstFatal(connection.promise, state, event.error ?? event.message);
227
- };
228
- const handleUnhandledRejection = (event) => {
229
- if (event.reason instanceof Error && state.recoverableHostErrors.has(event.reason)) return;
230
- reportFirstFatal(connection.promise, state, event.reason);
231
- };
232
- const startObservingHeight = () => {
233
- if (isDisposed || resizeObserver || state.isFillLayout) return;
234
- resizeObserver = new targetWindow.ResizeObserver(() => {
235
- if (resizeFrame !== null) return;
236
- resizeFrame = targetWindow.requestAnimationFrame(() => {
237
- resizeFrame = null;
238
- if (state.isInitialized && !state.isFillLayout) reportContentHeight(connection.promise, {
239
- targetWindow,
240
- state
241
- });
242
- });
243
- });
244
- resizeObserver.observe(targetWindow.document.body ?? targetWindow.document.documentElement);
245
- };
246
- const cleanup = () => {
247
- if (isDisposed) return;
248
- isDisposed = true;
249
- targetWindow.removeEventListener("error", handleWindowError, true);
250
- targetWindow.removeEventListener("unhandledrejection", handleUnhandledRejection);
251
- targetWindow.removeEventListener("beforeunload", cleanup);
252
- resizeObserver?.disconnect();
253
- resizeObserver = null;
254
- if (resizeFrame !== null) targetWindow.cancelAnimationFrame(resizeFrame);
255
- connection.destroy();
256
- state.fatalReportPromise = null;
257
- state.isInitialized = false;
258
- };
259
- ignoreConnectionFailure(connection.promise);
260
- targetWindow.addEventListener("error", handleWindowError, true);
261
- targetWindow.addEventListener("unhandledrejection", handleUnhandledRejection);
262
- targetWindow.addEventListener("beforeunload", cleanup, { once: true });
263
- return {
264
- observeContentHeight: startObservingHeight,
265
- dispose: cleanup
266
- };
267
- }
268
- async function ignoreConnectionFailure(hostPromise) {
269
- try {
270
- await hostPromise;
271
- } catch {}
272
- }
273
- async function waitForPluginUiPaint(targetWindow) {
274
- await new Promise((resolve) => {
275
- targetWindow.requestAnimationFrame(() => {
276
- targetWindow.requestAnimationFrame(() => resolve());
277
- });
278
- });
279
- }
280
- async function reportFirstFatal(hostPromise, state, error) {
281
- if (!state.fatalReportPromise) state.fatalReportPromise = sendFatalReport(hostPromise, getFatalMessage(error).slice(0, MAX_FATAL_MESSAGE_LENGTH));
282
- await state.fatalReportPromise;
283
- }
284
- async function sendFatalReport(hostPromise, message) {
285
- try {
286
- await (await hostPromise).reportFatal(message);
287
- } catch {}
288
- }
289
- async function reportContentHeight(hostPromise, { targetWindow, state }) {
290
- const contentElement = targetWindow.document.body ?? targetWindow.document.documentElement;
291
- const height = Math.max(contentElement.offsetHeight, contentElement.scrollHeight);
292
- if (!Number.isFinite(height)) return;
293
- try {
294
- const host = await hostPromise;
295
- const contentHeight = Math.min(Math.max(Math.ceil(height), MIN_CONTENT_HEIGHT), MAX_CONTENT_HEIGHT);
296
- if (!state.isInitialized || state.contentHeight === contentHeight) return;
297
- state.contentHeight = contentHeight;
298
- await host.reportContentHeight(contentHeight);
299
- } catch {}
300
- }
301
- function assertInitializationPayload(value) {
302
- if (!isInitializationPayload(value)) throw new TypeError("插件界面初始化参数无效。");
303
- }
304
- function isInitializationPayload(value) {
305
- if (!isRecord(value)) return false;
306
- if (value.configurationRevision !== void 0 && typeof value.configurationRevision !== "string") return false;
307
- if (value.activationGeneration !== void 0 && (!Number.isSafeInteger(value.activationGeneration) || Number(value.activationGeneration) < 0)) return false;
308
- return isContextIdentity(value.project) && isContextIdentity(value.workspace) && isViewIdentity(value.view);
309
- }
310
- function isContextIdentity(value) {
311
- return isRecord(value) && typeof value.id === "string" && value.id.length > 0;
312
- }
313
- function isViewIdentity(value) {
314
- return isContextIdentity(value) && isRecord(value) && typeof value.pluginId === "string" && value.pluginId.length > 0 && typeof value.title === "string" && value.title.length > 0;
315
- }
316
- function isRecord(value) {
317
- return value !== null && typeof value === "object" && !Array.isArray(value);
318
- }
319
- function getFatalMessage(error) {
320
- if (error instanceof Error) return error.message;
321
- if (typeof error === "string" && error.trim().length > 0) return error;
322
- return "插件界面遇到异常。";
323
- }
324
- //#endregion
325
- //#region src/ui/types.ts
326
- let PluginDesktopTarget = /* @__PURE__ */ function(PluginDesktopTarget) {
327
- PluginDesktopTarget["Editor"] = "editor";
328
- PluginDesktopTarget["Terminal"] = "terminal";
329
- PluginDesktopTarget["Folder"] = "folder";
330
- PluginDesktopTarget["Chatgpt"] = "chatgpt";
331
- return PluginDesktopTarget;
332
- }({});
333
- //#endregion
334
- //#region src/ui/index.ts
335
- /**
336
- * Penpal browser entry for trusted Workbase plugin views.
337
- */
338
- const BRIDGE_CHANNEL = "workbase-plugin-ui-v1";
339
- const HOST_ORIGIN_PARAMETER = "__workbaseHostOrigin";
340
- function defineWorkbasePluginUi(definition) {
341
- const targetWindow = window;
342
- return createPluginUiController(definition, {
343
- connectToHost: (methods) => createPenpalConnection(targetWindow, methods),
344
- targetWindow
345
- });
346
- }
347
- function createPenpalConnection(targetWindow, methods) {
348
- const connection = connect({
349
- channel: BRIDGE_CHANNEL,
350
- messenger: new WindowMessenger({
351
- allowedOrigins: resolveParentOrigins(targetWindow),
352
- remoteWindow: targetWindow.parent
353
- }),
354
- methods
355
- });
356
- return {
357
- destroy: connection.destroy,
358
- promise: connection.promise
359
- };
360
- }
361
- function resolveParentOrigins(targetWindow) {
362
- const hostOrigin = new URL(targetWindow.location.href).searchParams.get(HOST_ORIGIN_PARAMETER);
363
- return hostOrigin && hostOrigin !== "null" ? [hostOrigin] : ["*"];
364
- }
365
- //#endregion
366
- export { PluginDesktopTarget, PluginUiHostMethod, createPluginUiController, defineWorkbasePluginUi };
1
+ import { t as DEFAULT_VIEW_STATE_TOPIC } from "../host-services-cIH3aYQD.js";
2
+ import { a as createPluginUiController, i as PluginUiHostMethod, n as defineWorkbasePluginUi, r as PluginDesktopTarget, t as createPluginClient } from "../ui-DC0oqP79.js";
3
+ export { DEFAULT_VIEW_STATE_TOPIC, PluginDesktopTarget, PluginUiHostMethod, createPluginClient, createPluginUiController, defineWorkbasePluginUi };
@@ -1,4 +1,4 @@
1
- import { j as WorkbasePluginUi } from "../types-CPObI29j.js";
1
+ import { N as WorkbasePluginUi } from "../types-3v3whlPt.js";
2
2
  import { ReactNode } from "react";
3
3
  //#region src/ui/MarkdownLinks.dto.d.ts
4
4
  interface MarkdownLinksProps {
@@ -1,4 +1,4 @@
1
- import { D as PluginUiToastOptions, j as WorkbasePluginUi } from "../types-CPObI29j.js";
1
+ import { N as WorkbasePluginUi, k as PluginUiToastOptions } from "../types-3v3whlPt.js";
2
2
  //#region src/ui/model.d.ts
3
3
  /** A notification transport failure must not turn a completed operation into a failed one. */
4
4
  export declare function showOperationToast(host: Pick<WorkbasePluginUi, "showToast">, options: PluginUiToastOptions): void;
package/dist/ui/theme.css CHANGED
@@ -273,6 +273,12 @@
273
273
  .workbase-plugin-error .workbase-error-title { flex: 1; min-width: 0; margin: 0; color: var(--color-foreground); font-size: var(--workbase-type-body); font-weight: 650; line-height: 1.45; }
274
274
  .workbase-error-body { margin-inline-start: 28px; }
275
275
  .workbase-plugin-error .workbase-error-cause { max-width: 75ch; margin: 0; color: var(--color-foreground); font-size: var(--workbase-type-body); font-weight: 400; line-height: 1.55; white-space: pre-wrap; }
276
+ .workbase-plugin-error[data-variant="compact"] { padding: 8px 12px; }
277
+ .workbase-plugin-error[data-variant="compact"] .workbase-error-header { flex-wrap: wrap; gap: 6px 10px; }
278
+ .workbase-error-compact-copy { display: flex; flex: 1 1 24ch; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; min-width: 0; }
279
+ .workbase-plugin-error[data-variant="compact"] .workbase-error-title { flex: 0 1 auto; font-size: var(--workbase-type-meta); }
280
+ .workbase-plugin-error[data-variant="compact"] .workbase-error-cause { flex: 1 1 24ch; min-width: 0; color: var(--color-muted); font-size: var(--workbase-type-meta); line-height: 1.45; }
281
+ .workbase-error-compact-actions { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-inline-start: auto; }
276
282
  .workbase-error-actions, .workbase-inline-error { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
277
283
  .workbase-error-actions { margin-block-start: 10px; }
278
284
  .workbase-error-toggle, .workbase-error-disclosure, .workbase-inline-error > button {
@@ -356,6 +362,73 @@
356
362
  }
357
363
  @keyframes workbase-spin { to { transform: rotate(360deg); } }
358
364
 
365
+ .workbase-publish-button {
366
+ display: inline-flex;
367
+ align-items: center;
368
+ justify-content: center;
369
+ gap: 7px;
370
+ min-height: 36px;
371
+ padding: 6px 12px 6px 13px;
372
+ border: 1px solid color-mix(in srgb, var(--color-brand-gold) 52%, transparent);
373
+ border-radius: 8px;
374
+ background: var(--color-primary);
375
+ color: var(--color-primary-foreground);
376
+ box-shadow: 0 1px 3px rgb(138 80 0 / 16%);
377
+ font: inherit;
378
+ font-size: var(--workbase-type-body);
379
+ font-weight: 600;
380
+ line-height: 1.25;
381
+ white-space: nowrap;
382
+ cursor: pointer;
383
+ transition: background-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
384
+ }
385
+ .workbase-publish-button:hover:not(:disabled) {
386
+ background: var(--color-primary-hover);
387
+ box-shadow: 0 2px 6px rgb(138 80 0 / 22%);
388
+ }
389
+ .workbase-publish-button:active:not(:disabled) {
390
+ transform: translateY(1px);
391
+ }
392
+ .workbase-publish-button:disabled {
393
+ opacity: 0.55;
394
+ cursor: not-allowed;
395
+ box-shadow: none;
396
+ }
397
+ .workbase-publish-button:focus-visible {
398
+ outline: 2px solid var(--color-accent);
399
+ outline-offset: 2px;
400
+ }
401
+ .workbase-publish-icon {
402
+ display: inline-flex;
403
+ align-items: center;
404
+ justify-content: center;
405
+ width: 15px;
406
+ height: 15px;
407
+ flex-shrink: 0;
408
+ }
409
+ .workbase-publish-icon svg {
410
+ width: 15px;
411
+ height: 15px;
412
+ }
413
+ .workbase-publish-label {
414
+ min-width: 0;
415
+ }
416
+ .workbase-publish-count {
417
+ display: inline-flex;
418
+ align-items: center;
419
+ justify-content: center;
420
+ min-width: 20px;
421
+ height: 20px;
422
+ padding: 0 6px;
423
+ border-radius: 999px;
424
+ background: var(--color-brand-deep);
425
+ color: var(--color-brand-weak);
426
+ font-size: 11px;
427
+ font-weight: 700;
428
+ line-height: 1;
429
+ font-variant-numeric: tabular-nums;
430
+ }
431
+
359
432
  .workbase-empty-state {
360
433
  display: grid;
361
434
  min-height: 140px;