goatdee-canvas 0.0.71 → 0.0.72

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.cjs CHANGED
@@ -6393,42 +6393,33 @@ function useCanvasResize(args) {
6393
6393
  }, []);
6394
6394
  }
6395
6395
 
6396
- /**
6397
- * 监听 document 上的自定义 `onAction` 事件,把事件转发给调用方的
6398
- * `onAction` 回调,同时经 `reportAction` 上报到灯塔。
6399
- *
6400
- * 使用 ref 存储最新 props,外壳 listener 保持稳定,
6401
- * 可避免每次 props 变更都重新 add/remove 监听。
6402
- *
6403
- * 性能优化:除 `afterrender` 外,`onAction` 回调延迟到下一帧 paint 之后触发,
6404
- * 避免在 C++ 同步 `dispatchEvent` 的调用栈里跑 `getActiveObjects` + React 渲染,
6405
- * 阻塞当前帧的绘制(例如框选松手时清除选择框的那帧)。
6406
- * 具体调度:rAF + setTimeout(0),确保浏览器先完成这一帧的 paint 再通知业务侧;
6407
- * 灯塔上报保持同步,避免页面关闭/刷新时丢数据。
6408
- */
6396
+ function parseActionData(raw) {
6397
+ if (typeof raw !== "string" || raw === "") {
6398
+ return undefined;
6399
+ }
6400
+ try {
6401
+ const parsed = JSON.parse(raw);
6402
+ if (parsed !== null && typeof parsed === "object") {
6403
+ return parsed;
6404
+ }
6405
+ }
6406
+ catch (_a) { }
6407
+ return raw;
6408
+ }
6409
6409
  function useOnActionBridge(onAction, reportAction) {
6410
6410
  const handlerRef = react.useRef(() => { });
6411
6411
  const aliveRef = react.useRef(true);
6412
6412
  handlerRef.current = (event) => {
6413
+ if (!aliveRef.current)
6414
+ return;
6413
6415
  const detail = event.detail;
6414
6416
  const action = detail === null || detail === void 0 ? void 0 : detail.action;
6415
6417
  if (action == null || action === "")
6416
6418
  return;
6417
- const data = typeof (detail === null || detail === void 0 ? void 0 : detail.data) === "string" ? detail.data : undefined;
6419
+ const data = parseActionData(detail === null || detail === void 0 ? void 0 : detail.data);
6420
+ // 上报到灯塔
6418
6421
  reportAction(action);
6419
- if (action === "afterrender" ||
6420
- action === "modified" ||
6421
- action === "add") {
6422
- onAction === null || onAction === void 0 ? void 0 : onAction(action, data);
6423
- return;
6424
- }
6425
- requestAnimationFrame(() => {
6426
- setTimeout(() => {
6427
- if (!aliveRef.current)
6428
- return;
6429
- onAction === null || onAction === void 0 ? void 0 : onAction(action, data);
6430
- }, 0);
6431
- });
6422
+ onAction === null || onAction === void 0 ? void 0 : onAction(action, data);
6432
6423
  };
6433
6424
  react.useEffect(() => {
6434
6425
  aliveRef.current = true;