@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/{ExecutionLog.dto-Bq2u5C90.d.ts → ExecutionLog.dto-ig9GUWhK.d.ts} +1 -1
- package/dist/build.d.ts +54 -0
- package/dist/build.js +78 -0
- package/dist/components-V_fFZLTU.js +171 -0
- package/dist/host-services-cIH3aYQD.js +5 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/markdown.d.ts +1 -1
- package/dist/{types-CPObI29j.d.ts → types-3v3whlPt.d.ts} +22 -2
- package/dist/{types-WIMkhmH4.d.ts → types-D1Ezgwbv.d.ts} +24 -2
- package/dist/ui/components.d.ts +9 -2
- package/dist/ui/components.js +2 -131
- package/dist/ui/error-panel.d.ts +1 -0
- package/dist/ui/error-panel.js +68 -2
- package/dist/ui/execution-log.d.ts +1 -1
- package/dist/ui/hooks.d.ts +70 -0
- package/dist/ui/hooks.js +262 -0
- package/dist/ui/index.css +10 -1
- package/dist/ui/index.d.ts +24 -3
- package/dist/ui/index.js +3 -366
- package/dist/ui/markdown-links.d.ts +1 -1
- package/dist/ui/model.d.ts +1 -1
- package/dist/ui/theme.css +73 -0
- package/dist/ui-DC0oqP79.js +490 -0
- package/package.json +14 -2
- package/tsconfig.node.json +13 -0
- package/tsconfig.ui.json +18 -0
package/dist/ui/components.js
CHANGED
|
@@ -1,131 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
-
//#region src/ui/Components.dto.ts
|
|
5
|
-
let PluginStatusTone = /* @__PURE__ */ function(PluginStatusTone) {
|
|
6
|
-
PluginStatusTone["Success"] = "success";
|
|
7
|
-
PluginStatusTone["Warning"] = "warning";
|
|
8
|
-
PluginStatusTone["Danger"] = "danger";
|
|
9
|
-
PluginStatusTone["Info"] = "info";
|
|
10
|
-
PluginStatusTone["Neutral"] = "neutral";
|
|
11
|
-
return PluginStatusTone;
|
|
12
|
-
}({});
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/ui/components.tsx
|
|
15
|
-
/**
|
|
16
|
-
* Shared React primitives for Workbase plugins (status pill, inline error, empty state, error boundary).
|
|
17
|
-
* Implemented with semantic HTML and SDK CSS tokens to stay zero-dependency beyond React.
|
|
18
|
-
*/
|
|
19
|
-
const DEFAULT_ERROR_BOUNDARY_TITLE = "界面渲染异常";
|
|
20
|
-
const DEFAULT_ERROR_BOUNDARY_SCOPE = "当前插件视图。";
|
|
21
|
-
const DEFAULT_ERROR_BOUNDARY_RECOVERY = "可重试渲染当前视图;若反复出现,请刷新工作区或查看执行日志。";
|
|
22
|
-
const DEFAULT_RETRY_LABEL = "重试渲染";
|
|
23
|
-
const DEFAULT_DISMISS_LABEL = "关闭错误提示";
|
|
24
|
-
const PluginStatusPill = memo(function PluginStatusPill({ tone, label, isLoading = false, className, ...attributes }) {
|
|
25
|
-
return /* @__PURE__ */ jsxs("span", {
|
|
26
|
-
...attributes,
|
|
27
|
-
"data-tone": tone,
|
|
28
|
-
"data-loading": isLoading || void 0,
|
|
29
|
-
className: joinClassNames("workbase-pill", className),
|
|
30
|
-
children: [isLoading ? /* @__PURE__ */ jsx("span", {
|
|
31
|
-
"aria-hidden": "true",
|
|
32
|
-
className: "workbase-pill-spinner"
|
|
33
|
-
}) : /* @__PURE__ */ jsx("span", {
|
|
34
|
-
"aria-hidden": "true",
|
|
35
|
-
className: "workbase-pill-dot"
|
|
36
|
-
}), /* @__PURE__ */ jsx("span", { children: label })]
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
const PluginInlineError = memo(function PluginInlineError({ message, actionLabel, onAction, isActionDisabled = false, onDismiss, dismissLabel = DEFAULT_DISMISS_LABEL, className, ...attributes }) {
|
|
40
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
41
|
-
role: "alert",
|
|
42
|
-
...attributes,
|
|
43
|
-
className: joinClassNames("workbase-inline-error", className),
|
|
44
|
-
children: [
|
|
45
|
-
/* @__PURE__ */ jsx("span", { children: message }),
|
|
46
|
-
actionLabel && onAction ? /* @__PURE__ */ jsx("button", {
|
|
47
|
-
type: "button",
|
|
48
|
-
disabled: isActionDisabled,
|
|
49
|
-
onClick: onAction,
|
|
50
|
-
children: actionLabel
|
|
51
|
-
}) : null,
|
|
52
|
-
onDismiss ? /* @__PURE__ */ jsx("button", {
|
|
53
|
-
type: "button",
|
|
54
|
-
className: "workbase-error-close",
|
|
55
|
-
"aria-label": dismissLabel,
|
|
56
|
-
title: dismissLabel,
|
|
57
|
-
onClick: onDismiss
|
|
58
|
-
}) : null
|
|
59
|
-
]
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
const PluginEmptyState = memo(function PluginEmptyState({ title, description, icon, action, className, ...attributes }) {
|
|
63
|
-
return /* @__PURE__ */ jsxs("section", {
|
|
64
|
-
...attributes,
|
|
65
|
-
className: joinClassNames("workbase-empty-state", className),
|
|
66
|
-
children: [
|
|
67
|
-
icon ? /* @__PURE__ */ jsx("span", {
|
|
68
|
-
"aria-hidden": "true",
|
|
69
|
-
className: "workbase-empty-icon",
|
|
70
|
-
children: icon
|
|
71
|
-
}) : null,
|
|
72
|
-
/* @__PURE__ */ jsx("h2", {
|
|
73
|
-
className: "workbase-empty-title",
|
|
74
|
-
children: title
|
|
75
|
-
}),
|
|
76
|
-
description ? /* @__PURE__ */ jsx("p", {
|
|
77
|
-
className: "workbase-empty-description",
|
|
78
|
-
children: description
|
|
79
|
-
}) : null,
|
|
80
|
-
action ? /* @__PURE__ */ jsx("div", {
|
|
81
|
-
className: "workbase-empty-action",
|
|
82
|
-
children: action
|
|
83
|
-
}) : null
|
|
84
|
-
]
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
var PluginErrorBoundary = class extends Component {
|
|
88
|
-
state = {
|
|
89
|
-
error: null,
|
|
90
|
-
componentStack: null
|
|
91
|
-
};
|
|
92
|
-
static getDerivedStateFromError(error) {
|
|
93
|
-
return { error: error instanceof Error ? error : new Error(String(error ?? "未知渲染异常")) };
|
|
94
|
-
}
|
|
95
|
-
componentDidCatch(_error, info) {
|
|
96
|
-
this.setState({ componentStack: info.componentStack?.trim() || null });
|
|
97
|
-
}
|
|
98
|
-
handleReset = () => {
|
|
99
|
-
this.setState({
|
|
100
|
-
error: null,
|
|
101
|
-
componentStack: null
|
|
102
|
-
});
|
|
103
|
-
this.props.onReset?.();
|
|
104
|
-
};
|
|
105
|
-
render() {
|
|
106
|
-
const { error, componentStack } = this.state;
|
|
107
|
-
if (!error) return this.props.children;
|
|
108
|
-
const details = [error.stack || error.message, componentStack].filter(Boolean).join("\n\n");
|
|
109
|
-
return /* @__PURE__ */ jsx("div", {
|
|
110
|
-
className: "workbase-feedback-page workbase-error-boundary",
|
|
111
|
-
children: /* @__PURE__ */ jsx(PluginErrorPanel, {
|
|
112
|
-
title: this.props.title ?? DEFAULT_ERROR_BOUNDARY_TITLE,
|
|
113
|
-
error: error.message,
|
|
114
|
-
scope: this.props.scope ?? DEFAULT_ERROR_BOUNDARY_SCOPE,
|
|
115
|
-
recovery: this.props.recovery ?? DEFAULT_ERROR_BOUNDARY_RECOVERY,
|
|
116
|
-
technicalDetails: details,
|
|
117
|
-
children: /* @__PURE__ */ jsx("button", {
|
|
118
|
-
type: "button",
|
|
119
|
-
className: "workbase-error-retry",
|
|
120
|
-
onClick: this.handleReset,
|
|
121
|
-
children: this.props.retryLabel ?? DEFAULT_RETRY_LABEL
|
|
122
|
-
})
|
|
123
|
-
})
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
function joinClassNames(...values) {
|
|
128
|
-
return values.filter(Boolean).join(" ");
|
|
129
|
-
}
|
|
130
|
-
//#endregion
|
|
131
|
-
export { PluginEmptyState, PluginErrorBoundary, PluginInlineError, PluginStatusPill, PluginStatusTone };
|
|
1
|
+
import { a as PluginStatusPill, i as PluginPublicationButton, n as PluginErrorBoundary, o as PluginStatusTone, r as PluginInlineError, t as PluginEmptyState } from "../components-V_fFZLTU.js";
|
|
2
|
+
export { PluginEmptyState, PluginErrorBoundary, PluginInlineError, PluginPublicationButton, PluginStatusPill, PluginStatusTone };
|
package/dist/ui/error-panel.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ interface PluginErrorPanelProps extends HTMLAttributes<HTMLElement> {
|
|
|
7
7
|
readonly recovery: string;
|
|
8
8
|
readonly technicalDetails?: string;
|
|
9
9
|
readonly isDismissible?: boolean;
|
|
10
|
+
readonly variant?: "default" | "compact";
|
|
10
11
|
readonly children?: ReactNode;
|
|
11
12
|
}
|
|
12
13
|
//#endregion
|
package/dist/ui/error-panel.js
CHANGED
|
@@ -10,16 +10,82 @@ const PluginErrorPanel = memo(function PluginErrorPanel(props) {
|
|
|
10
10
|
props.technicalDetails
|
|
11
11
|
]));
|
|
12
12
|
});
|
|
13
|
-
function ErrorDetails({ title, error, scope, recovery, technicalDetails = error, isDismissible = false, children, className, ...attributes }) {
|
|
13
|
+
function ErrorDetails({ title, error, scope, recovery, technicalDetails = error, isDismissible = false, variant = "default", children, className, ...attributes }) {
|
|
14
14
|
const headingId = useId();
|
|
15
15
|
const detailsId = useId();
|
|
16
16
|
const [closed, setClosed] = useState(false);
|
|
17
17
|
const [showDetails, setShowDetails] = useState(false);
|
|
18
|
+
const isCompact = variant === "compact";
|
|
19
|
+
const summary = errorSummary(error);
|
|
18
20
|
function handleClose() {
|
|
19
21
|
setShowDetails(false);
|
|
20
22
|
setClosed(!closed);
|
|
21
23
|
}
|
|
22
24
|
if (closed && isDismissible) return null;
|
|
25
|
+
if (isCompact) return /* @__PURE__ */ jsxs("section", {
|
|
26
|
+
tabIndex: 0,
|
|
27
|
+
...attributes,
|
|
28
|
+
"data-variant": "compact",
|
|
29
|
+
role: closed ? void 0 : "alert",
|
|
30
|
+
"aria-labelledby": headingId,
|
|
31
|
+
className: ["workbase-plugin-error", className].filter(Boolean).join(" "),
|
|
32
|
+
children: [/* @__PURE__ */ jsxs("header", {
|
|
33
|
+
className: "workbase-error-header",
|
|
34
|
+
children: [
|
|
35
|
+
/* @__PURE__ */ jsxs("div", {
|
|
36
|
+
className: "workbase-error-compact-copy",
|
|
37
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
38
|
+
className: "workbase-error-title",
|
|
39
|
+
id: headingId,
|
|
40
|
+
children: title
|
|
41
|
+
}), !closed ? /* @__PURE__ */ jsx("p", {
|
|
42
|
+
className: "workbase-error-cause",
|
|
43
|
+
children: summary
|
|
44
|
+
}) : null]
|
|
45
|
+
}),
|
|
46
|
+
!closed ? /* @__PURE__ */ jsxs("div", {
|
|
47
|
+
className: "workbase-error-compact-actions",
|
|
48
|
+
children: [children, /* @__PURE__ */ jsxs("button", {
|
|
49
|
+
type: "button",
|
|
50
|
+
className: "workbase-error-disclosure",
|
|
51
|
+
"aria-expanded": showDetails,
|
|
52
|
+
"aria-controls": detailsId,
|
|
53
|
+
onClick: () => setShowDetails(!showDetails),
|
|
54
|
+
children: [showDetails ? "收起详情" : "查看详情", /* @__PURE__ */ jsx("svg", {
|
|
55
|
+
"aria-hidden": "true",
|
|
56
|
+
width: "14",
|
|
57
|
+
height: "14",
|
|
58
|
+
viewBox: "0 0 24 24",
|
|
59
|
+
fill: "none",
|
|
60
|
+
stroke: "currentColor",
|
|
61
|
+
strokeWidth: "1.8",
|
|
62
|
+
strokeLinecap: "round",
|
|
63
|
+
strokeLinejoin: "round",
|
|
64
|
+
children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })
|
|
65
|
+
})]
|
|
66
|
+
})]
|
|
67
|
+
}) : null,
|
|
68
|
+
/* @__PURE__ */ jsx("button", {
|
|
69
|
+
type: "button",
|
|
70
|
+
className: closed ? "workbase-error-toggle" : "workbase-error-toggle workbase-error-close",
|
|
71
|
+
"aria-label": closed ? "查看错误详情" : "关闭错误提示",
|
|
72
|
+
title: closed ? void 0 : "关闭错误提示",
|
|
73
|
+
"aria-expanded": isDismissible ? void 0 : !closed,
|
|
74
|
+
onClick: handleClose,
|
|
75
|
+
children: closed ? "查看错误详情" : null
|
|
76
|
+
})
|
|
77
|
+
]
|
|
78
|
+
}), !closed ? /* @__PURE__ */ jsxs("dl", {
|
|
79
|
+
className: "workbase-error-details",
|
|
80
|
+
id: detailsId,
|
|
81
|
+
hidden: !showDetails,
|
|
82
|
+
children: [
|
|
83
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", { children: "影响范围" }), /* @__PURE__ */ jsx("dd", { children: scope })] }),
|
|
84
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", { children: "处理建议" }), /* @__PURE__ */ jsx("dd", { children: recovery })] }),
|
|
85
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", { children: "技术详情" }), /* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx("pre", { children: technicalDetails }) })] })
|
|
86
|
+
]
|
|
87
|
+
}) : null]
|
|
88
|
+
});
|
|
23
89
|
return /* @__PURE__ */ jsxs("section", {
|
|
24
90
|
tabIndex: 0,
|
|
25
91
|
...attributes,
|
|
@@ -46,7 +112,7 @@ function ErrorDetails({ title, error, scope, recovery, technicalDetails = error,
|
|
|
46
112
|
children: [
|
|
47
113
|
/* @__PURE__ */ jsx("p", {
|
|
48
114
|
className: "workbase-error-cause",
|
|
49
|
-
children:
|
|
115
|
+
children: summary
|
|
50
116
|
}),
|
|
51
117
|
/* @__PURE__ */ jsxs("div", {
|
|
52
118
|
className: "workbase-error-actions",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as ExecutionLogRecord, t as ExecutionLogEntry } from "../ExecutionLog.dto-
|
|
1
|
+
import { r as ExecutionLogRecord, t as ExecutionLogEntry } from "../ExecutionLog.dto-ig9GUWhK.js";
|
|
2
2
|
//#region src/ui/ExecutionLogTimeline.dto.d.ts
|
|
3
3
|
export declare enum ExecutionLogDisplay {
|
|
4
4
|
Full = "full",
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { N as WorkbasePluginUi, _ as PluginUiInitializationPayload } from "../types-3v3whlPt.js";
|
|
2
|
+
import { ReactNode, RefObject } from "react";
|
|
3
|
+
//#region src/ui/hooks.d.ts
|
|
4
|
+
export interface ReactRootLike {
|
|
5
|
+
readonly render: (children: ReactNode) => void;
|
|
6
|
+
}
|
|
7
|
+
export interface MountedPluginViewContext {
|
|
8
|
+
readonly host: WorkbasePluginUi;
|
|
9
|
+
readonly initialization: PluginUiInitializationPayload;
|
|
10
|
+
readonly contextKey: string;
|
|
11
|
+
}
|
|
12
|
+
export interface MountPluginViewOptions {
|
|
13
|
+
readonly createRoot: (container: Element) => ReactRootLike;
|
|
14
|
+
readonly elementId?: string;
|
|
15
|
+
readonly errorTitle: string;
|
|
16
|
+
readonly errorScope: string;
|
|
17
|
+
readonly errorRecovery?: string;
|
|
18
|
+
readonly keyFor?: (initialization: PluginUiInitializationPayload) => string;
|
|
19
|
+
readonly wrap?: (children: ReactNode) => ReactNode;
|
|
20
|
+
readonly render: (context: MountedPluginViewContext) => ReactNode;
|
|
21
|
+
}
|
|
22
|
+
export interface UsePluginViewStateOptions<State> {
|
|
23
|
+
readonly host: WorkbasePluginUi;
|
|
24
|
+
readonly load: (emit: (partial: State) => void) => Promise<State>;
|
|
25
|
+
readonly initialState?: State | null;
|
|
26
|
+
readonly stateTopic?: string | null;
|
|
27
|
+
readonly onState?: (next: State, previous: State | null) => void;
|
|
28
|
+
readonly pollIntervalMs?: number | ((state: State | null, error: string | null) => number | null);
|
|
29
|
+
readonly refreshOnFocus?: boolean;
|
|
30
|
+
readonly refreshOnFilesChanged?: boolean;
|
|
31
|
+
readonly observeVisibility?: boolean;
|
|
32
|
+
readonly focusCooldownMs?: number;
|
|
33
|
+
readonly fallbackError?: string;
|
|
34
|
+
readonly isBlocked?: () => boolean;
|
|
35
|
+
readonly loadOnMount?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface PluginViewStateResult<State> {
|
|
38
|
+
readonly data: State | null;
|
|
39
|
+
readonly error: string | null;
|
|
40
|
+
readonly isRefreshing: boolean;
|
|
41
|
+
readonly isVisible: boolean;
|
|
42
|
+
readonly viewRef: (node: HTMLElement | null) => void;
|
|
43
|
+
readonly setError: (message: string | null) => void;
|
|
44
|
+
readonly clearError: () => void;
|
|
45
|
+
readonly refresh: () => Promise<State | null>;
|
|
46
|
+
readonly acceptData: (next: State) => void;
|
|
47
|
+
readonly invalidatePending: () => void;
|
|
48
|
+
}
|
|
49
|
+
export interface UsePluginActionOptions {
|
|
50
|
+
readonly onError?: (message: string) => void;
|
|
51
|
+
readonly fallbackError?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface PluginActionResult<ActionId> {
|
|
54
|
+
readonly busyAction: ActionId | null;
|
|
55
|
+
readonly isBusy: boolean;
|
|
56
|
+
readonly isBusyRef: RefObject<boolean>;
|
|
57
|
+
readonly isMountedRef: RefObject<boolean>;
|
|
58
|
+
readonly run: <Value>(actionId: ActionId, task: () => Promise<Value>) => Promise<Value | undefined>;
|
|
59
|
+
}
|
|
60
|
+
/** Mounts a Workbase plugin view with shared style nonce, error boundary and workspace key isolation. */
|
|
61
|
+
export declare function mountPluginView(options: MountPluginViewOptions): WorkbasePluginUi;
|
|
62
|
+
/**
|
|
63
|
+
* Manages cached view state, stale-response protection, in-flight deduplication,
|
|
64
|
+
* backend State Sync pushes, file-change notifications and visibility-aware polling.
|
|
65
|
+
*/
|
|
66
|
+
export declare function usePluginViewState<State>(options: UsePluginViewStateOptions<State>): PluginViewStateResult<State>;
|
|
67
|
+
/** Serializes mutating plugin actions so concurrent clicks never overlap or leak stale errors. */
|
|
68
|
+
export declare function usePluginAction<ActionId>(options?: UsePluginActionOptions): PluginActionResult<ActionId>;
|
|
69
|
+
export declare function buildViewContextKey(payload: PluginUiInitializationPayload): string;
|
|
70
|
+
//#endregion
|
package/dist/ui/hooks.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { t as DEFAULT_VIEW_STATE_TOPIC } from "../host-services-cIH3aYQD.js";
|
|
2
|
+
import { n as defineWorkbasePluginUi } from "../ui-DC0oqP79.js";
|
|
3
|
+
import { n as PluginErrorBoundary } from "../components-V_fFZLTU.js";
|
|
4
|
+
import { initializeWorkbaseUiStyles } from "./theme.js";
|
|
5
|
+
import { Fragment, useCallback, useEffect, useRef, useState } from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
//#region src/ui/hooks.tsx
|
|
8
|
+
/**
|
|
9
|
+
* React view mounting, state-sync subscription and serialized action hooks for Workbase plugins.
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_ROOT_ELEMENT_ID = "root";
|
|
12
|
+
const DEFAULT_LOAD_ERROR = "插件数据读取失败,请重试。";
|
|
13
|
+
/** Mounts a Workbase plugin view with shared style nonce, error boundary and workspace key isolation. */
|
|
14
|
+
function mountPluginView(options) {
|
|
15
|
+
const { createRoot, elementId = DEFAULT_ROOT_ELEMENT_ID, errorTitle, errorScope, errorRecovery, keyFor = buildViewContextKey, wrap, render } = options;
|
|
16
|
+
const container = document.getElementById(elementId);
|
|
17
|
+
if (!container) throw new Error(`插件视图挂载节点 #${elementId} 不存在。`);
|
|
18
|
+
initializeWorkbaseUiStyles();
|
|
19
|
+
const root = createRoot(container);
|
|
20
|
+
const host = defineWorkbasePluginUi({ onInit(initialization) {
|
|
21
|
+
const contextKey = keyFor(initialization);
|
|
22
|
+
const content = /* @__PURE__ */ jsx(PluginErrorBoundary, {
|
|
23
|
+
title: errorTitle,
|
|
24
|
+
scope: errorScope,
|
|
25
|
+
recovery: errorRecovery,
|
|
26
|
+
children: /* @__PURE__ */ jsx(Fragment, { children: render({
|
|
27
|
+
host,
|
|
28
|
+
initialization,
|
|
29
|
+
contextKey
|
|
30
|
+
}) }, contextKey)
|
|
31
|
+
});
|
|
32
|
+
root.render(wrap ? wrap(content) : content);
|
|
33
|
+
} });
|
|
34
|
+
return host;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Manages cached view state, stale-response protection, in-flight deduplication,
|
|
38
|
+
* backend State Sync pushes, file-change notifications and visibility-aware polling.
|
|
39
|
+
*/
|
|
40
|
+
function usePluginViewState(options) {
|
|
41
|
+
const { host, initialState = null, stateTopic = DEFAULT_VIEW_STATE_TOPIC, refreshOnFocus = false, refreshOnFilesChanged = false, observeVisibility = false, focusCooldownMs = 0, fallbackError = DEFAULT_LOAD_ERROR, loadOnMount = !observeVisibility } = options;
|
|
42
|
+
const [viewElement, setViewElement] = useState(null);
|
|
43
|
+
const mountedRef = useRef(true);
|
|
44
|
+
const requestVersionRef = useRef(0);
|
|
45
|
+
const pendingRef = useRef(null);
|
|
46
|
+
const lastReadAtRef = useRef(0);
|
|
47
|
+
const dataRef = useRef(initialState);
|
|
48
|
+
const loadRef = useRef(options.load);
|
|
49
|
+
const onStateRef = useRef(options.onState);
|
|
50
|
+
const pollIntervalRef = useRef(options.pollIntervalMs);
|
|
51
|
+
const isBlockedRef = useRef(options.isBlocked);
|
|
52
|
+
loadRef.current = options.load;
|
|
53
|
+
onStateRef.current = options.onState;
|
|
54
|
+
pollIntervalRef.current = options.pollIntervalMs;
|
|
55
|
+
isBlockedRef.current = options.isBlocked;
|
|
56
|
+
const [data, setData] = useState(initialState);
|
|
57
|
+
const [error, setError] = useState(null);
|
|
58
|
+
const [isRefreshing, setIsRefreshing] = useState(false);
|
|
59
|
+
const [isVisible, setIsVisible] = useState(!observeVisibility);
|
|
60
|
+
const acceptData = useCallback((next) => {
|
|
61
|
+
const previous = dataRef.current;
|
|
62
|
+
dataRef.current = next;
|
|
63
|
+
lastReadAtRef.current = Date.now();
|
|
64
|
+
requestVersionRef.current += 1;
|
|
65
|
+
setData(next);
|
|
66
|
+
setError(null);
|
|
67
|
+
onStateRef.current?.(next, previous);
|
|
68
|
+
}, []);
|
|
69
|
+
const invalidatePending = useCallback(() => {
|
|
70
|
+
requestVersionRef.current += 1;
|
|
71
|
+
pendingRef.current = null;
|
|
72
|
+
setIsRefreshing(false);
|
|
73
|
+
}, []);
|
|
74
|
+
const clearError = useCallback(() => setError(null), []);
|
|
75
|
+
const refresh = useCallback(async () => {
|
|
76
|
+
if (pendingRef.current) return pendingRef.current;
|
|
77
|
+
if (!mountedRef.current || isBlockedRef.current?.()) return null;
|
|
78
|
+
const version = requestVersionRef.current;
|
|
79
|
+
setIsRefreshing(true);
|
|
80
|
+
const emit = (partial) => {
|
|
81
|
+
if (!mountedRef.current || requestVersionRef.current !== version) return;
|
|
82
|
+
const previous = dataRef.current;
|
|
83
|
+
dataRef.current = partial;
|
|
84
|
+
setData(partial);
|
|
85
|
+
onStateRef.current?.(partial, previous);
|
|
86
|
+
};
|
|
87
|
+
const request = (async () => {
|
|
88
|
+
try {
|
|
89
|
+
const next = await loadRef.current(emit);
|
|
90
|
+
if (!mountedRef.current || requestVersionRef.current !== version) return null;
|
|
91
|
+
const previous = dataRef.current;
|
|
92
|
+
dataRef.current = next;
|
|
93
|
+
lastReadAtRef.current = Date.now();
|
|
94
|
+
setData(next);
|
|
95
|
+
setError(null);
|
|
96
|
+
onStateRef.current?.(next, previous);
|
|
97
|
+
return next;
|
|
98
|
+
} catch (failure) {
|
|
99
|
+
if (mountedRef.current && requestVersionRef.current === version) setError(readableErrorMessage(failure, fallbackError));
|
|
100
|
+
return null;
|
|
101
|
+
} finally {
|
|
102
|
+
if (requestVersionRef.current === version) {
|
|
103
|
+
pendingRef.current = null;
|
|
104
|
+
if (mountedRef.current) setIsRefreshing(false);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
})();
|
|
108
|
+
pendingRef.current = request;
|
|
109
|
+
return request;
|
|
110
|
+
}, [fallbackError]);
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
mountedRef.current = true;
|
|
113
|
+
return () => {
|
|
114
|
+
mountedRef.current = false;
|
|
115
|
+
requestVersionRef.current += 1;
|
|
116
|
+
pendingRef.current = null;
|
|
117
|
+
};
|
|
118
|
+
}, []);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (loadOnMount) refresh();
|
|
121
|
+
}, [loadOnMount, refresh]);
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
if (stateTopic === null || typeof host.view.onStateChanged !== "function") return;
|
|
124
|
+
return host.view.onStateChanged((pushed) => {
|
|
125
|
+
if (!mountedRef.current) return;
|
|
126
|
+
acceptData(pushed);
|
|
127
|
+
}, stateTopic);
|
|
128
|
+
}, [
|
|
129
|
+
acceptData,
|
|
130
|
+
host,
|
|
131
|
+
stateTopic
|
|
132
|
+
]);
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
if (!refreshOnFilesChanged || typeof host.view.onFilesChanged !== "function") return;
|
|
135
|
+
return host.view.onFilesChanged(() => {
|
|
136
|
+
refresh();
|
|
137
|
+
});
|
|
138
|
+
}, [
|
|
139
|
+
host,
|
|
140
|
+
refresh,
|
|
141
|
+
refreshOnFilesChanged
|
|
142
|
+
]);
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (!observeVisibility) {
|
|
145
|
+
setIsVisible(true);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
let isIntersecting = false;
|
|
149
|
+
const syncVisibility = () => setIsVisible(isIntersecting && document.visibilityState === "visible");
|
|
150
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
151
|
+
isIntersecting = Boolean(entry?.isIntersecting);
|
|
152
|
+
syncVisibility();
|
|
153
|
+
});
|
|
154
|
+
if (viewElement) observer.observe(viewElement);
|
|
155
|
+
document.addEventListener("visibilitychange", syncVisibility);
|
|
156
|
+
return () => {
|
|
157
|
+
observer.disconnect();
|
|
158
|
+
document.removeEventListener("visibilitychange", syncVisibility);
|
|
159
|
+
};
|
|
160
|
+
}, [observeVisibility, viewElement]);
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
if (!isVisible) return;
|
|
163
|
+
const triggerRefresh = () => {
|
|
164
|
+
if (document.visibilityState !== "visible") return;
|
|
165
|
+
if (isBlockedRef.current?.()) return;
|
|
166
|
+
if (focusCooldownMs > 0 && Date.now() - lastReadAtRef.current < focusCooldownMs) return;
|
|
167
|
+
refresh();
|
|
168
|
+
};
|
|
169
|
+
if (observeVisibility) triggerRefresh();
|
|
170
|
+
if (!refreshOnFocus) return;
|
|
171
|
+
window.addEventListener("focus", triggerRefresh);
|
|
172
|
+
if (!observeVisibility) document.addEventListener("visibilitychange", triggerRefresh);
|
|
173
|
+
return () => {
|
|
174
|
+
window.removeEventListener("focus", triggerRefresh);
|
|
175
|
+
if (!observeVisibility) document.removeEventListener("visibilitychange", triggerRefresh);
|
|
176
|
+
};
|
|
177
|
+
}, [
|
|
178
|
+
focusCooldownMs,
|
|
179
|
+
isVisible,
|
|
180
|
+
observeVisibility,
|
|
181
|
+
refresh,
|
|
182
|
+
refreshOnFocus
|
|
183
|
+
]);
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if (!isVisible) return;
|
|
186
|
+
const resolver = pollIntervalRef.current;
|
|
187
|
+
const interval = typeof resolver === "function" ? resolver(data, error) : resolver;
|
|
188
|
+
if (typeof interval !== "number" || interval <= 0) return;
|
|
189
|
+
const delay = interval;
|
|
190
|
+
let cancelled = false;
|
|
191
|
+
let timer = window.setTimeout(poll, delay);
|
|
192
|
+
async function poll() {
|
|
193
|
+
await refresh();
|
|
194
|
+
if (!cancelled) timer = window.setTimeout(poll, delay);
|
|
195
|
+
}
|
|
196
|
+
return () => {
|
|
197
|
+
cancelled = true;
|
|
198
|
+
window.clearTimeout(timer);
|
|
199
|
+
};
|
|
200
|
+
}, [
|
|
201
|
+
data,
|
|
202
|
+
error,
|
|
203
|
+
isVisible,
|
|
204
|
+
refresh
|
|
205
|
+
]);
|
|
206
|
+
return {
|
|
207
|
+
data,
|
|
208
|
+
error,
|
|
209
|
+
isRefreshing,
|
|
210
|
+
isVisible,
|
|
211
|
+
viewRef: setViewElement,
|
|
212
|
+
setError,
|
|
213
|
+
clearError,
|
|
214
|
+
refresh,
|
|
215
|
+
acceptData,
|
|
216
|
+
invalidatePending
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/** Serializes mutating plugin actions so concurrent clicks never overlap or leak stale errors. */
|
|
220
|
+
function usePluginAction(options = {}) {
|
|
221
|
+
const { fallbackError = "操作未完成,请重试。" } = options;
|
|
222
|
+
const mountedRef = useRef(true);
|
|
223
|
+
const isBusyRef = useRef(false);
|
|
224
|
+
const onErrorRef = useRef(options.onError);
|
|
225
|
+
onErrorRef.current = options.onError;
|
|
226
|
+
const [busyAction, setBusyAction] = useState(null);
|
|
227
|
+
useEffect(() => {
|
|
228
|
+
mountedRef.current = true;
|
|
229
|
+
return () => {
|
|
230
|
+
mountedRef.current = false;
|
|
231
|
+
};
|
|
232
|
+
}, []);
|
|
233
|
+
const run = useCallback(async (actionId, task) => {
|
|
234
|
+
if (!mountedRef.current || isBusyRef.current) return;
|
|
235
|
+
isBusyRef.current = true;
|
|
236
|
+
setBusyAction(actionId);
|
|
237
|
+
try {
|
|
238
|
+
return await task();
|
|
239
|
+
} catch (failure) {
|
|
240
|
+
if (mountedRef.current) onErrorRef.current?.(readableErrorMessage(failure, fallbackError));
|
|
241
|
+
return;
|
|
242
|
+
} finally {
|
|
243
|
+
isBusyRef.current = false;
|
|
244
|
+
if (mountedRef.current) setBusyAction(null);
|
|
245
|
+
}
|
|
246
|
+
}, [fallbackError]);
|
|
247
|
+
return {
|
|
248
|
+
busyAction,
|
|
249
|
+
isBusy: busyAction !== null,
|
|
250
|
+
isBusyRef,
|
|
251
|
+
isMountedRef: mountedRef,
|
|
252
|
+
run
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function buildViewContextKey(payload) {
|
|
256
|
+
return `${payload.project.id}:${payload.workspace.id}:${payload.activationGeneration ?? 0}`;
|
|
257
|
+
}
|
|
258
|
+
function readableErrorMessage(error, fallback) {
|
|
259
|
+
return error instanceof Error && error.message.trim() ? error.message : fallback;
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
262
|
+
export { buildViewContextKey, mountPluginView, usePluginAction, usePluginViewState };
|
package/dist/ui/index.css
CHANGED
|
@@ -190,10 +190,19 @@ h2 {
|
|
|
190
190
|
.status-page .operation-feedback { padding-top: 8px; }
|
|
191
191
|
|
|
192
192
|
.configuration-page-tabs { display: inline-flex; align-items: center; gap: 2px; width: max-content; max-width: 100%; padding: 4px; border-radius: 10px; background: var(--color-surface-muted); }
|
|
193
|
-
.configuration-page-tabs button { min-height: 32px; border: 0; border-radius: 7px; background: transparent; padding: 4px 13px; color: var(--color-muted); font: inherit; font-size: var(--workbase-type-body); font-weight: 600; cursor: pointer; white-space: nowrap; }
|
|
193
|
+
.configuration-page-tabs button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 32px; border: 0; border-radius: 7px; background: transparent; padding: 4px 13px; color: var(--color-muted); font: inherit; font-size: var(--workbase-type-body); font-weight: 600; cursor: pointer; white-space: nowrap; }
|
|
194
194
|
.configuration-page-tabs button:hover { color: var(--color-foreground); }
|
|
195
195
|
.configuration-page-tabs button[aria-pressed="true"] { background: var(--color-surface); color: var(--color-foreground); box-shadow: 0 1px 4px rgb(55 48 31 / 13%); }
|
|
196
196
|
.configuration-page-tabs button:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }
|
|
197
|
+
.configuration-page-tabs button[data-modified="true"]::after,
|
|
198
|
+
.configuration-tabs button[data-modified="true"]::after {
|
|
199
|
+
content: "";
|
|
200
|
+
width: 6px;
|
|
201
|
+
height: 6px;
|
|
202
|
+
flex-shrink: 0;
|
|
203
|
+
border-radius: 50%;
|
|
204
|
+
background: var(--color-warning);
|
|
205
|
+
}
|
|
197
206
|
.configuration-manager { display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; font-size: var(--workbase-type-body); line-height: 1.6; }
|
|
198
207
|
.configuration-manager > :not(.configuration-resource-grid) { flex-shrink: 0; }
|
|
199
208
|
.configuration-view { min-width: 0; }
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { et as DEFAULT_VIEW_STATE_TOPIC, f as PluginCommandExecutionResult } from "../types-D1Ezgwbv.js";
|
|
2
|
+
import { A as PluginUiTransportConnection, C as PluginUiPromptType, D as PluginUiStateChange, E as PluginUiRepositoryPushTarget, M as PluginUiViewIdentity, N as WorkbasePluginUi, O as PluginUiStatus, P as WorkbasePluginUiDefinition, S as PluginUiPromptOptions, T as PluginUiRepositoryPushResult, _ as PluginUiInitializationPayload, a as PluginUiCommands, b as PluginUiOutputOptions, c as PluginUiDesktopOpenOptions, d as PluginUiFileFilter, f as PluginUiFileSelectOptions, g as PluginUiHostMethods, h as PluginUiHostError, i as PluginUiCommandExecuteOptions, j as PluginUiView, k as PluginUiToastOptions, l as PluginUiDesktopOpenResult, m as PluginUiFileSelectionScope, n as PluginUiActivationState, o as PluginUiContextIdentity, p as PluginUiFileSelectionItemType, r as PluginUiClientMethods, s as PluginUiControllerOptions, t as PluginDesktopTarget, u as PluginUiExecutionChange, v as PluginUiNavigateOptions, w as PluginUiRepositoryPushOutcome, x as PluginUiPromptChoice, y as PluginUiOpenViewOptions } from "../types-3v3whlPt.js";
|
|
2
3
|
//#region src/ui/controller.d.ts
|
|
3
4
|
export declare enum PluginUiHostMethod {
|
|
4
5
|
InteractionDismiss = "interaction.dismiss",
|
|
@@ -20,11 +21,31 @@ export declare enum PluginUiHostMethod {
|
|
|
20
21
|
StatusResolve = "status.resolve",
|
|
21
22
|
ToastShow = "toast.show",
|
|
22
23
|
ViewCall = "view.call",
|
|
23
|
-
ViewModified = "view.modified"
|
|
24
|
+
ViewModified = "view.modified",
|
|
25
|
+
ViewActivationErrorHandled = "view.activationErrorHandled"
|
|
24
26
|
}
|
|
25
27
|
export declare function createPluginUiController(definition: WorkbasePluginUiDefinition, options: PluginUiControllerOptions): WorkbasePluginUi;
|
|
26
28
|
//#endregion
|
|
27
29
|
//#region src/ui/index.d.ts
|
|
30
|
+
type ContractEndpoint = (...args: never[]) => unknown;
|
|
31
|
+
type EndpointOutput<Endpoint extends ContractEndpoint> = Awaited<ReturnType<Endpoint>>;
|
|
32
|
+
type CallArgs<Endpoint extends ContractEndpoint> = Parameters<Endpoint>;
|
|
33
|
+
type CommandArgs<Endpoint extends ContractEndpoint> = [] extends Parameters<Endpoint> ? [input?: Parameters<Endpoint>[0], options?: PluginUiCommandExecuteOptions] : [input: Parameters<Endpoint>[0], options?: PluginUiCommandExecuteOptions];
|
|
34
|
+
export interface PluginContract {
|
|
35
|
+
readonly views?: Readonly<Record<string, ContractEndpoint>>;
|
|
36
|
+
readonly commands?: Readonly<Record<string, ContractEndpoint>>;
|
|
37
|
+
readonly statuses?: Readonly<Record<string, ContractEndpoint>>;
|
|
38
|
+
readonly states?: Readonly<Record<string, unknown>>;
|
|
39
|
+
}
|
|
40
|
+
export interface PluginTypedClient<Contract extends PluginContract> {
|
|
41
|
+
readonly host: WorkbasePluginUi;
|
|
42
|
+
readonly view: <Method extends keyof NonNullable<Contract['views']> & string>(method: Method, ...args: CallArgs<NonNullable<Contract['views']>[Method]>) => Promise<EndpointOutput<NonNullable<Contract['views']>[Method]>>;
|
|
43
|
+
readonly command: <CommandId extends keyof NonNullable<Contract['commands']> & string>(commandId: CommandId, ...args: CommandArgs<NonNullable<Contract['commands']>[CommandId]>) => Promise<PluginCommandExecutionResult<EndpointOutput<NonNullable<Contract['commands']>[CommandId]>>>;
|
|
44
|
+
readonly status: <StatusId extends keyof NonNullable<Contract['statuses']> & string>(statusId: StatusId, ...args: CallArgs<NonNullable<Contract['statuses']>[StatusId]>) => Promise<EndpointOutput<NonNullable<Contract['statuses']>[StatusId]>>;
|
|
45
|
+
readonly onState: <Topic extends keyof NonNullable<Contract['states']> & string>(topic: Topic, listener: (state: NonNullable<Contract['states']>[Topic]) => void) => () => void;
|
|
46
|
+
}
|
|
47
|
+
/** Creates an end-to-end typed wrapper over the Workbase plugin UI bridge with zero runtime schema overhead. */
|
|
48
|
+
export declare function createPluginClient<Contract extends PluginContract>(host: WorkbasePluginUi): PluginTypedClient<Contract>;
|
|
28
49
|
export declare function defineWorkbasePluginUi(definition: WorkbasePluginUiDefinition): WorkbasePluginUi;
|
|
29
50
|
//#endregion
|
|
30
|
-
export { PluginDesktopTarget, type PluginUiClientMethods, type PluginUiCommandExecuteOptions, type PluginUiCommands, type PluginUiContextIdentity, type PluginUiControllerOptions, type PluginUiDesktopOpenOptions, type PluginUiDesktopOpenResult, type PluginUiExecutionChange, type PluginUiFileFilter, type PluginUiFileSelectOptions, type PluginUiFileSelectionItemType, type PluginUiFileSelectionScope, type PluginUiHostError, type PluginUiHostMethods, type PluginUiInitializationPayload, type PluginUiNavigateOptions, type PluginUiOpenViewOptions, type PluginUiOutputOptions, type PluginUiPromptChoice, type PluginUiPromptOptions, type PluginUiPromptType, type PluginUiRepositoryPushOutcome, type PluginUiRepositoryPushResult, type PluginUiRepositoryPushTarget, type PluginUiStatus, type PluginUiToastOptions, type PluginUiTransportConnection, type PluginUiView, type PluginUiViewIdentity, type WorkbasePluginUi, type WorkbasePluginUiDefinition };
|
|
51
|
+
export { DEFAULT_VIEW_STATE_TOPIC, PluginDesktopTarget, type PluginUiActivationState, type PluginUiClientMethods, type PluginUiCommandExecuteOptions, type PluginUiCommands, type PluginUiContextIdentity, type PluginUiControllerOptions, type PluginUiDesktopOpenOptions, type PluginUiDesktopOpenResult, type PluginUiExecutionChange, type PluginUiFileFilter, type PluginUiFileSelectOptions, type PluginUiFileSelectionItemType, type PluginUiFileSelectionScope, type PluginUiHostError, type PluginUiHostMethods, type PluginUiInitializationPayload, type PluginUiNavigateOptions, type PluginUiOpenViewOptions, type PluginUiOutputOptions, type PluginUiPromptChoice, type PluginUiPromptOptions, type PluginUiPromptType, type PluginUiRepositoryPushOutcome, type PluginUiRepositoryPushResult, type PluginUiRepositoryPushTarget, type PluginUiStateChange, type PluginUiStatus, type PluginUiToastOptions, type PluginUiTransportConnection, type PluginUiView, type PluginUiViewIdentity, type WorkbasePluginUi, type WorkbasePluginUiDefinition };
|