@blocklet/pages-kit 0.6.38 → 0.6.40

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.
@@ -119,12 +119,7 @@ const initDynamicParsePropertyValueHandlers = () => {
119
119
  initDynamicPropertyHandlersPromise = (async () => {
120
120
  dynamicPropertyHandlers = {};
121
121
  if ((0, common_1.isBrowserEnv)()) {
122
- // colorConvert 目前需要前端环境才能处理,依赖 mui theme
123
- // @ts-ignore
124
- const colorConvertFn = globalThis[common_1.COLOR_CONVERT_FUNCTION_NAME];
125
- if (typeof colorConvertFn === 'function') {
126
- dynamicPropertyHandlers.color = (value) => colorConvertFn(value);
127
- }
122
+ // do nothing
128
123
  }
129
124
  return dynamicPropertyHandlers;
130
125
  })();
@@ -147,12 +147,12 @@ function parseColor(color = '') {
147
147
  * @param _theme - 主题对象,默认为全局主题
148
148
  * @returns 转换后的颜色字符串
149
149
  */
150
- function colorConvert(color, _theme = blockletTheme) {
150
+ function colorConvert(color, theme = blockletTheme) {
151
151
  if ((0, common_1.isMuiColorKey)(color)) {
152
152
  if (color === 'transparent') {
153
153
  return 'transparent';
154
154
  }
155
- return (0, get_1.default)(_theme.palette, color, color);
155
+ return (0, get_1.default)(theme.palette, color, color);
156
156
  }
157
157
  // 处理渐变和普通颜色
158
158
  if (isGradient(color)) {
@@ -163,10 +163,6 @@ function colorConvert(color, _theme = blockletTheme) {
163
163
  }
164
164
  return color || '';
165
165
  }
166
- if ((0, common_1.isBrowserEnv)()) {
167
- // @ts-ignore inject colorConvert to globalThis
168
- globalThis[common_1.COLOR_CONVERT_FUNCTION_NAME] = colorConvert;
169
- }
170
166
  function getTransparentBackground() {
171
167
  return 'repeating-conic-gradient(#CCCCCC 0% 25%, #FFFFFF 0% 50%) 50% / 10px 10px';
172
168
  }
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useMemo } from 'react';
3
3
  import { ErrorBoundary } from 'react-error-boundary';
4
+ import { useColorConvert } from '../../contexts/color';
4
5
  import { RenderNestedComponent, parsePropertyValue } from '../../utils/property';
5
6
  import BlockletReactComponentRenderer from './BlockletReactComponentRenderer';
6
7
  import { DevProvider, useDev } from './DevProvider';
@@ -25,6 +26,7 @@ function ComponentRenderer({ renderCount = 0, blockletId, blockletTitle, compone
25
26
  }
26
27
  const component = useComponent({ ...props, dev });
27
28
  const ctx = useCustomComponentRenderer();
29
+ const colorConvert = useColorConvert();
28
30
  // 传递过来的参数,需要确保经过前端 parsePropertyValue 处理,并且补全不存在的参数
29
31
  const parsedProps = useMemo(() => {
30
32
  const result = {
@@ -41,10 +43,13 @@ function ComponentRenderer({ renderCount = 0, blockletId, blockletTitle, compone
41
43
  result[key] = parsePropertyValue(property, result[key] ?? defaultValue, {
42
44
  locale: props?.locale,
43
45
  defaultLocale,
46
+ propertyHandlers: {
47
+ color: (value) => colorConvert(value),
48
+ },
44
49
  });
45
50
  });
46
51
  return result;
47
- }, [props?.props, component?.properties, component?.props]);
52
+ }, [props?.props, component?.properties, component?.props, colorConvert]);
48
53
  const renderComponentChildren = (Component) => {
49
54
  const children = _jsx(Renderer, { renderCount: renderCount + 1, ...props, Component: Component, props: parsedProps });
50
55
  return ctx?.customRendererComponent ? (_jsx(ctx.customRendererComponent, { Component: Component, children: children })) : (children);