@blocklet/pages-kit 0.4.128 → 0.4.129
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/lib/cjs/components/CustomComponentRenderer/ErrorComponent.js +24 -2
- package/lib/cjs/components/CustomComponentRenderer/index.js +4 -2
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/types/builtin.js +2 -1
- package/lib/cjs/utils/inject-global-components.js +9 -5
- package/lib/esm/components/CustomComponentRenderer/ErrorComponent.js +24 -2
- package/lib/esm/components/CustomComponentRenderer/index.js +4 -2
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/types/builtin.js +1 -0
- package/lib/esm/utils/inject-global-components.js +10 -6
- package/lib/types/components/CustomComponentRenderer/ErrorComponent.d.ts +3 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types/builtin.d.ts +1 -0
- package/package.json +1 -1
|
@@ -3,9 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ComponentError = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const material_1 = require("@mui/material");
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const ComponentError = ({ title = 'Component Failed to Load', message, componentId, componentName, blockletId, blockletTitle, showHints = false, error, resetErrorBoundary, delay = 0, shouldShow, }) => {
|
|
8
|
+
const [showError, setShowError] = (0, react_1.useState)(delay === 0);
|
|
9
|
+
// 处理延迟显示逻辑
|
|
10
|
+
(0, react_1.useEffect)(() => {
|
|
11
|
+
// 如果没有延迟,直接显示
|
|
12
|
+
if (delay === 0)
|
|
13
|
+
return undefined;
|
|
14
|
+
const timer = setTimeout(() => {
|
|
15
|
+
// 如果有额外显示条件,只有条件满足时才显示
|
|
16
|
+
if (typeof shouldShow === 'function') {
|
|
17
|
+
if (shouldShow()) {
|
|
18
|
+
setShowError(true);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
setShowError(true);
|
|
23
|
+
}
|
|
24
|
+
}, delay);
|
|
25
|
+
return () => clearTimeout(timer);
|
|
26
|
+
}, [delay, shouldShow]);
|
|
8
27
|
const displayMessage = message || (error ? error.message : 'Unknown error');
|
|
28
|
+
if (!showError) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
9
31
|
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
10
32
|
p: 3,
|
|
11
33
|
border: '1px dashed #d32f2f',
|
|
@@ -79,9 +79,11 @@ function ComponentRenderer({ renderCount = 0, blockletId, blockletTitle, compone
|
|
|
79
79
|
if (dev?.mode === 'draft' && dev && dev.components?.[props.componentId] === undefined) {
|
|
80
80
|
return ((0, jsx_runtime_1.jsx)(ErrorComponent_1.ComponentError, { componentId: props.componentId, componentName: componentName, blockletId: blockletId, blockletTitle: blockletTitle, message: "Component not found in available components", showHints: true }));
|
|
81
81
|
}
|
|
82
|
-
//
|
|
82
|
+
// 如果什么都没有,但是有 transpile 的错误,则抛出错误(延迟 10 秒后显示), safari 下兼容性问题
|
|
83
|
+
// https://github.com/sveltejs/kit/issues/7805
|
|
84
|
+
// https://bugs.webkit.org/show_bug.cgi?id=242740
|
|
83
85
|
if (component?.error) {
|
|
84
|
-
|
|
86
|
+
return (0, jsx_runtime_1.jsx)(ErrorComponent_1.ComponentError, { error: component.error, delay: 10 * 1000 });
|
|
85
87
|
}
|
|
86
88
|
return null;
|
|
87
89
|
}
|