@blocklet/pages-kit 0.4.127 → 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.
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChunksMountPointGlobalVariableName = exports.BuiltinModulesGlobalVariableName = void 0;
3
+ exports.RelativeModulesGlobalVariableName = exports.ChunksMountPointGlobalVariableName = exports.BuiltinModulesGlobalVariableName = void 0;
4
4
  exports.BuiltinModulesGlobalVariableName = '__PAGES_KIT_BUILTIN_MODULES__';
5
5
  exports.ChunksMountPointGlobalVariableName = '__PAGES_KIT_CHUNKS_MOUNT_POINT__';
6
+ exports.RelativeModulesGlobalVariableName = '__PAGES_KIT_RELATIVE_MODULES__';
@@ -75,6 +75,7 @@ function injectGlobalComponents() {
75
75
  };
76
76
  }
77
77
  win.React = react_1.default;
78
+ win[builtin_1.RelativeModulesGlobalVariableName] = {};
78
79
  // create module map
79
80
  const modules = {
80
81
  React: react,
@@ -139,12 +140,15 @@ function injectGlobalComponents() {
139
140
  window?.blocklet?.prefix ||
140
141
  '/';
141
142
  const fullUrl = (0, ufo_1.joinURL)(window.location.origin, relativeChunksMountPoint, 'chunks', fileName);
142
- if (enableShim) {
143
- const mod = window.importShim(/* @vite-ignore */ fullUrl);
144
- return mod;
143
+ if (!win[builtin_1.RelativeModulesGlobalVariableName][fullUrl]) {
144
+ if (enableShim) {
145
+ win[builtin_1.RelativeModulesGlobalVariableName][fullUrl] = window.importShim(/* @vite-ignore */ fullUrl);
146
+ }
147
+ else {
148
+ win[builtin_1.RelativeModulesGlobalVariableName][fullUrl] = Promise.resolve(`${fullUrl}`).then(s => __importStar(require(s)));
149
+ }
145
150
  }
146
- const mod = Promise.resolve(`${fullUrl}`).then(s => __importStar(require(s)));
147
- return mod;
151
+ return win[builtin_1.RelativeModulesGlobalVariableName][fullUrl];
148
152
  }
149
153
  return null;
150
154
  },
@@ -1,8 +1,30 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Box, Typography, Button } from '@mui/material';
3
- export const ComponentError = ({ title = 'Component Failed to Load', message, componentId, componentName, blockletId, blockletTitle, showHints = false, error, resetErrorBoundary, }) => {
4
- // 如果提供了error但没有message,使用error.message
3
+ import { useEffect, useState } from 'react';
4
+ export const ComponentError = ({ title = 'Component Failed to Load', message, componentId, componentName, blockletId, blockletTitle, showHints = false, error, resetErrorBoundary, delay = 0, shouldShow, }) => {
5
+ const [showError, setShowError] = useState(delay === 0);
6
+ // 处理延迟显示逻辑
7
+ useEffect(() => {
8
+ // 如果没有延迟,直接显示
9
+ if (delay === 0)
10
+ return undefined;
11
+ const timer = setTimeout(() => {
12
+ // 如果有额外显示条件,只有条件满足时才显示
13
+ if (typeof shouldShow === 'function') {
14
+ if (shouldShow()) {
15
+ setShowError(true);
16
+ }
17
+ }
18
+ else {
19
+ setShowError(true);
20
+ }
21
+ }, delay);
22
+ return () => clearTimeout(timer);
23
+ }, [delay, shouldShow]);
5
24
  const displayMessage = message || (error ? error.message : 'Unknown error');
25
+ if (!showError) {
26
+ return null;
27
+ }
6
28
  return (_jsxs(Box, { sx: {
7
29
  p: 3,
8
30
  border: '1px dashed #d32f2f',
@@ -45,9 +45,6 @@ function ComponentRenderer({ renderCount = 0, blockletId, blockletTitle, compone
45
45
  });
46
46
  return result;
47
47
  }, [props?.props, component?.properties, component?.props]);
48
- if (component?.error) {
49
- throw component.error;
50
- }
51
48
  const renderComponentChildren = (Component) => {
52
49
  const children = _jsx(Renderer, { renderCount: renderCount + 1, ...props, Component: Component, props: parsedProps });
53
50
  return ctx?.customRendererComponent ? (_jsx(ctx.customRendererComponent, { Component: Component, children: children })) : (children);
@@ -62,6 +59,12 @@ function ComponentRenderer({ renderCount = 0, blockletId, blockletTitle, compone
62
59
  if (dev?.mode === 'draft' && dev && dev.components?.[props.componentId] === undefined) {
63
60
  return (_jsx(ComponentError, { componentId: props.componentId, componentName: componentName, blockletId: blockletId, blockletTitle: blockletTitle, message: "Component not found in available components", showHints: true }));
64
61
  }
62
+ // 如果什么都没有,但是有 transpile 的错误,则抛出错误(延迟 10 秒后显示), safari 下兼容性问题
63
+ // https://github.com/sveltejs/kit/issues/7805
64
+ // https://bugs.webkit.org/show_bug.cgi?id=242740
65
+ if (component?.error) {
66
+ return _jsx(ComponentError, { error: component.error, delay: 10 * 1000 });
67
+ }
65
68
  return null;
66
69
  }
67
70
  function Renderer({ renderCount, Component, locale, props, }) {
@@ -150,6 +150,7 @@ export const customComponentStates = () => {
150
150
  components: Object.fromEntries(Object.entries({ ...PRELOAD_COMPONENTS_STATE?.components })
151
151
  .map(([componentId, preload]) => {
152
152
  let Component;
153
+ // umd 格式的逻辑,会走到这里
153
154
  if (preload.componentModuleGlobalVariable) {
154
155
  const m = window[preload.componentModuleGlobalVariable];
155
156
  // handle the global variable