@blocklet/editor 2.2.18 → 2.2.20

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.
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
3
3
  import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, Typography, Skeleton, styled, } from '@mui/material';
4
4
  import isEmpty from 'lodash/isEmpty';
5
- import { useLocalStorageState } from 'ahooks';
5
+ import { useLocalStorageState, useDebounceFn } from 'ahooks';
6
6
  import { useEffect, useMemo, useState, lazy, Suspense } from 'react';
7
7
  import SettingsOutlinedIcon from '@mui/icons-material/SettingsOutlined';
8
8
  import SplitPane, { Pane } from 'split-pane-react';
@@ -44,6 +44,8 @@ export function PagesKitComponentRenderer({ id, name, properties, onPropertiesCh
44
44
  const [loading, setLoading] = useState(true);
45
45
  const [open, setOpen] = useState(false);
46
46
  const [pendingProperties, setPendingProperties] = useState(properties || {});
47
+ const [isDragging, setIsDragging] = useState(false);
48
+ const [renderComponentTrigger, setRenderComponentTrigger] = useState(0);
47
49
  const handleClick = () => {
48
50
  setOpen(true);
49
51
  };
@@ -55,7 +57,8 @@ export function PagesKitComponentRenderer({ id, name, properties, onPropertiesCh
55
57
  onPropertiesChange(pendingProperties);
56
58
  setOpen(false);
57
59
  };
58
- const instanceId = useMemo(() => `${id}-${hashCode(JSON.stringify(pendingProperties))}`, [id, pendingProperties]);
60
+ // 直接用 properties 生成 instanceId,确保只生成一次
61
+ const instanceId = useMemo(() => `${id}-${hashCode(JSON.stringify(properties || {}))}`, [id, properties]);
59
62
  useEffect(() => {
60
63
  const load = async () => {
61
64
  const state = customComponentStates().getState();
@@ -87,16 +90,16 @@ export function PagesKitComponentRenderer({ id, name, properties, onPropertiesCh
87
90
  if (isBlockletRunning('pages-kit')) {
88
91
  load();
89
92
  }
90
- }, [id, name, pendingProperties, locale]);
91
- const componentStates = customComponentStates().getState()?.state?.components;
93
+ }, [id, instanceId, locale]);
92
94
  // 组装所有组件数据,使其能被 ParametersConfig 组件使用,不能去掉,否则无法渲染 EditorComponent
93
95
  const allComponents = useMemo(() => {
96
+ // 不要修改这个逻辑,否则会导致组件无法渲染
94
97
  return mapValues(customComponentStates().getState()?.state?.components || {}, ({ component }) => ({
95
98
  blockletId: 'z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o',
96
99
  blockletTitle: 'Pages Kit',
97
100
  data: component,
98
101
  }));
99
- }, [componentStates]);
102
+ }, [JSON.stringify(customComponentStates().getState()?.state?.components)]);
100
103
  const component = useMemo(() => allComponents?.[id]?.data, [allComponents, id]);
101
104
  const mergedPropertiesValues = useMemo(() => {
102
105
  const realLocale = getRealLocale(pendingProperties, locale);
@@ -110,7 +113,20 @@ export function PagesKitComponentRenderer({ id, name, properties, onPropertiesCh
110
113
  ];
111
114
  }));
112
115
  }, [component, locale, pendingProperties]);
113
- const componentRenderer = useMemo(() => (_jsx(CustomComponentRenderer, { instanceId: instanceId, componentId: id, locale: locale, dev: { mode }, properties: mergedPropertiesValues })), [instanceId, id, locale, mergedPropertiesValues, mode, component]);
116
+ // 防抖触发重新渲染
117
+ const { run: triggerRerender } = useDebounceFn(() => {
118
+ setRenderComponentTrigger((prev) => prev + 1);
119
+ }, { wait: 300 });
120
+ // 当属性变化时,触发防抖渲染
121
+ useEffect(() => {
122
+ triggerRerender();
123
+ }, [mergedPropertiesValues]);
124
+ const componentRenderer = useMemo(() => {
125
+ return (_jsx(CustomComponentRenderer, { instanceId: instanceId, componentId: id, locale: locale, dev: { mode, components: allComponents }, properties: mergedPropertiesValues }));
126
+ },
127
+ // 添加 renderComponentTrigger 依赖,确保组件延迟渲染
128
+ // 而 mergedPropertiesValues 变化时,组件不会立即重新渲染, 所以不需要添加 mergedPropertiesValues 依赖
129
+ [instanceId, id, locale, mode, allComponents, renderComponentTrigger]);
114
130
  if (loading || !component) {
115
131
  return null;
116
132
  }
@@ -135,7 +151,7 @@ export function PagesKitComponentRenderer({ id, name, properties, onPropertiesCh
135
151
  '.full-screen-container': {
136
152
  zIndex: '1300 !important',
137
153
  },
138
- }, children: _jsxs(StyledSplitPane, { split: "vertical", sizes: splitSizes, onChange: setSplitSizes, sashRender: SashRender, children: [_jsx(Pane, { minSize: 200, children: _jsx(Box, { sx: { flex: 1, mr: 1, overflow: 'auto', height: '100%' }, children: componentRenderer }) }), _jsx(Pane, { minSize: 200, maxSize: "70%", style: {
154
+ }, children: _jsxs(StyledSplitPane, { split: "vertical", sizes: splitSizes, onChange: setSplitSizes, sashRender: SashRender, className: isDragging ? 'dragging' : '', onDragStart: () => setIsDragging(true), onDragEnd: () => setIsDragging(false), children: [_jsx(Pane, { minSize: 200, children: _jsx(Box, { sx: { flex: 1, mr: 1, overflow: 'auto', height: '100%' }, children: componentRenderer }) }), _jsx(Pane, { minSize: 200, maxSize: "70%", style: {
139
155
  overflow: 'auto',
140
156
  }, children: _jsx(Box, { sx: {
141
157
  ml: 2,
@@ -157,9 +173,9 @@ export function PagesKitComponentRenderer({ id, name, properties, onPropertiesCh
157
173
  * 这确保了语言切换时数据不会丢失,且多语言共享未翻译的内容
158
174
  */
159
175
  onChange: ({ id: propertyId, value }) => {
176
+ if (!locale || !propertyId)
177
+ return;
160
178
  setPendingProperties((prevProperties) => {
161
- if (!locale || !propertyId || !value?.value)
162
- return prevProperties;
163
179
  // 创建新的属性对象
164
180
  const updatedProperties = { ...prevProperties };
165
181
  const realLocale = getRealLocale(updatedProperties, locale);
@@ -203,6 +219,12 @@ const StyledSplitPane = styled(SplitPane) `
203
219
  .react-split__sash {
204
220
  z-index: 1000; // resolve the bug of uploader zIndex
205
221
  }
222
+
223
+ &.dragging {
224
+ * {
225
+ user-select: none !important;
226
+ }
227
+ }
206
228
  `;
207
229
  function SashRender() {
208
230
  return _jsx(DragHandle, {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/editor",
3
- "version": "2.2.18",
3
+ "version": "2.2.20",
4
4
  "main": "lib/index.js",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -24,11 +24,11 @@
24
24
  ]
25
25
  },
26
26
  "dependencies": {
27
- "@blocklet/code-editor": "^0.4.255",
27
+ "@blocklet/code-editor": "^0.4.256",
28
28
  "@blocklet/embed": "^0.2.3",
29
29
  "@blocklet/js-sdk": "^1.16.41",
30
- "@blocklet/pages-kit": "^0.4.102",
31
- "@blocklet/pages-kit-runtime": "^0.4.104",
30
+ "@blocklet/pages-kit": "^0.4.105",
31
+ "@blocklet/pages-kit-runtime": "^0.4.105",
32
32
  "@excalidraw/excalidraw": "^0.14.2",
33
33
  "@iconify/iconify": "^3.1.1",
34
34
  "@iconify/icons-tabler": "^1.2.95",
@@ -67,7 +67,7 @@
67
67
  "ufo": "^1.5.4",
68
68
  "url-join": "^4.0.1",
69
69
  "zustand": "^4.5.5",
70
- "@blocklet/pdf": "^2.2.18"
70
+ "@blocklet/pdf": "^2.2.20"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@babel/core": "^7.25.2",