@pisell/private-materials 6.12.371 → 6.12.373

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.
@@ -22,7 +22,7 @@ function resolveLocalizedText(value, translationOriginal, localeOverride) {
22
22
  const locale = localeOverride || ((_locales$getLocale = locales.getLocale) === null || _locales$getLocale === void 0 ? void 0 : _locales$getLocale.call(locales)) || locales.locale || "en";
23
23
  const normalized = ((_locales$formatLocale = locales.formatLocale) === null || _locales$formatLocale === void 0 ? void 0 : _locales$formatLocale.call(locales, locale)) || locale;
24
24
  const record = value;
25
- return record[normalized] || record[locale] || record.auto || record.default || record.original || record.en || record["zh-CN"] || record["zh-HK"] || record.ja || record.pt || record.kitchen || Object.keys(record).sort().map((key) => record[key]).find((text) => typeof text === "string" && text) || "";
25
+ return record[normalized] || record[locale] || record.original || record.default || record.auto || record.en || record["zh-CN"] || record["zh-HK"] || record.ja || record.pt || record.kitchen || Object.keys(record).sort().map((key) => record[key]).find((text) => typeof text === "string" && text) || "";
26
26
  }
27
27
  return String(value);
28
28
  }
@@ -1,6 +1,7 @@
1
1
  import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
2
  import useScrollActivity from "../../../hooks/useScrollActivity.js";
3
- import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
+ import { observeTransitions } from "./observeTransitions.js";
4
+ import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
4
5
  import { Button } from "antd";
5
6
  import classNames from "classnames";
6
7
  import { createPortal } from "react-dom";
@@ -8,7 +9,6 @@ import "./index.less";
8
9
  //#region src/pro/compensatedPisellContainer/floatingLayer/index.tsx
9
10
  const prefixCls = "pisell-lowcode-floating-layer";
10
11
  const legacyDrawerPrefixCls = "pisell-lowcode-drawer";
11
- const motionDuration = 300;
12
12
  const ModalButton = Button;
13
13
  const overlayBaseZIndex = 600;
14
14
  const overlayZIndexStep = 10;
@@ -72,35 +72,28 @@ const getFloatingLayoutState = (isLayoutChanging = false) => {
72
72
  viewportSize: getViewportSize()
73
73
  };
74
74
  };
75
- const isSameFloatingLayout = (prevLayout, nextLayout) => {
76
- return Math.abs(prevLayout.bodyScale.x - nextLayout.bodyScale.x) < .001 && Math.abs(prevLayout.bodyScale.y - nextLayout.bodyScale.y) < .001 && prevLayout.viewportSize.width === nextLayout.viewportSize.width && prevLayout.viewportSize.height === nextLayout.viewportSize.height && prevLayout.isLayoutChanging === nextLayout.isLayoutChanging;
75
+ const isSameFloatingGeometry = (prevLayout, nextLayout) => {
76
+ return Math.abs(prevLayout.bodyScale.x - nextLayout.bodyScale.x) < .001 && Math.abs(prevLayout.bodyScale.y - nextLayout.bodyScale.y) < .001 && prevLayout.viewportSize.width === nextLayout.viewportSize.width && prevLayout.viewportSize.height === nextLayout.viewportSize.height;
77
77
  };
78
78
  const useBodyScaleViewport = () => {
79
79
  const [layoutState, setLayoutState] = useState(() => getFloatingLayoutState(false));
80
80
  const updateFrameRef = useRef();
81
- const settleTimerRef = useRef();
81
+ const settleFrameRef = useRef();
82
82
  useEffect(() => {
83
83
  var _window$visualViewpor;
84
84
  if (typeof window === "undefined" || typeof document === "undefined") return;
85
- const setNextLayout = (isLayoutChanging) => {
86
- const nextLayout = getFloatingLayoutState(isLayoutChanging);
87
- setLayoutState((prevLayout) => isSameFloatingLayout(prevLayout, nextLayout) ? prevLayout : nextLayout);
88
- };
89
- const markLayoutSettled = () => {
90
- if (settleTimerRef.current) window.clearTimeout(settleTimerRef.current);
91
- settleTimerRef.current = window.setTimeout(() => {
92
- setNextLayout(false);
93
- }, motionDuration);
85
+ const updateGeometry = () => {
86
+ const nextLayout = getFloatingLayoutState(true);
87
+ setLayoutState((prevLayout) => isSameFloatingGeometry(prevLayout, nextLayout) ? prevLayout : nextLayout);
94
88
  };
95
89
  const scheduleScaleViewportUpdate = () => {
96
90
  if (updateFrameRef.current) window.cancelAnimationFrame(updateFrameRef.current);
97
91
  updateFrameRef.current = window.requestAnimationFrame(() => {
98
92
  updateFrameRef.current = void 0;
99
- setNextLayout(true);
100
- markLayoutSettled();
93
+ updateGeometry();
101
94
  });
102
95
  };
103
- setNextLayout(false);
96
+ updateGeometry();
104
97
  window.addEventListener("resize", scheduleScaleViewportUpdate);
105
98
  (_window$visualViewpor = window.visualViewport) === null || _window$visualViewpor === void 0 || _window$visualViewpor.addEventListener("resize", scheduleScaleViewportUpdate);
106
99
  const bodyObserver = new MutationObserver(scheduleScaleViewportUpdate);
@@ -111,12 +104,21 @@ const useBodyScaleViewport = () => {
111
104
  return () => {
112
105
  var _window$visualViewpor2;
113
106
  if (updateFrameRef.current) window.cancelAnimationFrame(updateFrameRef.current);
114
- if (settleTimerRef.current) window.clearTimeout(settleTimerRef.current);
115
107
  window.removeEventListener("resize", scheduleScaleViewportUpdate);
116
108
  (_window$visualViewpor2 = window.visualViewport) === null || _window$visualViewpor2 === void 0 || _window$visualViewpor2.removeEventListener("resize", scheduleScaleViewportUpdate);
117
109
  bodyObserver.disconnect();
118
110
  };
119
111
  }, []);
112
+ useLayoutEffect(() => {
113
+ if (!layoutState.isLayoutChanging) return;
114
+ document.body.getBoundingClientRect();
115
+ settleFrameRef.current = requestAnimationFrame(() => {
116
+ setLayoutState((current) => _objectSpread2(_objectSpread2({}, current), {}, { isLayoutChanging: false }));
117
+ });
118
+ return () => {
119
+ if (settleFrameRef.current !== void 0) cancelAnimationFrame(settleFrameRef.current);
120
+ };
121
+ }, [layoutState]);
120
122
  return layoutState;
121
123
  };
122
124
  const getDefaultDrawerSize = (size) => {
@@ -233,7 +235,13 @@ const TransformFloatingLayer = (props) => {
233
235
  shouldAutoHideHeaderFooter
234
236
  ]);
235
237
  const [rendered, setRendered] = useState(mergedOpen);
236
- const [motionOpen, setMotionOpen] = useState(mergedOpen);
238
+ const [motion, setMotion] = useState({
239
+ open: false,
240
+ id: 0
241
+ });
242
+ const motionOpen = motion.open;
243
+ const wrapperRef = useRef(null);
244
+ const maskRef = useRef(null);
237
245
  const shouldRenderLayer = rendered || mergedOpen;
238
246
  const skipCurrentEnterMotion = skipEnterMotion && mergedOpen;
239
247
  const effectiveMotionOpen = skipCurrentEnterMotion ? true : motionOpen;
@@ -241,10 +249,16 @@ const TransformFloatingLayer = (props) => {
241
249
  const overlayIdRef = useRef();
242
250
  const autoZIndexRef = useRef();
243
251
  const autoZIndexActiveRef = useRef(false);
244
- const mountedRef = useRef(false);
245
- const renderedRef = useRef(mergedOpen);
246
- const motionFrameRef = useRef();
247
- const motionTimerRef = useRef();
252
+ const hasOpenedRef = useRef(false);
253
+ const motionRunRef = useRef(0);
254
+ const motionOptionsRef = useRef({
255
+ afterOpenChange,
256
+ shouldDestroyOnClose
257
+ });
258
+ motionOptionsRef.current = {
259
+ afterOpenChange,
260
+ shouldDestroyOnClose
261
+ };
248
262
  if (overlayIdRef.current === void 0) overlayIdRef.current = getNextOverlayId();
249
263
  const overlayId = overlayIdRef.current;
250
264
  const releaseAutoZIndex = () => {
@@ -260,50 +274,49 @@ const TransformFloatingLayer = (props) => {
260
274
  autoZIndexActiveRef.current = true;
261
275
  }
262
276
  const mergedZIndex = (_ref = zIndex !== null && zIndex !== void 0 ? zIndex : autoZIndexRef.current) !== null && _ref !== void 0 ? _ref : overlayBaseZIndex;
263
- const updateRendered = (nextRendered) => {
264
- renderedRef.current = nextRendered;
265
- setRendered(nextRendered);
266
- };
267
277
  const handleClose = (event) => {
268
278
  const closeHandler = mode === "modal" ? onCancel || onClose : onClose || onCancel;
269
279
  closeHandler === null || closeHandler === void 0 || closeHandler(event);
270
280
  };
271
- useEffect(() => {
281
+ useEffect(() => () => releaseAutoZIndex(), []);
282
+ useLayoutEffect(() => {
283
+ const id = ++motionRunRef.current;
284
+ let frame;
285
+ if (mergedOpen) {
286
+ hasOpenedRef.current = true;
287
+ setRendered(true);
288
+ }
289
+ if (mergedOpen && !skipEnterMotion && !motionOpen) {
290
+ var _wrapperRef$current, _maskRef$current;
291
+ (_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 || _wrapperRef$current.getBoundingClientRect();
292
+ (_maskRef$current = maskRef.current) === null || _maskRef$current === void 0 || _maskRef$current.getBoundingClientRect();
293
+ frame = requestAnimationFrame(() => {
294
+ frame = requestAnimationFrame(() => setMotion({
295
+ open: true,
296
+ id
297
+ }));
298
+ });
299
+ } else setMotion({
300
+ open: mergedOpen,
301
+ id
302
+ });
272
303
  return () => {
273
- if (motionFrameRef.current) window.cancelAnimationFrame(motionFrameRef.current);
274
- if (motionTimerRef.current) window.clearTimeout(motionTimerRef.current);
275
- releaseAutoZIndex();
304
+ ++motionRunRef.current;
305
+ if (frame !== void 0) cancelAnimationFrame(frame);
276
306
  };
277
- }, []);
278
- useEffect(() => {
279
- if (typeof window === "undefined") return;
280
- if (motionFrameRef.current) window.cancelAnimationFrame(motionFrameRef.current);
281
- if (motionTimerRef.current) window.clearTimeout(motionTimerRef.current);
282
- if (mergedOpen) if (renderedRef.current) setMotionOpen(true);
283
- else {
284
- updateRendered(true);
285
- setMotionOpen(false);
286
- motionFrameRef.current = window.requestAnimationFrame(() => {
287
- setMotionOpen(true);
288
- });
289
- }
290
- else setMotionOpen(false);
291
- if (!mountedRef.current) {
292
- mountedRef.current = true;
293
- return;
294
- }
295
- motionTimerRef.current = window.setTimeout(() => {
296
- afterOpenChange === null || afterOpenChange === void 0 || afterOpenChange(mergedOpen);
297
- if (!mergedOpen) {
307
+ }, [mergedOpen, skipEnterMotion]);
308
+ useLayoutEffect(() => {
309
+ if (!hasOpenedRef.current || motion.id !== motionRunRef.current || motion.open !== mergedOpen) return;
310
+ return observeTransitions([wrapperRef.current, maskRef.current].filter((element) => element !== null), () => {
311
+ var _motionOptionsRef$cur, _motionOptionsRef$cur2;
312
+ if (motion.id !== motionRunRef.current) return;
313
+ if (!motion.open) {
298
314
  releaseAutoZIndex();
299
- if (shouldDestroyOnClose) updateRendered(false);
315
+ if (motionOptionsRef.current.shouldDestroyOnClose) setRendered(false);
300
316
  }
301
- }, motionDuration);
302
- }, [
303
- afterOpenChange,
304
- mergedOpen,
305
- shouldDestroyOnClose
306
- ]);
317
+ (_motionOptionsRef$cur = (_motionOptionsRef$cur2 = motionOptionsRef.current).afterOpenChange) === null || _motionOptionsRef$cur === void 0 || _motionOptionsRef$cur.call(_motionOptionsRef$cur2, motion.open);
318
+ });
319
+ }, [motion, mergedOpen]);
307
320
  useEffect(() => {
308
321
  if (!mergedOpen || keyboard === false || typeof window === "undefined") return;
309
322
  const handleKeyDown = (event) => {
@@ -410,12 +423,14 @@ const TransformFloatingLayer = (props) => {
410
423
  className: classNames(`${prefixCls}-root`, `${prefixCls}-mode-${mode}`, `${prefixCls}-${centered && mode === "modal" ? "center" : placement}`, getLegacyDrawerRootClasses(mode, placement), rootClassName, wrapClassName, layerClassNames === null || layerClassNames === void 0 ? void 0 : layerClassNames.root),
411
424
  style: _objectSpread2(_objectSpread2(_objectSpread2({ zIndex: mergedZIndex }, rootScaleStyle), rootStyle), styles === null || styles === void 0 ? void 0 : styles.root)
412
425
  }, mask ? /* @__PURE__ */ React.createElement("div", {
426
+ ref: maskRef,
413
427
  className: classNames(`${prefixCls}-mask`, getLegacyDrawerClass(mode, "mask"), layerClassNames === null || layerClassNames === void 0 ? void 0 : layerClassNames.mask),
414
428
  style: maskStyle,
415
429
  onClick: (event) => {
416
430
  if (event.target === event.currentTarget && maskClosable) handleClose(event);
417
431
  }
418
432
  }) : null, /* @__PURE__ */ React.createElement("div", {
433
+ ref: wrapperRef,
419
434
  className: classNames(`${prefixCls}-content-wrapper`, getLegacyDrawerWrapperClasses(mode), className, layerClassNames === null || layerClassNames === void 0 ? void 0 : layerClassNames.wrapper),
420
435
  style: wrapperStyle
421
436
  }, modalRender ? modalRender(contentNode) : contentNode)) : null;
@@ -0,0 +1,65 @@
1
+ //#region src/pro/compensatedPisellContainer/floatingLayer/observeTransitions.ts
2
+ /** Observe only the shell's own transitions, never animations inside its content. */
3
+ const observeTransitions = (elements, onSettled) => {
4
+ let disposed = false;
5
+ let frame;
6
+ const pendingEvents = /* @__PURE__ */ new Map();
7
+ const supportsAnimations = elements.every((element) => typeof element.getAnimations === "function");
8
+ const isMotionProperty = (property) => property === "opacity" || property === "transform";
9
+ const check = () => {
10
+ if (disposed) return;
11
+ if (supportsAnimations) {
12
+ const transitions = [];
13
+ elements.forEach((element) => {
14
+ transitions.push(...element.getAnimations().filter((animation) => isMotionProperty(animation.transitionProperty) && animation.playState !== "finished" && animation.playState !== "idle"));
15
+ });
16
+ if (transitions.length) {
17
+ Promise.all(transitions.map((animation) => animation.finished.catch(() => void 0))).then(check);
18
+ return;
19
+ }
20
+ } else if ([...pendingEvents.values()].some((properties) => properties.size)) return;
21
+ disposed = true;
22
+ removeListeners();
23
+ onSettled();
24
+ };
25
+ const scheduleCheck = () => {
26
+ if (frame !== void 0) cancelAnimationFrame(frame);
27
+ frame = requestAnimationFrame(check);
28
+ };
29
+ const handleTransition = (event) => {
30
+ const transition = event;
31
+ if (event.target !== event.currentTarget || !isMotionProperty(transition.propertyName)) return;
32
+ const element = event.currentTarget;
33
+ const properties = pendingEvents.get(element);
34
+ if (event.type === "transitionrun") properties.add(transition.propertyName);
35
+ else {
36
+ properties.delete(transition.propertyName);
37
+ scheduleCheck();
38
+ }
39
+ };
40
+ const removeListeners = () => {
41
+ elements.forEach((element) => {
42
+ element.removeEventListener("transitionrun", handleTransition);
43
+ element.removeEventListener("transitionend", handleTransition);
44
+ element.removeEventListener("transitioncancel", handleTransition);
45
+ });
46
+ };
47
+ elements.forEach((element) => {
48
+ pendingEvents.set(element, /* @__PURE__ */ new Set());
49
+ if (!supportsAnimations) {
50
+ element.addEventListener("transitionrun", handleTransition);
51
+ element.addEventListener("transitionend", handleTransition);
52
+ element.addEventListener("transitioncancel", handleTransition);
53
+ }
54
+ element.getBoundingClientRect();
55
+ });
56
+ if (supportsAnimations) Promise.resolve().then(check);
57
+ else frame = requestAnimationFrame(scheduleCheck);
58
+ return () => {
59
+ disposed = true;
60
+ if (frame !== void 0) cancelAnimationFrame(frame);
61
+ removeListeners();
62
+ };
63
+ };
64
+ //#endregion
65
+ export { observeTransitions };