@cfp-studio/analyzer-api 0.1.14 → 0.1.15
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/index.d.mts +40 -7
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -15,11 +15,12 @@ import { ValueType } from "@cfp-studio/type-analyzer";
|
|
|
15
15
|
*
|
|
16
16
|
* ## 设计约束
|
|
17
17
|
*
|
|
18
|
-
* 1.
|
|
18
|
+
* 1. **内联样式**:面板渲染在用户页面之上,会继承用户的全局 CSS
|
|
19
19
|
* (Umi / antd 的 reset 等)。用内联样式避免被覆盖。
|
|
20
20
|
* 2. **不污染 Runtime Tree**:面板元素带 `data-preview-error-panel`,
|
|
21
21
|
* `iframe` 的 `runtime-bridge.walk()` 会跳过它 —— 否则错误面板会出现在组件树里。
|
|
22
22
|
* 3. **不写源码、不发网络**:纯本地渲染。
|
|
23
|
+
* 4. **独立于框架渲染器**:面板挂在 `document.body` 下,不放进 `#root`(原因见 `renderErrorPanel`)。
|
|
23
24
|
*/
|
|
24
25
|
interface RenderErrorPanelOptions {
|
|
25
26
|
/** 错误本体(`Error` 或任何被 throw 的值)。 */
|
|
@@ -35,13 +36,45 @@ interface RenderErrorPanelOptions {
|
|
|
35
36
|
/** 面板元素的标记属性:`runtime-bridge.walk()` 据此跳过。 */
|
|
36
37
|
declare const ERROR_PANEL_ATTRIBUTE = "data-preview-error-panel";
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
+
* 错误遮罩层的 id:整个预览页只存在一个。
|
|
39
40
|
*
|
|
40
|
-
*
|
|
41
|
+
* 固定在 `document.body` 下,**不放进 `#root`** —— `#root` 由框架的渲染器独占
|
|
42
|
+
*(ReactDOM 清非托管子节点、Vue/Solid 同理),面板放进去会跟着一起被抹掉。
|
|
41
43
|
*/
|
|
42
|
-
declare
|
|
43
|
-
/**
|
|
44
|
-
|
|
44
|
+
declare const ERROR_PANEL_ID = "cfp-error-panel";
|
|
45
|
+
/**
|
|
46
|
+
* 把错误面板渲染成预览页的**独立覆盖层**。
|
|
47
|
+
*
|
|
48
|
+
* 返回一个清理函数,移除面板。重复调用会先移除旧面板(全页只留一个)。
|
|
49
|
+
*
|
|
50
|
+
* ## 为什么不再写进传进来的 container
|
|
51
|
+
*
|
|
52
|
+
* 旧实现 `container.appendChild(panel)` 把面板塞进 `#root`,实测症状(真实反馈):
|
|
53
|
+
* 「错误页面闪现一下,然后被正常页面/白屏覆盖」。原因是双重的:
|
|
54
|
+
* 1. `#root` 归框架渲染器管,它一重渲染就清掉非托管的子节点;
|
|
55
|
+
* 2. `runNewRender` 的 catch 会 `root.innerHTML = rootHtml` 回滚快照。
|
|
56
|
+
*
|
|
57
|
+
* 所以面板必须活在**框架渲染器管不到的地方**。`container` 参数保留仅用于
|
|
58
|
+
* 「遮罩要盖在哪个区域」—— 目前是整页,忽略该参数也符合语义,保留它是为了
|
|
59
|
+
* 兼容 5 个插件现有的调用点。
|
|
60
|
+
*
|
|
61
|
+
* ## 遮罩(`options.dimBackdrop`,默认开)
|
|
62
|
+
*
|
|
63
|
+
* 保存后失败时,上一次成功的内容可能还在(`runNewRender` 会回填快照)。
|
|
64
|
+
* 面板直接用半透明遮罩铺满并阻止穿透点击,避免成功画面干扰阅读错误信息。
|
|
65
|
+
*/
|
|
66
|
+
declare function renderErrorPanel(_container: Element, options: RenderErrorPanelOptions & {
|
|
67
|
+
dimBackdrop?: boolean;
|
|
68
|
+
}): () => void;
|
|
69
|
+
/**
|
|
70
|
+
* 移除全页的错误面板(幂等)。
|
|
71
|
+
*
|
|
72
|
+
* `container` 参数保留只是为了兼容旧调用点 —— 面板现在挂在 `document.body` 下,
|
|
73
|
+
* 已不依赖具体容器。
|
|
74
|
+
*/
|
|
75
|
+
declare function clearErrorPanel(_container?: Element): void;
|
|
76
|
+
/** 当前是否正显示错误面板(供宿主判断要不要保留旧画面)。 */
|
|
77
|
+
declare function isErrorPanelVisible(): boolean;
|
|
45
78
|
/**
|
|
46
79
|
* 把任意被 throw 的值归一成 `{ message, stack }`。
|
|
47
80
|
*
|
|
@@ -106,4 +139,4 @@ type WrapperLanguage = "tsx" | "jsx" | "vue" | "svelte" | "ts" | "js";
|
|
|
106
139
|
/** 默认 wrapper 路径:`__previewjs__/Wrapper.<language>`。 */
|
|
107
140
|
declare function wrapperPathFor(language: WrapperLanguage): string;
|
|
108
141
|
//#endregion
|
|
109
|
-
export { Analyzer, AnalyzerFactory, AnalyzerOptions, BasePreviewable, BasicComponent, Component, ComponentAnalysis, ERROR_PANEL_ATTRIBUTE, FileSourcePosition, PreviewableId, RenderErrorPanelOptions, SpecialTypes, Story, StoryAnalysis, StoryArgs, WrapperLanguage, clearErrorPanel, decodePreviewableId, defineSpecialTypes, describeError, generatePreviewableId, mergeSpecialTypes, renderErrorPanel, wrapperPathFor };
|
|
142
|
+
export { Analyzer, AnalyzerFactory, AnalyzerOptions, BasePreviewable, BasicComponent, Component, ComponentAnalysis, ERROR_PANEL_ATTRIBUTE, ERROR_PANEL_ID, FileSourcePosition, PreviewableId, RenderErrorPanelOptions, SpecialTypes, Story, StoryAnalysis, StoryArgs, WrapperLanguage, clearErrorPanel, decodePreviewableId, defineSpecialTypes, describeError, generatePreviewableId, isErrorPanelVisible, mergeSpecialTypes, renderErrorPanel, wrapperPathFor };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const e=`data-preview-error-panel`;function
|
|
1
|
+
const e=`data-preview-error-panel`,t=`cfp-error-panel`;function n(n,i){r();let{error:o,previewableName:c,componentStack:l}=i,{message:u,stack:d}=a(o),f=i.dimBackdrop!==!1,p=document.getElementById(`cfp-error-panel`)??document.createElement(`div`);p.id=t,p.setAttribute(e,``),p.style.cssText=[`position: fixed`,`inset: 0`,`z-index: 2147483647`,`box-sizing: border-box`,`margin: 0`,`padding: 24px`,`overflow: auto`,`display: flex`,`align-items: flex-start`,`justify-content: center`,f?`background: rgba(24, 24, 27, 0.55)`:`background: transparent`,f?`pointer-events: auto`:`pointer-events: none`].join(`;`);let m=document.createElement(`div`);m.setAttribute(e,``),m.style.cssText=[`position: relative`,`box-sizing: border-box`,`pointer-events: auto`,`width: 100%`,`max-width: 760px`,`margin: 0`,`padding: 20px 24px`,`font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif`,`font-size: 13px`,`line-height: 1.6`,`color: #c0392b`,`background: #fff5f5`,`border: 1px solid #f5b7b1`,`border-radius: 8px`,`box-shadow: 0 8px 32px rgba(0, 0, 0, 0.28)`,`text-align: left`].join(`;`);let h=document.createElement(`div`);h.style.cssText=`font-size: 14px; font-weight: 600; margin-bottom: 8px`,h.textContent=c?`${c} 渲染失败`:`组件渲染失败`;let g=document.createElement(`pre`);if(g.style.cssText=[`margin: 0 0 12px`,`padding: 0`,`font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`,`font-size: 12px`,`line-height: 1.5`,`white-space: pre-wrap`,`word-break: break-word`,`color: #922b21`].join(`;`),g.textContent=u,m.appendChild(h),m.appendChild(g),l){let e=document.createElement(`pre`);e.style.cssText=[`margin: 0`,`padding: 10px 12px`,`background: rgba(192, 57, 43, 0.06)`,`border-radius: 6px`,`font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`,`font-size: 11px`,`line-height: 1.5`,`max-height: 240px`,`overflow: auto`,`white-space: pre-wrap`,`word-break: break-word`,`color: #7b241c`].join(`;`),e.textContent=s(l,12),m.appendChild(e)}if(!l&&d){let e=document.createElement(`pre`);e.style.cssText=[`margin: 0`,`padding: 10px 12px`,`background: rgba(192, 57, 43, 0.06)`,`border-radius: 6px`,`font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`,`font-size: 11px`,`line-height: 1.5`,`max-height: 200px`,`overflow: auto`,`white-space: pre-wrap`,`word-break: break-word`,`color: #7b241c`].join(`;`),e.textContent=s(d,6),m.appendChild(e)}return p.appendChild(m),p.isConnected||document.body.appendChild(p),()=>{p.remove()}}function r(n){document.getElementById(t)?.remove(),document.querySelectorAll(`[${e}]`).forEach(e=>e.remove())}function i(){return document.getElementById(t)!==null}function a(e){if(e instanceof Error)return{message:e.message||e.name,stack:e.stack};if(typeof e==`string`)return{message:e,stack:void 0};if(e&&typeof e==`object`){let t=e;return{message:typeof t.message==`string`?t.message:o(e),stack:typeof t.stack==`string`?t.stack:void 0}}return{message:String(e),stack:void 0}}function o(e){try{return JSON.stringify(e)}catch{return String(e)}}function s(e,t){let n=e.split(`
|
|
2
2
|
`);return n.length>t?`${n.slice(0,t).join(`
|
|
3
|
-
`)}\n…`:e}function
|
|
3
|
+
`)}\n…`:e}function c(e){return`${e.filePath.replace(/\\/g,`/`)}:${e.name}`}function l(e){if(e.lastIndexOf(`:`)===-1)throw Error(`无效的 ID: "${e}"`);let[t,n]=e.split(`:`);return{filePath:t,name:n}}function u(e){return e}function d(...e){let t={};for(let n of e)n&&Object.assign(t,n);return t}function f(e){return`__previewjs__/Wrapper.${e}`}export{e as ERROR_PANEL_ATTRIBUTE,t as ERROR_PANEL_ID,r as clearErrorPanel,l as decodePreviewableId,u as defineSpecialTypes,a as describeError,c as generatePreviewableId,i as isErrorPanelVisible,d as mergeSpecialTypes,n as renderErrorPanel,f as wrapperPathFor};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cfp-studio/analyzer-api",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"pino": "9.11.0",
|
|
26
26
|
"pino-pretty": "13.1.1",
|
|
27
|
-
"@cfp-studio/vfs": "2.1.8",
|
|
28
27
|
"@cfp-studio/serializable-values": "9.0.8",
|
|
28
|
+
"@cfp-studio/vfs": "2.1.8",
|
|
29
29
|
"@cfp-studio/type-analyzer": "10.1.8"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|