@univerjs/design 0.22.1 → 0.23.0

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/lib/cjs/index.js CHANGED
@@ -6,6 +6,7 @@ let tailwind_merge = require("tailwind-merge");
6
6
  let react_jsx_runtime = require("react/jsx-runtime");
7
7
  let class_variance_authority = require("class-variance-authority");
8
8
  let _radix_ui_react_slot = require("@radix-ui/react-slot");
9
+ let _radix_ui_react_direction = require("@radix-ui/react-direction");
9
10
  let _radix_ui_react_dialog = require("@radix-ui/react-dialog");
10
11
  let _radix_ui_react_popover = require("@radix-ui/react-popover");
11
12
  let react_dom = require("react-dom");
@@ -261,16 +262,24 @@ function isBrowser() {
261
262
  //#region src/components/config-provider/ConfigProvider.tsx
262
263
  const ConfigContext = (0, react.createContext)({ mountContainer: isBrowser() ? document.body : null });
263
264
  function ConfigProvider(props) {
264
- const { children, locale, mountContainer } = props;
265
+ const { children, locale, mountContainer, direction } = props;
265
266
  const value = (0, react.useMemo)(() => {
266
267
  return {
267
268
  locale,
269
+ direction,
268
270
  mountContainer
269
271
  };
270
- }, [locale, mountContainer]);
272
+ }, [
273
+ locale,
274
+ direction,
275
+ mountContainer
276
+ ]);
271
277
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConfigContext.Provider, {
272
278
  value,
273
- children
279
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_direction.DirectionProvider, {
280
+ dir: direction !== null && direction !== void 0 ? direction : "ltr",
281
+ children
282
+ })
274
283
  });
275
284
  }
276
285
 
@@ -1925,6 +1934,7 @@ function DraggableList(props) {
1925
1934
  const pressedHandleIdRef = (0, react.useRef)(null);
1926
1935
  const dragSourceIdRef = (0, react.useRef)(null);
1927
1936
  const dragStartIndexRef = (0, react.useRef)(-1);
1937
+ const { direction } = (0, react.useContext)(ConfigContext);
1928
1938
  (0, react.useEffect)(() => {
1929
1939
  if (!draggingId) {
1930
1940
  setDisplayList(list);
@@ -2057,6 +2067,7 @@ function DraggableList(props) {
2057
2067
  }, itemId);
2058
2068
  })
2059
2069
  }), canUsePortal && draggingItem && ghostPosition && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2070
+ dir: direction,
2060
2071
  className: clsx$1("univer-pointer-events-none univer-fixed univer-rounded-md univer-border univer-border-gray-200 univer-bg-white univer-shadow-lg dark:!univer-border-gray-700 dark:!univer-bg-gray-800"),
2061
2072
  style: {
2062
2073
  zIndex: 2147483647,
@@ -2389,6 +2400,7 @@ function Gallery(props) {
2389
2400
  const [isVisible, setIsVisible] = (0, react.useState)(false);
2390
2401
  const [activeImageIndex, setActiveImageIndex] = (0, react.useState)(0);
2391
2402
  const [zoomLevel, setZoomLevel] = (0, react.useState)(1);
2403
+ const { direction } = (0, react.useContext)(ConfigContext);
2392
2404
  const dialogRef = (0, react.useRef)(null);
2393
2405
  const activeImage = (0, react.useMemo)(() => images[activeImageIndex], [activeImageIndex, images]);
2394
2406
  (0, react.useEffect)(() => {
@@ -2436,6 +2448,7 @@ function Gallery(props) {
2436
2448
  }
2437
2449
  return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2438
2450
  "data-u-comp": "gallery",
2451
+ dir: direction,
2439
2452
  role: "dialog",
2440
2453
  "aria-modal": "true",
2441
2454
  "aria-label": "Image gallery",
@@ -2829,6 +2842,7 @@ function Segmented({ items, value, defaultValue, onChange, className = "" }) {
2829
2842
  //#region src/components/tooltip/Tooltip.tsx
2830
2843
  function Tooltip(props) {
2831
2844
  const { children, className, asChild = true, title, placement = "bottom", showIfEllipsis = false, visible: controlledVisible, onVisibleChange } = props;
2845
+ const { direction } = (0, react.useContext)(ConfigContext);
2832
2846
  const [uncontrolledVisible, setUncontrolledVisible] = (0, react.useState)(false);
2833
2847
  const isControlled = controlledVisible !== void 0;
2834
2848
  const visible = isControlled ? controlledVisible : uncontrolledVisible;
@@ -2971,6 +2985,7 @@ function Tooltip(props) {
2971
2985
  var _coords$top, _coords$left;
2972
2986
  tooltipNode = (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2973
2987
  ref: tooltipRef,
2988
+ dir: direction,
2974
2989
  role: "tooltip",
2975
2990
  className: clsx$1("univer-animate-in univer-fade-in-0 univer-zoom-in-95 univer-pointer-events-auto univer-absolute univer-z-[1081] univer-box-border univer-w-fit univer-max-w-sm univer-text-balance univer-rounded-lg univer-bg-gray-700 univer-px-2.5 univer-py-2 univer-text-xs univer-font-medium univer-text-white univer-shadow-lg univer-drop-shadow-sm dark:!univer-bg-gray-100 dark:!univer-text-gray-900", className),
2976
2991
  style: {
@@ -3434,7 +3449,7 @@ function Popup(props) {
3434
3449
  const { children, visible = false, offset = [0, 0], overflowVisible = false, placementY = "below" } = props;
3435
3450
  const nodeRef = (0, react.useRef)(null);
3436
3451
  const [realOffset, setRealOffset] = (0, react.useState)(HIDDEN_POPUP_OFFSET);
3437
- const { mountContainer } = (0, react.useContext)(ConfigContext);
3452
+ const { mountContainer, direction } = (0, react.useContext)(ConfigContext);
3438
3453
  const calculateOffset = () => {
3439
3454
  const element = nodeRef.current;
3440
3455
  if (!element) return null;
@@ -3490,6 +3505,7 @@ function Popup(props) {
3490
3505
  },
3491
3506
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
3492
3507
  ref: nodeRef,
3508
+ dir: direction,
3493
3509
  className: "univer-popup",
3494
3510
  style: {
3495
3511
  left: realOffset[0] + POPUP_POINTER_OFFSET,
package/lib/es/index.js CHANGED
@@ -5,6 +5,7 @@ import { twMerge } from "tailwind-merge";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
6
  import { cva } from "class-variance-authority";
7
7
  import { Slot } from "@radix-ui/react-slot";
8
+ import { DirectionProvider } from "@radix-ui/react-direction";
8
9
  import { Close, Content, Description, Overlay, Portal, Root, Title } from "@radix-ui/react-dialog";
9
10
  import { Content as Content$1, Portal as Portal$1, Root as Root$1, Trigger } from "@radix-ui/react-popover";
10
11
  import { createPortal } from "react-dom";
@@ -260,16 +261,24 @@ function isBrowser() {
260
261
  //#region src/components/config-provider/ConfigProvider.tsx
261
262
  const ConfigContext = createContext({ mountContainer: isBrowser() ? document.body : null });
262
263
  function ConfigProvider(props) {
263
- const { children, locale, mountContainer } = props;
264
+ const { children, locale, mountContainer, direction } = props;
264
265
  const value = useMemo(() => {
265
266
  return {
266
267
  locale,
268
+ direction,
267
269
  mountContainer
268
270
  };
269
- }, [locale, mountContainer]);
271
+ }, [
272
+ locale,
273
+ direction,
274
+ mountContainer
275
+ ]);
270
276
  return /* @__PURE__ */ jsx(ConfigContext.Provider, {
271
277
  value,
272
- children
278
+ children: /* @__PURE__ */ jsx(DirectionProvider, {
279
+ dir: direction !== null && direction !== void 0 ? direction : "ltr",
280
+ children
281
+ })
273
282
  });
274
283
  }
275
284
 
@@ -1924,6 +1933,7 @@ function DraggableList(props) {
1924
1933
  const pressedHandleIdRef = useRef(null);
1925
1934
  const dragSourceIdRef = useRef(null);
1926
1935
  const dragStartIndexRef = useRef(-1);
1936
+ const { direction } = useContext(ConfigContext);
1927
1937
  useEffect(() => {
1928
1938
  if (!draggingId) {
1929
1939
  setDisplayList(list);
@@ -2056,6 +2066,7 @@ function DraggableList(props) {
2056
2066
  }, itemId);
2057
2067
  })
2058
2068
  }), canUsePortal && draggingItem && ghostPosition && createPortal(/* @__PURE__ */ jsx("div", {
2069
+ dir: direction,
2059
2070
  className: clsx("univer-pointer-events-none univer-fixed univer-rounded-md univer-border univer-border-gray-200 univer-bg-white univer-shadow-lg dark:!univer-border-gray-700 dark:!univer-bg-gray-800"),
2060
2071
  style: {
2061
2072
  zIndex: 2147483647,
@@ -2388,6 +2399,7 @@ function Gallery(props) {
2388
2399
  const [isVisible, setIsVisible] = useState(false);
2389
2400
  const [activeImageIndex, setActiveImageIndex] = useState(0);
2390
2401
  const [zoomLevel, setZoomLevel] = useState(1);
2402
+ const { direction } = useContext(ConfigContext);
2391
2403
  const dialogRef = useRef(null);
2392
2404
  const activeImage = useMemo(() => images[activeImageIndex], [activeImageIndex, images]);
2393
2405
  useEffect(() => {
@@ -2435,6 +2447,7 @@ function Gallery(props) {
2435
2447
  }
2436
2448
  return createPortal(/* @__PURE__ */ jsxs("div", {
2437
2449
  "data-u-comp": "gallery",
2450
+ dir: direction,
2438
2451
  role: "dialog",
2439
2452
  "aria-modal": "true",
2440
2453
  "aria-label": "Image gallery",
@@ -2828,6 +2841,7 @@ function Segmented({ items, value, defaultValue, onChange, className = "" }) {
2828
2841
  //#region src/components/tooltip/Tooltip.tsx
2829
2842
  function Tooltip(props) {
2830
2843
  const { children, className, asChild = true, title, placement = "bottom", showIfEllipsis = false, visible: controlledVisible, onVisibleChange } = props;
2844
+ const { direction } = useContext(ConfigContext);
2831
2845
  const [uncontrolledVisible, setUncontrolledVisible] = useState(false);
2832
2846
  const isControlled = controlledVisible !== void 0;
2833
2847
  const visible = isControlled ? controlledVisible : uncontrolledVisible;
@@ -2970,6 +2984,7 @@ function Tooltip(props) {
2970
2984
  var _coords$top, _coords$left;
2971
2985
  tooltipNode = createPortal(/* @__PURE__ */ jsxs("div", {
2972
2986
  ref: tooltipRef,
2987
+ dir: direction,
2973
2988
  role: "tooltip",
2974
2989
  className: clsx("univer-animate-in univer-fade-in-0 univer-zoom-in-95 univer-pointer-events-auto univer-absolute univer-z-[1081] univer-box-border univer-w-fit univer-max-w-sm univer-text-balance univer-rounded-lg univer-bg-gray-700 univer-px-2.5 univer-py-2 univer-text-xs univer-font-medium univer-text-white univer-shadow-lg univer-drop-shadow-sm dark:!univer-bg-gray-100 dark:!univer-text-gray-900", className),
2975
2990
  style: {
@@ -3433,7 +3448,7 @@ function Popup(props) {
3433
3448
  const { children, visible = false, offset = [0, 0], overflowVisible = false, placementY = "below" } = props;
3434
3449
  const nodeRef = useRef(null);
3435
3450
  const [realOffset, setRealOffset] = useState(HIDDEN_POPUP_OFFSET);
3436
- const { mountContainer } = useContext(ConfigContext);
3451
+ const { mountContainer, direction } = useContext(ConfigContext);
3437
3452
  const calculateOffset = () => {
3438
3453
  const element = nodeRef.current;
3439
3454
  if (!element) return null;
@@ -3489,6 +3504,7 @@ function Popup(props) {
3489
3504
  },
3490
3505
  children: /* @__PURE__ */ jsx("section", {
3491
3506
  ref: nodeRef,
3507
+ dir: direction,
3492
3508
  className: "univer-popup",
3493
3509
  style: {
3494
3510
  left: realOffset[0] + POPUP_POINTER_OFFSET,
package/lib/index.js CHANGED
@@ -5,6 +5,7 @@ import { twMerge } from "tailwind-merge";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
6
  import { cva } from "class-variance-authority";
7
7
  import { Slot } from "@radix-ui/react-slot";
8
+ import { DirectionProvider } from "@radix-ui/react-direction";
8
9
  import { Close, Content, Description, Overlay, Portal, Root, Title } from "@radix-ui/react-dialog";
9
10
  import { Content as Content$1, Portal as Portal$1, Root as Root$1, Trigger } from "@radix-ui/react-popover";
10
11
  import { createPortal } from "react-dom";
@@ -260,16 +261,24 @@ function isBrowser() {
260
261
  //#region src/components/config-provider/ConfigProvider.tsx
261
262
  const ConfigContext = createContext({ mountContainer: isBrowser() ? document.body : null });
262
263
  function ConfigProvider(props) {
263
- const { children, locale, mountContainer } = props;
264
+ const { children, locale, mountContainer, direction } = props;
264
265
  const value = useMemo(() => {
265
266
  return {
266
267
  locale,
268
+ direction,
267
269
  mountContainer
268
270
  };
269
- }, [locale, mountContainer]);
271
+ }, [
272
+ locale,
273
+ direction,
274
+ mountContainer
275
+ ]);
270
276
  return /* @__PURE__ */ jsx(ConfigContext.Provider, {
271
277
  value,
272
- children
278
+ children: /* @__PURE__ */ jsx(DirectionProvider, {
279
+ dir: direction !== null && direction !== void 0 ? direction : "ltr",
280
+ children
281
+ })
273
282
  });
274
283
  }
275
284
 
@@ -1924,6 +1933,7 @@ function DraggableList(props) {
1924
1933
  const pressedHandleIdRef = useRef(null);
1925
1934
  const dragSourceIdRef = useRef(null);
1926
1935
  const dragStartIndexRef = useRef(-1);
1936
+ const { direction } = useContext(ConfigContext);
1927
1937
  useEffect(() => {
1928
1938
  if (!draggingId) {
1929
1939
  setDisplayList(list);
@@ -2056,6 +2066,7 @@ function DraggableList(props) {
2056
2066
  }, itemId);
2057
2067
  })
2058
2068
  }), canUsePortal && draggingItem && ghostPosition && createPortal(/* @__PURE__ */ jsx("div", {
2069
+ dir: direction,
2059
2070
  className: clsx("univer-pointer-events-none univer-fixed univer-rounded-md univer-border univer-border-gray-200 univer-bg-white univer-shadow-lg dark:!univer-border-gray-700 dark:!univer-bg-gray-800"),
2060
2071
  style: {
2061
2072
  zIndex: 2147483647,
@@ -2388,6 +2399,7 @@ function Gallery(props) {
2388
2399
  const [isVisible, setIsVisible] = useState(false);
2389
2400
  const [activeImageIndex, setActiveImageIndex] = useState(0);
2390
2401
  const [zoomLevel, setZoomLevel] = useState(1);
2402
+ const { direction } = useContext(ConfigContext);
2391
2403
  const dialogRef = useRef(null);
2392
2404
  const activeImage = useMemo(() => images[activeImageIndex], [activeImageIndex, images]);
2393
2405
  useEffect(() => {
@@ -2435,6 +2447,7 @@ function Gallery(props) {
2435
2447
  }
2436
2448
  return createPortal(/* @__PURE__ */ jsxs("div", {
2437
2449
  "data-u-comp": "gallery",
2450
+ dir: direction,
2438
2451
  role: "dialog",
2439
2452
  "aria-modal": "true",
2440
2453
  "aria-label": "Image gallery",
@@ -2828,6 +2841,7 @@ function Segmented({ items, value, defaultValue, onChange, className = "" }) {
2828
2841
  //#region src/components/tooltip/Tooltip.tsx
2829
2842
  function Tooltip(props) {
2830
2843
  const { children, className, asChild = true, title, placement = "bottom", showIfEllipsis = false, visible: controlledVisible, onVisibleChange } = props;
2844
+ const { direction } = useContext(ConfigContext);
2831
2845
  const [uncontrolledVisible, setUncontrolledVisible] = useState(false);
2832
2846
  const isControlled = controlledVisible !== void 0;
2833
2847
  const visible = isControlled ? controlledVisible : uncontrolledVisible;
@@ -2970,6 +2984,7 @@ function Tooltip(props) {
2970
2984
  var _coords$top, _coords$left;
2971
2985
  tooltipNode = createPortal(/* @__PURE__ */ jsxs("div", {
2972
2986
  ref: tooltipRef,
2987
+ dir: direction,
2973
2988
  role: "tooltip",
2974
2989
  className: clsx("univer-animate-in univer-fade-in-0 univer-zoom-in-95 univer-pointer-events-auto univer-absolute univer-z-[1081] univer-box-border univer-w-fit univer-max-w-sm univer-text-balance univer-rounded-lg univer-bg-gray-700 univer-px-2.5 univer-py-2 univer-text-xs univer-font-medium univer-text-white univer-shadow-lg univer-drop-shadow-sm dark:!univer-bg-gray-100 dark:!univer-text-gray-900", className),
2975
2990
  style: {
@@ -3433,7 +3448,7 @@ function Popup(props) {
3433
3448
  const { children, visible = false, offset = [0, 0], overflowVisible = false, placementY = "below" } = props;
3434
3449
  const nodeRef = useRef(null);
3435
3450
  const [realOffset, setRealOffset] = useState(HIDDEN_POPUP_OFFSET);
3436
- const { mountContainer } = useContext(ConfigContext);
3451
+ const { mountContainer, direction } = useContext(ConfigContext);
3437
3452
  const calculateOffset = () => {
3438
3453
  const element = nodeRef.current;
3439
3454
  if (!element) return null;
@@ -3489,6 +3504,7 @@ function Popup(props) {
3489
3504
  },
3490
3505
  children: /* @__PURE__ */ jsx("section", {
3491
3506
  ref: nodeRef,
3507
+ dir: direction,
3492
3508
  className: "univer-popup",
3493
3509
  style: {
3494
3510
  left: realOffset[0] + POPUP_POINTER_OFFSET,
@@ -17,6 +17,7 @@ import type { ReactNode } from 'react';
17
17
  export interface IConfigProviderProps {
18
18
  children: ReactNode;
19
19
  locale?: any;
20
+ direction?: 'ltr' | 'rtl';
20
21
  mountContainer: HTMLElement | null;
21
22
  }
22
23
  export declare const ConfigContext: import("react").Context<Omit<IConfigProviderProps, "children">>;