@spotpatch/runtime 1.9.0 → 1.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/dist/{chunk-AXKYJRAM.js → chunk-7ES63LA7.js} +2 -13
- package/dist/chunk-7ES63LA7.js.map +1 -0
- package/dist/chunk-NII5OBAN.js +14 -0
- package/dist/chunk-NII5OBAN.js.map +1 -0
- package/dist/chunk-XBD55BCF.js +14 -0
- package/dist/chunk-XBD55BCF.js.map +1 -0
- package/dist/data-flow-panel.js +5 -3
- package/dist/data-flow-panel.js.map +1 -1
- package/dist/external-handoff-panel.cjs +1002 -0
- package/dist/external-handoff-panel.cjs.map +1 -0
- package/dist/external-handoff-panel.d.cts +36 -0
- package/dist/external-handoff-panel.d.ts +36 -0
- package/dist/external-handoff-panel.js +959 -0
- package/dist/external-handoff-panel.js.map +1 -0
- package/dist/index.cjs +102 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +104 -7
- package/dist/index.js.map +1 -1
- package/package.json +15 -2
- package/dist/chunk-AXKYJRAM.js.map +0 -1
|
@@ -5,15 +5,6 @@ var UI_Z_INDEX = Object.freeze({
|
|
|
5
5
|
controls: 2147483647
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
// src/ui/data-flow-panel-contract.ts
|
|
9
|
-
var DATA_FLOW_EXTENSION_KEY = /* @__PURE__ */ Symbol.for("spotpatch.data-flow.extension.v1");
|
|
10
|
-
function registerDataFlowExtension(extension, target = globalThis) {
|
|
11
|
-
target[DATA_FLOW_EXTENSION_KEY] = extension;
|
|
12
|
-
}
|
|
13
|
-
function getDataFlowExtension(target = globalThis) {
|
|
14
|
-
return target[DATA_FLOW_EXTENSION_KEY];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
8
|
// src/ui/dom.ts
|
|
18
9
|
function createMarkedElement(document, tagName) {
|
|
19
10
|
const element = document.createElement(tagName);
|
|
@@ -32,8 +23,6 @@ export {
|
|
|
32
23
|
UI_MARKER_ATTRIBUTE,
|
|
33
24
|
UI_Z_INDEX,
|
|
34
25
|
createMarkedElement,
|
|
35
|
-
createButton
|
|
36
|
-
registerDataFlowExtension,
|
|
37
|
-
getDataFlowExtension
|
|
26
|
+
createButton
|
|
38
27
|
};
|
|
39
|
-
//# sourceMappingURL=chunk-
|
|
28
|
+
//# sourceMappingURL=chunk-7ES63LA7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ui/ui-constants.ts","../src/ui/dom.ts"],"sourcesContent":["export const UI_MARKER_ATTRIBUTE = \"data-spotpatch-ui\" as const;\n\nexport const UI_Z_INDEX = Object.freeze({\n highlight: 2_147_483_646,\n controls: 2_147_483_647,\n});\n","import { UI_MARKER_ATTRIBUTE } from \"./ui-constants.js\";\n\nexport function createMarkedElement<K extends keyof HTMLElementTagNameMap>(\n document: Document,\n tagName: K,\n): HTMLElementTagNameMap[K] {\n const element = document.createElement(tagName);\n element.setAttribute(UI_MARKER_ATTRIBUTE, \"\");\n return element;\n}\n\nexport function createButton(\n document: Document,\n label: string,\n className = \"\",\n): HTMLButtonElement {\n const button = createMarkedElement(document, \"button\");\n button.type = \"button\";\n button.className = className;\n button.textContent = label;\n return button;\n}\n"],"mappings":";AAAO,IAAM,sBAAsB;AAE5B,IAAM,aAAa,OAAO,OAAO;AAAA,EACtC,WAAW;AAAA,EACX,UAAU;AACZ,CAAC;;;ACHM,SAAS,oBACd,UACA,SAC0B;AAC1B,QAAM,UAAU,SAAS,cAAc,OAAO;AAC9C,UAAQ,aAAa,qBAAqB,EAAE;AAC5C,SAAO;AACT;AAEO,SAAS,aACd,UACA,OACA,YAAY,IACO;AACnB,QAAM,SAAS,oBAAoB,UAAU,QAAQ;AACrD,SAAO,OAAO;AACd,SAAO,YAAY;AACnB,SAAO,cAAc;AACrB,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/ui/data-flow-panel-contract.ts
|
|
2
|
+
var DATA_FLOW_EXTENSION_KEY = /* @__PURE__ */ Symbol.for("spotpatch.data-flow.extension.v1");
|
|
3
|
+
function registerDataFlowExtension(extension, target = globalThis) {
|
|
4
|
+
target[DATA_FLOW_EXTENSION_KEY] = extension;
|
|
5
|
+
}
|
|
6
|
+
function getDataFlowExtension(target = globalThis) {
|
|
7
|
+
return target[DATA_FLOW_EXTENSION_KEY];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
registerDataFlowExtension,
|
|
12
|
+
getDataFlowExtension
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=chunk-NII5OBAN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ui/data-flow-panel-contract.ts"],"sourcesContent":["import type {\n ComponentDataFlowReport,\n NetworkObservation,\n PageDataFlowReport,\n SpotPatchLocale,\n} from \"@spotpatch/shared\";\n\nimport type { DataFlowComponentRegistration } from \"../data-flow/data-flow-runtime.js\";\n\nexport type DataFlowPanelStatus = \"disabled\" | \"idle\" | \"loading\" | \"ready\" | \"error\";\n\nexport interface DataFlowPanelSnapshot {\n readonly status: DataFlowPanelStatus;\n readonly report?: ComponentDataFlowReport | PageDataFlowReport;\n readonly message?: string;\n}\n\nexport interface DataFlowViewState {\n readonly component: DataFlowPanelSnapshot;\n readonly page: DataFlowPanelSnapshot;\n readonly observationCount: number;\n}\n\nexport interface DataFlowPanel {\n readonly root: HTMLElement;\n readonly refreshButton: HTMLButtonElement;\n readonly styles: HTMLStyleElement;\n readonly dispose: () => void;\n readonly render: (state: DataFlowViewState) => void;\n readonly resetView: () => void;\n}\n\nexport type DataFlowPanelFactory = (\n document: Document,\n enabled: boolean,\n locale: () => SpotPatchLocale,\n changesRoot: HTMLElement,\n diagnosticsRoot: HTMLElement,\n onViewChange: () => void,\n) => DataFlowPanel;\n\nexport interface DataFlowExtension {\n readonly createPanel: DataFlowPanelFactory;\n readonly getComponentRegistration: (\n component: object,\n ) => DataFlowComponentRegistration | undefined;\n readonly observations: (routeKey: string) => readonly NetworkObservation[];\n readonly mergeComponentReport: (\n report: ComponentDataFlowReport,\n observations: readonly NetworkObservation[],\n ) => ComponentDataFlowReport;\n readonly mergePageReport: (\n report: PageDataFlowReport,\n observations: readonly NetworkObservation[],\n ) => PageDataFlowReport;\n}\n\nconst DATA_FLOW_EXTENSION_KEY = Symbol.for(\"spotpatch.data-flow.extension.v1\");\ntype ExtensionStore = Partial<Record<symbol, DataFlowExtension>>;\n\nexport function registerDataFlowExtension(\n extension: DataFlowExtension,\n target: ExtensionStore = globalThis,\n): void {\n target[DATA_FLOW_EXTENSION_KEY] = extension;\n}\n\nexport function getDataFlowExtension(\n target: ExtensionStore = globalThis,\n): DataFlowExtension | undefined {\n return target[DATA_FLOW_EXTENSION_KEY];\n}\n"],"mappings":";AAyDA,IAAM,0BAA0B,uBAAO,IAAI,kCAAkC;AAGtE,SAAS,0BACd,WACA,SAAyB,YACnB;AACN,SAAO,uBAAuB,IAAI;AACpC;AAEO,SAAS,qBACd,SAAyB,YACM;AAC/B,SAAO,OAAO,uBAAuB;AACvC;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/ui/external-handoff-contract.ts
|
|
2
|
+
var EXTERNAL_HANDOFF_EXTENSION_KEY = /* @__PURE__ */ Symbol.for("spotpatch.external-handoff.v1");
|
|
3
|
+
function registerExternalHandoffExtension(extension) {
|
|
4
|
+
globalThis[EXTERNAL_HANDOFF_EXTENSION_KEY] = extension;
|
|
5
|
+
}
|
|
6
|
+
function getExternalHandoffExtension() {
|
|
7
|
+
return globalThis[EXTERNAL_HANDOFF_EXTENSION_KEY];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
registerExternalHandoffExtension,
|
|
12
|
+
getExternalHandoffExtension
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=chunk-XBD55BCF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ui/external-handoff-contract.ts"],"sourcesContent":["import type {\n ErrorCode,\n ExternalHandoffCapability,\n ExternalHandoffPublishResult,\n ExternalHandoffStatusResult,\n ExternalHandoffFramework,\n SpotAnnotation,\n SpotPatchLocale,\n} from \"@spotpatch/shared/external-handoff-browser\";\n\nexport interface ExternalHandoffPanel {\n readonly refreshButton: HTMLButtonElement;\n readonly root: HTMLElement;\n readonly sendButton: HTMLButtonElement;\n readonly styles: HTMLStyleElement;\n readonly confirmDisclosure: (annotation: SpotAnnotation) => Promise<boolean>;\n readonly dispose: () => void;\n readonly renderCapability: (capability: ExternalHandoffCapability) => void;\n readonly renderError: (code?: ErrorCode, retryable?: boolean) => void;\n readonly renderPublishResult: (result: ExternalHandoffPublishResult) => void;\n readonly renderPublishing: () => void;\n readonly renderStatus: (result: ExternalHandoffStatusResult) => void;\n readonly resolveButton: HTMLButtonElement;\n readonly setBusy: (busy: boolean) => void;\n readonly setContextReady: (ready: boolean) => void;\n readonly setSelectionVisible: (visible: boolean) => void;\n}\n\nexport interface ExternalHandoffWorkflow {\n readonly cancelPending: () => void;\n readonly dispose: () => void;\n readonly mount: () => void;\n}\n\nexport interface ExternalHandoffExtension {\n readonly createPanel: (\n document: Document,\n framework: ExternalHandoffFramework,\n locale: () => SpotPatchLocale,\n sessionId: string,\n subscribeLocale: (listener: () => void) => () => void,\n onViewChange: () => void,\n ) => ExternalHandoffPanel;\n readonly createWorkflow: (\n fetch: typeof globalThis.fetch,\n panel: ExternalHandoffPanel,\n selectedAnnotation: () => SpotAnnotation | undefined,\n sessionToken: string,\n window: Window,\n ) => ExternalHandoffWorkflow;\n}\n\nconst EXTERNAL_HANDOFF_EXTENSION_KEY = Symbol.for(\"spotpatch.external-handoff.v1\");\ntype ExtensionStore = Partial<Record<symbol, ExternalHandoffExtension>>;\n\nexport function registerExternalHandoffExtension(\n extension: ExternalHandoffExtension,\n): void {\n (globalThis as ExtensionStore)[EXTERNAL_HANDOFF_EXTENSION_KEY] = extension;\n}\n\nexport function getExternalHandoffExtension(): ExternalHandoffExtension | undefined {\n return (globalThis as ExtensionStore)[EXTERNAL_HANDOFF_EXTENSION_KEY];\n}\n"],"mappings":";AAoDA,IAAM,iCAAiC,uBAAO,IAAI,+BAA+B;AAG1E,SAAS,iCACd,WACM;AACN,EAAC,WAA8B,8BAA8B,IAAI;AACnE;AAEO,SAAS,8BAAoE;AAClF,SAAQ,WAA8B,8BAA8B;AACtE;","names":[]}
|
package/dist/data-flow-panel.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createButton,
|
|
3
|
-
createMarkedElement,
|
|
4
2
|
getDataFlowExtension,
|
|
5
3
|
registerDataFlowExtension
|
|
6
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NII5OBAN.js";
|
|
5
|
+
import {
|
|
6
|
+
createButton,
|
|
7
|
+
createMarkedElement
|
|
8
|
+
} from "./chunk-7ES63LA7.js";
|
|
7
9
|
|
|
8
10
|
// src/ui/data-flow-panel.ts
|
|
9
11
|
var LABELS = Object.freeze({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ui/data-flow-panel.ts"],"sourcesContent":["import type { DataDependency, SpotPatchLocale } from \"@spotpatch/shared\";\n\nimport { createButton, createMarkedElement } from \"./dom.js\";\nimport type {\n DataFlowPanel,\n DataFlowPanelSnapshot,\n DataFlowViewState,\n} from \"./data-flow-panel-contract.js\";\n\ninterface Labels {\n readonly bindings: string;\n readonly changes: string;\n readonly componentEmpty: string;\n readonly componentTab: string;\n readonly componentTitle: string;\n readonly consumed: string;\n readonly declared: string;\n readonly diagnostics: string;\n readonly disabled: string;\n readonly error: string;\n readonly evidence: string;\n readonly loading: string;\n readonly logicalObserved: string;\n readonly noParameters: string;\n readonly observed: string;\n readonly pageEmpty: string;\n readonly pageTab: string;\n readonly pageTitle: string;\n readonly parameters: string;\n readonly refresh: string;\n readonly unknown: string;\n}\n\nconst LABELS = Object.freeze({\n \"zh-CN\": Object.freeze({\n bindings: \"数据去向\",\n changes: \"修改说明\",\n componentEmpty: \"当前组件没有找到可证明的接口。未找到不等于没有请求。\",\n componentTab: \"数据链路\",\n componentTitle: \"组件数据链路\",\n consumed: \"读取字段\",\n declared: \"代码声明,尚未在本次页面会话中观测\",\n diagnostics: \"诊断\",\n disabled: \"数据链路能力未启用,请在插件配置中设置 dataFlow: {}。\",\n error: \"数据链路报告加载失败\",\n evidence: \"证据\",\n loading: \"正在分析源码并合并运行时证据…\",\n logicalObserved: \"本次会话已进入 tRPC 调用链\",\n noParameters: \"未提取到可证明的参数键\",\n observed: \"本次会话已实际请求\",\n pageEmpty: \"当前已选页面范围内没有静态接口或运行时网络记录。\",\n pageTab: \"页面接口\",\n pageTitle: \"页面接口\",\n parameters: \"请求参数\",\n refresh: \"刷新证据\",\n unknown: \"未知\",\n }),\n \"en-US\": Object.freeze({\n bindings: \"Data destinations\",\n changes: \"Changes\",\n componentEmpty:\n \"No proven interface was found for this component. This does not prove that no request exists.\",\n componentTab: \"Data flow\",\n componentTitle: \"Component data flow\",\n consumed: \"Consumed fields\",\n declared: \"Declared in code, not observed in this page session\",\n diagnostics: \"Diagnostics\",\n disabled: \"Data flow is disabled. Set dataFlow: {} in the plugin options.\",\n error: \"Failed to load the data-flow report\",\n evidence: \"Evidence\",\n loading: \"Analyzing source and merging runtime evidence…\",\n logicalObserved: \"Dispatched through the tRPC link in this session\",\n noParameters: \"No proven parameter keys were extracted\",\n observed: \"Actually requested in this session\",\n pageEmpty:\n \"No static interface or runtime traffic is available for the selected page scope.\",\n pageTab: \"Page APIs\",\n pageTitle: \"Page interfaces\",\n parameters: \"Request parameters\",\n refresh: \"Refresh evidence\",\n unknown: \"Unknown\",\n }),\n}) satisfies Readonly<Record<SpotPatchLocale, Labels>>;\n\nfunction badge(document: Document, text: string, tone: string): HTMLElement {\n const element = createMarkedElement(document, \"span\");\n element.className = \"spotpatch-data-flow-badge\";\n element.dataset.tone = tone;\n element.textContent = text;\n return element;\n}\n\nfunction detailRow(document: Document, label: string, value: string): HTMLElement {\n const row = createMarkedElement(document, \"div\");\n row.className = \"spotpatch-data-flow-detail\";\n const key = createMarkedElement(document, \"span\");\n key.textContent = label;\n const content = createMarkedElement(document, \"code\");\n content.textContent = value;\n row.append(key, content);\n return row;\n}\n\nfunction renderDependency(\n document: Document,\n dependency: DataDependency,\n labels: Labels,\n): HTMLElement {\n const card = createMarkedElement(document, \"article\");\n card.className = \"spotpatch-data-flow-card\";\n const header = createMarkedElement(document, \"div\");\n header.className = \"spotpatch-data-flow-card-head\";\n const endpoint = createMarkedElement(document, \"div\");\n endpoint.className = \"spotpatch-data-flow-endpoint\";\n const method = createMarkedElement(document, \"strong\");\n method.textContent = dependency.method ?? labels.unknown;\n const path = createMarkedElement(document, \"code\");\n path.textContent =\n dependency.url === undefined\n ? (dependency.operation ?? labels.unknown)\n : `${dependency.url.origin ?? \"\"}${dependency.url.pathname}`;\n endpoint.append(method, path);\n const states = createMarkedElement(document, \"div\");\n states.className = \"spotpatch-data-flow-badges\";\n states.append(\n badge(\n document,\n dependency.execution === \"observed\"\n ? dependency.kind === \"rpc\"\n ? labels.logicalObserved\n : labels.observed\n : labels.declared,\n dependency.execution === \"observed\" ? \"success\" : \"neutral\",\n ),\n badge(\n document,\n dependency.proof,\n dependency.proof === \"proven\" ? \"proof\" : \"warning\",\n ),\n badge(document, dependency.association, \"neutral\"),\n );\n header.append(endpoint, states);\n\n const parameters =\n dependency.parameters.length === 0\n ? labels.noParameters\n : dependency.parameters\n .map(\n (parameter) =>\n `${parameter.position}.${parameter.path}${parameter.type === undefined ? \"\" : `: ${parameter.type}`}${parameter.sensitive ? \" [sensitive]\" : \"\"}${parameter.condition === undefined ? \"\" : ` [when ${parameter.condition}]`}`,\n )\n .join(\"\\n\");\n const consumed =\n dependency.response.consumedFields.length === 0\n ? labels.unknown\n : dependency.response.consumedFields.join(\", \");\n const bindings =\n dependency.suppliedBindings.length === 0\n ? labels.unknown\n : dependency.suppliedBindings.join(\", \");\n const body = createMarkedElement(document, \"div\");\n body.className = \"spotpatch-data-flow-card-body\";\n const observationIds = new Set(dependency.observationIds);\n const staticEvidenceCount = dependency.evidenceIds.filter(\n (id) => !observationIds.has(id),\n ).length;\n body.append(\n detailRow(document, labels.parameters, parameters),\n detailRow(document, labels.consumed, consumed),\n detailRow(document, labels.bindings, bindings),\n detailRow(\n document,\n labels.evidence,\n `${String(staticEvidenceCount)} static · ${String(dependency.observationIds.length)} runtime`,\n ),\n );\n card.append(header, body);\n return card;\n}\n\nfunction createReportRoot(\n document: Document,\n titleText: string,\n): Readonly<{ root: HTMLElement; status: HTMLElement; list: HTMLElement }> {\n const root = createMarkedElement(document, \"section\");\n root.className = \"spotpatch-data-flow-panel\";\n const title = createMarkedElement(document, \"h3\");\n title.textContent = titleText;\n const status = createMarkedElement(document, \"p\");\n status.className = \"spotpatch-data-flow-status\";\n const list = createMarkedElement(document, \"div\");\n list.className = \"spotpatch-data-flow-list\";\n root.append(title, status, list);\n return Object.freeze({ root, status, list });\n}\n\nexport function createDataFlowPanel(\n document: Document,\n enabled: boolean,\n locale: () => SpotPatchLocale,\n changesRoot: HTMLElement,\n diagnosticsRoot: HTMLElement,\n onViewChange: () => void,\n): DataFlowPanel {\n let labels = LABELS[locale()];\n const component = createReportRoot(document, labels.componentTitle);\n const page = createReportRoot(document, labels.pageTitle);\n const refreshButton = createButton(document, labels.refresh);\n const styles = document.createElement(\"style\");\n styles.textContent = DATA_FLOW_PANEL_STYLES;\n refreshButton.classList.add(\"spotpatch-data-flow-refresh\");\n component.root.prepend(refreshButton);\n const root = createMarkedElement(document, \"div\");\n const tabs = createMarkedElement(document, \"nav\");\n tabs.className = \"spotpatch-view-tabs\";\n tabs.setAttribute(\"aria-label\", \"SpotPatch views\");\n tabs.setAttribute(\"role\", \"tablist\");\n const views = new Map([\n [\"changes\", changesRoot],\n [\"component-data\", component.root],\n [\"page-data\", page.root],\n [\"diagnostics\", diagnosticsRoot],\n ]);\n const tabButtons = new Map<string, HTMLButtonElement>();\n let activeView = \"changes\";\n for (const id of views.keys()) {\n const button = createButton(document, \"\");\n button.dataset.viewId = id;\n button.id = `spotpatch-view-${id}-tab`;\n button.setAttribute(\"role\", \"tab\");\n button.setAttribute(\"aria-selected\", String(id === activeView));\n const view = views.get(id);\n view?.setAttribute(\"aria-labelledby\", button.id);\n view?.setAttribute(\"role\", \"tabpanel\");\n if (!enabled && (id === \"component-data\" || id === \"page-data\")) {\n button.hidden = true;\n }\n tabButtons.set(id, button);\n tabs.append(button);\n }\n root.append(tabs, ...views.values());\n\n function selectView(viewId: string): void {\n if (!views.has(viewId)) return;\n activeView = viewId;\n for (const [id, view] of views) {\n view.hidden = id !== viewId;\n const button = tabButtons.get(id);\n button?.setAttribute(\"aria-selected\", String(id === viewId));\n if (button !== undefined) button.tabIndex = id === viewId ? 0 : -1;\n }\n onViewChange();\n }\n\n function handleTabClick(event: Event): void {\n if (!(event.target instanceof HTMLButtonElement)) return;\n const viewId = event.target.dataset.viewId;\n if (viewId !== undefined) selectView(viewId);\n }\n\n tabs.addEventListener(\"click\", handleTabClick);\n selectView(activeView);\n\n function renderSnapshot(\n target: ReturnType<typeof createReportRoot>,\n snapshot: DataFlowPanelSnapshot,\n empty: string,\n ): void {\n target.list.replaceChildren();\n target.status.dataset.state = snapshot.status;\n if (!enabled || snapshot.status === \"disabled\") {\n target.status.textContent = labels.disabled;\n return;\n }\n if (snapshot.status === \"loading\") {\n target.status.textContent = labels.loading;\n return;\n }\n if (snapshot.status === \"error\") {\n target.status.textContent = snapshot.message ?? labels.error;\n return;\n }\n const report = snapshot.report;\n const diagnosticCodes =\n report === undefined\n ? \"\"\n : [...new Set(report.diagnostics.map(({ code }) => code))].join(\", \");\n const diagnosticSuffix =\n diagnosticCodes.length === 0\n ? \"\"\n : ` · ${labels.diagnostics}: ${diagnosticCodes}`;\n if (report === undefined || report.dependencies.length === 0) {\n target.status.textContent = `${empty}${diagnosticSuffix}`;\n return;\n }\n target.status.textContent = `${String(report.dependencies.length)} · ${report.completeness.complete ? \"complete\" : \"partial\"}${diagnosticSuffix}`;\n target.list.append(\n ...report.dependencies.map((dependency) =>\n renderDependency(document, dependency, labels),\n ),\n );\n }\n\n return Object.freeze({\n root,\n refreshButton,\n styles,\n dispose(): void {\n tabs.removeEventListener(\"click\", handleTabClick);\n },\n render(state: DataFlowViewState): void {\n labels = LABELS[locale()];\n const tabLabels = [\n labels.changes,\n labels.componentTab,\n labels.pageTab,\n labels.diagnostics,\n ];\n [...tabButtons.values()].forEach((button, index) => {\n button.textContent = tabLabels[index] ?? \"\";\n });\n refreshButton.textContent = `${labels.refresh} · ${String(state.observationCount)}`;\n refreshButton.disabled = !enabled || state.component.status === \"loading\";\n renderSnapshot(component, state.component, labels.componentEmpty);\n renderSnapshot(page, state.page, labels.pageEmpty);\n },\n resetView(): void {\n selectView(\"changes\");\n },\n });\n}\n\nconst DATA_FLOW_PANEL_STYLES = `\n .spotpatch-view-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin-bottom: 12px; padding: 3px; border: 1px solid rgb(255 255 255 / 7%); border-radius: 9px; background: rgb(3 7 18 / 42%); }\n .spotpatch-view-tabs button { min-width: 0; border: 0; border-radius: 7px; padding: 7px 5px; color: var(--spotpatch-text-muted); background: transparent; cursor: pointer; font-size: 10.5px; }\n .spotpatch-view-tabs button[aria-selected=\"true\"] { color: #f8fafc; background: rgb(139 124 247 / 18%); }\n .spotpatch-data-flow-panel { position: relative; }\n .spotpatch-data-flow-panel > h3 { margin: 0 0 3px; color: #f3f4f6; font-size: 13px; }\n .spotpatch-data-flow-refresh { position: absolute; top: -4px; right: 0; border: 1px solid rgb(139 124 247 / 30%); border-radius: 7px; padding: 4px 8px; color: #c4baff; background: rgb(139 124 247 / 8%); cursor: pointer; font-size: 10.5px; }\n .spotpatch-data-flow-refresh:disabled { cursor: not-allowed; opacity: .45; }\n .spotpatch-data-flow-status { margin: 0 0 10px; color: var(--spotpatch-text-muted); font-size: 10.5px; line-height: 1.5; }\n .spotpatch-data-flow-list { display: grid; gap: 8px; }\n .spotpatch-data-flow-card { overflow: hidden; border: 1px solid rgb(255 255 255 / 8%); border-radius: 9px; background: rgb(255 255 255 / 2.5%); }\n .spotpatch-data-flow-card-head { display: grid; gap: 7px; padding: 10px; border-bottom: 1px solid rgb(255 255 255 / 7%); }\n .spotpatch-data-flow-endpoint { display: flex; min-width: 0; align-items: center; gap: 8px; }\n .spotpatch-data-flow-endpoint strong { color: #79d9e7; font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }\n .spotpatch-data-flow-endpoint code { min-width: 0; overflow: hidden; color: #f8fafc; font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }\n .spotpatch-data-flow-badges { display: flex; flex-wrap: wrap; gap: 4px; }\n .spotpatch-data-flow-badge { border-radius: 999px; padding: 2px 6px; color: #9ca3af; background: rgb(255 255 255 / 5%); font-size: 9px; }\n .spotpatch-data-flow-badge[data-tone=\"success\"] { color: #6ee7b7; background: rgb(16 185 129 / 10%); }\n .spotpatch-data-flow-badge[data-tone=\"proof\"] { color: #c4b5fd; background: rgb(139 92 246 / 11%); }\n .spotpatch-data-flow-badge[data-tone=\"warning\"] { color: #fcd34d; background: rgb(245 158 11 / 10%); }\n .spotpatch-data-flow-card-body { display: grid; gap: 7px; padding: 10px; }\n .spotpatch-data-flow-detail { display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 8px; align-items: start; }\n .spotpatch-data-flow-detail > span { color: var(--spotpatch-text-muted); font-size: 10px; }\n .spotpatch-data-flow-detail > code { overflow-wrap: anywhere; color: #cbd5e1; font: 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }\n`;\n"],"mappings":";;;;;;;;AAiCA,IAAM,SAAS,OAAO,OAAO;AAAA,EAC3B,SAAS,OAAO,OAAO;AAAA,IACrB,UAAU;AAAA,IACV,SAAS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IACA;AAAA,IACA,UAAgB;AACd,WAAK,oBAAoB,SAAS,cAAc;AAAA,IAClD;AAAA,IACA,OAAO,OAAgC;AACrC,eAAS,OAAO,OAAO,CAAC;AACxB,YAAM,YAAY;AAAA,QAChB,OAAO;AAAA,QACP,OAAO;AAAA,QACP,OAAO;AAAA,QACP,OAAO;AAAA,MACT;AACA,OAAC,GAAG,WAAW,OAAO,CAAC,EAAE,QAAQ,CAAC,QAAQ,UAAU;AAClD,eAAO,cAAc,UAAU,KAAK,KAAK;AAAA,MAC3C,CAAC;AACD,oBAAc,cAAc,GAAG,OAAO,OAAO,SAAM,OAAO,MAAM,gBAAgB,CAAC;AACjF,oBAAc,WAAW,CAAC,WAAW,MAAM,UAAU,WAAW;AAChE,qBAAe,WAAW,MAAM,WAAW,OAAO,cAAc;AAChE,qBAAe,MAAM,MAAM,MAAM,OAAO,SAAS;AAAA,IACnD;AAAA,IACA,YAAkB;AAChB,iBAAW,SAAS;AAAA,IACtB;AAAA,EACF,CAAC;AACH;AAEA,IAAM,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/ui/data-flow-panel.ts"],"sourcesContent":["import type { DataDependency, SpotPatchLocale } from \"@spotpatch/shared\";\n\nimport { createButton, createMarkedElement } from \"./dom.js\";\nimport type {\n DataFlowPanel,\n DataFlowPanelSnapshot,\n DataFlowViewState,\n} from \"./data-flow-panel-contract.js\";\n\ninterface Labels {\n readonly bindings: string;\n readonly changes: string;\n readonly componentEmpty: string;\n readonly componentTab: string;\n readonly componentTitle: string;\n readonly consumed: string;\n readonly declared: string;\n readonly diagnostics: string;\n readonly disabled: string;\n readonly error: string;\n readonly evidence: string;\n readonly loading: string;\n readonly logicalObserved: string;\n readonly noParameters: string;\n readonly observed: string;\n readonly pageEmpty: string;\n readonly pageTab: string;\n readonly pageTitle: string;\n readonly parameters: string;\n readonly refresh: string;\n readonly unknown: string;\n}\n\nconst LABELS = Object.freeze({\n \"zh-CN\": Object.freeze({\n bindings: \"数据去向\",\n changes: \"修改说明\",\n componentEmpty: \"当前组件没有找到可证明的接口。未找到不等于没有请求。\",\n componentTab: \"数据链路\",\n componentTitle: \"组件数据链路\",\n consumed: \"读取字段\",\n declared: \"代码声明,尚未在本次页面会话中观测\",\n diagnostics: \"诊断\",\n disabled: \"数据链路能力未启用,请在插件配置中设置 dataFlow: {}。\",\n error: \"数据链路报告加载失败\",\n evidence: \"证据\",\n loading: \"正在分析源码并合并运行时证据…\",\n logicalObserved: \"本次会话已进入 tRPC 调用链\",\n noParameters: \"未提取到可证明的参数键\",\n observed: \"本次会话已实际请求\",\n pageEmpty: \"当前已选页面范围内没有静态接口或运行时网络记录。\",\n pageTab: \"页面接口\",\n pageTitle: \"页面接口\",\n parameters: \"请求参数\",\n refresh: \"刷新证据\",\n unknown: \"未知\",\n }),\n \"en-US\": Object.freeze({\n bindings: \"Data destinations\",\n changes: \"Changes\",\n componentEmpty:\n \"No proven interface was found for this component. This does not prove that no request exists.\",\n componentTab: \"Data flow\",\n componentTitle: \"Component data flow\",\n consumed: \"Consumed fields\",\n declared: \"Declared in code, not observed in this page session\",\n diagnostics: \"Diagnostics\",\n disabled: \"Data flow is disabled. Set dataFlow: {} in the plugin options.\",\n error: \"Failed to load the data-flow report\",\n evidence: \"Evidence\",\n loading: \"Analyzing source and merging runtime evidence…\",\n logicalObserved: \"Dispatched through the tRPC link in this session\",\n noParameters: \"No proven parameter keys were extracted\",\n observed: \"Actually requested in this session\",\n pageEmpty:\n \"No static interface or runtime traffic is available for the selected page scope.\",\n pageTab: \"Page APIs\",\n pageTitle: \"Page interfaces\",\n parameters: \"Request parameters\",\n refresh: \"Refresh evidence\",\n unknown: \"Unknown\",\n }),\n}) satisfies Readonly<Record<SpotPatchLocale, Labels>>;\n\nfunction badge(document: Document, text: string, tone: string): HTMLElement {\n const element = createMarkedElement(document, \"span\");\n element.className = \"spotpatch-data-flow-badge\";\n element.dataset.tone = tone;\n element.textContent = text;\n return element;\n}\n\nfunction detailRow(document: Document, label: string, value: string): HTMLElement {\n const row = createMarkedElement(document, \"div\");\n row.className = \"spotpatch-data-flow-detail\";\n const key = createMarkedElement(document, \"span\");\n key.textContent = label;\n const content = createMarkedElement(document, \"code\");\n content.textContent = value;\n row.append(key, content);\n return row;\n}\n\nfunction renderDependency(\n document: Document,\n dependency: DataDependency,\n labels: Labels,\n): HTMLElement {\n const card = createMarkedElement(document, \"article\");\n card.className = \"spotpatch-data-flow-card\";\n const header = createMarkedElement(document, \"div\");\n header.className = \"spotpatch-data-flow-card-head\";\n const endpoint = createMarkedElement(document, \"div\");\n endpoint.className = \"spotpatch-data-flow-endpoint\";\n const method = createMarkedElement(document, \"strong\");\n method.textContent = dependency.method ?? labels.unknown;\n const path = createMarkedElement(document, \"code\");\n path.textContent =\n dependency.url === undefined\n ? (dependency.operation ?? labels.unknown)\n : `${dependency.url.origin ?? \"\"}${dependency.url.pathname}`;\n endpoint.append(method, path);\n const states = createMarkedElement(document, \"div\");\n states.className = \"spotpatch-data-flow-badges\";\n states.append(\n badge(\n document,\n dependency.execution === \"observed\"\n ? dependency.kind === \"rpc\"\n ? labels.logicalObserved\n : labels.observed\n : labels.declared,\n dependency.execution === \"observed\" ? \"success\" : \"neutral\",\n ),\n badge(\n document,\n dependency.proof,\n dependency.proof === \"proven\" ? \"proof\" : \"warning\",\n ),\n badge(document, dependency.association, \"neutral\"),\n );\n header.append(endpoint, states);\n\n const parameters =\n dependency.parameters.length === 0\n ? labels.noParameters\n : dependency.parameters\n .map(\n (parameter) =>\n `${parameter.position}.${parameter.path}${parameter.type === undefined ? \"\" : `: ${parameter.type}`}${parameter.sensitive ? \" [sensitive]\" : \"\"}${parameter.condition === undefined ? \"\" : ` [when ${parameter.condition}]`}`,\n )\n .join(\"\\n\");\n const consumed =\n dependency.response.consumedFields.length === 0\n ? labels.unknown\n : dependency.response.consumedFields.join(\", \");\n const bindings =\n dependency.suppliedBindings.length === 0\n ? labels.unknown\n : dependency.suppliedBindings.join(\", \");\n const body = createMarkedElement(document, \"div\");\n body.className = \"spotpatch-data-flow-card-body\";\n const observationIds = new Set(dependency.observationIds);\n const staticEvidenceCount = dependency.evidenceIds.filter(\n (id) => !observationIds.has(id),\n ).length;\n body.append(\n detailRow(document, labels.parameters, parameters),\n detailRow(document, labels.consumed, consumed),\n detailRow(document, labels.bindings, bindings),\n detailRow(\n document,\n labels.evidence,\n `${String(staticEvidenceCount)} static · ${String(dependency.observationIds.length)} runtime`,\n ),\n );\n card.append(header, body);\n return card;\n}\n\nfunction createReportRoot(\n document: Document,\n titleText: string,\n): Readonly<{ root: HTMLElement; status: HTMLElement; list: HTMLElement }> {\n const root = createMarkedElement(document, \"section\");\n root.className = \"spotpatch-data-flow-panel\";\n const title = createMarkedElement(document, \"h3\");\n title.textContent = titleText;\n const status = createMarkedElement(document, \"p\");\n status.className = \"spotpatch-data-flow-status\";\n const list = createMarkedElement(document, \"div\");\n list.className = \"spotpatch-data-flow-list\";\n root.append(title, status, list);\n return Object.freeze({ root, status, list });\n}\n\nexport function createDataFlowPanel(\n document: Document,\n enabled: boolean,\n locale: () => SpotPatchLocale,\n changesRoot: HTMLElement,\n diagnosticsRoot: HTMLElement,\n onViewChange: () => void,\n): DataFlowPanel {\n let labels = LABELS[locale()];\n const component = createReportRoot(document, labels.componentTitle);\n const page = createReportRoot(document, labels.pageTitle);\n const refreshButton = createButton(document, labels.refresh);\n const styles = document.createElement(\"style\");\n styles.textContent = DATA_FLOW_PANEL_STYLES;\n refreshButton.classList.add(\"spotpatch-data-flow-refresh\");\n component.root.prepend(refreshButton);\n const root = createMarkedElement(document, \"div\");\n const tabs = createMarkedElement(document, \"nav\");\n tabs.className = \"spotpatch-view-tabs\";\n tabs.setAttribute(\"aria-label\", \"SpotPatch views\");\n tabs.setAttribute(\"role\", \"tablist\");\n const views = new Map([\n [\"changes\", changesRoot],\n [\"component-data\", component.root],\n [\"page-data\", page.root],\n [\"diagnostics\", diagnosticsRoot],\n ]);\n const tabButtons = new Map<string, HTMLButtonElement>();\n let activeView = \"changes\";\n for (const id of views.keys()) {\n const button = createButton(document, \"\");\n button.dataset.viewId = id;\n button.id = `spotpatch-view-${id}-tab`;\n button.setAttribute(\"role\", \"tab\");\n button.setAttribute(\"aria-selected\", String(id === activeView));\n const view = views.get(id);\n view?.setAttribute(\"aria-labelledby\", button.id);\n view?.setAttribute(\"role\", \"tabpanel\");\n if (!enabled && (id === \"component-data\" || id === \"page-data\")) {\n button.hidden = true;\n }\n tabButtons.set(id, button);\n tabs.append(button);\n }\n root.append(tabs, ...views.values());\n\n function selectView(viewId: string): void {\n if (!views.has(viewId)) return;\n activeView = viewId;\n for (const [id, view] of views) {\n view.hidden = id !== viewId;\n const button = tabButtons.get(id);\n button?.setAttribute(\"aria-selected\", String(id === viewId));\n if (button !== undefined) button.tabIndex = id === viewId ? 0 : -1;\n }\n onViewChange();\n }\n\n function handleTabClick(event: Event): void {\n if (!(event.target instanceof HTMLButtonElement)) return;\n const viewId = event.target.dataset.viewId;\n if (viewId !== undefined) selectView(viewId);\n }\n\n tabs.addEventListener(\"click\", handleTabClick);\n selectView(activeView);\n\n function renderSnapshot(\n target: ReturnType<typeof createReportRoot>,\n snapshot: DataFlowPanelSnapshot,\n empty: string,\n ): void {\n target.list.replaceChildren();\n target.status.dataset.state = snapshot.status;\n if (!enabled || snapshot.status === \"disabled\") {\n target.status.textContent = labels.disabled;\n return;\n }\n if (snapshot.status === \"loading\") {\n target.status.textContent = labels.loading;\n return;\n }\n if (snapshot.status === \"error\") {\n target.status.textContent = snapshot.message ?? labels.error;\n return;\n }\n const report = snapshot.report;\n const diagnosticCodes =\n report === undefined\n ? \"\"\n : [...new Set(report.diagnostics.map(({ code }) => code))].join(\", \");\n const diagnosticSuffix =\n diagnosticCodes.length === 0\n ? \"\"\n : ` · ${labels.diagnostics}: ${diagnosticCodes}`;\n if (report === undefined || report.dependencies.length === 0) {\n target.status.textContent = `${empty}${diagnosticSuffix}`;\n return;\n }\n target.status.textContent = `${String(report.dependencies.length)} · ${report.completeness.complete ? \"complete\" : \"partial\"}${diagnosticSuffix}`;\n target.list.append(\n ...report.dependencies.map((dependency) =>\n renderDependency(document, dependency, labels),\n ),\n );\n }\n\n return Object.freeze({\n root,\n refreshButton,\n styles,\n dispose(): void {\n tabs.removeEventListener(\"click\", handleTabClick);\n },\n render(state: DataFlowViewState): void {\n labels = LABELS[locale()];\n const tabLabels = [\n labels.changes,\n labels.componentTab,\n labels.pageTab,\n labels.diagnostics,\n ];\n [...tabButtons.values()].forEach((button, index) => {\n button.textContent = tabLabels[index] ?? \"\";\n });\n refreshButton.textContent = `${labels.refresh} · ${String(state.observationCount)}`;\n refreshButton.disabled = !enabled || state.component.status === \"loading\";\n renderSnapshot(component, state.component, labels.componentEmpty);\n renderSnapshot(page, state.page, labels.pageEmpty);\n },\n resetView(): void {\n selectView(\"changes\");\n },\n });\n}\n\nconst DATA_FLOW_PANEL_STYLES = `\n .spotpatch-view-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin-bottom: 12px; padding: 3px; border: 1px solid rgb(255 255 255 / 7%); border-radius: 9px; background: rgb(3 7 18 / 42%); }\n .spotpatch-view-tabs button { min-width: 0; border: 0; border-radius: 7px; padding: 7px 5px; color: var(--spotpatch-text-muted); background: transparent; cursor: pointer; font-size: 10.5px; }\n .spotpatch-view-tabs button[aria-selected=\"true\"] { color: #f8fafc; background: rgb(139 124 247 / 18%); }\n .spotpatch-data-flow-panel { position: relative; }\n .spotpatch-data-flow-panel > h3 { margin: 0 0 3px; color: #f3f4f6; font-size: 13px; }\n .spotpatch-data-flow-refresh { position: absolute; top: -4px; right: 0; border: 1px solid rgb(139 124 247 / 30%); border-radius: 7px; padding: 4px 8px; color: #c4baff; background: rgb(139 124 247 / 8%); cursor: pointer; font-size: 10.5px; }\n .spotpatch-data-flow-refresh:disabled { cursor: not-allowed; opacity: .45; }\n .spotpatch-data-flow-status { margin: 0 0 10px; color: var(--spotpatch-text-muted); font-size: 10.5px; line-height: 1.5; }\n .spotpatch-data-flow-list { display: grid; gap: 8px; }\n .spotpatch-data-flow-card { overflow: hidden; border: 1px solid rgb(255 255 255 / 8%); border-radius: 9px; background: rgb(255 255 255 / 2.5%); }\n .spotpatch-data-flow-card-head { display: grid; gap: 7px; padding: 10px; border-bottom: 1px solid rgb(255 255 255 / 7%); }\n .spotpatch-data-flow-endpoint { display: flex; min-width: 0; align-items: center; gap: 8px; }\n .spotpatch-data-flow-endpoint strong { color: #79d9e7; font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }\n .spotpatch-data-flow-endpoint code { min-width: 0; overflow: hidden; color: #f8fafc; font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }\n .spotpatch-data-flow-badges { display: flex; flex-wrap: wrap; gap: 4px; }\n .spotpatch-data-flow-badge { border-radius: 999px; padding: 2px 6px; color: #9ca3af; background: rgb(255 255 255 / 5%); font-size: 9px; }\n .spotpatch-data-flow-badge[data-tone=\"success\"] { color: #6ee7b7; background: rgb(16 185 129 / 10%); }\n .spotpatch-data-flow-badge[data-tone=\"proof\"] { color: #c4b5fd; background: rgb(139 92 246 / 11%); }\n .spotpatch-data-flow-badge[data-tone=\"warning\"] { color: #fcd34d; background: rgb(245 158 11 / 10%); }\n .spotpatch-data-flow-card-body { display: grid; gap: 7px; padding: 10px; }\n .spotpatch-data-flow-detail { display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 8px; align-items: start; }\n .spotpatch-data-flow-detail > span { color: var(--spotpatch-text-muted); font-size: 10px; }\n .spotpatch-data-flow-detail > code { overflow-wrap: anywhere; color: #cbd5e1; font: 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }\n`;\n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